Skip to content

Commit df9a313

Browse files
Add support for copernicusmarine without depth (#2746)
* Add support for copernicusmarine without depth And convert NaNs to zeroes (for interpolators) * Removing filling NaNs in convert As will be done in model, per #2762
1 parent f38e0d1 commit df9a313

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/parcels/convert.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ def _maybe_swap_depth_direction(ds: xr.Dataset) -> xr.Dataset:
241241
return ds
242242

243243

244+
def _maybe_expand_depth_dimension(ds: xr.Dataset) -> xr.Dataset:
245+
if "depth" not in ds.dims:
246+
ds = ds.expand_dims(dim={"depth": [0]}, axis=1)
247+
logger.info("No depth dimension found in dataset. Added a singleton depth dimension.")
248+
return ds
249+
250+
244251
# TODO is this function still needed, now that we require users to provide field names explicitly?
245252
def _discover_U_and_V(ds: xr.Dataset, cf_standard_names_fallbacks) -> xr.Dataset:
246253
# Assumes that the dataset has U and V data
@@ -541,6 +548,7 @@ def copernicusmarine_to_sgrid(
541548
ds.attrs.clear() # Clear global attributes from the merging
542549

543550
ds = _maybe_rename_coords(ds, _COPERNICUS_MARINE_AXIS_VARNAMES)
551+
ds = _maybe_expand_depth_dimension(ds)
544552

545553
if "W" in ds.data_vars:
546554
# Negate W to convert from up positive to down positive (as that's the direction of positive z)

tests/test_convert.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ def test_convert_copernicusmarine_no_logs(ds, caplog):
174174
assert caplog.text == ""
175175

176176

177+
def test_convert_copernicusmarine_nodepth(caplog):
178+
ds = datasets_circulation_models["ds_copernicusmarine"]
179+
ds = ds.isel(depth=0).drop_vars("depth")
180+
ds_fset = convert.copernicusmarine_to_sgrid(fields={"uo": ds["uo"]})
181+
FieldSet.from_sgrid_conventions(ds_fset)
182+
assert "No depth dimension found in dataset. Added a singleton depth dimension." in caplog.text
183+
184+
177185
def test_convert_fesom_to_ugrid():
178186
grid_file = open_remote_dataset("Benchmarks_FESOM2-baroclinic-gyre/grid")
179187
data_files = open_remote_dataset("Benchmarks_FESOM2-baroclinic-gyre/data")

0 commit comments

Comments
 (0)