Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions cf_xarray/criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"height_above_mean_sea_level",
),
"positive": ("up", "down"),
"_CoordinateZisPositive": ("up", "down"),
},
"X": {
"standard_name": (
Expand Down
47 changes: 47 additions & 0 deletions cf_xarray/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,53 @@ def test_missing_variable_in_coordinates() -> None:
assert_identical(airds.time, airds.air.cf.mean(["X", "Y"]).cf["time"])


@pytest.mark.parametrize("positive", ["up", "down"])
@pytest.mark.parametrize("as_dataarray", [False, True])
def test_cdm_vertical_direction(positive, as_dataarray):
ds = xr.Dataset(
{"data": ("level", [1, 2])},
coords={"level": ("level", [0, 1], {"_CoordinateZisPositive": positive})},
)
obj = ds["data"] if as_dataarray else ds
assert obj.cf.coordinates["vertical"] == ["level"]
xr.testing.assert_identical(obj.cf["vertical"], ds["level"])


@pytest.mark.parametrize("value", ["sideways", "UP", "", "Vertical"])
def test_cdm_invalid_vertical_direction(value):
ds = xr.Dataset(
coords={"level": ("level", [0, 1], {"_CoordinateZisPositive": value})}
)
assert "vertical" not in ds.cf.coordinates


@pytest.mark.parametrize(
("axis_type", "axis"),
[
("Lat", "latitude"),
("Lon", "longitude"),
("GeoX", "X"),
("GeoY", "Y"),
("GeoZ", "Z"),
("Height", "Z"),
("Pressure", "Z"),
("Time", "T"),
],
)
def test_existing_cdm_axis_types(axis_type, axis):
ds = xr.Dataset(
coords={"coord": ("coord", [0, 1], {"_CoordinateAxisType": axis_type})}
)
xr.testing.assert_identical(ds.cf[axis], ds["coord"])


def test_cdm_transform_is_not_vertical_coordinate():
ds = xr.Dataset(
{"transform": xr.DataArray(0, attrs={"_CoordinateTransformType": "Vertical"})}
)
assert "vertical" not in ds.cf.coordinates


def test_Z_vs_vertical_ROMS() -> None:
from ..datasets import romsds

Expand Down
6 changes: 6 additions & 0 deletions doc/coord_axes.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ This table lists these internal criteria

Any DataArray that has `standard_name: "latitude"` or `_CoordinateAxisType: "Lat"` or `"units": "degrees_north"` in its `attrs` will be identified as the `"latitude"` variable by cf-xarray. Similarly for other coordinate names.

The Unidata [CDM coordinate attributes](https://docs.unidata.ucar.edu/netcdf-java/current/userguide/coord_attr_conv.html)
`_CoordinateAxisType` and `_CoordinateZisPositive` are also recognized.
`_CoordinateZisPositive: "up"` or `"down"` identifies a `"vertical"` coordinate,
just like the CF `positive` attribute. This does not implement CDM coordinate
transforms or interpret `_CoordinateAxes` references.

## Axis Names

Similar criteria exist for the concept of "axes".
Expand Down
Loading