Repository navigation
intial fix for geos dimension bug - #1861
Conversation
Sevans711
left a comment
There was a problem hiding this comment.
Looks good overall, I have a few thoughts but they are all nonblocking, it would be okay to merge as-is.
- This PR changes the UxDataset.from_xarray() behavior using the MCVE from the bug report; before this PR the result contained coordinates for "n_face", but now it does not. I think dropping the coordinates for "n_face" in this case is fine, but please confirm whether this change is intentional (either via comment in thread or by updating PR overview).
- see inline suggestions
cmdupuis3
left a comment
There was a problem hiding this comment.
One minor thing you could add:. from_xarray(da.isel(nf=[0, 1]), uxgrid=g) produces 288 faces and is silently paired with an 864-face grid. Main's Dataset path already has this problem; the branch makes it reachable from a DataArray too. A cheap fix: compare the stacked length against uxgrid.n_face / uxgrid.n_node and raise DimensionError.
if isinstance(ds, xr.DataArray):
ds = _stack_geos_cs(ds)
else:
# shallow copy, so the caller's Dataset keeps its original variables
ds = ds.copy()
for var_name in list(ds.coords) + list(ds.data_vars):
ds[var_name] = _stack_geos_cs(ds[var_name])
for dim, expected in (("n_face", grid.n_face), ("n_node", grid.n_node)):
if dim in ds.dims and ds.sizes[dim] != expected:
raise DimensionError(
f"GEOS-CS data flattens to {ds.sizes[dim]} elements along '{dim}', "
f"but the Grid has {expected}. Keep all six tiles ('nf') and the "
"full horizontal extent when converting."
)
Co-authored-by: Sam Evans <[email protected]>
Co-authored-by: Sam Evans <[email protected]>
|
@Sevans711 |
Closes #1835
Overview
UxDataArray.from_xarraypassed the DataArray to_map_dims_to_ugrid, whose GEOS-CS branch loops overds.data_vars. Every GEOS-CS face or node field raisedAttributeError: 'DataArray' object has no attribute 'data_vars'.The GEOS branch now uses a helper,
_stack_geos_cs, that flattens one DataArray from(nf, Ydim, Xdim)ton_faceand from(nf, YCdim, XCdim)ton_node, without creating a MultiIndex. A Dataset runs the existing loop on a shallow copy.Also fixes the

UxDataArray.from_xarraydocstring, which said it returns aUxDatasetand an instance where the ` wasn't used correctlyEnsures these are guaranteed within the GEOS reader:
Expected Usage
The problem occurs during
.from_xarrayhence why the data was read in with xarray firstPR Checklist
General
Testing & Benchmarking
Documentation and Examples
docs/api.rst; internal (private) function names start with an underscore (_)AI Disclosure
AI Usage:
Claude Code