Repository navigation
Check SGRID node dimensions and coordinates against the dataset - #3035
Merged
Merged
Conversation
Add ds.sgrid.assert_metadata_ds_consistency() which, in addition to the existing face/node size check, asserts that: - node_dimensions coordinate variables have axis attributes X then Y - node_coordinates exist, are defined on the node dimensions (1D coords along their own axis), and have longitude/latitude units in X then Y order when in degrees SGridDatasetInconsistency now subclasses ValueError. Also fix croco_to_sgrid node_dimensions (xi_rho, eta_rho), and update the example datasets to use per-axis degree units and to define node dimension coordinates in the sgrid_dataset strategy.
VeckoTheGecko
commented
Nov 4, 2026
VeckoTheGecko
left a comment
Contributor
Author
There was a problem hiding this comment.
Some changes to the test suite/data generation was needed to attach this new metadata. There is also a change to convert.croco_to_sgrid.
There's no change to the docs - everything works like before.
| max_lat = 90.0 if mesh_str == "spherical" else 1e6 | ||
| unit = "degrees" if mesh_str == "spherical" else "m" | ||
| x_unit = "degrees_east" if mesh_str == "spherical" else "m" | ||
| y_unit = "degrees_north" if mesh_str == "spherical" else "m" |
Contributor
Author
There was a problem hiding this comment.
This change isn't strictly necessary, but I think it being more explicit is nice
Comment on lines
+177
to
+184
| # A 1D node coordinate (i.e., a rectilinear grid) must lie along its own axis. If one of the node | ||
| # dimensions has been indexed away (e.g., via isel) a 2D coordinate can legitimately be 1D along the other | ||
| if both_node_dims_in_ds and da.ndim == 1 and da.dims != (node_dim,): | ||
| raise SGridDatasetInconsistency( | ||
| f"Node coordinate {coord!r} is 1D with dims {da.dims}, but as entry {expected_axis!r} in " | ||
| f"node_coordinates={metadata.node_coordinates!r} it is expected to be defined on node dimension {node_dim!r}. " | ||
| f'HINT: Make sure node_coordinates in the SGRID metadata is ordered as "X" then "Y".' | ||
| ) |
| ) | ||
|
|
||
|
|
||
| def _assert_node_coordinates_well_defined(ds: xr.Dataset, metadata: SGrid2DMetadata): |
Contributor
Author
There was a problem hiding this comment.
I think this function is the main thing worth reviewing @erikvansebille
erikvansebille
approved these changes
Nov 4, 2026
erikvansebille
left a comment
Member
There was a problem hiding this comment.
Looks very good - thanks for adding this code to check the SGrid consistency!
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.
Description
There was some existing tooling for checking that SGRID metadata was consistent with the underlying dataset (this logic was in a function
assert_metadata_ds_consistency). This consistency check was limited to the padding time and number of observations along dimensions (i.e., a padding of None means that there is one less edge than nodes, etc.).This PR extends the consistency checks to also ensure:
This PR also makes the function
assert_metadata_ds_consistencya method on the accessor, making it more accesible to the rest of the code.minor changes
SGridDatasetInconsistency now subclasses ValueError.
Also fix croco_to_sgrid node_dimensions (xi_rho, eta_rho), and update the example datasets to use per-axis degree units and to define node dimension coordinates in the sgrid_dataset strategy.
Checklist
mainfor normal development,v3-supportfor v3 support)AI Disclosure