Repository navigation
Conversation
erogluorhan
left a comment
There was a problem hiding this comment.
Choosing lon/lat by standard_name is a good fix, and a file with node_coordinates = "y x" now reads correctly. But this PR rejects projected UGRID files, which #1525 made loadable and docs/user-guide/grid-formats.rst ("Projected (Non-Spherical) Coordinates") documents as working for loading and plotting. #901 asked for that support, not for an error, so I don't think this should close #901.
- Full suite on the PR: 1295 passed. None of the existing projected tests reach
_read_ugrid(test_projected.pybuildsux.Grid(ds)directly), so nothing noticed the change in behavior. - Opened small UGRID files with
ux.open_grid(path)onmainand on the PR (results in the inline comments). - Mutation: reducing the degree-units list to
{""}still passes the whole suite, so the unit check is untested.
Before merge: keep projected node coordinates loading (or get a maintainer decision to drop #1525's behavior and update the docs), and fix the unit list.
| ) | ||
| else: | ||
| # Projected centers may be retained, but are not spherical coordinates. | ||
| continue |
There was a problem hiding this comment.
(non-blocking) Behavior change worth putting in the description: face_coordinates/edge_coordinates are now always used. On main they were renamed only if face_lon/face_lat already existed, which in practice left them unused. For a file with face_coordinates="cx cy" (cx=0.3), face_lon changes from the computed centroid (0.333) to 0.3. I think this is right, but it should be stated.
There was a problem hiding this comment.
Code is fine; just the description note left.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved coordinate-handling defects can misinterpret radians or projected values as degrees, trigger geometry recursion, and reject previously supported geographic inputs.
5 open issues
Prevent projected coordinates from reaching Cartesian consumers · New Reject projected mappings before positional fallback · New Convert selected radian coordinates to degrees · New Allow compatible partial geographic metadata in fallback · New Accept deg units in the geographic-coordinate fallback · New
What changed in this PR
Updates UXarray’s UGRID reader to select geographic coordinates using CF metadata rather than assuming coordinate order, addressing the projected-coordinate concern in #901.
Changes:
- Selects node, edge and face longitude/latitude by
standard_name, with a legacy positional fallback. - Rejects node pairs identified as projected by standard names or units, while retaining unselected coordinate variables.
- Adds tests for reordered coordinates, chunked loading, projected inputs, mixed coordinate sets and legacy files.
| File | Description |
|---|---|
uxarray/io/_ugrid.py |
Adds metadata-based coordinate selection and projected-node validation. |
test/io/test_ugrid_coordinates.py |
Tests geographic selection, projected-coordinate handling and legacy compatibility. |
Review effort: Balanced
| geographic = {ds[name].attrs.get("standard_name"): name for name in names} | ||
| if "longitude" in geographic and "latitude" in geographic: | ||
| lon_name, lat_name = geographic["longitude"], geographic["latitude"] |
| "degree_n", | ||
| "radian", | ||
| "radians", | ||
| } |
| coord_dict[lon_name] = f"{location}_lon" | ||
| coord_dict[lat_name] = f"{location}_lat" |
| if "longitude" in geographic and "latitude" in geographic: | ||
| lon_name, lat_name = geographic["longitude"], geographic["latitude"] | ||
| elif len(names) == 2 and all( | ||
| not ds[name].attrs.get("standard_name") |
| and ds[name].attrs.get("units", "").lower() | ||
| in { | ||
| "", | ||
| "degree", |
|
@erogluorhan thanks for the review, all three points are addressed in e6bc9d0. I kept |
erogluorhan
left a comment
There was a problem hiding this comment.
Thanks @rajeeja, all of my points seem fixed, Closes #901 is fine with me after your clarification.
I am approving it now. Please see a few tiny points below though:
Please update the description: it still says projected coordinates are rejected.
Separately, and not from this PR: Claude found that face_areas on a projected grid returns a meaningless value with no error (a UTM triangle of 5000 m² gives 0.855, same on main). Could you open an issue to make geometry on projected grids raise?
…ates-901 # Conflicts: # uxarray/io/_ugrid.py


Closes #901.
Select longitude and latitude by CF
standard_name. Projected-only coordinates still load with the existing warning, and geographicface_coordinatesandedge_coordinatesfrom the file are now used as given.