Repository navigation
rework grid dims and coordinates - #469
Merged
Merged
Conversation
to_dataarray's dims are (nlay, nrow, ncol), (nlay, ncpl) or (nodes,), the names the generated classes' shapes and utils/grid.py already use, in place of (layer, y, x), (layer, face) and (node,). y and x read as world coordinates, which these indices aren't. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
to_dataarray's dims are (layer, row, col), (layer, node) or (node,). The DFNs' sizing names read badly in a selection (isel(nlay=0)), and xarray has no dim aliases. A DISV layer's cell is a node, as in DISU. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
node means a vertex in UGRID, which xugrid users see alongside these. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Heads and budgets read from a DIS model are (time, layer, row, col), as for package arrays, in place of (time, layer, y, x). x and y stay as world coordinates on col and row, indexed so they select. No 1-based layer coordinate on DIS or DISV output: as for inputs, a position is the index. DISV output keeps xugrid's face dim, which its topology needs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wpbonelli
marked this pull request as ready for review
October 15, 2026 13:51
DISV heads and budgets were on xugrid's default face dim, mesh2d_nFaces. Name it cell, as on DISV input arrays; UGRID lets a mesh name its face dim. Horizontal flows stay on the mesh's edges. The flow-ja-face connectivity's n/m dim, which was also called cell, is now nm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StructuredGrid's k/i/j and VertexGrid's k/icpl coordinates held 0..n-1 along nlay/nrow/ncol/ncpl, which a position already gives (isel), and k clashed with NPF's k, so a grid's dataset couldn't merge with NPF's. node stays, as the only thing on the nodes dim. x/y/z world coordinates are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StructuredGrid's dims are (layer, row, col) and VertexGrid's (layer, cell), as for package arrays, so a grid's dataset merges with a package's. The global node coordinate goes too, as an index coordinate. grid.dims gives the sizes by their DFN names for a package's dims=, which the examples used dataset.sizes for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As for package arrays: UGRID's node is a vertex. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
to_dataarray assigns x on col and y on row for DIS (from delr/delc and the origin), indexed so arrays select by them like DIS output does, and x and y on the cells for DISV and DISU (from cell2d). A standalone package has no geometry and gets none. Rotated grids get none for now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
x/y are world coordinates everywhere, rotated about the grid's origin by angrot as in MF6. DISV/DISU cell centres and DISV output vertices are rotated. A rotated DIS grid's x/y are 2-D on (row, col), and not indexed, since xarray can't index 2-D coordinates. The grb readers used to ignore angrot, placing rotated output unrotated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rotated DIS grid's rows and columns don't line up with world x and y, so 2-D world x/y can't be indexed. Rather than commit to those, its arrays get no x/y for now. A follow-up will give them local x/y in the grid's own frame, as MF6's netCDF output has, with the rotation as grid-mapping metadata. A rotated StructuredGrid's x/y are local, matching to_xarray(). DISV/DISU centres and vertices stay rotated into world coordinates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rotated DIS grid's x/y are in its own frame, zero at the lower-left corner, as MF6 writes them to netCDF, and indexed like an unrotated grid's. Structured arrays get a scalar projection coordinate, named in their grid_mapping attr as in CF and our netCDF writer, whose attrs (xorigin, yorigin, angrot) place x/y in the world. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wpbonelli
added a commit
that referenced
this pull request
Oct 17, 2026
) Follow-up to #469. On a rotated DIS grid, x/y are local: zero-based, in the grid's frame, as MF6 writes them to netCDF. The rotation lives in the projection coordinate. This PR adds world coordinates and world selection on top of that Relation to other work * Xarray structured grid index #207 asked for a structured grid index so DIS data can be selected by layer/row/column * rework grid dims and coordinates #469 covered layer/row/column: the dims are layer/row/col, so isel works directly and no custom index is needed for it * This PR covers the point queries: CellIndex is the structured grid index, without a method sel gives the containing cell, and method="nearest" gives the nearest center. Rotation, which the design doc didn't consider, is handled as an overlay of world coordinates rather than by world-valued x/y. * As in flopy3, a point on an edge between cells goes to the lower-numbered cell. * Still open under Xarray structured grid index #207: selecting by z (vertical profiles, elevation ranges), spatial selection on DISV/DISU, and radius queries. The .grid accessor (Xarray (structured) grid accessor #208) comes next and will expose sel_world and the rest
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.
Rename grid dims returned by
to_dataarray(layer, row, col)instead of(layer, y, x)(layer, cell)(node,)(same as before)Similar renaming for the head/budget readers:
(time, layer, row, col)(time, layer, cell)And add cell centers as
x/ycoordinates when the model has a discretization: oncol/rowfor DIS (indexed, sosel(x=..., y=..., method="nearest")works), oncell/nodefor DISV/DISU. Standalone packages have no geometry, so they get none. Rotated DIS grids get local x/y, zero at the lower-left corner, as in MF6's netCDF output. Every structured array gets a scalar projection coordinate (CF grid-mapping style, named in its grid_mapping attr) whose attrs xorigin/yorigin/angrot place x/y in the world. DISV/DISU centres and vertices are rotated into world coordinates.Reasons:
y/xseemed like world coordinates but weren'tnlay,nrow, ...) are awkward in selections (isel(nlay=0)), and xarray has no dim aliases, so name the dims for the axes and keep the DFN names for looking up dim sizescellrather thannodefor DISV, to avoid confusion with UGRID where "node" means vertex, and the other MF6 sense where it means 3d center of the cell. DISV inputs and outputs now matchNetCDF file handling is unchanged; the readers rename MF6's
x/y/nmesh_faceon load.It's now necessary to explicitly pass
x="x", y="y"to contour plots of DIS output.