Skip to content

Include UGRID topology vars when subsetting with .cf#648

Merged
dcherian merged 2 commits into
mainfrom
ugrid-include-topology-vars
Jun 12, 2026
Merged

Include UGRID topology vars when subsetting with .cf#648
dcherian merged 2 commits into
mainfrom
ugrid-include-topology-vars

Conversation

@dcherian

Copy link
Copy Markdown
Contributor

Follows the UGRID mesh attribute when subsetting with ds.cf[[var]] — the UGRID analogue of #640 (which did this for SGRID grid_topology).

When a data variable references a mesh_topology variable via its mesh attribute, ds.cf[[var]] now pulls in:

  • the mesh_topology variable itself,
  • its connectivity variables (face_node_connectivity, edge_node_connectivity, face_edge_connectivity, face_face_connectivity, edge_face_connectivity, boundary_node_connectivity), and
  • its coordinate variables (node_coordinates, edge_coordinates, face_coordinates).

Only names actually present in the dataset are propagated. The DataArray form (ds.cf[var]) attaches only dim-compatible coordinates, as with the SGRID/grid_mapping paths.

Implementation

  • New cf_xarray/ugrid.py with get_mesh_variables(ds, mesh_var_name) returning (connectivity, coordinates), mirroring sgrid.get_topology_coords.
  • get_associated_variable_names gains a mesh key and follows the mesh attribute.
  • Test + docs.

Motivation

Downstream grid-detection code (e.g. xpublish-tiles) currently works around this by detecting on the full dataset whenever a variable points at a UGRID mesh, because ds.cf[[var]] drops the mesh topology, connectivity, and node coordinates. This makes the cf subset self-contained for UGRID, matching SGRID behavior.

dcherian and others added 2 commits June 12, 2026 12:15
Follow the UGRID `mesh` attribute when subsetting with `ds.cf[[var]]`, the
UGRID analogue of #640. The referenced `mesh_topology` variable, its
connectivity variables (`face_node_connectivity`, `edge_node_connectivity`,
...), and its coordinate variables (`node_coordinates`, `edge_coordinates`,
`face_coordinates`) are now pulled in alongside the data variable. Only names
present in the dataset are propagated.
@dcherian dcherian enabled auto-merge (squash) June 12, 2026 18:18
@dcherian dcherian merged commit 09b5701 into main Jun 12, 2026
11 checks passed
@dcherian dcherian deleted the ugrid-include-topology-vars branch June 12, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant