@@ -827,8 +827,9 @@ def _check_and_roll_longitude(self, ds, indexers) -> xr.Dataset:
827827 def to_regular (self ):
828828 # Infering latitude and longitude steps from the x and y coordinates.
829829 if isinstance (self .domain .crs , RotatedGeogCS ):
830- lat_step = np .ptp (self .y .values ) / (self .y .values .size - 1 )
831- lon_step = np .ptp (self .x .values ) / (self .x .values .size - 1 )
830+ lat_step = round (np .ptp (self .y .values ) / (self .y .values .size - 1 ), 2 )
831+ lat_step = round (np .ptp (self .y .values ) / (self .y .values .size - 1 ), 2 )
832+ lon_step = round (np .ptp (self .x .values ) / (self .x .values .size - 1 ), 2 )
832833 else :
833834 raise NotImplementedError (
834835 f"'{ type (self .domain .crs ).__name__ } ' is not supported as a "
@@ -982,10 +983,16 @@ def regrid(
982983 coords_out = {"lat_b" : lat_b , "lon_b" : lon_b }
983984
984985 # Regridding
985- in_ = self .to_xarray (encoding = False ).rename (names_in )
986+ try :
987+ in_ = self .to_xarray (encoding = False ).rename (names_in )
988+ except :
989+ in_ = self .to_xarray (encoding = False )
986990 if coords_in :
987991 in_ = in_ .assign_coords (coords = coords_in )
988- out = target .to_xarray (encoding = False ).to_dataset ().rename (names_out )
992+ try :
993+ out = target .to_xarray (encoding = False ).to_dataset ().rename (names_out )
994+ except :
995+ out = target .to_xarray (encoding = False ).to_dataset ()
989996 if coords_out :
990997 out = out .assign_coords (coords = coords_out )
991998 regrid_kwa = {
@@ -1000,7 +1007,10 @@ def regrid(
10001007 except PermissionError :
10011008 regridder = xe .Regridder (** regrid_kwa )
10021009 result = regridder (in_ , keep_attrs = True , skipna = False )
1003- result = result .rename ({v : k for k , v in names_in .items ()})
1010+ try :
1011+ result = result .rename ({v : k for k , v in names_in .items ()})
1012+ except :
1013+ pass
10041014 result [self .name ].encoding = in_ [self .name ].encoding
10051015 if not isinstance (target .crs , GeogCS ):
10061016 missing_coords = {
@@ -1062,37 +1072,22 @@ def resample(
10621072 """
10631073 ds = self .to_xarray (encoding = False )
10641074 encodings = ds .encoding
1065- if frequency == '1D' :
1066- match operator :
1067- case "max" :
1068- ds = ds .coarsen (time = 24 ).max ()
1069- case "min" :
1070- ds = ds .coarsen (time = 24 ).min ()
1071- case "sum" :
1072- ds = ds .coarsen (time = 24 ).sum ()
1073- case "mean" :
1074- ds = ds .coarsen (time = 24 ).mean ()
1075- case "median" :
1076- ds = ds .coarsen (time = 24 ).median ()
1077- case _:
1078- raise NotImplementedError (f"Operator { operator } not implemented." )
1079- else :
1080- ds = ds .resample (time = frequency )
1081- match operator :
1082- case "max" :
1083- ds = ds .max (dim = "time" )
1084- case "min" :
1085- ds = ds .min (dim = "time" )
1086- case "sum" :
1087- ds = ds .sum (dim = "time" )
1088- case "mean" :
1089- ds = ds .mean (dim = "time" )
1090- case "median" :
1091- ds = ds .median (dim = "time" )
1092- case _:
1093- raise NotImplementedError (f"Operator { operator } not implemented." )
1075+ ds = ds .resample (time = frequency )
1076+ match operator :
1077+ case "max" :
1078+ ds = ds .max (dim = "time" )
1079+ case "min" :
1080+ ds = ds .min (dim = "time" )
1081+ case "sum" :
1082+ ds = ds .sum (dim = "time" )
1083+ case "mean" :
1084+ ds = ds .mean (dim = "time" )
1085+ case "median" :
1086+ ds = ds .median (dim = "time" )
1087+ case _:
1088+ raise NotImplementedError (f"Operator { operator } not implemented." )
10941089 ds .encoding = encodings
1095- field = Field .from_xarray (ds , ncvar = self .name )
1090+ field = Field .from_xarray (ds , ncvar = self .name , id_pattern = self . _id_pattern , mapping = self . _mapping , copy = False )
10961091 field .domain .crs = self .domain .crs
10971092 field .domain ._type = self .domain ._type
10981093 field .domain ._calculate_missing_lat_and_lon ()
0 commit comments