Skip to content

Fixes decoding parametric coord #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cf_xarray/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,7 @@ def decode_vertical_coords(self, *, outnames=None, prefix=None):
f"Coordinate function for {stdname!r} not implmented yet. Contributions welcome!"
) from None

ds.coords[zname] = transform.from_terms(terms)
ds.coords[zname] = transform.from_terms(terms).decode()


@xr.register_dataarray_accessor("cf")
Expand Down
15 changes: 11 additions & 4 deletions cf_xarray/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,15 +1306,22 @@ def test_Z_vs_vertical_ROMS() -> None:


def test_decode_vertical_coords() -> None:
# 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.cf.decode_vertical_coords(outnames={"s_rho": "z_rho"})

assert romsds.z_rho.shape == (2, 30)
assert romsds.z_rho.attrs["standard_name"] == "height_above_geopotential_datum"

romsds.drop_vars("z_rho")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
romsds.drop_vars("z_rho")
romsds = romsds.drop_vars("z_rho")


with pytest.raises(
AssertionError, match="if prefix is None, outnames must be provided"
):
romsds.cf.decode_vertical_coords()

# 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"

with pytest.warns(DeprecationWarning):
romsds.cf.decode_vertical_coords(prefix="z_rho")

Expand Down
Loading