File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ def rectify_dataset(
131131 coordinate variables are ignored in the output.
132132 """
133133 source_ds = _select_variables (source_ds , variables )
134- source_ds = _ensure_increasing_x (source_ds )
134+ source_ds = _ensure_increasing_x (source_ds , gm = source_gm )
135135
136136 source_gm = source_gm or GridMapping .from_dataset (source_ds )
137137 source_ds = normalize_grid_mapping (source_ds , source_gm )
@@ -730,9 +730,15 @@ def _rectify_block(
730730 return data_rectified
731731
732732
733- def _ensure_increasing_x (ds : xr .Dataset ) -> xr .Dataset :
734- gm_proxy = next (iter (get_dataset_grid_mapping_proxies (ds ).values ()))
735- x_coords = gm_proxy .coords .x
733+ def _ensure_increasing_x (ds : xr .Dataset , gm : GridMapping | None = None ) -> xr .Dataset :
734+ if gm is None :
735+ gm_proxies = get_dataset_grid_mapping_proxies (ds )
736+ if not gm_proxies :
737+ raise ValueError ("cannot find any grid mapping in dataset" )
738+ gm_proxy = next (iter (gm_proxies .values ()))
739+ x_coords = gm_proxy .coords .x
740+ else :
741+ x_coords = gm .x_coords
736742 x_diff = x_coords [0 , 1 ] - x_coords [0 , 0 ]
737743 if - 180 < x_diff < 0 :
738744 x_dim = x_coords .dims [1 ]
You can’t perform that action at this time.
0 commit comments