Skip to content
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

Refactor spatial related functions under spatial package #656

Merged
merged 23 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0700863
Move trajectory into sub-package
isVoid Aug 15, 2022
6a9b0dd
Organize test files in the same folder structure
isVoid Aug 15, 2022
eb35b2c
Group interpolate under `trajectory` category.
isVoid Aug 15, 2022
a007d57
reorganize spline tests
isVoid Aug 15, 2022
265874a
Create new hierarchy for spatial functions
isVoid Aug 16, 2022
bf01510
Organize tests in the same hierarchy as code
isVoid Aug 16, 2022
b2017fb
Refactor `CubicSpline` to be independent of `trajectory` component.
isVoid Aug 16, 2022
943c5a8
Match test files structure
isVoid Aug 16, 2022
8125efe
style
isVoid Aug 16, 2022
dd78588
Merge branch 'refactor/trajectory' into refactor/spatial
isVoid Aug 17, 2022
4b77ee2
Update documentation
isVoid Aug 17, 2022
e0845f2
Update top level module visibility
isVoid Aug 17, 2022
060c562
Merge branch 'branch-22.10' of https://github.com/rapidsai/cuspatial …
isVoid Aug 18, 2022
bed6c62
add sections to spatial api reference
isVoid Aug 18, 2022
b14806d
Revert "Refactor `CubicSpline` to be independent of `trajectory` comp…
isVoid Aug 19, 2022
5915ce9
Revert "Move trajectory into sub-package"
isVoid Aug 19, 2022
9d3ab98
Expose spatial package to top level API
isVoid Aug 19, 2022
d673faa
style, license date
isVoid Aug 19, 2022
30c3f87
Add project wide config file for black
isVoid Aug 19, 2022
7b7f7eb
black format
isVoid Aug 19, 2022
a812008
renaming the files to new suggestion
isVoid Aug 23, 2022
516157a
Update docs/source/api_docs/spatial.rst
isVoid Aug 23, 2022
2219db0
Merge branch 'branch-22.10' of https://github.com/rapidsai/cuspatial …
isVoid Aug 23, 2022
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
Prev Previous commit
Next Next commit
black format
  • Loading branch information
isVoid committed Aug 19, 2022
commit 7b7f7ebe58a9b1a9dbf0269ceb9683afed926f7f
7 changes: 3 additions & 4 deletions python/cuspatial/cuspatial/core/spatial/bound.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Copyright (c) 2022, NVIDIA CORPORATION.

from cudf import DataFrame
from cudf.core.column import as_column

from cuspatial._lib.polygon_bounding_boxes import (
polygon_bounding_boxes as cpp_polygon_bounding_boxes,
)
from cuspatial._lib.polyline_bounding_boxes import (
polyline_bounding_boxes as cpp_polyline_bounding_boxes,
)

from cuspatial.utils.column_utils import normalize_point_columns

from cudf.core.column import as_column
from cudf import DataFrame


def polygon_bounding_boxes(poly_offsets, ring_offsets, xs, ys):
"""Compute the minimum bounding-boxes for a set of polygons.
Expand Down
4 changes: 3 additions & 1 deletion python/cuspatial/cuspatial/core/spatial/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ def points_in_spatial_window(min_x, max_x, min_y, max_y, xs, ys):
"""
xs, ys = normalize_point_columns(as_column(xs), as_column(ys))
return DataFrame._from_data(
*spatial_window.points_in_spatial_window(min_x, max_x, min_y, max_y, xs, ys)
*spatial_window.points_in_spatial_window(
min_x, max_x, min_y, max_y, xs, ys
)
)
4 changes: 3 additions & 1 deletion python/cuspatial/cuspatial/core/spatial/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from cuspatial.utils.column_utils import normalize_point_columns


def quadtree_on_points(xs, ys, x_min, x_max, y_min, y_max, scale, max_depth, min_size):
def quadtree_on_points(
xs, ys, x_min, x_max, y_min, y_max, scale, max_depth, min_size
):
"""Construct a quadtree from a set of points for a given area-of-interest
bounding box.

Expand Down
19 changes: 14 additions & 5 deletions python/cuspatial/cuspatial/core/spatial/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
from cudf import DataFrame
from cudf.core.column import as_column

from cuspatial._lib import spatial_join
from cuspatial._lib.point_in_polygon import (
point_in_polygon as cpp_point_in_polygon,
)
from cuspatial._lib import spatial_join

from cuspatial.utils.column_utils import normalize_point_columns
from cuspatial.utils import gis_utils
from cuspatial.utils.column_utils import normalize_point_columns


def point_in_polygon(
Expand Down Expand Up @@ -242,7 +241,12 @@ def quadtree_point_in_polygon(
Indices of each point that intersects with a polygon.
"""

(points_x, points_y, poly_points_x, poly_points_y,) = normalize_point_columns(
(
points_x,
points_y,
poly_points_x,
poly_points_y,
) = normalize_point_columns(
as_column(points_x),
as_column(points_y),
as_column(poly_points_x),
Expand Down Expand Up @@ -313,7 +317,12 @@ def quadtree_point_to_nearest_polyline(
distance : cudf.Series
Distances between each point and its nearest polyline.
"""
(points_x, points_y, poly_points_x, poly_points_y,) = normalize_point_columns(
(
points_x,
points_y,
poly_points_x,
poly_points_y,
) = normalize_point_columns(
as_column(points_x),
as_column(points_y),
as_column(poly_points_x),
Expand Down
17 changes: 9 additions & 8 deletions python/cuspatial/cuspatial/core/spatial/measure.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# Copyright (c) 2022, NVIDIA CORPORATION.

from cuspatial._lib.spatial import (
haversine_distance as cpp_haversine_distance,
)
from cudf import DataFrame, Series
from cudf.core.column import as_column

from cuspatial._lib.hausdorff import (
directed_hausdorff_distance as cpp_directed_hausdorff_distance,
)
from cuspatial._lib.linestring_distance import (
pairwise_linestring_distance as cpp_pairwise_linestring_distance,
)

from cuspatial._lib.spatial import haversine_distance as cpp_haversine_distance
from cuspatial.utils.column_utils import normalize_point_columns

from cudf import DataFrame, Series
from cudf.core.column import as_column


def directed_hausdorff_distance(xs, ys, space_offsets):
"""Compute the directed Hausdorff distances between all pairs of
Expand Down Expand Up @@ -210,5 +207,9 @@ def pairwise_linestring_distance(offsets1, xs1, ys1, offsets2, xs2, ys2):
offsets1 = as_column(offsets1, dtype="int32")
offsets2 = as_column(offsets2, dtype="int32")
return Series._from_data(
{None: cpp_pairwise_linestring_distance(offsets1, xs1, ys1, offsets2, xs2, ys2)}
{
None: cpp_pairwise_linestring_distance(
offsets1, xs1, ys1, offsets2, xs2, ys2
)
}
)
1 change: 1 addition & 0 deletions python/cuspatial/cuspatial/core/spatial/project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2022, NVIDIA CORPORATION.

from cudf import DataFrame

from cuspatial._lib.spatial import (
lonlat_to_cartesian as cpp_lonlat_to_cartesian,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@ def test_centered():
result = cuspatial.points_in_spatial_window(
-1, 1, -1, 1, cudf.Series([0.0]), cudf.Series([0.0])
)
cudf.testing.assert_frame_equal(result, cudf.DataFrame({"x": [0.0], "y": [0.0]}))
cudf.testing.assert_frame_equal(
result, cudf.DataFrame({"x": [0.0], "y": [0.0]})
)


@pytest.mark.parametrize("coords", [(-1.0, -1.0), (-1.0, 1.0), (1.0, -1.0), (1.0, 1.0)])
@pytest.mark.parametrize(
"coords", [(-1.0, -1.0), (-1.0, 1.0), (1.0, -1.0), (1.0, 1.0)]
)
def test_corners(coords):
x, y = coords
result = cuspatial.points_in_spatial_window(
-1.1, 1.1, -1.1, 1.1, cudf.Series([x]), cudf.Series([y])
)
cudf.testing.assert_frame_equal(result, cudf.DataFrame({"x": [x], "y": [y]}))
cudf.testing.assert_frame_equal(
result, cudf.DataFrame({"x": [x], "y": [y]})
)


def test_pair():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ def test_polygon_join_small(dtype):
intersections,
cudf.DataFrame(
{
"poly_offset": cudf.Series([3, 3, 1, 2, 1, 1, 0, 3], dtype=np.uint32),
"poly_offset": cudf.Series(
[3, 3, 1, 2, 1, 1, 0, 3], dtype=np.uint32
),
"quad_offset": cudf.Series(
[10, 11, 6, 6, 12, 13, 2, 2], dtype=np.uint32
),
Expand Down Expand Up @@ -486,7 +488,9 @@ def test_quadtree_point_in_polygon_small(dtype):
)


def run_test_quadtree_point_to_nearest_polyline_small(dtype, expected_distances):
def run_test_quadtree_point_to_nearest_polyline_small(
dtype, expected_distances
):
x_min = 0
x_max = 8
y_min = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def test_camera_corners(corner):
result = cuspatial.lonlat_to_cartesian(
x[corner], y[corner], cudf.Series(x[corner]), cudf.Series(y[corner])
)
cudf.testing.assert_frame_equal(result, cudf.DataFrame({"x": [0.0], "y": [0.0]}))
cudf.testing.assert_frame_equal(
result, cudf.DataFrame({"x": [0.0], "y": [0.0]})
)


def test_longest_distance():
Expand Down Expand Up @@ -74,7 +76,9 @@ def test_zeros():
result = cuspatial.lonlat_to_cartesian(
0.0, 0.0, cudf.Series([0.0]), cudf.Series([0.0])
)
cudf.testing.assert_frame_equal(result, cudf.DataFrame({"x": [0.0], "y": [0.0]}))
cudf.testing.assert_frame_equal(
result, cudf.DataFrame({"x": [0.0], "y": [0.0]})
)


def test_values():
Expand Down