Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
af7b92d
refactor(GridIntersect): deprecations
dbrakenhoff Nov 27, 2025
9483c74
feat(GridIntersect): support numpy arrays with geometries in intersec…
dbrakenhoff Nov 27, 2025
3dc27c4
refactor(GridIntersect): consistency and cleanup
dbrakenhoff Nov 27, 2025
79faf9f
feat(GridIntersect): fast point location method
dbrakenhoff Nov 27, 2025
4107bff
refactor(GridIntersect): improve naming and plotting
dbrakenhoff Nov 27, 2025
8660978
feat(Gridintersect): support handling z-coordinates for points
dbrakenhoff Nov 27, 2025
cbcf9c7
remove deprecated class from util init
dbrakenhoff Nov 27, 2025
bbc5ac3
test(GridIntersect): update tests
dbrakenhoff Nov 27, 2025
6cddfc8
remove option `handle_z="drop"` from points_to_cellids()
dbrakenhoff Nov 27, 2025
407378f
feat(GridIntersect): improve plotting and update example nb
dbrakenhoff Nov 27, 2025
3968ce3
ruff
dbrakenhoff Nov 27, 2025
ae92d24
fix tests
dbrakenhoff Nov 27, 2025
2a8070e
ruff
dbrakenhoff Nov 27, 2025
3df8f4b
test(GridIntersect): remove all references to deprecated method kwarg
dbrakenhoff Nov 27, 2025
a2bc699
forgot one
dbrakenhoff Nov 27, 2025
6953bfb
refactor(GridIntersect): more cleanup
dbrakenhoff Nov 27, 2025
d967150
Improve intersect output results:
dbrakenhoff Dec 17, 2025
a20dd2d
Switch output as dataframe flag to None
dbrakenhoff Dec 17, 2025
78a48a1
switch handle_z to boolean
dbrakenhoff Dec 17, 2025
2c751e5
improve gridintersect docstrings
dbrakenhoff Dec 17, 2025
2efa446
improve gridintersect tests:
dbrakenhoff Dec 17, 2025
9b0f36b
Update grid intersect notebook
dbrakenhoff Dec 17, 2025
d3ad9a1
Merge branch 'develop' into update_gridintersect
dbrakenhoff Dec 17, 2025
d59310f
use int dtype everywhere
dbrakenhoff Dec 17, 2025
a3db6cb
set dataframe kwarg in gridintersect to suppress warnings
dbrakenhoff Dec 17, 2025
7db052d
make layer column dtype int
dbrakenhoff Dec 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 172 additions & 79 deletions .docs/Notebooks/grid_intersection_example.py

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions .docs/Notebooks/groundwater2023_watershed_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def densify_geometry(line, step, keep_internal_nodes=True):

# function to set the active and inactive model area
def set_idomain(grid, boundary):
ix = GridIntersect(grid, method="vertex", rtree=True)
result = ix.intersect(Polygon(boundary))
ix = GridIntersect(grid, rtree=True)
result = ix.intersect(Polygon(boundary), geo_dataframe=False)
idx = list(result.cellids)
idx = np.array(idx, dtype=int)
nr = idx.shape[0]
Expand Down Expand Up @@ -241,10 +241,10 @@ def set_idomain(grid, boundary):
extrapolate_edges=True,
)

ixs = flopy.utils.GridIntersect(struct_grid, method="structured")
ixs = flopy.utils.GridIntersect(struct_grid)
cellids = []
for sg in sgs:
v = ixs.intersect(LineString(sg), sort_by_cellid=True)
v = ixs.intersect(LineString(sg), sort_by_cellid=True, geo_dataframe=False)
cellids += v["cellids"].tolist()
intersection_sg = np.zeros(struct_grid.shape[1:])
for loc in cellids:
Expand Down Expand Up @@ -315,10 +315,10 @@ def set_idomain(grid, boundary):
extrapolate_edges=True,
)

ixs = flopy.utils.GridIntersect(struct_vrc_grid, method="structured")
ixs = flopy.utils.GridIntersect(struct_vrc_grid)
cellids = []
for sg in sgs:
v = ixs.intersect(LineString(sg), sort_by_cellid=True)
v = ixs.intersect(LineString(sg), sort_by_cellid=True, geo_dataframe=False)
cellids += v["cellids"].tolist()
intersection_sg_vrc = np.zeros(struct_vrc_grid.shape[1:])
for loc in cellids:
Expand Down Expand Up @@ -419,20 +419,20 @@ def set_idomain(grid, boundary):
top_nested_grid = [top_ngp, top_ngc]

# +
ixs = flopy.utils.GridIntersect(struct_gridp, method="structured")
ixs = flopy.utils.GridIntersect(struct_gridp)
cellids = []
for sg in sgs:
v = ixs.intersect(LineString(sg), sort_by_cellid=True)
v = ixs.intersect(LineString(sg), sort_by_cellid=True, geo_dataframe=False)
cellids += v["cellids"].tolist()
intersection_ngp = np.zeros(struct_gridp.shape[1:])
for loc in cellids:
intersection_ngp[loc] = 1
intersection_ngp[idomainp[0] == 0] = 0

ixs = flopy.utils.GridIntersect(struct_gridc, method="structured")
ixs = flopy.utils.GridIntersect(struct_gridc)
cellids = []
for sg in sgs:
v = ixs.intersect(LineString(sg), sort_by_cellid=True)
v = ixs.intersect(LineString(sg), sort_by_cellid=True, geo_dataframe=False)
cellids += v["cellids"].tolist()
intersection_ngc = np.zeros(struct_gridc.shape[1:])
for loc in cellids:
Expand Down Expand Up @@ -515,10 +515,10 @@ def set_idomain(grid, boundary):
extrapolate_edges=True,
)

ixs = flopy.utils.GridIntersect(quadtree_grid, method="vertex")
ixs = flopy.utils.GridIntersect(quadtree_grid)
cellids = []
for sg in sgs:
v = ixs.intersect(LineString(sg), sort_by_cellid=True)
v = ixs.intersect(LineString(sg), sort_by_cellid=True, geo_dataframe=False)
cellids += v["cellids"].tolist()
intersection_qg = np.zeros(quadtree_grid.shape[1:])
for loc in cellids:
Expand Down Expand Up @@ -583,14 +583,14 @@ def set_idomain(grid, boundary):
extrapolate_edges=True,
)

ixs = flopy.utils.GridIntersect(triangular_grid) # , method="vertex")
ixs = flopy.utils.GridIntersect(triangular_grid)
cellids = []
for sg in sgs:
v = ixs.intersect(
LineString(sg),
return_all_intersections=True,
keepzerolengths=False,
sort_by_cellid=True,
geo_dataframe=False,
)
cellids += v["cellids"].tolist()
intersection_tg = np.zeros(triangular_grid.shape[1:])
Expand Down Expand Up @@ -633,14 +633,14 @@ def set_idomain(grid, boundary):
extrapolate_edges=True,
)

ixs = flopy.utils.GridIntersect(voronoi_grid, method="vertex")
ixs = flopy.utils.GridIntersect(voronoi_grid)
cellids = []
for sg in sgs:
v = ixs.intersect(
LineString(sg),
return_all_intersections=True,
keepzerolengths=False,
sort_by_cellid=True,
geo_dataframe=False,
)
cellids += v["cellids"].tolist()
intersection_vg = np.zeros(voronoi_grid.shape[1:])
Expand Down
12 changes: 6 additions & 6 deletions .docs/Notebooks/mf6_parallel_model_splitting_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ def string2geom(geostring, conversion=None):

# +
# calculate and set idomain
ix = flopy.utils.GridIntersect(modelgrid, method="vertex", rtree=True)
result = ix.intersect(Polygon(boundary_polygon))
ix = flopy.utils.GridIntersect(modelgrid, rtree=True)
result = ix.intersect(Polygon(boundary_polygon), geo_dataframe=False)
idxs = tuple(zip(*result.cellids))
idomain = np.zeros((nrow, ncol), dtype=int)
idomain[idxs] = 1
Expand All @@ -369,10 +369,10 @@ def string2geom(geostring, conversion=None):

# Intersect the stream segments with the modelgrid

ixs = flopy.utils.GridIntersect(modelgrid, method="structured")
ixs = flopy.utils.GridIntersect(modelgrid)
cellids = []
for seg in segs:
v = ixs.intersect(LineString(seg), sort_by_cellid=True)
v = ixs.intersect(LineString(seg), sort_by_cellid=True, geo_dataframe=False)
cellids += v["cellids"].tolist()
intersection_rg = np.zeros(modelgrid.shape[1:])
for loc in cellids:
Expand Down Expand Up @@ -401,11 +401,11 @@ def string2geom(geostring, conversion=None):

# +
# intersect stream segs to simulate as drains
ixs = flopy.utils.GridIntersect(modelgrid, method="structured")
ixs = flopy.utils.GridIntersect(modelgrid)
drn_cellids = []
drn_lengths = []
for seg in segs:
v = ixs.intersect(LineString(seg), sort_by_cellid=True)
v = ixs.intersect(LineString(seg), sort_by_cellid=True, geo_dataframe=False)
drn_cellids += v["cellids"].tolist()
drn_lengths += v["lengths"].tolist()
# -
Expand Down
3 changes: 1 addition & 2 deletions .docs/md/optional_dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ Dependencies for optional features are listed below. These may be installed with
| `.resample_to_grid()` in `flopy.utils.rasters` | **scipy.interpolate** |
| `.interpolate()` in `flopy.mf6.utils.reference` `StructuredSpatialReference` class | **scipy.interpolate** |
| `.get_authority_crs()` in `flopy.utils.crs` | **pyproj** >= 2.2.0 |
| `.generate_classes()` in `flopy.mf6.utils` | [**modflow-devtools**](https://github.com/MODFLOW-ORG/modflow-devtools) |
| `.generate_classes()` in `flopy.mf6.utils` | [**modflow-devtools**](https://github.com/MODFLOW-ORG/modflow-devtools) |
| `GridIntersect()` in `flopy.utils.gridintersect` | **shapely** |
| `GridIntersect().plot_polygon()` in `flopy.utils.gridintersect` | **shapely** and **descartes** |
| `Raster()` in `flopy.utils.Raster` | **rasterio**, **rasterstats**, **affine**, and **scipy** |
| `Raster().sample_polygon()` in `flopy.utils.Raster` | **shapely** |
| `Raster().crop()` in `flopy.utils.Raster` | **shapely** |
Expand Down
Loading
Loading