-
Notifications
You must be signed in to change notification settings - Fork 326
bug: Grid intersect taking excessively long on simple voronoi grid #2152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @langevin-usgs, thanks for posting this issue. I can reproduce it locally. It seems like GridIntersect is taking forever to parse the cell2d list and construct the polygons. I'm a bit confused why I haven't noticed it before, but it looks like the code to build the geometries could use an update. Creating the geometries using the following code is near instantaneous on my pc: geoms = [shapely.polygons(modelgrid.get_cell_vertices(node)) for node in range(modelgrid.nnodes)] Modifying def _vtx_grid_to_geoms_cellids(self):
shapely_geo = import_optional_dependency("shapely.geometry")
geoms = [shapely_geo.polygons(self.mfgrid.get_cell_vertices(node)) for node in range(self.mfgrid.nnodes)]
return np.array(geoms), np.arange(self.mfgrid.nnodes) Changing the max area to 1000**2 runs in about 0.5s on my PC now. I'll submit a PR. |
Excellent, @dbrakenhoff. Thanks for looking at this so quickly. I was hoping it was something simple. Looking forward to the fix as it will help me right away with some dev work. |
I'm testing the fix, but running into some issues regarding rotated/offset grids. Do you happen to know how to efficiently obtain local x,y coordinates from a VertexGrid? Or would it be simpler to transform the resulting geometries using affine or something along those lines? |
grid.py has a |
There are a couple of options. 1) |
- improve performance _vtx_grid_to_geoms_cellids()
Thanks @langevin-usgs, @jlarsen-usgs, I've submitted a PR. |
Describe the bug
The grid intersect routine is timing out on a relatively simple voronoi grid
To Reproduce
This script demonstrates the problem. It creates a simple voronoi grid and plots it. The next block, however, takes 2 mins on my computer, and doesn't finish in a reasonable amount of time if the grid if more finely discretized.
Now do some intersecting...
Expected behavior
Seems like this intersection should only take a few seconds. Note, that it would be nice to be able to change the maximum_area down to 1000**2.
The text was updated successfully, but these errors were encountered: