From e3d360e2530f484ba8e46d963a7203101d804bf2 Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Thu, 5 Sep 2019 21:23:01 -0500 Subject: [PATCH 1/9] Refactoring to use python API --- .../cuspatial/{bindings => _lib}/GDFError.py | 0 .../cuspatial/{bindings => _lib}/__init__.py | 0 .../cuspatial/{bindings => _lib}/query.pxd | 0 .../cuspatial/{bindings => _lib}/query.pyx | 0 .../{bindings => _lib}/soa_readers.pxd | 0 .../{bindings => _lib}/soa_readers.pyx | 0 .../cuspatial/{bindings => _lib}/spatial.pxd | 0 .../cuspatial/{bindings => _lib}/spatial.pyx | 0 .../{bindings => _lib}/trajectory.pxd | 0 .../{bindings => _lib}/trajectory.pyx | 0 python/cuspatial/cuspatial/core/gis.py | 72 +++++++++++++++++++ python/cuspatial/cuspatial/core/gis.py.bak | 70 ++++++++++++++++++ python/cuspatial/cuspatial/core/gis.py~ | 72 +++++++++++++++++++ python/cuspatial/cuspatial/core/trajectory.py | 0 .../cuspatial/core/trajectory.py.bak | 0 python/cuspatial/cuspatial/io/soa.py | 16 +++++ python/cuspatial/cuspatial/io/soa.py.bak | 16 +++++ python/cuspatial/cuspatial/io/soa.py~ | 1 + .../tests/test_hausdorff_distance.py | 2 +- .../tests/test_haversine_distance.py | 2 +- .../cuspatial/tests/test_lonlat2coord.py | 2 +- python/cuspatial/cuspatial/tests/test_pip.py | 24 +++---- python/cuspatial/cuspatial/tests/test_traj.py | 2 +- .../cuspatial/{cuspatial => }/demos/README.md | 0 .../demos/hausdorff_clustering_test_toy.py | 2 +- .../hausdorff_distance_verify_locust256.py | 4 +- .../demos/haversine_distance_test_nyctaxi.py | 2 +- .../demos/pip_test_gdal_locust.py | 0 .../demos/pip_test_shapely_locust.py | 0 .../demos/pip_verify_shapely_locust.py | 4 +- .../demos/stq_test_soa_locust.py | 6 +- .../demos/traj_test_soa_locust.py | 6 +- python/cuspatial/setup.py | 2 +- 33 files changed, 276 insertions(+), 29 deletions(-) rename python/cuspatial/cuspatial/{bindings => _lib}/GDFError.py (100%) rename python/cuspatial/cuspatial/{bindings => _lib}/__init__.py (100%) rename python/cuspatial/cuspatial/{bindings => _lib}/query.pxd (100%) rename python/cuspatial/cuspatial/{bindings => _lib}/query.pyx (100%) rename python/cuspatial/cuspatial/{bindings => _lib}/soa_readers.pxd (100%) rename python/cuspatial/cuspatial/{bindings => _lib}/soa_readers.pyx (100%) rename python/cuspatial/cuspatial/{bindings => _lib}/spatial.pxd (100%) rename python/cuspatial/cuspatial/{bindings => _lib}/spatial.pyx (100%) rename python/cuspatial/cuspatial/{bindings => _lib}/trajectory.pxd (100%) rename python/cuspatial/cuspatial/{bindings => _lib}/trajectory.pyx (100%) create mode 100644 python/cuspatial/cuspatial/core/gis.py create mode 100644 python/cuspatial/cuspatial/core/gis.py.bak create mode 100644 python/cuspatial/cuspatial/core/gis.py~ create mode 100644 python/cuspatial/cuspatial/core/trajectory.py create mode 100644 python/cuspatial/cuspatial/core/trajectory.py.bak create mode 100644 python/cuspatial/cuspatial/io/soa.py create mode 100644 python/cuspatial/cuspatial/io/soa.py.bak create mode 100644 python/cuspatial/cuspatial/io/soa.py~ rename python/cuspatial/{cuspatial => }/demos/README.md (100%) rename python/cuspatial/{cuspatial => }/demos/hausdorff_clustering_test_toy.py (97%) rename python/cuspatial/{cuspatial => }/demos/hausdorff_distance_verify_locust256.py (97%) rename python/cuspatial/{cuspatial => }/demos/haversine_distance_test_nyctaxi.py (95%) rename python/cuspatial/{cuspatial => }/demos/pip_test_gdal_locust.py (100%) rename python/cuspatial/{cuspatial => }/demos/pip_test_shapely_locust.py (100%) rename python/cuspatial/{cuspatial => }/demos/pip_verify_shapely_locust.py (94%) rename python/cuspatial/{cuspatial => }/demos/stq_test_soa_locust.py (81%) rename python/cuspatial/{cuspatial => }/demos/traj_test_soa_locust.py (91%) diff --git a/python/cuspatial/cuspatial/bindings/GDFError.py b/python/cuspatial/cuspatial/_lib/GDFError.py similarity index 100% rename from python/cuspatial/cuspatial/bindings/GDFError.py rename to python/cuspatial/cuspatial/_lib/GDFError.py diff --git a/python/cuspatial/cuspatial/bindings/__init__.py b/python/cuspatial/cuspatial/_lib/__init__.py similarity index 100% rename from python/cuspatial/cuspatial/bindings/__init__.py rename to python/cuspatial/cuspatial/_lib/__init__.py diff --git a/python/cuspatial/cuspatial/bindings/query.pxd b/python/cuspatial/cuspatial/_lib/query.pxd similarity index 100% rename from python/cuspatial/cuspatial/bindings/query.pxd rename to python/cuspatial/cuspatial/_lib/query.pxd diff --git a/python/cuspatial/cuspatial/bindings/query.pyx b/python/cuspatial/cuspatial/_lib/query.pyx similarity index 100% rename from python/cuspatial/cuspatial/bindings/query.pyx rename to python/cuspatial/cuspatial/_lib/query.pyx diff --git a/python/cuspatial/cuspatial/bindings/soa_readers.pxd b/python/cuspatial/cuspatial/_lib/soa_readers.pxd similarity index 100% rename from python/cuspatial/cuspatial/bindings/soa_readers.pxd rename to python/cuspatial/cuspatial/_lib/soa_readers.pxd diff --git a/python/cuspatial/cuspatial/bindings/soa_readers.pyx b/python/cuspatial/cuspatial/_lib/soa_readers.pyx similarity index 100% rename from python/cuspatial/cuspatial/bindings/soa_readers.pyx rename to python/cuspatial/cuspatial/_lib/soa_readers.pyx diff --git a/python/cuspatial/cuspatial/bindings/spatial.pxd b/python/cuspatial/cuspatial/_lib/spatial.pxd similarity index 100% rename from python/cuspatial/cuspatial/bindings/spatial.pxd rename to python/cuspatial/cuspatial/_lib/spatial.pxd diff --git a/python/cuspatial/cuspatial/bindings/spatial.pyx b/python/cuspatial/cuspatial/_lib/spatial.pyx similarity index 100% rename from python/cuspatial/cuspatial/bindings/spatial.pyx rename to python/cuspatial/cuspatial/_lib/spatial.pyx diff --git a/python/cuspatial/cuspatial/bindings/trajectory.pxd b/python/cuspatial/cuspatial/_lib/trajectory.pxd similarity index 100% rename from python/cuspatial/cuspatial/bindings/trajectory.pxd rename to python/cuspatial/cuspatial/_lib/trajectory.pxd diff --git a/python/cuspatial/cuspatial/bindings/trajectory.pyx b/python/cuspatial/cuspatial/_lib/trajectory.pyx similarity index 100% rename from python/cuspatial/cuspatial/bindings/trajectory.pyx rename to python/cuspatial/cuspatial/_lib/trajectory.pyx diff --git a/python/cuspatial/cuspatial/core/gis.py b/python/cuspatial/cuspatial/core/gis.py new file mode 100644 index 000000000..08e0864bf --- /dev/null +++ b/python/cuspatial/cuspatial/core/gis.py @@ -0,0 +1,72 @@ +# COPYRIGHT 2019 NVIDIA + +from cuspatial._lib.spatial import cpp_point_in_polygon_bitmap + +def directed_hausdorff_distance(): + """ Compute the directed Hausdorff distances between any groupings + of polygons. + + params + x: x coordinates + y: y coordinates + count: size of each polygon + + Parameters + ---------- + {params} + + returns + DataFrame: 'min', 'max' columns of Hausdorff distances for each polygon + """ + pass + +def haversine_distance(p1_lat, p1_lon, p2_lat, p2_lon): + """ Compute the haversine distances between an arbitrary list of lat/lon + pairs + + params + p1_lat: latitude of first set of coords + p1_lon: longitude of first set of coords + p2_lat: latitude of second set of coords + p2_lon: longitude of second set of coords + + Parameters + ---------- + {params} + + returns + Series: distance between all pairs of lat/lon coords + """ + pass + +def lonlat_to_xy_km_coordinates(camera_latlon, lon_coords, lat_coords): + """ Convert lonlat coordinates to km x,y coordinates based on some camera + origin. + + params + camera_latlon: Series - latitude and longitude of camera + lon_coords: Series of longitude coords to convert to x + lat_coords: Series of latitude coords to convert to y + + Parameters + ---------- + {params} + + returns + DataFrame: 'x', 'y' columns for new km positions of coords + """ + pass + +def point_in_polygon_bitmap(x_points, y_points, + polygon_ids, polygon_end_indices, polygons_x, polygons_y): + """ Compute from a set of points and a set of polygons which points fall + within which polygons. + + Parameters + ---------- + {params} + """ + return cpp_point_in_polygon_bitmap( + x_points, y_points, + polygon_ids, polygon_end_indices, polygons_x, polygons_y + ) diff --git a/python/cuspatial/cuspatial/core/gis.py.bak b/python/cuspatial/cuspatial/core/gis.py.bak new file mode 100644 index 000000000..8ef569481 --- /dev/null +++ b/python/cuspatial/cuspatial/core/gis.py.bak @@ -0,0 +1,70 @@ +# COPYRIGHT 2019 NVIDIA + +def directed_hausdorff_distance() + """ Compute the directed Hausdorff distances between any groupings + of polygons. + + params + x: x coordinates + y: y coordinates + count: size of each polygon + + Parameters + ---------- + {params} + + returns + DataFrame: 'min', 'max' columns of Hausdorff distances for each polygon + """ + pass + +def haversine_distance(p1_lat, p1_lon, p2_lat, p2_lon): + """ Compute the haversine distances between an arbitrary list of lat/lon + pairs + + params + p1_lat: latitude of first set of coords + p1_lon: longitude of first set of coords + p2_lat: latitude of second set of coords + p2_lon: longitude of second set of coords + + Parameters + ---------- + {params} + + returns + Series: distance between all pairs of lat/lon coords + """ + pass + +def lonlat_to_xy_km_coordinates(camera_latlon, lon_coords, lat_coords): + """ Convert lonlat coordinates to km x,y coordinates based on some camera + origin. + + params + camera_latlon: Series - latitude and longitude of camera + lon_coords: Series of longitude coords to convert to x + lat_coords: Series of latitude coords to convert to y + + Parameters + ---------- + {params} + + returns + DataFrame: 'x', 'y' columns for new km positions of coords + """ + pass + +def point_in_polygon_bitmap(x_points, y_points, + polygon_ids, polygon_end_indices, polygon_coordinates): + """ Compute from a set of points and a set of polygons which points fall + within which polygons. + + Parameters + ---------- + {params} + """ + return cpp_point_in_polygon_bitmap( + x_points, y_points, + polygon_ids, polygon_end_indices, polygon_coordinates + ) diff --git a/python/cuspatial/cuspatial/core/gis.py~ b/python/cuspatial/cuspatial/core/gis.py~ new file mode 100644 index 000000000..87b300c62 --- /dev/null +++ b/python/cuspatial/cuspatial/core/gis.py~ @@ -0,0 +1,72 @@ +# COPYRIGHT 2019 NVIDIA + +from cuspatial._lib.spatial import cpp_point_in_polygon_bitmap + +def directed_hausdorff_distance(): + """ Compute the directed Hausdorff distances between any groupings + of polygons. + + params + x: x coordinates + y: y coordinates + count: size of each polygon + + Parameters + ---------- + {params} + + returns + DataFrame: 'min', 'max' columns of Hausdorff distances for each polygon + """ + pass + +def haversine_distance(p1_lat, p1_lon, p2_lat, p2_lon): + """ Compute the haversine distances between an arbitrary list of lat/lon + pairs + + params + p1_lat: latitude of first set of coords + p1_lon: longitude of first set of coords + p2_lat: latitude of second set of coords + p2_lon: longitude of second set of coords + + Parameters + ---------- + {params} + + returns + Series: distance between all pairs of lat/lon coords + """ + pass + +def lonlat_to_xy_km_coordinates(camera_latlon, lon_coords, lat_coords): + """ Convert lonlat coordinates to km x,y coordinates based on some camera + origin. + + params + camera_latlon: Series - latitude and longitude of camera + lon_coords: Series of longitude coords to convert to x + lat_coords: Series of latitude coords to convert to y + + Parameters + ---------- + {params} + + returns + DataFrame: 'x', 'y' columns for new km positions of coords + """ + pass + +def point_in_polygon_bitmap(x_points, y_points, + polygon_ids, polygon_end_indices, polygons_x, polygons_y): + """ Compute from a set of points and a set of polygons which points fall + within which polygons. + + Parameters + ---------- + {params} + """ + return cpp_point_in_polygon_bitmap( + x_points, y_points, + polygon_ids, polygon_end_indices, polygon_coordinates + ) diff --git a/python/cuspatial/cuspatial/core/trajectory.py b/python/cuspatial/cuspatial/core/trajectory.py new file mode 100644 index 000000000..e69de29bb diff --git a/python/cuspatial/cuspatial/core/trajectory.py.bak b/python/cuspatial/cuspatial/core/trajectory.py.bak new file mode 100644 index 000000000..e69de29bb diff --git a/python/cuspatial/cuspatial/io/soa.py b/python/cuspatial/cuspatial/io/soa.py new file mode 100644 index 000000000..aa25d7433 --- /dev/null +++ b/python/cuspatial/cuspatial/io/soa.py @@ -0,0 +1,16 @@ +# COPYRIGHT 2019 NVIDIA + +def read_uint(filename): + pass + +def read_ts(filename): + pass + +def read_points_lonlat(filename): + pass + +def read_points_xy_km(filename): + pass + +def read_polygon(filename): + pass diff --git a/python/cuspatial/cuspatial/io/soa.py.bak b/python/cuspatial/cuspatial/io/soa.py.bak new file mode 100644 index 000000000..aa25d7433 --- /dev/null +++ b/python/cuspatial/cuspatial/io/soa.py.bak @@ -0,0 +1,16 @@ +# COPYRIGHT 2019 NVIDIA + +def read_uint(filename): + pass + +def read_ts(filename): + pass + +def read_points_lonlat(filename): + pass + +def read_points_xy_km(filename): + pass + +def read_polygon(filename): + pass diff --git a/python/cuspatial/cuspatial/io/soa.py~ b/python/cuspatial/cuspatial/io/soa.py~ new file mode 100644 index 000000000..3a95cb1c9 --- /dev/null +++ b/python/cuspatial/cuspatial/io/soa.py~ @@ -0,0 +1 @@ +# COPYRIGHT 2019 NVIDIA diff --git a/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py b/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py index 73c5e8abb..37b9d7b6f 100644 --- a/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py +++ b/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py @@ -20,7 +20,7 @@ import cudf from cudf.tests.utils import assert_eq from cudf.core import column -import cuspatial.bindings.spatial as gis +import cuspatial._lib.spatial as gis def test_zeros(): distance = gis.cpp_directed_hausdorff_distance( diff --git a/python/cuspatial/cuspatial/tests/test_haversine_distance.py b/python/cuspatial/cuspatial/tests/test_haversine_distance.py index 06b4ebfd2..7fa87bf7f 100644 --- a/python/cuspatial/cuspatial/tests/test_haversine_distance.py +++ b/python/cuspatial/cuspatial/tests/test_haversine_distance.py @@ -12,7 +12,7 @@ import cudf from cudf.core import column from cudf.tests.utils import assert_eq -import cuspatial.bindings.spatial as gis +import cuspatial._lib.spatial as gis def test_zeros(): distance = gis.cpp_haversine_distance( diff --git a/python/cuspatial/cuspatial/tests/test_lonlat2coord.py b/python/cuspatial/cuspatial/tests/test_lonlat2coord.py index effe89925..eabe5640d 100644 --- a/python/cuspatial/cuspatial/tests/test_lonlat2coord.py +++ b/python/cuspatial/cuspatial/tests/test_lonlat2coord.py @@ -4,7 +4,7 @@ import cudf from cudf.tests.utils import assert_eq import numpy as np -import cuspatial.bindings.spatial as gis +import cuspatial._lib.spatial as gis """ GPU accelerated coordinate transformation test: (log/lat)==>(x/y), relative to a camera origin diff --git a/python/cuspatial/cuspatial/tests/test_pip.py b/python/cuspatial/cuspatial/tests/test_pip.py index a485626d9..cc79e5e1a 100644 --- a/python/cuspatial/cuspatial/tests/test_pip.py +++ b/python/cuspatial/cuspatial/tests/test_pip.py @@ -4,11 +4,11 @@ import cudf from cudf.tests.utils import assert_eq import numpy as np -import cuspatial.bindings.spatial as gis +import cuspatial.core.gis as gis def test_missing_0(): with pytest.raises(RuntimeError): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series(), cudf.Series([0.0]), cudf.Series([0.0]), @@ -19,7 +19,7 @@ def test_missing_0(): def test_missing_1(): with pytest.raises(RuntimeError): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series([0.0]), cudf.Series(), cudf.Series([0.0]), @@ -30,7 +30,7 @@ def test_missing_1(): def test_missing_2(): with pytest.raises(RuntimeError): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series([0.0]), cudf.Series([0.0]), cudf.Series(), @@ -41,7 +41,7 @@ def test_missing_2(): def test_missing_3(): with pytest.raises(RuntimeError): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series([0.0]), cudf.Series([0.0]), cudf.Series([0.0]), @@ -52,7 +52,7 @@ def test_missing_3(): def test_missing_4(): with pytest.raises(RuntimeError): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series([0.0]), cudf.Series([0.0]), cudf.Series([0.0]), @@ -63,7 +63,7 @@ def test_missing_4(): def test_missing_5(): with pytest.raises(RuntimeError): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series([0.0]), cudf.Series([0.0]), cudf.Series([0.0]), @@ -73,7 +73,7 @@ def test_missing_5(): ) def test_zeros(): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series([0.0]), cudf.Series([0.0]), cudf.Series([0.0]), @@ -84,7 +84,7 @@ def test_zeros(): assert_eq(cudf.Series(result), cudf.Series([0]).astype('int32')) def test_one_point_in(): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series([0]), cudf.Series([0]), cudf.Series([1]), @@ -95,7 +95,7 @@ def test_one_point_in(): assert_eq(cudf.Series(result), cudf.Series([1]).astype('int32')) def test_one_point_out(): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series([1]), cudf.Series([1]), cudf.Series([1]), @@ -106,7 +106,7 @@ def test_one_point_out(): assert_eq(cudf.Series(result), cudf.Series([0]).astype('int32')) def test_dataset(): - result = gis.cpp_point_in_polygon_bitmap( + result = gis.point_in_polygon_bitmap( cudf.Series([0, -8, 6.0]), cudf.Series([0, -8, 6.0]), cudf.Series([1, 2]), @@ -114,7 +114,7 @@ def test_dataset(): cudf.Series([-10.0, 5, 5, -10, -10, 0, 10, 10, 0, 0]), cudf.Series([-10.0, -10, 5, 5, -10, 0, 0, 10, 10, 0]), ) - # The result of cpp_point_in_polygon_bitmap is a binary bitmap of + # The result of point_in_polygon_bitmap is a binary bitmap of # coordinates inside of the polgyon. print(np.binary_repr(result.data.to_array()[0], width=2)) assert_eq(cudf.Series(result), cudf.Series([3, 1, 2]).astype('int32')) diff --git a/python/cuspatial/cuspatial/tests/test_traj.py b/python/cuspatial/cuspatial/tests/test_traj.py index 390f33ebc..c83a5b66f 100644 --- a/python/cuspatial/cuspatial/tests/test_traj.py +++ b/python/cuspatial/cuspatial/tests/test_traj.py @@ -8,7 +8,7 @@ import cudf from cudf.tests.utils import assert_eq import numpy as np -import cuspatial.bindings.trajectory as traj +import cuspatial._lib.trajectory as traj def test_subset_trajectory_id_zeros(): result = traj.cpp_subset_trajectory_id( diff --git a/python/cuspatial/cuspatial/demos/README.md b/python/cuspatial/demos/README.md similarity index 100% rename from python/cuspatial/cuspatial/demos/README.md rename to python/cuspatial/demos/README.md diff --git a/python/cuspatial/cuspatial/demos/hausdorff_clustering_test_toy.py b/python/cuspatial/demos/hausdorff_clustering_test_toy.py similarity index 97% rename from python/cuspatial/cuspatial/demos/hausdorff_clustering_test_toy.py rename to python/cuspatial/demos/hausdorff_clustering_test_toy.py index d2cd1155e..7f49e28dc 100644 --- a/python/cuspatial/cuspatial/demos/hausdorff_clustering_test_toy.py +++ b/python/cuspatial/demos/hausdorff_clustering_test_toy.py @@ -12,7 +12,7 @@ import numpy as np import time from cudf.core import column -import cuspatial.bindings.spatial as gis +import cuspatial._lib.spatial as gis from scipy.spatial.distance import directed_hausdorff from sklearn.cluster import AgglomerativeClustering,DBSCAN diff --git a/python/cuspatial/cuspatial/demos/hausdorff_distance_verify_locust256.py b/python/cuspatial/demos/hausdorff_distance_verify_locust256.py similarity index 97% rename from python/cuspatial/cuspatial/demos/hausdorff_distance_verify_locust256.py rename to python/cuspatial/demos/hausdorff_distance_verify_locust256.py index d2029c97e..f05f03286 100644 --- a/python/cuspatial/cuspatial/demos/hausdorff_distance_verify_locust256.py +++ b/python/cuspatial/demos/hausdorff_distance_verify_locust256.py @@ -13,8 +13,8 @@ import pickle from scipy.spatial.distance import directed_hausdorff -import cuspatial.bindings.spatial as gis -import cuspatial.bindings.soa_readers as readers +import cuspatial._lib.spatial as gis +import cuspatial._lib.soa_readers as readers data_dir = "/home/jianting/trajcode/" data_set = "locust256" diff --git a/python/cuspatial/cuspatial/demos/haversine_distance_test_nyctaxi.py b/python/cuspatial/demos/haversine_distance_test_nyctaxi.py similarity index 95% rename from python/cuspatial/cuspatial/demos/haversine_distance_test_nyctaxi.py rename to python/cuspatial/demos/haversine_distance_test_nyctaxi.py index 02280a47a..5f5a7f236 100644 --- a/python/cuspatial/cuspatial/demos/haversine_distance_test_nyctaxi.py +++ b/python/cuspatial/demos/haversine_distance_test_nyctaxi.py @@ -1,7 +1,7 @@ import time import cudf from cudf.core import column -import cuspatial.bindings.spatial as gis +import cuspatial._lib.spatial as gis start = time.time() # data dowloaded from https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2009-01.csv diff --git a/python/cuspatial/cuspatial/demos/pip_test_gdal_locust.py b/python/cuspatial/demos/pip_test_gdal_locust.py similarity index 100% rename from python/cuspatial/cuspatial/demos/pip_test_gdal_locust.py rename to python/cuspatial/demos/pip_test_gdal_locust.py diff --git a/python/cuspatial/cuspatial/demos/pip_test_shapely_locust.py b/python/cuspatial/demos/pip_test_shapely_locust.py similarity index 100% rename from python/cuspatial/cuspatial/demos/pip_test_shapely_locust.py rename to python/cuspatial/demos/pip_test_shapely_locust.py diff --git a/python/cuspatial/cuspatial/demos/pip_verify_shapely_locust.py b/python/cuspatial/demos/pip_verify_shapely_locust.py similarity index 94% rename from python/cuspatial/cuspatial/demos/pip_verify_shapely_locust.py rename to python/cuspatial/demos/pip_verify_shapely_locust.py index af643c790..62745f717 100644 --- a/python/cuspatial/cuspatial/demos/pip_verify_shapely_locust.py +++ b/python/cuspatial/demos/pip_verify_shapely_locust.py @@ -6,8 +6,8 @@ import numpy as np import time -import cuspatial.bindings.spatial as gis -import cuspatial.bindings.soa_readers as readers +import cuspatial._lib.spatial as gis +import cuspatial._lib.soa_readers as readers from cudf.core import column from shapely.geometry import Polygon, Point from shapely.geometry import shape diff --git a/python/cuspatial/cuspatial/demos/stq_test_soa_locust.py b/python/cuspatial/demos/stq_test_soa_locust.py similarity index 81% rename from python/cuspatial/cuspatial/demos/stq_test_soa_locust.py rename to python/cuspatial/demos/stq_test_soa_locust.py index ae9ac2aa1..52fcea6b8 100644 --- a/python/cuspatial/cuspatial/demos/stq_test_soa_locust.py +++ b/python/cuspatial/demos/stq_test_soa_locust.py @@ -6,9 +6,9 @@ import numpy as np import pandas as pd -import cuspatial.bindings.trajectory as traj -import cuspatial.bindings.stq as stq -import cuspatial.bindings.soa_readers as readers +import cuspatial._lib.trajectory as traj +import cuspatial._lib.stq as stq +import cuspatial._lib.soa_readers as readers from cudf.core import column import cudf diff --git a/python/cuspatial/cuspatial/demos/traj_test_soa_locust.py b/python/cuspatial/demos/traj_test_soa_locust.py similarity index 91% rename from python/cuspatial/cuspatial/demos/traj_test_soa_locust.py rename to python/cuspatial/demos/traj_test_soa_locust.py index 2a90a02f7..ac71f2dc1 100644 --- a/python/cuspatial/cuspatial/demos/traj_test_soa_locust.py +++ b/python/cuspatial/demos/traj_test_soa_locust.py @@ -5,9 +5,9 @@ import numpy as np import pandas as pd -import cuspatial.bindings.spatial as gis -import cuspatial.bindings.trajectory as traj -import cuspatial.bindings.soa_readers as readers +import cuspatial._lib.spatial as gis +import cuspatial._lib.trajectory as traj +import cuspatial._lib.soa_readers as readers import cuspatial.utils.traj_utils as tools data_dir = "/home/jianting/cuspatial/data/" diff --git a/python/cuspatial/setup.py b/python/cuspatial/setup.py index b400bf159..97533592d 100644 --- a/python/cuspatial/setup.py +++ b/python/cuspatial/setup.py @@ -11,7 +11,7 @@ from setuptools.extension import Extension install_requires = ["numba", "cython"] -cython_files = ["cuspatial/bindings/**/*.pyx"] +cython_files = ["cuspatial/_lib/**/*.pyx"] extensions = [ Extension( From 2c07dff033ca1831334f21769b6af088c8a20e58 Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Thu, 5 Sep 2019 21:25:41 -0500 Subject: [PATCH 2/9] Temp files! --- python/cuspatial/cuspatial/core/gis.py~ | 72 ------------------------- python/cuspatial/cuspatial/io/soa.py~ | 1 - 2 files changed, 73 deletions(-) delete mode 100644 python/cuspatial/cuspatial/core/gis.py~ delete mode 100644 python/cuspatial/cuspatial/io/soa.py~ diff --git a/python/cuspatial/cuspatial/core/gis.py~ b/python/cuspatial/cuspatial/core/gis.py~ deleted file mode 100644 index 87b300c62..000000000 --- a/python/cuspatial/cuspatial/core/gis.py~ +++ /dev/null @@ -1,72 +0,0 @@ -# COPYRIGHT 2019 NVIDIA - -from cuspatial._lib.spatial import cpp_point_in_polygon_bitmap - -def directed_hausdorff_distance(): - """ Compute the directed Hausdorff distances between any groupings - of polygons. - - params - x: x coordinates - y: y coordinates - count: size of each polygon - - Parameters - ---------- - {params} - - returns - DataFrame: 'min', 'max' columns of Hausdorff distances for each polygon - """ - pass - -def haversine_distance(p1_lat, p1_lon, p2_lat, p2_lon): - """ Compute the haversine distances between an arbitrary list of lat/lon - pairs - - params - p1_lat: latitude of first set of coords - p1_lon: longitude of first set of coords - p2_lat: latitude of second set of coords - p2_lon: longitude of second set of coords - - Parameters - ---------- - {params} - - returns - Series: distance between all pairs of lat/lon coords - """ - pass - -def lonlat_to_xy_km_coordinates(camera_latlon, lon_coords, lat_coords): - """ Convert lonlat coordinates to km x,y coordinates based on some camera - origin. - - params - camera_latlon: Series - latitude and longitude of camera - lon_coords: Series of longitude coords to convert to x - lat_coords: Series of latitude coords to convert to y - - Parameters - ---------- - {params} - - returns - DataFrame: 'x', 'y' columns for new km positions of coords - """ - pass - -def point_in_polygon_bitmap(x_points, y_points, - polygon_ids, polygon_end_indices, polygons_x, polygons_y): - """ Compute from a set of points and a set of polygons which points fall - within which polygons. - - Parameters - ---------- - {params} - """ - return cpp_point_in_polygon_bitmap( - x_points, y_points, - polygon_ids, polygon_end_indices, polygon_coordinates - ) diff --git a/python/cuspatial/cuspatial/io/soa.py~ b/python/cuspatial/cuspatial/io/soa.py~ deleted file mode 100644 index 3a95cb1c9..000000000 --- a/python/cuspatial/cuspatial/io/soa.py~ +++ /dev/null @@ -1 +0,0 @@ -# COPYRIGHT 2019 NVIDIA From 5d6ea34ed1e4b567d2916475ee37e0c5eb779ecb Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Thu, 5 Sep 2019 21:27:14 -0500 Subject: [PATCH 3/9] More temp filesgit status --- python/cuspatial/cuspatial/core/gis.py.bak | 70 ------------------- .../cuspatial/core/trajectory.py.bak | 0 python/cuspatial/cuspatial/io/soa.py.bak | 16 ----- 3 files changed, 86 deletions(-) delete mode 100644 python/cuspatial/cuspatial/core/gis.py.bak delete mode 100644 python/cuspatial/cuspatial/core/trajectory.py.bak delete mode 100644 python/cuspatial/cuspatial/io/soa.py.bak diff --git a/python/cuspatial/cuspatial/core/gis.py.bak b/python/cuspatial/cuspatial/core/gis.py.bak deleted file mode 100644 index 8ef569481..000000000 --- a/python/cuspatial/cuspatial/core/gis.py.bak +++ /dev/null @@ -1,70 +0,0 @@ -# COPYRIGHT 2019 NVIDIA - -def directed_hausdorff_distance() - """ Compute the directed Hausdorff distances between any groupings - of polygons. - - params - x: x coordinates - y: y coordinates - count: size of each polygon - - Parameters - ---------- - {params} - - returns - DataFrame: 'min', 'max' columns of Hausdorff distances for each polygon - """ - pass - -def haversine_distance(p1_lat, p1_lon, p2_lat, p2_lon): - """ Compute the haversine distances between an arbitrary list of lat/lon - pairs - - params - p1_lat: latitude of first set of coords - p1_lon: longitude of first set of coords - p2_lat: latitude of second set of coords - p2_lon: longitude of second set of coords - - Parameters - ---------- - {params} - - returns - Series: distance between all pairs of lat/lon coords - """ - pass - -def lonlat_to_xy_km_coordinates(camera_latlon, lon_coords, lat_coords): - """ Convert lonlat coordinates to km x,y coordinates based on some camera - origin. - - params - camera_latlon: Series - latitude and longitude of camera - lon_coords: Series of longitude coords to convert to x - lat_coords: Series of latitude coords to convert to y - - Parameters - ---------- - {params} - - returns - DataFrame: 'x', 'y' columns for new km positions of coords - """ - pass - -def point_in_polygon_bitmap(x_points, y_points, - polygon_ids, polygon_end_indices, polygon_coordinates): - """ Compute from a set of points and a set of polygons which points fall - within which polygons. - - Parameters - ---------- - {params} - """ - return cpp_point_in_polygon_bitmap( - x_points, y_points, - polygon_ids, polygon_end_indices, polygon_coordinates - ) diff --git a/python/cuspatial/cuspatial/core/trajectory.py.bak b/python/cuspatial/cuspatial/core/trajectory.py.bak deleted file mode 100644 index e69de29bb..000000000 diff --git a/python/cuspatial/cuspatial/io/soa.py.bak b/python/cuspatial/cuspatial/io/soa.py.bak deleted file mode 100644 index aa25d7433..000000000 --- a/python/cuspatial/cuspatial/io/soa.py.bak +++ /dev/null @@ -1,16 +0,0 @@ -# COPYRIGHT 2019 NVIDIA - -def read_uint(filename): - pass - -def read_ts(filename): - pass - -def read_points_lonlat(filename): - pass - -def read_points_xy_km(filename): - pass - -def read_polygon(filename): - pass From 761fa513e611f821b223a2b06d1ec5a52f5e2af5 Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Thu, 5 Sep 2019 21:41:10 -0500 Subject: [PATCH 4/9] Refactor gis.py and tests --- python/cuspatial/cuspatial/core/gis.py | 33 +++++++++++++++---- .../tests/test_hausdorff_distance.py | 18 +++++----- .../tests/test_haversine_distance.py | 14 ++++---- .../cuspatial/tests/test_lonlat2coord.py | 22 ++++++------- 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/python/cuspatial/cuspatial/core/gis.py b/python/cuspatial/cuspatial/core/gis.py index 08e0864bf..9441b0808 100644 --- a/python/cuspatial/cuspatial/core/gis.py +++ b/python/cuspatial/cuspatial/core/gis.py @@ -1,8 +1,13 @@ # COPYRIGHT 2019 NVIDIA -from cuspatial._lib.spatial import cpp_point_in_polygon_bitmap +from cuspatial._lib.spatial import ( + cpp_directed_hausdorff_distance, + cpp_haversine_distance, + cpp_lonlat2coord, + cpp_point_in_polygon_bitmap +) -def directed_hausdorff_distance(): +def directed_hausdorff_distance(x, y, count): """ Compute the directed Hausdorff distances between any groupings of polygons. @@ -18,7 +23,7 @@ def directed_hausdorff_distance(): returns DataFrame: 'min', 'max' columns of Hausdorff distances for each polygon """ - pass + return cpp_directed_hausdorff_distance(x, y, count) def haversine_distance(p1_lat, p1_lon, p2_lat, p2_lon): """ Compute the haversine distances between an arbitrary list of lat/lon @@ -37,14 +42,15 @@ def haversine_distance(p1_lat, p1_lon, p2_lat, p2_lon): returns Series: distance between all pairs of lat/lon coords """ - pass + return cpp_haversine_distance(p1_lat, p1_lon, p2_lat, p2_lon) -def lonlat_to_xy_km_coordinates(camera_latlon, lon_coords, lat_coords): +def lonlat_to_xy_km_coordinates(camera_lon, camera_lat, lon_coords, lat_coords): """ Convert lonlat coordinates to km x,y coordinates based on some camera origin. params - camera_latlon: Series - latitude and longitude of camera + camera_lon: float64 - longitude camera + camera_lat: float64 - latitude camera lon_coords: Series of longitude coords to convert to x lat_coords: Series of latitude coords to convert to y @@ -55,16 +61,29 @@ def lonlat_to_xy_km_coordinates(camera_latlon, lon_coords, lat_coords): returns DataFrame: 'x', 'y' columns for new km positions of coords """ - pass + return cpp_lonlat2coord(camera_lon, camera_lat, lon_coords, lat_coords) def point_in_polygon_bitmap(x_points, y_points, polygon_ids, polygon_end_indices, polygons_x, polygons_y): """ Compute from a set of points and a set of polygons which points fall within which polygons. + params + x_points: x coordinates of points to test + y_points: y coordinates of points to test + polygon_ids: a unique integer id for each polygon + polygon_end_indices: the (n+1)th vertex of the final coordinate of each + polygon in the next parameters + polygons_x: x coordinates of all polygon points + polygons_y: y coordinates of all polygon points + Parameters ---------- {params} + + returns + Series: one int32 for each point. This int32 is a binary bitmap specifying + true or false for each of 32 polygons. """ return cpp_point_in_polygon_bitmap( x_points, y_points, diff --git a/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py b/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py index 37b9d7b6f..f92ca9bf6 100644 --- a/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py +++ b/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py @@ -20,10 +20,10 @@ import cudf from cudf.tests.utils import assert_eq from cudf.core import column -import cuspatial._lib.spatial as gis +from cuspatial.core import gis def test_zeros(): - distance = gis.cpp_directed_hausdorff_distance( + distance = gis.directed_hausdorff_distance( cudf.Series([0.0]), cudf.Series([0.0]), cudf.Series([1]) @@ -32,7 +32,7 @@ def test_zeros(): def test_empty_x(): with pytest.raises(RuntimeError): - distance = gis.cpp_directed_hausdorff_distance( + distance = gis.directed_hausdorff_distance( cudf.Series(), cudf.Series([0]), cudf.Series([0]) @@ -40,7 +40,7 @@ def test_empty_x(): def test_empty_y(): with pytest.raises(RuntimeError): - distance = gis.cpp_directed_hausdorff_distance( + distance = gis.directed_hausdorff_distance( cudf.Series([0]), cudf.Series(), cudf.Series([0]) @@ -48,7 +48,7 @@ def test_empty_y(): def test_empty_counts(): with pytest.raises(RuntimeError): - distance = gis.cpp_directed_hausdorff_distance( + distance = gis.directed_hausdorff_distance( cudf.Series([0]), cudf.Series([0]), cudf.Series() @@ -67,7 +67,7 @@ def test_large(): pnt_x = cudf.Series(py_x) pnt_y = cudf.Series(py_y) cnt = cudf.Series(py_cnt) - distance=gis.cpp_directed_hausdorff_distance(pnt_x,pnt_y,cnt) + distance=gis.directed_hausdorff_distance(pnt_x,pnt_y,cnt) num_set=len(cnt) matrix=distance.data.to_array().reshape(num_set,num_set) @@ -75,14 +75,14 @@ def test_large(): assert np.allclose(distance.data.to_array(), expect) def test_count_one(): - distance = gis.cpp_directed_hausdorff_distance( + distance = gis.directed_hausdorff_distance( cudf.Series([0.0, 0.0]), cudf.Series([0.0, 1.0]), cudf.Series([1, 1])) assert_eq(cudf.Series([0, 1.0, 1, 0]), cudf.Series(distance)) def test_count_two(): - distance = gis.cpp_directed_hausdorff_distance( + distance = gis.directed_hausdorff_distance( cudf.Series([0.0, 0.0, 1.0, 0.0]), cudf.Series([0.0, -1.0, 1.0, -1.0]), cudf.Series([2, 2])) @@ -104,7 +104,7 @@ def test_values(): pnt_x =cudf.Series(py_x) pnt_y= cudf.Series(py_y) cnt= cudf.Series(py_cnt) - distance=gis.cpp_directed_hausdorff_distance(pnt_x,pnt_y,cnt) + distance=gis.directed_hausdorff_distance(pnt_x,pnt_y,cnt) num_set=len(cnt) matrix=distance.data.to_array().reshape(num_set,num_set) diff --git a/python/cuspatial/cuspatial/tests/test_haversine_distance.py b/python/cuspatial/cuspatial/tests/test_haversine_distance.py index 7fa87bf7f..476cf2355 100644 --- a/python/cuspatial/cuspatial/tests/test_haversine_distance.py +++ b/python/cuspatial/cuspatial/tests/test_haversine_distance.py @@ -12,10 +12,10 @@ import cudf from cudf.core import column from cudf.tests.utils import assert_eq -import cuspatial._lib.spatial as gis +import cuspatial.core.gis as gis def test_zeros(): - distance = gis.cpp_haversine_distance( + distance = gis.haversine_distance( cudf.Series([0.0]), cudf.Series([0.0]), cudf.Series([0.0]), @@ -25,7 +25,7 @@ def test_zeros(): def test_empty_x1(): with pytest.raises(RuntimeError): - distance = gis.cpp_haversine_distance( + distance = gis.haversine_distance( cudf.Series(), cudf.Series([0]), cudf.Series([0]), @@ -34,7 +34,7 @@ def test_empty_x1(): def test_empty_y1(): with pytest.raises(RuntimeError): - distance = gis.cpp_haversine_distance( + distance = gis.haversine_distance( cudf.Series([0]), cudf.Series(), cudf.Series([0]), @@ -43,7 +43,7 @@ def test_empty_y1(): def test_empty_x2(): with pytest.raises(RuntimeError): - distance = gis.cpp_haversine_distance( + distance = gis.haversine_distance( cudf.Series([0]), cudf.Series([0]), cudf.Series([0]), @@ -52,7 +52,7 @@ def test_empty_x2(): def test_empty_y2(): with pytest.raises(RuntimeError): - distance = gis.cpp_haversine_distance( + distance = gis.haversine_distance( cudf.Series([0]), cudf.Series([0]), cudf.Series([0]), @@ -76,7 +76,7 @@ def test_triple(): pnt_y1.append(cities[i][1]) pnt_x2.append(cities[j][0]) pnt_y2.append(cities[j][1]) - distance = gis.cpp_haversine_distance( + distance = gis.haversine_distance( cudf.Series(pnt_x1), cudf.Series(pnt_y1), cudf.Series(pnt_x2), diff --git a/python/cuspatial/cuspatial/tests/test_lonlat2coord.py b/python/cuspatial/cuspatial/tests/test_lonlat2coord.py index eabe5640d..367d630c3 100644 --- a/python/cuspatial/cuspatial/tests/test_lonlat2coord.py +++ b/python/cuspatial/cuspatial/tests/test_lonlat2coord.py @@ -4,7 +4,7 @@ import cudf from cudf.tests.utils import assert_eq import numpy as np -import cuspatial._lib.spatial as gis +from cuspatial.core import gis """ GPU accelerated coordinate transformation test: (log/lat)==>(x/y), relative to a camera origin @@ -14,28 +14,28 @@ def test_camera_oob_0(): with pytest.raises(RuntimeError): - x, y = gis.cpp_lonlat2coord(-200, 0, + x, y = gis.lonlat_to_xy_km_coordinates(-200, 0, cudf.Series([0]), cudf.Series([0]) ) def test_camera_oob_1(): with pytest.raises(RuntimeError): - x, y = gis.cpp_lonlat2coord(200, 0, + x, y = gis.lonlat_to_xy_km_coordinates(200, 0, cudf.Series([0]), cudf.Series([0]) ) def test_camera_oob_2(): with pytest.raises(RuntimeError): - x, y = gis.cpp_lonlat2coord(0, -100, + x, y = gis.lonlat_to_xy_km_coordinates(0, -100, cudf.Series([0]), cudf.Series([0]) ) def test_camera_oob_3(): with pytest.raises(RuntimeError): - x, y = gis.cpp_lonlat2coord(0, 100, + x, y = gis.lonlat_to_xy_km_coordinates(0, 100, cudf.Series([0]), cudf.Series([0]) ) @@ -44,7 +44,7 @@ def test_camera_oob_3(): def test_camera_corners(corner): x = [-180, 180, -180, 180] y = [-90, 90, 90, -90] - x, y = gis.cpp_lonlat2coord(x[corner], y[corner], + x, y = gis.lonlat_to_xy_km_coordinates(x[corner], y[corner], cudf.Series(x[corner]), cudf.Series(y[corner]) ) @@ -52,7 +52,7 @@ def test_camera_corners(corner): assert y[0] == 0 def test_longest_distance(): - x, y = gis.cpp_lonlat2coord(-180, -90, + x, y = gis.lonlat_to_xy_km_coordinates(-180, -90, cudf.Series([180]), cudf.Series([90]) ) @@ -60,7 +60,7 @@ def test_longest_distance(): assert y[0] == -20000.0 def test_half_distance(): - x, y = gis.cpp_lonlat2coord(-180, -90, + x, y = gis.lonlat_to_xy_km_coordinates(-180, -90, cudf.Series([0]), cudf.Series([0]) ) @@ -69,13 +69,13 @@ def test_half_distance(): def test_missing_coords(): with pytest.raises(RuntimeError): - x, y = gis.cpp_lonlat2coord(-180, -90, + x, y = gis.lonlat_to_xy_km_coordinates(-180, -90, cudf.Series(), cudf.Series([0]) ) def test_zeros(): - coords_x, coords_y = gis.cpp_lonlat2coord( + coords_x, coords_y = gis.lonlat_to_xy_km_coordinates( 0.0, 0.0, cudf.Series([0.0]), @@ -93,6 +93,6 @@ def test_values(): py_lat=cudf.Series([42.49207437, 42.49202408,42.49266787]) #note: x/y coordinates in killometers -km - x,y=gis.cpp_lonlat2coord(cam_lon, cam_lat, py_lon, py_lat) + x,y=gis.lonlat_to_xy_km_coordinates(cam_lon, cam_lat, py_lon, py_lat) print(cudf.Series(x)) print(cudf.Series(y)) From 0015a266174dae66ee091860b3bea5bdcf1d8efd Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Fri, 6 Sep 2019 08:56:45 -0500 Subject: [PATCH 5/9] Trajectory python API --- python/cuspatial/cuspatial/core/gis.py | 2 +- python/cuspatial/cuspatial/core/trajectory.py | 128 ++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) diff --git a/python/cuspatial/cuspatial/core/gis.py b/python/cuspatial/cuspatial/core/gis.py index 9441b0808..63207a621 100644 --- a/python/cuspatial/cuspatial/core/gis.py +++ b/python/cuspatial/cuspatial/core/gis.py @@ -1,4 +1,4 @@ -# COPYRIGHT 2019 NVIDIA +# Copyright (c) 2019, NVIDIA CORPORATION. from cuspatial._lib.spatial import ( cpp_directed_hausdorff_distance, diff --git a/python/cuspatial/cuspatial/core/trajectory.py b/python/cuspatial/cuspatial/core/trajectory.py index e69de29bb..904626ee4 100644 --- a/python/cuspatial/cuspatial/core/trajectory.py +++ b/python/cuspatial/cuspatial/core/trajectory.py @@ -0,0 +1,128 @@ +# Copyright (c) 2019, NVIDIA CORPORATION. + +import cudf +import warnings +from cuspatial._lib.trajectory import ( + cpp_subset_trajectory_id, + cpp_trajectory_spatial_bounds, + cpp_derive_trajectories, + cpp_trajectory_distance_and_speed, +) + +warnings.warn("Duplicates cuDF functionality", DeprecationWarning) +def subset_trajectory_id(trajectory_ids, in_x, in_y, point_ids, timestamps): + """ + Deprecated + """ + return cpp_subset_trajectory_id( + trajectory_ids, + in_x, + in_y, + point_ids, + timestamps + ) + +def spatial_bounds( + x_coords, y_coords, trajectory_size, trajectory_end_position): + """ Compute the bounding boxes of sets of trajectories. + + Parameters + ---------- + {params} + + Examples + -------- + >>> result = trajectory.spatial_bounds( + >>> cudf.Series([0, 2, 1, 3, 2]), + >>> cudf.Series([0, 2, 1, 3, 2]), + >>> cudf.Series([2, 3]), + >>> cudf.Series([2, 5]), + >>> ) + >>> print(result) + x1 y1 x2 y2 + 0 0.0 0.0 2.0 2.0 + 1 1.0 1.0 3.0 3.0 + """ + return cpp_trajectory_spatial_bounds( + x_coords, + y_coords, + trajectory_size, + trajectory_end_position + ) + +def derive(x_coords, y_coords, object_ids, timestamps): + """ Derive trajectories from points, timestamps, and ids. + Parameters + ---------- + {params} + + Returns + ------- + result_tuple : tuple (number of discovered trajectories, + DataFrame + id, length, and positions of trajectories for feeding into + compute_distance_and_speed + + Examples + -------- + import cudf + num_trajectories, result = trajectory.derive( + cudf.Series([0, 1, 2, 3]), + cudf.Series([0, 0, 1, 1]) + cudf.Series([0, 0, 1, 1]) + cudf.Series([0, 10, 0, 10]) + ) + print(num_trajectories) + 2 + print(result) + trajectory_id length position + 0 0 2 2 + 1 1 2 4) + """ + return cpp_derive_trajectories( + x_coords, + y_coords, + object_ids, + timestamps + ) + +def distance_and_speed(x_coords, y_coords, timestamps, length, position): + """ Compute the distance travelled and speed of sets of trajectories + + Parameters + ---------- + {params} + + Returns + ------- + result : DataFrame + meters - travelled distance of trajectory + speed - speed in m/sec of trajectory + + Examples + -------- + Compute the distance and speed of the above derived trajectories + result = trajectory.distance_and_speed(x, y, timestamps, + result['length'], + result['position']) + print(result) + meters speed + trajectory_id + 0 1000.0 100000.000000 + 1 1000.0 111111.109375 + """ + result = cpp_trasectory_distance_and_speed( + x_coords, + y_coords, + timestamps, + length, + position + ) + df = cudf.DataFrame({ + 'meters': result[0], + 'speed': result[1] + }) + df.index.name = 'trajectory_id' + return df + + From 522bf0887fff6af699370d5f97ea81173bb1480b Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Fri, 6 Sep 2019 09:10:53 -0500 Subject: [PATCH 6/9] Use trajectory package for traj tests. --- python/cuspatial/cuspatial/core/trajectory.py | 2 +- python/cuspatial/cuspatial/tests/test_traj.py | 76 ++++++++++--------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/python/cuspatial/cuspatial/core/trajectory.py b/python/cuspatial/cuspatial/core/trajectory.py index 904626ee4..40f058b29 100644 --- a/python/cuspatial/cuspatial/core/trajectory.py +++ b/python/cuspatial/cuspatial/core/trajectory.py @@ -111,7 +111,7 @@ def distance_and_speed(x_coords, y_coords, timestamps, length, position): 0 1000.0 100000.000000 1 1000.0 111111.109375 """ - result = cpp_trasectory_distance_and_speed( + result = cpp_trajectory_distance_and_speed( x_coords, y_coords, timestamps, diff --git a/python/cuspatial/cuspatial/tests/test_traj.py b/python/cuspatial/cuspatial/tests/test_traj.py index c83a5b66f..054c983c9 100644 --- a/python/cuspatial/cuspatial/tests/test_traj.py +++ b/python/cuspatial/cuspatial/tests/test_traj.py @@ -8,10 +8,10 @@ import cudf from cudf.tests.utils import assert_eq import numpy as np -import cuspatial._lib.trajectory as traj +from cuspatial.core import trajectory -def test_subset_trajectory_id_zeros(): - result = traj.cpp_subset_trajectory_id( +def test_subset_id_zeros(): + result = trajectory.subset_trajectory_id( cudf.Series([0]), cudf.Series([0]), cudf.Series([0]), @@ -22,8 +22,8 @@ def test_subset_trajectory_id_zeros(): 'ids': cudf.Series([0]).astype('int32'), 'timestamp': cudf.Series([0]).astype('datetime64[ms]')})) -def test_subset_trajectory_id_ones(): - result = traj.cpp_subset_trajectory_id( +def test_subset_id_ones(): + result = trajectory.subset_trajectory_id( cudf.Series([1]), cudf.Series([1]), cudf.Series([1]), @@ -34,9 +34,9 @@ def test_subset_trajectory_id_ones(): 'ids': cudf.Series([1]).astype('int32'), 'timestamp': cudf.Series([1]).astype('datetime64[ms]')})) -def test_subset_trajectory_id_random(): +def test_subset_id_random(): np.random.seed(0) - result = traj.cpp_subset_trajectory_id( + result = trajectory.subset_trajectory_id( cudf.Series(np.random.randint(0, 10, 10)), cudf.Series(np.random.randint(0, 10, 10)), cudf.Series(np.random.randint(0, 10, 10)), @@ -52,7 +52,7 @@ def test_subset_trajectory_id_random(): ).astype('datetime64[ms]')})) def test_spatial_bounds_zeros(): - result = traj.cpp_trajectory_spatial_bounds( + result = trajectory.spatial_bounds( cudf.Series([0]), cudf.Series([0]), cudf.Series([0]), @@ -65,7 +65,7 @@ def test_spatial_bounds_zeros(): })) def test_spatial_bounds_ones(): - result = traj.cpp_trajectory_spatial_bounds( + result = trajectory.spatial_bounds( cudf.Series([1]), cudf.Series([1]), cudf.Series([1]), @@ -78,7 +78,7 @@ def test_spatial_bounds_ones(): })) def test_spatial_bounds_zero_to_one(): - result = traj.cpp_trajectory_spatial_bounds( + result = trajectory.spatial_bounds( cudf.Series([0, 0]), cudf.Series([0, 1]), cudf.Series([2]), @@ -91,7 +91,7 @@ def test_spatial_bounds_zero_to_one(): })) def test_spatial_bounds_zero_to_one_xy(): - result = traj.cpp_trajectory_spatial_bounds( + result = trajectory.spatial_bounds( cudf.Series([0, 1]), cudf.Series([0, 1]), cudf.Series([2]), @@ -104,7 +104,7 @@ def test_spatial_bounds_zero_to_one_xy(): })) def test_spatial_bounds_subsetted(): - result = traj.cpp_trajectory_spatial_bounds( + result = trajectory.spatial_bounds( cudf.Series([0, 1, -1, 2]), cudf.Series([0, 1, -1, 2]), cudf.Series([2, 2]), @@ -117,7 +117,7 @@ def test_spatial_bounds_subsetted(): })) def test_spatial_bounds_intersected(): - result = traj.cpp_trajectory_spatial_bounds( + result = trajectory.spatial_bounds( cudf.Series([0, 2, 1, 3]), cudf.Series([0, 2, 1, 3]), cudf.Series([2, 2]), @@ -130,7 +130,7 @@ def test_spatial_bounds_intersected(): })) def test_spatial_bounds_two_and_three(): - result = traj.cpp_trajectory_spatial_bounds( + result = trajectory.spatial_bounds( cudf.Series([0, 2, 1, 3, 2]), cudf.Series([0, 2, 1, 3, 2]), cudf.Series([2, 3]), @@ -144,7 +144,7 @@ def test_spatial_bounds_two_and_three(): def test_derive_trajectories_zeros(): - num_trajectories = traj.cpp_derive_trajectories( + num_trajectories = trajectory.derive( cudf.Series([0]), cudf.Series([0]), cudf.Series([0]), @@ -158,7 +158,7 @@ def test_derive_trajectories_zeros(): })) def test_derive_trajectories_ones(): - num_trajectories = traj.cpp_derive_trajectories( + num_trajectories = trajectory.derive( cudf.Series([1]), cudf.Series([1]), cudf.Series([1]), @@ -172,7 +172,7 @@ def test_derive_trajectories_ones(): })) def test_derive_trajectories_two(): - num_trajectories = traj.cpp_derive_trajectories( + num_trajectories = trajectory.derive( cudf.Series([0, 1]), cudf.Series([0, 1]), cudf.Series([0, 1]), @@ -187,7 +187,7 @@ def test_derive_trajectories_two(): def test_derive_trajectories_many(): np.random.seed(0) - num_trajectories = traj.cpp_derive_trajectories( + num_trajectories = trajectory.derive( cudf.Series(np.random.randint(0, 10, 10)), cudf.Series(np.random.randint(0, 10, 10)), cudf.Series(np.random.randint(0, 10, 10)), @@ -200,52 +200,52 @@ def test_derive_trajectories_many(): 'position': cudf.Series([2, 4, 5, 7, 8, 10]).astype('int32'), })) -def test_trajectory_distance_and_speed_zeros(): - dist, speed = traj.cpp_trajectory_distance_and_speed( +def test_distance_and_speed_zeros(): + result = trajectory.distance_and_speed( cudf.Series([0]), cudf.Series([0]), cudf.Series([0]), cudf.Series([0]), cudf.Series([0]), ) - assert_eq(dist, cudf.Series([-2.0])) - assert_eq(speed, cudf.Series([-2.0])) + assert_eq(result['meters'], cudf.Series([-2.0]), check_names=False) + assert_eq(result['speed'], cudf.Series([-2.0]), check_names=False) -def test_trajectory_distance_and_speed_ones(): - dist, speed = traj.cpp_trajectory_distance_and_speed( +def test_distance_and_speed_ones(): + result = trajectory.distance_and_speed( cudf.Series([1]), cudf.Series([1]), cudf.Series([1]), cudf.Series([1]), cudf.Series([1]), ) - assert_eq(dist, cudf.Series([-2.0])) - assert_eq(speed, cudf.Series([-2.0])) + assert_eq(result['meters'], cudf.Series([-2.0]), check_names=False) + assert_eq(result['speed'], cudf.Series([-2.0]), check_names=False) -def test_one_trajectory_one_meter_one_second(): - dist, speed = traj.cpp_trajectory_distance_and_speed( +def test_one_one_meter_one_second(): + result = trajectory.distance_and_speed( cudf.Series([0.0, 0.001]), cudf.Series([0.0, 0.0]), cudf.Series([0, 1000]), cudf.Series([2]), cudf.Series([2]), ) - assert_eq(dist, cudf.Series([1.0])) - assert_eq(speed, cudf.Series([1.0])) + assert_eq(result['meters'], cudf.Series([1.0]), check_names=False) + assert_eq(result['speed'], cudf.Series([1.0]), check_names=False) def test_two_trajectories_one_meter_one_second(): - dist, speed = traj.cpp_trajectory_distance_and_speed( + result = trajectory.distance_and_speed( cudf.Series([0.0, 0.001, 0.0, 0.0]), cudf.Series([0.0, 0.0, 0.0, 0.001]), cudf.Series([0, 1000, 0, 1000]), cudf.Series([2, 2]), cudf.Series([2, 4]), ) - assert_eq(dist, cudf.Series([1.0, 1.0])) - assert_eq(speed, cudf.Series([1.0, 1.0])) + assert_eq(result['meters'], cudf.Series([1.0, 1.0]), check_names=False) + assert_eq(result['speed'], cudf.Series([1.0, 1.0]), check_names=False) -def test_trajectory_distance_and_speed_single_trajectory(): - dist, speed = traj.cpp_trajectory_distance_and_speed( +def test_distance_and_speed_single_trajectory(): + result = trajectory.distance_and_speed( cudf.Series([ 1.0, 2.0, 3.0, 5.0, 7.0, 1.0, 2.0, 3.0, 6.0, 0.0, 3.0, 6.0]), cudf.Series([ @@ -254,5 +254,7 @@ def test_trajectory_distance_and_speed_single_trajectory(): cudf.Series([5, 4, 3]), cudf.Series([5, 9, 12]), ) - assert_eq(dist, cudf.Series([7892.922363, 6812.55908203125, 8485.28125])) - assert_eq(speed, cudf.Series([1973230.625, 2270853., 4242640.5])) # fast! + assert_eq(result['meters'], cudf.Series( + [7892.922363, 6812.55908203125, 8485.28125]), check_names=False) + assert_eq(result['speed'], cudf.Series( + [1973230.625, 2270853., 4242640.5]), check_names=False) # fast! From 43a7dc69bf0077186a19c154d893d47351046405 Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Fri, 6 Sep 2019 09:12:20 -0500 Subject: [PATCH 7/9] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2fa72de2..748ddc7fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - PR #7 Initial code - PR #18 Python initial unit tests and bindings +- PR #32 Python API first pass ## Improvements From 25085480f62fa2d7c783ed8b5ea78b8eaeba1bc2 Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Fri, 6 Sep 2019 09:46:20 -0500 Subject: [PATCH 8/9] clean up test files --- .../cuspatial/tests/test_hausdorff_distance.py | 14 -------------- .../cuspatial/tests/test_haversine_distance.py | 9 +-------- .../cuspatial/cuspatial/tests/test_lonlat2coord.py | 6 ------ python/cuspatial/cuspatial/tests/test_pip.py | 2 +- python/cuspatial/cuspatial/tests/test_traj.py | 4 ---- 5 files changed, 2 insertions(+), 33 deletions(-) diff --git a/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py b/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py index f92ca9bf6..bff42a35d 100644 --- a/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py +++ b/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py @@ -1,19 +1,5 @@ # Copyright (c) 2019, NVIDIA CORPORATION. -""" -A toy example to demonstrate how to convert python arrays into cuSpatial inputs, -invoke the GPU accelerated directed Hausdorff distance computing function in -cuSpatial, convert the results back to python array(s) again to be feed into -scipy clustering APIs. - -For the toy example, by desgin, both AgglomerativeClustering and DBSCAN cluster -the 2nd and third trajectories into one cluster while leaving the first -trajectory as the second cluster. - -To run the demo, first install scipy and scikit-learn -by "conda install -c conda-forge scipy scikit-learn" under cudf_dev environment -""" - import pytest import numpy as np import time diff --git a/python/cuspatial/cuspatial/tests/test_haversine_distance.py b/python/cuspatial/cuspatial/tests/test_haversine_distance.py index 476cf2355..417b6e334 100644 --- a/python/cuspatial/cuspatial/tests/test_haversine_distance.py +++ b/python/cuspatial/cuspatial/tests/test_haversine_distance.py @@ -1,18 +1,11 @@ # Copyright (c) 2019, NVIDIA CORPORATION. -""" -GPU-accelerated Haversine distance computation among three cities: New York, Paris and Sydney -Results match https://www.vcalc.com/wiki/vCalc/Haversine+-+Distance - -Note: make sure cudf_dev conda environment is activated -""" - import pytest import numpy as np import cudf from cudf.core import column from cudf.tests.utils import assert_eq -import cuspatial.core.gis as gis +from cuspatial.core import gis def test_zeros(): distance = gis.haversine_distance( diff --git a/python/cuspatial/cuspatial/tests/test_lonlat2coord.py b/python/cuspatial/cuspatial/tests/test_lonlat2coord.py index 367d630c3..696ed7159 100644 --- a/python/cuspatial/cuspatial/tests/test_lonlat2coord.py +++ b/python/cuspatial/cuspatial/tests/test_lonlat2coord.py @@ -6,12 +6,6 @@ import numpy as np from cuspatial.core import gis -""" -GPU accelerated coordinate transformation test: (log/lat)==>(x/y), relative to a camera origin - -Note: make sure cudf_dev conda environment is activated -""" - def test_camera_oob_0(): with pytest.raises(RuntimeError): x, y = gis.lonlat_to_xy_km_coordinates(-200, 0, diff --git a/python/cuspatial/cuspatial/tests/test_pip.py b/python/cuspatial/cuspatial/tests/test_pip.py index cc79e5e1a..6f66e2729 100644 --- a/python/cuspatial/cuspatial/tests/test_pip.py +++ b/python/cuspatial/cuspatial/tests/test_pip.py @@ -4,7 +4,7 @@ import cudf from cudf.tests.utils import assert_eq import numpy as np -import cuspatial.core.gis as gis +from cuspatial.core import gis def test_missing_0(): with pytest.raises(RuntimeError): diff --git a/python/cuspatial/cuspatial/tests/test_traj.py b/python/cuspatial/cuspatial/tests/test_traj.py index 054c983c9..c38caca17 100644 --- a/python/cuspatial/cuspatial/tests/test_traj.py +++ b/python/cuspatial/cuspatial/tests/test_traj.py @@ -1,9 +1,5 @@ # Copyright (c) 2019, NVIDIA CORPORATION. -""" -GPU-based coordinate transformation demo: (log/lat)==>(x/y), relative to a camera origin -""" - import pytest import cudf from cudf.tests.utils import assert_eq From 3c83afb9ed1c84d448a9be121b057b99f6612aa0 Mon Sep 17 00:00:00 2001 From: "H. Thomson Comer" Date: Fri, 6 Sep 2019 10:44:39 -0500 Subject: [PATCH 9/9] More cleanup, updating, fix the demo, add soa readers --- python/cuspatial/cuspatial/core/gis.py | 6 +++- python/cuspatial/cuspatial/io/soa.py | 32 +++++++++++++---- .../cuspatial/tests/test_lonlat2coord.py | 35 +++++++++---------- .../cuspatial/demos/traj_test_soa_locust.py | 18 ++++------ 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/python/cuspatial/cuspatial/core/gis.py b/python/cuspatial/cuspatial/core/gis.py index 63207a621..703e51580 100644 --- a/python/cuspatial/cuspatial/core/gis.py +++ b/python/cuspatial/cuspatial/core/gis.py @@ -1,5 +1,6 @@ # Copyright (c) 2019, NVIDIA CORPORATION. +from cudf import DataFrame from cuspatial._lib.spatial import ( cpp_directed_hausdorff_distance, cpp_haversine_distance, @@ -61,7 +62,10 @@ def lonlat_to_xy_km_coordinates(camera_lon, camera_lat, lon_coords, lat_coords): returns DataFrame: 'x', 'y' columns for new km positions of coords """ - return cpp_lonlat2coord(camera_lon, camera_lat, lon_coords, lat_coords) + result = cpp_lonlat2coord(camera_lon, camera_lat, lon_coords, lat_coords) + return DataFrame({'x': result[0], + 'y': result[1] + }) def point_in_polygon_bitmap(x_points, y_points, polygon_ids, polygon_end_indices, polygons_x, polygons_y): diff --git a/python/cuspatial/cuspatial/io/soa.py b/python/cuspatial/cuspatial/io/soa.py index aa25d7433..3649fb63d 100644 --- a/python/cuspatial/cuspatial/io/soa.py +++ b/python/cuspatial/cuspatial/io/soa.py @@ -1,16 +1,36 @@ -# COPYRIGHT 2019 NVIDIA +# Copyright (c) 2019, NVIDIA CORPORATION. + +from cudf import Series, DataFrame +from cuspatial._lib.soa_readers import ( + cpp_read_uint_soa, + cpp_read_ts_soa, + cpp_read_pnt_lonlat_soa, + cpp_read_pnt_xy_soa, + cpp_read_polygon_soa +) def read_uint(filename): - pass + return Series(cpp_read_uint_soa(filename)) def read_ts(filename): - pass + return Series(cpp_read_ts_soa(filename)) def read_points_lonlat(filename): - pass + result = cpp_read_pnt_lonlat_soa(filename) + return DataFrame({'lon': result[0], + 'lat': result[1] + }) def read_points_xy_km(filename): - pass + result = cpp_read_pnt_xy_soa(filename) + return DataFrame({'x': result[0], + 'y': result[1] + }) def read_polygon(filename): - pass + result = cpp_read_polygon_soa(filename) + return DataFrame({'f_pos': result[0], + 'r_pos': result[1], + 'x': result[2], + 'y': result[3] + }) diff --git a/python/cuspatial/cuspatial/tests/test_lonlat2coord.py b/python/cuspatial/cuspatial/tests/test_lonlat2coord.py index 696ed7159..a171451b2 100644 --- a/python/cuspatial/cuspatial/tests/test_lonlat2coord.py +++ b/python/cuspatial/cuspatial/tests/test_lonlat2coord.py @@ -8,28 +8,28 @@ def test_camera_oob_0(): with pytest.raises(RuntimeError): - x, y = gis.lonlat_to_xy_km_coordinates(-200, 0, + result = gis.lonlat_to_xy_km_coordinates(-200, 0, cudf.Series([0]), cudf.Series([0]) ) def test_camera_oob_1(): with pytest.raises(RuntimeError): - x, y = gis.lonlat_to_xy_km_coordinates(200, 0, + result = gis.lonlat_to_xy_km_coordinates(200, 0, cudf.Series([0]), cudf.Series([0]) ) def test_camera_oob_2(): with pytest.raises(RuntimeError): - x, y = gis.lonlat_to_xy_km_coordinates(0, -100, + result = gis.lonlat_to_xy_km_coordinates(0, -100, cudf.Series([0]), cudf.Series([0]) ) def test_camera_oob_3(): with pytest.raises(RuntimeError): - x, y = gis.lonlat_to_xy_km_coordinates(0, 100, + result = gis.lonlat_to_xy_km_coordinates(0, 100, cudf.Series([0]), cudf.Series([0]) ) @@ -38,46 +38,45 @@ def test_camera_oob_3(): def test_camera_corners(corner): x = [-180, 180, -180, 180] y = [-90, 90, 90, -90] - x, y = gis.lonlat_to_xy_km_coordinates(x[corner], y[corner], + result = gis.lonlat_to_xy_km_coordinates(x[corner], y[corner], cudf.Series(x[corner]), cudf.Series(y[corner]) ) - assert x[0] == 0 - assert y[0] == 0 + result = cudf.DataFrame({'x': [0], 'y': [0]}) def test_longest_distance(): - x, y = gis.lonlat_to_xy_km_coordinates(-180, -90, + result = gis.lonlat_to_xy_km_coordinates(-180, -90, cudf.Series([180]), cudf.Series([90]) ) - assert x[0] == -40000.0 - assert y[0] == -20000.0 + assert_eq(result, cudf.DataFrame({'x': [-40000.0], + 'y': [-20000.0] + })) def test_half_distance(): - x, y = gis.lonlat_to_xy_km_coordinates(-180, -90, + result = gis.lonlat_to_xy_km_coordinates(-180, -90, cudf.Series([0]), cudf.Series([0]) ) - assert x[0] == -14142.135623730952 - assert y[0] == -10000.0 + assert_eq(result, cudf.DataFrame({'x': [-14142.135623730952], + 'y': [-10000.0] + })) def test_missing_coords(): with pytest.raises(RuntimeError): - x, y = gis.lonlat_to_xy_km_coordinates(-180, -90, + result = gis.lonlat_to_xy_km_coordinates(-180, -90, cudf.Series(), cudf.Series([0]) ) def test_zeros(): - coords_x, coords_y = gis.lonlat_to_xy_km_coordinates( + result = gis.lonlat_to_xy_km_coordinates( 0.0, 0.0, cudf.Series([0.0]), cudf.Series([0.0]) ) - assert_eq(cudf.Series(coords_x), cudf.Series(coords_y)) - assert cudf.Series(coords_x)[0] == 0 - assert cudf.Series(coords_y)[0] == 0 + assert_eq(result, cudf.DataFrame({'x': [0.0], 'y': [0.0]})) def test_values(): cam_lon = -90.66511046 diff --git a/python/cuspatial/demos/traj_test_soa_locust.py b/python/cuspatial/demos/traj_test_soa_locust.py index ac71f2dc1..c4a4bbb66 100644 --- a/python/cuspatial/demos/traj_test_soa_locust.py +++ b/python/cuspatial/demos/traj_test_soa_locust.py @@ -10,7 +10,7 @@ import cuspatial._lib.soa_readers as readers import cuspatial.utils.traj_utils as tools -data_dir = "/home/jianting/cuspatial/data/" +data_dir = "./" df = pd.read_csv(data_dir + "its_camera_2.csv") this_cam = df.loc[df["cameraIdString"] == "HWY_20_AND_LOCUST"] cam_lon = np.double(this_cam.iloc[0]["originLon"]) @@ -30,17 +30,11 @@ y, m, d, hh, mm, ss, wd, yd, ms, pid = tools.get_ts_struct(ts_0) pnt_x, pnt_y = gis.cpp_lonlat2coord(cam_lon, cam_lat, pnt_lon, pnt_lat) -num_traj, tid, len, pos = traj.cpp_coord2traj(pnt_x, pnt_y, id, ts) - +num_traj, trajectories = traj.cpp_derive_trajectories(pnt_x, pnt_y, id, ts) +# = num_traj, tid, len, pos = y, m, d, hh, mm, ss, wd, yd, ms, pid = tools.get_ts_struct(ts_0) - -dist, speed = traj.cpp_traj_distspeed(pnt_x, pnt_y, ts, len, pos) +dist, speed = traj.cpp_trajectory_distance_and_speed(pnt_x, pnt_y, ts, trajectories['length'], trajectories['position']) print(dist.data.to_array()[0], speed.data.to_array()[0]) -x1, y1, x2, y2 = traj.cpp_traj_sbbox(pnt_x, pnt_y, len, pos) -print( - x1.data.to_array()[0], - x2.data.to_array()[0], - y1.data.to_array()[0], - y2.data.to_array()[0], -) +boxes = traj.cpp_trajectory_spatial_bounds(pnt_x, pnt_y, trajectories['length'], trajectories['position']) +print(boxes.head())