@@ -886,19 +886,27 @@ def __init__(self, *data: Iterable[T]):
886
886
def __len__ (self ) -> int :
887
887
return len (self ._data )
888
888
889
- def __getitem__ (self , key : Union [str , int ]) -> T :
889
+ def __getitem__ (self , key : Union [int , str ]) -> T :
890
890
if isinstance (key , str ):
891
891
return self .find (key )
892
892
return self ._data [key ]
893
893
894
- def __contains__ (self , key : Union [str , int ]) -> bool :
894
+ def __contains__ (self , key : Union [T , str ]) -> bool :
895
895
if isinstance (key , str ):
896
896
try :
897
897
self .find (key )
898
898
return True
899
899
except KeyError :
900
900
return False
901
- return super ().__contains__ (key )
901
+ return key in self ._data
902
+
903
+ def index (self , key : Union [T , str ], * args ) -> int :
904
+ if isinstance (key , str ):
905
+ try :
906
+ key = self .find (key )
907
+ except KeyError :
908
+ raise ValueError from None
909
+ return self ._data .index (key , * args )
902
910
903
911
def __repr__ (self ) -> str :
904
912
return repr (self ._data )
@@ -1079,10 +1087,15 @@ def link_mask(self, *masks: np.ndarray):
1079
1087
self ._mask = masks
1080
1088
self .fabm .set_mask (self .pmodel , * self ._mask )
1081
1089
1082
- def _get_mask (self ) -> Union [np .ndarray , Sequence [np .ndarray ]]:
1083
- return self ._mask [0 ] if len (self ._mask ) == 1 else self ._mask
1084
-
1085
- def _set_mask (self , values : Union [npt .ArrayLike , Sequence [npt .ArrayLike ]]):
1090
+ @property
1091
+ def mask (self ) -> Union [np .ndarray , Sequence [np .ndarray ], None ]:
1092
+ mask = self ._mask
1093
+ if mask is not None and len (mask ) == 1 :
1094
+ mask = mask [0 ]
1095
+ return mask
1096
+
1097
+ @mask .setter
1098
+ def mask (self , values : Union [npt .ArrayLike , Sequence [npt .ArrayLike ]]):
1086
1099
if self .fabm .mask_type == 1 :
1087
1100
values = (values ,)
1088
1101
if len (values ) != self .fabm .mask_type :
@@ -1096,8 +1109,6 @@ def _set_mask(self, values: Union[npt.ArrayLike, Sequence[npt.ArrayLike]]):
1096
1109
if value is not mask :
1097
1110
mask [...] = value
1098
1111
1099
- mask = property (_get_mask , _set_mask )
1100
-
1101
1112
def link_bottom_index (self , indices : np .ndarray ):
1102
1113
if not self .fabm .variable_bottom_index :
1103
1114
raise FABMException (
@@ -1401,7 +1412,7 @@ def _update_configuration(self, settings: Optional[Tuple] = None):
1401
1412
+ self .horizontal_dependencies
1402
1413
+ self .scalar_dependencies
1403
1414
)
1404
- self .variables = (
1415
+ self .variables : NamedObjectList [ VariableFromPointer ] = (
1405
1416
self .state_variables + self .diagnostic_variables + self .dependencies
1406
1417
)
1407
1418
@@ -1414,7 +1425,7 @@ def _update_configuration(self, settings: Optional[Tuple] = None):
1414
1425
1415
1426
self .itime = - 1.0
1416
1427
1417
- def getRates (self , t : float = None , surface : bool = True , bottom : bool = True ):
1428
+ def getRates (self , t : Optional [ float ] = None , surface : bool = True , bottom : bool = True ):
1418
1429
"""Returns the local rate of change in state variables,
1419
1430
given the current state and environment.
1420
1431
"""
@@ -1451,7 +1462,7 @@ def getRates(self, t: float = None, surface: bool = True, bottom: bool = True):
1451
1462
1452
1463
def get_sources (
1453
1464
self ,
1454
- t : float = None ,
1465
+ t : Optional [ float ] = None ,
1455
1466
out : Optional [Tuple [np .ndarray , np .ndarray , np .ndarray ]] = None ,
1456
1467
) -> Tuple [np .ndarray , np .ndarray , np .ndarray ]:
1457
1468
if t is None :
0 commit comments