Skip to content

Commit 1cd26f9

Browse files
Merge pull request #2492 from erikvansebille/convert_nemo_with_deptht
Support for GLO12 C-grid data
2 parents 8f3431f + bf8116d commit 1cd26f9

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/parcels/convert.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@
7777
}
7878

7979

80-
def _maybe_bring_UV_depths_to_depth(ds):
81-
if "U" in ds.variables and "depthu" in ds.U.coords and "depth" in ds.coords:
82-
ds["U"] = ds["U"].assign_coords(depthu=ds["depth"].values).rename({"depthu": "depth"})
83-
if "V" in ds.variables and "depthv" in ds.V.coords and "depth" in ds.coords:
84-
ds["V"] = ds["V"].assign_coords(depthv=ds["depth"].values).rename({"depthv": "depth"})
80+
def _maybe_bring_other_depths_to_depth(ds):
81+
if "depth" in ds.coords:
82+
for var in ds.data_vars:
83+
for old_depth in ["depthu", "depthv", "deptht", "depthw"]:
84+
if old_depth in ds[var].dims:
85+
ds[var] = ds[var].assign_coords(**{old_depth: ds["depth"].values}).rename({old_depth: "depth"})
8586
return ds
8687

8788

@@ -279,7 +280,7 @@ def nemo_to_sgrid(*, fields: dict[str, xr.Dataset | xr.DataArray], coords: xr.Da
279280
ds = xr.merge(list(fields.values()) + [coords])
280281
ds = _maybe_rename_variables(ds, _NEMO_VARNAMES_MAPPING)
281282
ds = _maybe_create_depth_dim(ds)
282-
ds = _maybe_bring_UV_depths_to_depth(ds)
283+
ds = _maybe_bring_other_depths_to_depth(ds)
283284
ds = _drop_unused_dimensions_and_coords(ds, _NEMO_DIMENSION_COORD_NAMES)
284285
ds = _assign_dims_as_coords(ds, _NEMO_DIMENSION_COORD_NAMES)
285286
ds = _set_coords(ds, _NEMO_DIMENSION_COORD_NAMES)

0 commit comments

Comments
 (0)