Skip to content

Commit b11e491

Browse files
authored
Fixes decoding parametric coord (#561)
* Fixes decoding parametric coord * Fixes drop_vars usage
1 parent 360483e commit b11e491

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cf_xarray/accessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2810,7 +2810,7 @@ def decode_vertical_coords(self, *, outnames=None, prefix=None):
28102810
f"Coordinate function for {stdname!r} not implmented yet. Contributions welcome!"
28112811
) from None
28122812

2813-
ds.coords[zname] = transform.from_terms(terms)
2813+
ds.coords[zname] = transform.from_terms(terms).decode()
28142814

28152815

28162816
@xr.register_dataarray_accessor("cf")

cf_xarray/tests/test_accessor.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -1306,15 +1306,25 @@ def test_Z_vs_vertical_ROMS() -> None:
13061306

13071307

13081308
def test_decode_vertical_coords() -> None:
1309+
# Fixes 'UnboundLocalError: cannot access local variable 'romsds' where it is not associated with a value'
1310+
from ..datasets import romsds
1311+
1312+
# needs standard names on `eta` and `depth` to derive computed standard name
1313+
romsds.h.attrs["standard_name"] = "sea_floor_depth_below_geopotential_datum"
1314+
romsds.zeta.attrs["standard_name"] = "sea_surface_height_above_geopotential_datum"
1315+
1316+
romsds.cf.decode_vertical_coords(outnames={"s_rho": "z_rho"})
1317+
1318+
assert romsds.z_rho.shape == (2, 30)
1319+
assert romsds.z_rho.attrs["standard_name"] == "height_above_geopotential_datum"
1320+
1321+
romsds = romsds.drop_vars("z_rho")
1322+
13091323
with pytest.raises(
13101324
AssertionError, match="if prefix is None, outnames must be provided"
13111325
):
13121326
romsds.cf.decode_vertical_coords()
13131327

1314-
# needs standard names on `eta` and `depth` to derive computed standard name
1315-
romsds.h.attrs["standard_name"] = "sea_floor_depth_below_ geopotential_datum"
1316-
romsds.zeta.attrs["standard_name"] = "sea_surface_height_above_ geopotential_datum"
1317-
13181328
with pytest.warns(DeprecationWarning):
13191329
romsds.cf.decode_vertical_coords(prefix="z_rho")
13201330

0 commit comments

Comments
 (0)