Skip to content

Commit f0c1b5c

Browse files
Merge branch 'v4-dev' into convert_api_use_fields_for_coords
2 parents 3a5db5b + 1cd26f9 commit f0c1b5c

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

.github/workflows/additional.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v5
1515
- uses: astral-sh/setup-uv@v7
16+
with:
17+
version: "0.9.26"
1618
- run: |
17-
uv run --with 'minimum-dependency-versions @ git+https://github.com/xarray-contrib/minimum-dependency-versions@v1.0.0' \
18-
python -m minimum_versions validate \
19+
uvx --from xarray-minimum-dependency-policy==2.0.0 \
20+
minimum-versions validate \
1921
--policy=.github/ci/policy.yaml \
2022
--manifest-path=./pixi.toml \
2123
pixi:test-minimum
@@ -25,7 +27,6 @@ jobs:
2527
runs-on: "ubuntu-latest"
2628

2729
steps:
28-
- uses: actions/checkout@v5
2930
- uses: actions/checkout@v5
3031
- uses: prefix-dev/setup-pixi@v0.9.0
3132
- run: pixi run docs-linkcheck

src/parcels/convert.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)