Include UGRID topology vars when subsetting with .cf#648
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows the UGRID
meshattribute when subsetting withds.cf[[var]]— the UGRID analogue of #640 (which did this for SGRIDgrid_topology).When a data variable references a
mesh_topologyvariable via itsmeshattribute,ds.cf[[var]]now pulls in:mesh_topologyvariable itself,face_node_connectivity,edge_node_connectivity,face_edge_connectivity,face_face_connectivity,edge_face_connectivity,boundary_node_connectivity), andnode_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
cf_xarray/ugrid.pywithget_mesh_variables(ds, mesh_var_name)returning(connectivity, coordinates), mirroringsgrid.get_topology_coords.get_associated_variable_namesgains ameshkey and follows themeshattribute.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.