From 63f1809a96622385f64bf81a9b7964b7be479532 Mon Sep 17 00:00:00 2001 From: Alexandre Georges Date: Mon, 6 Jul 2026 10:27:34 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20rename=20SCHISM=20geographic=20coords=20?= =?UTF-8?q?in=20=5Frename=5Fcoords=20for=20uxarray=20=E2=89=A5=202025.08?= =?UTF-8?q?=20compatibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit uxarray's _read_ugrid gained an outer existence guard between v2025.06.0 and v2025.08.0: face/edge coordinate renaming via the face_coordinates UGRID attribute now only fires if variables literally named "face_lon"/"face_lat" already exist in the dataset. Since suxarray stores pre-transformed coordinates as SCHISM_hgrid_face_lon/lat (not face_lon/lat), the rename was silently skipped, leaving face_lon absent from _ds. Without face_lon, uxarray's _populate_face_centroids falls back to the Cartesian branch. It finds face_x in _ds (UTM easting, renamed by _rename_coords) and grabs face_y (UTM northing) and face_z (SCHISM bottom-layer depth in negative meters, stored by _assign_z_coords) as if they were unit-sphere Cartesian coordinates. It then calls: lat = arcsin(face_z) # arcsin only defined for z ∈ [-1, 1] arctan2 used for lon never produces NaN, so face_lon is unaffected. arcsin on depth values outside [-1, 1] produces NaN, so only face_lat is corrupted. On the Bay-Delta test domain, about ~4% (~21K of 538K) faces get corrupted. Fix: add explicit SCHISM_hgrid_{node,face,edge}_lon/lat → {node,face,edge}_lon/lat renaming in _rename_coords with if-guards. Under uxarray 2025.06, _read_ugrid already consumed these names so the guards are false (no-op). Under 2025.08+, the rename ensures face_lon is present in _ds before uxarray's lazy centroid property fires, taking _populate_face_centroids down the correct else-branch (converts existing face_lon/lat to face_x/y/z) with no recomputation. --- pyproject.toml | 2 +- suxarray/io/_schismgrid.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 40f9e27..894898f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ classifiers = [ "Programming Language :: Python :: 3.12", ] dependencies = [ - "uxarray==2025.6.0", + "uxarray==2025.12.0", "shapely>=2.0", "Click>=7.0" ] diff --git a/suxarray/io/_schismgrid.py b/suxarray/io/_schismgrid.py index db609d1..5d30dc2 100644 --- a/suxarray/io/_schismgrid.py +++ b/suxarray/io/_schismgrid.py @@ -357,6 +357,16 @@ def _rename_coords( } data = data.rename(coord_dict) # Patch for dimension name renaming. + if "SCHISM_hgrid_node_lon" in data: + data = data.rename({"SCHISM_hgrid_node_lon": "node_lon", + "SCHISM_hgrid_node_lat": "node_lat"}) + if "SCHISM_hgrid_face_lon" in data: + data = data.rename({"SCHISM_hgrid_face_lon": "face_lon", + "SCHISM_hgrid_face_lat": "face_lat"}) + if "SCHISM_hgrid_edge_lon" in data: + data = data.rename({"SCHISM_hgrid_edge_lon": "edge_lon", + "SCHISM_hgrid_edge_lat": "edge_lat"}) + if "nSCHISM_hgrid_edge" in data.dims: data = data.rename({"nSCHISM_hgrid_edge": "n_edge"}) if "nSCHISM_hgrid_face" in data.dims: