Repository navigation
world-coordinate and containing-cell selection on structured grids - #485
Merged
Merged
Conversation
Arrays on a rotated structured grid, whose x/y are local, get the cells' world coordinates as unindexed x_world/y_world on (row, col), computed from the projection coordinate. sel_world selects by world coordinates, converting to local through to_local, the inverse of to_world; on other grids it's sel. With a CRS, projection has crs_wkt (wrapped with the rotation if rotated) and grid_mapping_name, as MF6 writes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The grb has no CRS, so take crs_wkt, grid_mapping_name and the rest from the file's projection variable, keeping the grb's placement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sel_world without a method missed even a cell's own world centre on a rotated grid, since rotating to local coordinates rounds. Match to within a billionth of the grid's extent instead; other points still raise, as with sel. Test that projection and the world coordinates survive concat and a netCDF round trip, and note that combining arrays on differently placed grids keeps the first's projection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Index x/y with CellIndex, a PandasIndex that also keeps each cell's edges, from the dx/dy cell sizes, so sel without a method gives the cell containing the point rather than needing its centre. Edges go to the cell east or north, points outside raise, and method="nearest" still picks the nearest centre. Package arrays and a StructuredGrid's dataset get dx/dy, as hds/cbc output has, and sel_world no longer needs a tolerance for rotation rounding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A point on the edge between two cells now gets the one with the lower index (west or north), as with flopy's StructuredGrid.intersect, rather than the east or north one. Ties are within the edge tolerance, so a point rounded a hair off an edge (e.g. by rotation) goes to the same cell as one exactly on it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wpbonelli
marked this pull request as ready for review
October 17, 2026 14:44
wpbonelli
added a commit
to wpbonelli/pyphoenix-project
that referenced
this pull request
Oct 17, 2026
as modflowpy#208 and modflowpy#485 have it, and alongside xugrid's ugrid Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 17, 2026
Merged
Merged
wpbonelli
added a commit
that referenced
this pull request
Oct 17, 2026
Follow-up to #485. CellIndex used PandasIndex's join and concat, which build a new index without the cell edges. So after a + b on overlapping grids, xr.align, or concat along row/col, sel(x=, y=) without a method needed exact centers again. * join and concat keep each cell's edges, in any order * aligning grids with a cell at the same centre but different edges raises ValueError * index_xy skips a scalar x or y (e.g. a single row) instead of failing
wpbonelli
added a commit
that referenced
this pull request
Oct 17, 2026
wpbonelli
added a commit
that referenced
this pull request
Oct 17, 2026
* layer_bounds(top, botm) builds (z_top, z_bot) with the same shape as botm * layer_at(z, z_top, z_bot) gives the layer * sel_z(obj, z, outside="nan") selects the cell containing z. vertical columns where z is outside the model are NaN, or raise KeyError with outside="raise", dask-backed arrays stay lazy * mask_z(obj, zmin, zmax, how="overlap" | "within" | "center") is a boolean mask over cells An elevation on a layer boundary goes to the upper layer, as in flopy3's intersect and #485's x/y edges. Bounds come from z_top/z_bot coordinates or are passed in, nothing attaches them yet, soon this will be wired up to #487
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.
Follow-up to #469. On a rotated DIS grid,
x/yare local: zero-based, in the grid's frame, as MF6 writes them to netCDF. The rotation lives in theprojectioncoordinate. This PR adds world coordinates and world selection on top of thatRelation to other work
layer/row/col, soiselworks directly and no custom index is needed for itCellIndexis the structured grid index, without amethodselgives the containing cell, andmethod="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-valuedx/y..gridaccessor (Xarray (structured) grid accessor #208) comes next and will exposesel_worldand the rest