diff --git a/cf_xarray/datasets.py b/cf_xarray/datasets.py index facefa1e..f2483860 100644 --- a/cf_xarray/datasets.py +++ b/cf_xarray/datasets.py @@ -129,6 +129,7 @@ # fmt: on romsds.coords["hc"] = 20.0 romsds.coords["h"] = 603.9 +romsds.h.attrs["standard_name"] = "sea_floor_depth_below_geopotential_datum" romsds.coords["Vtransform"] = 2.0 # fmt: off romsds.coords["Cs_r"] = ( @@ -143,7 +144,11 @@ -5.20560097e-04, -5.75774004e-05], ) # fmt: on -romsds["zeta"] = ("ocean_time", [-0.155356, -0.127435]) +romsds["zeta"] = ( + "ocean_time", + [-0.155356, -0.127435], + {"standard_name": "sea_surface_height_above_geopotential_datum"}, +) romsds["temp"] = ( ("ocean_time", "s_rho"), [np.linspace(20, 30, 30)] * 2, diff --git a/cf_xarray/tests/test_accessor.py b/cf_xarray/tests/test_accessor.py index 225bab8c..6657be46 100644 --- a/cf_xarray/tests/test_accessor.py +++ b/cf_xarray/tests/test_accessor.py @@ -1785,10 +1785,8 @@ def test_decode_vertical_coords() -> None: # Fixes 'UnboundLocalError: cannot access local variable 'romsds' where it is not associated with a value' from ..datasets import romsds - # needs standard names on `eta` and `depth` to derive computed standard name - romsds.h.attrs["standard_name"] = "sea_floor_depth_below_geopotential_datum" - romsds.zeta.attrs["standard_name"] = "sea_surface_height_above_geopotential_datum" - + # romsds already carries standard names on `eta` and `depth`, so the + # computed standard name can be derived without any extra setup. romsds.cf.decode_vertical_coords(outnames={"s_rho": "z_rho"}) assert romsds.z_rho.shape == (2, 30)