@@ -1043,20 +1043,14 @@ def nanCheckMap(data, filename, name):
1043
1043
warnings .warn (LisfloodWarning ("Warning: {} of {} land values of {} (binding: '{}') are NaN" .format (is_nan .sum (), is_nan .size , filename , name )))
1044
1044
1045
1045
1046
- def xarray_reader (path ):
1047
- ds = xr .open_mfdataset (path + '.nc' , engine = 'netcdf4' , chunks = {'time' : 'auto' }, combine = 'by_coords' )
1048
- variable_names = [k for k in ds .variables if len (ds .variables [k ].dims ) == 3 ]
1049
- if len (variable_names ) > 1 :
1050
- raise LisfloodWarning ('More than one variable in dataset {}' .format (path ))
1051
- elif len (variable_names ) == 0 :
1052
- raise LisfloodWarning ('Could not find a valid variable in dataset {}' .format (path ))
1053
- else :
1054
- var_name = variable_names [0 ]
1055
- da = ds [var_name ]
1056
- return da
1046
+ def compress_xarray (data ):
1047
+ maskinfo = MaskInfo .instance ()
1048
+ mask = maskinfo .info .mask .flatten ()
1049
+ data_masked = np .compress (np .logical_not (mask ), data .values )
1050
+ return data_masked
1057
1051
1058
1052
1059
- def extract_step_xr ( da , timestep ):
1053
+ def date_from_step ( timestep ):
1060
1054
1061
1055
settings = LisSettings .instance ()
1062
1056
binding = settings .binding
@@ -1069,5 +1063,23 @@ def extract_step_xr(da, timestep):
1069
1063
if type (currentDate ) is not datetime .datetime :
1070
1064
currentDate = begin + datetime .timedelta (days = (currentDate - 1 ) * dt_day )
1071
1065
1072
- data = da .sel (time = currentDate )
1073
- return compressArray (data , pcr = False , name = da .name )
1066
+ return currentDate
1067
+
1068
+
1069
+ def xarray_reader (path ):
1070
+ ds = xr .open_mfdataset (path + '.nc' , engine = 'netcdf4' , chunks = {'time' : 'auto' }, combine = 'by_coords' )
1071
+ variable_names = [k for k in ds .variables if len (ds .variables [k ].dims ) == 3 ]
1072
+ if len (variable_names ) > 1 :
1073
+ raise LisfloodWarning ('More than one variable in dataset {}' .format (path ))
1074
+ elif len (variable_names ) == 0 :
1075
+ raise LisfloodWarning ('Could not find a valid variable in dataset {}' .format (path ))
1076
+ else :
1077
+ var_name = variable_names [0 ]
1078
+ da = ds [var_name ]
1079
+ return da
1080
+
1081
+
1082
+ def extract_step_xr (da , timestep ):
1083
+ cur_date = date_from_step (timestep )
1084
+ data = da .sel (time = cur_date )
1085
+ return compress_xarray (data )
0 commit comments