Skip to content

Commit 6b57a4f

Browse files
committed
Update error message
1 parent caab3f2 commit 6b57a4f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/parcels/_core/fieldset.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ def from_copernicusmarine(ds: xr.Dataset):
204204
expected_axes = set("XYZT") # TODO: Update after we have support for 2D spatial fields
205205
if missing_axes := (expected_axes - set(ds.cf.axes)):
206206
raise ValueError(
207-
f"Dataset missing metadata for axes {missing_axes} to have coordinates for all {expected_axes} axes according to CF conventions. HINT: Add metadata attribute axis - e.g., ds['lat'].attrs['axis'] = 'Y'"
207+
f"Dataset missing CF compliant metadata for axes "
208+
f"{missing_axes}. Expected 'axis' attribute to be set "
209+
f"on all dimension axes {expected_axes}. "
210+
"HINT: Add xarray metadata attribute 'axis' to dimension - e.g., ds['lat'].attrs['axis'] = 'Y'"
208211
)
209212

210213
ds = _rename_coords_copernicusmarine(ds)

tests/test_fieldset.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ def test_fieldset_from_copernicusmarine(ds, caplog):
232232
assert "renamed it to 'V'" in caplog.text
233233

234234

235+
@pytest.mark.parametrize("ds", [datasets_circulation_models["ds_copernicusmarine"].copy()])
236+
def test_fieldset_from_copernicusmarine_missing_axis(ds, caplog):
237+
del ds["latitude"].attrs["axis"]
238+
239+
with pytest.raises(
240+
ValueError,
241+
match="Dataset missing CF compliant metadata for axes "
242+
".*. Expected 'axis' attribute to be set "
243+
"on all dimension axes .*. "
244+
"HINT: Add xarray metadata attribute 'axis' to dimension .*",
245+
):
246+
FieldSet.from_copernicusmarine(ds)
247+
248+
235249
def test_fieldset_from_copernicusmarine_no_currents(caplog):
236250
ds = datasets_circulation_models["ds_copernicusmarine"].cf.drop_vars(
237251
["eastward_sea_water_velocity", "northward_sea_water_velocity"]

0 commit comments

Comments
 (0)