Skip to content

Commit ade1362

Browse files
authored
Support grid_topology, mesh_topology CF roles. (#420)
1 parent 0f79d98 commit ade1362

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

cf_xarray/criteria.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@
99
from typing import Mapping, MutableMapping, Tuple
1010

1111
cf_role_criteria: Mapping[str, Mapping[str, str]] = {
12-
k: {"cf_role": k} for k in ("timeseries_id", "profile_id", "trajectory_id")
12+
k: {"cf_role": k}
13+
for k in (
14+
# CF Discrete sampling geometry
15+
"timeseries_id",
16+
"profile_id",
17+
"trajectory_id",
18+
# SGRID
19+
"grid_topology",
20+
# UGRID
21+
"mesh_topology",
22+
)
1323
}
1424

1525
coordinate_criteria: MutableMapping[str, MutableMapping[str, Tuple]] = {

cf_xarray/tests/test_accessor.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,18 @@ def test_cf_role() -> None:
17661766
dsg.foo.cf.plot(x="trajectory_id")
17671767

17681768

1769+
def test_grid_topology() -> None:
1770+
ds = xr.Dataset(
1771+
data_vars={},
1772+
coords={
1773+
"mesh": (tuple(), 1, {"cf_role": "mesh_topology"}),
1774+
"grid": (tuple(), 1, {"cf_role": "grid_topology"}),
1775+
},
1776+
)
1777+
assert_identical(ds.cf["grid_topology"], ds.grid.reset_coords(drop=True))
1778+
assert_identical(ds.cf["mesh_topology"], ds.mesh.reset_coords(drop=True))
1779+
1780+
17691781
@requires_scipy
17701782
def test_curvefit() -> None:
17711783
from cf_xarray.datasets import airds

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ or using ``conda``
5353
bounds
5454
coding
5555
dsg
56+
sgrid_ugrid
5657
geometry
5758
plotting
5859
custom-criteria

doc/sgrid_ugrid.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SGRID / UGRID
2+
3+
`cf_xarray` support identifying either the `mesh_topology` (UGRID) or `grid_topology` (SGRID) variables using the `cf_role` attribute.
4+
5+
Further support for interpreting the SGRID and UGRID conventions can be added. Contributions are welcome!

0 commit comments

Comments
 (0)