-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ GPU accelerated point in polygon using cuspatial
A very fast way to find points inside polygons! This is really just a convenience function that wraps around `cuspatial.point_in_polygon`, hiding all sorts of boilerplate. Specifically, this handles: 1. Converting a geopandas geodataframe into a cuspatial friendly format, see rapidsai/cuspatial#165 2. Hacky workaround the 31 polygon limit using a for-loop, based on https://github.com/rapidsai/cuspatial/blob/branch-0.15/notebooks/nyc_taxi_years_correlation.ipynb 3. Outputting actual string labels from the geodataframe, instead of non human readable index numbers Also added tests for this in test_spatiotemporal_gpu.py, though it won't work on the CI, only locally where a GPU is available.
- Loading branch information
Showing
4 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Tests GPU accelerated spatial algorithms | ||
""" | ||
|
||
import geopandas as gpd | ||
import numpy as np | ||
import pytest | ||
import shapely.geometry | ||
|
||
from deepicedrain import point_in_polygon_gpu | ||
|
||
cudf = pytest.importorskip(modname="cudf") | ||
|
||
|
||
def test_point_in_polygon_gpu(): | ||
""" | ||
Tests that the Point in Polygon GPU algorithm works | ||
""" | ||
points_df: cudf.DataFrame = cudf.DataFrame( | ||
data={ | ||
"x": np.linspace(start=-200, stop=200, num=50), | ||
"y": np.linspace(start=-160, stop=160, num=50), | ||
} | ||
) | ||
polygon = { | ||
"placename": ["South Pole"], | ||
"geometry": shapely.geometry.box(minx=-5, maxx=5, miny=-5, maxy=5).buffer(100), | ||
} | ||
poly_df: gpd.GeoDataFrame = gpd.GeoDataFrame(polygon) | ||
|
||
point_labels = point_in_polygon_gpu( | ||
points_df=points_df, poly_df=poly_df, poly_label_col="placename" | ||
) | ||
assert isinstance(point_labels, cudf.Series) | ||
assert point_labels.count() == 20 # Count non-NaN labels | ||
assert list(point_labels.unique().to_pandas()) == [None, "South Pole"] |