@@ -93,11 +93,12 @@ def _pick_expected_coords(coords: xr.Dataset, expected_coord_names: list[str]) -
9393 return xr .Dataset (coords_to_use )
9494
9595
96- def _maybe_bring_UV_depths_to_depth (ds ):
97- if "U" in ds .variables and "depthu" in ds .U .coords and "depth" in ds .coords :
98- ds ["U" ] = ds ["U" ].assign_coords (depthu = ds ["depth" ].values ).rename ({"depthu" : "depth" })
99- if "V" in ds .variables and "depthv" in ds .V .coords and "depth" in ds .coords :
100- ds ["V" ] = ds ["V" ].assign_coords (depthv = ds ["depth" ].values ).rename ({"depthv" : "depth" })
96+ def _maybe_bring_other_depths_to_depth (ds ):
97+ if "depth" in ds .coords :
98+ for var in ds .data_vars :
99+ for old_depth in ["depthu" , "depthv" , "deptht" , "depthw" ]:
100+ if old_depth in ds [var ].dims :
101+ ds [var ] = ds [var ].assign_coords (** {old_depth : ds ["depth" ].values }).rename ({old_depth : "depth" })
101102 return ds
102103
103104
@@ -295,7 +296,7 @@ def nemo_to_sgrid(*, fields: dict[str, xr.Dataset | xr.DataArray], coords: xr.Da
295296 ds = xr .merge (list (fields .values ()) + [coords ])
296297 ds = _maybe_rename_variables (ds , _NEMO_VARNAMES_MAPPING )
297298 ds = _maybe_create_depth_dim (ds )
298- ds = _maybe_bring_UV_depths_to_depth (ds )
299+ ds = _maybe_bring_other_depths_to_depth (ds )
299300 ds = _drop_unused_dimensions_and_coords (ds , _NEMO_DIMENSION_COORD_NAMES )
300301 ds = _assign_dims_as_coords (ds , _NEMO_DIMENSION_COORD_NAMES )
301302 ds = _set_coords (ds , _NEMO_DIMENSION_COORD_NAMES )
0 commit comments