def test_empty(dtype): order, quadtree = cuspatial.quadtree_on_points( cudf.Series([], dtype=dtype), # x cudf.Series([], dtype=dtype), # y *bbox_1, # bbox 1, # scale 1, # max_depth 1, # min_size ) poly_bboxes = cuspatial.polygon_bounding_boxes( cudf.Series(), cudf.Series(), cudf.Series([], dtype=dtype), cudf.Series([], dtype=dtype), ) # empty should not throw intersections = cuspatial.join_quadtree_and_bounding_boxes( quadtree, poly_bboxes, *bbox_1, 1, 1, # bbox # scale # max_depth ) cudf.testing.assert_frame_equal( intersections, cudf.DataFrame({ "poly_offset": cudf.Series([], dtype=np.uint32), "quad_offset": cudf.Series([], dtype=np.uint32), }), )
def test_polygon_join_small(dtype): x_min = 0 x_max = 8 y_min = 0 y_max = 8 scale = 1 max_depth = 3 min_size = 12 points_x = small_points_x.astype(dtype) points_y = small_points_y.astype(dtype) poly_points_x = small_poly_xs.astype(dtype) poly_points_y = small_poly_ys.astype(dtype) point_indices, quadtree = cuspatial.quadtree_on_points( points_x, points_y, x_min, x_max, y_min, y_max, scale, max_depth, min_size, ) poly_bboxes = cuspatial.polygon_bounding_boxes( small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth, ) cudf.testing.assert_frame_equal( intersections, cudf.DataFrame({ "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), }), )
def test_two_points(dtype): order, quadtree = cuspatial.quadtree_on_points( cudf.Series([0.5, 1.5]).astype(dtype), # x cudf.Series([0.5, 1.5]).astype(dtype), # y *bbox_2, # bbox 1, # scale 1, # max_depth 1, # min_size ) assert_eq( quadtree, cudf.DataFrame({ "key": cudf.Series([0, 3], dtype=np.int32), "level": cudf.Series([0, 0], dtype=np.int8), "is_quad": cudf.Series([0, 0], dtype=np.bool_), "length": cudf.Series([1, 1], dtype=np.int32), "offset": cudf.Series([0, 1], dtype=np.int32), }), )
def test_one_point(dtype): order, quadtree = cuspatial.quadtree_on_points( cudf.Series([0.5]).astype(dtype), # x cudf.Series([0.5]).astype(dtype), # y *bbox_1, # bbox 1, # scale 1, # max_depth 1, # min_size ) cudf.testing.assert_frame_equal( quadtree, cudf.DataFrame({ "key": cudf.Series([0], dtype=np.uint32), "level": cudf.Series([0], dtype=np.uint8), "is_quad": cudf.Series([0], dtype=np.bool_), "length": cudf.Series([1], dtype=np.uint32), "offset": cudf.Series([0], dtype=np.uint32), }), )
def test_empty(): # empty should not throw order, quadtree = cuspatial.quadtree_on_points( cudf.Series([]), # x cudf.Series([]), # y *bbox_1, # bbox 1, # scale 1, # max_depth 1, # min_size ) assert_eq( quadtree, cudf.DataFrame({ "key": cudf.Series([], dtype=np.int32), "level": cudf.Series([], dtype=np.int8), "is_quad": cudf.Series([], dtype=np.bool_), "length": cudf.Series([], dtype=np.int32), "offset": cudf.Series([], dtype=np.int32), }), )
def get_updated_df_quadtree_pip(lat, lon, nodes_df): min_x, min_y, max_x, max_y = (nodes_df["x"].min(), nodes_df["y"].min(), nodes_df["x"].max(), nodes_df["y"].max()) max_depth = 6 min_size = 50 scale = max(max_x - min_x, max_y - min_y) // (1 << max_depth) point_indices, quadtree = cuspatial.quadtree_on_points( nodes_df.x, nodes_df.y, min_x, max_x, min_y, max_y, scale, max_depth, min_size, ) poly_offsets, ring_offsets = cudf.Series([0], index=["selection"]),[0] poly_bboxes = cuspatial.polygon_bounding_boxes( poly_offsets, ring_offsets, lat, lon, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( quadtree, poly_bboxes, min_x, max_x, min_y, max_y, scale, max_depth, ) polygons_and_points = cuspatial.quadtree_point_in_polygon( intersections, quadtree, point_indices, nodes_df.x, nodes_df.y, poly_offsets, ring_offsets, lat, lon, ) return nodes_df.loc[polygons_and_points.point_index]
def run_test_quadtree_point_to_nearest_polyline_small(dtype, expected_distances): x_min = 0 x_max = 8 y_min = 0 y_max = 8 scale = 1 max_depth = 3 min_size = 12 expansion_radius = 2.0 points_x = small_points_x.astype(dtype) points_y = small_points_y.astype(dtype) poly_points_x = small_poly_xs.astype(dtype) poly_points_y = small_poly_ys.astype(dtype) point_indices, quadtree = cuspatial.quadtree_on_points( points_x, points_y, x_min, x_max, y_min, y_max, scale, max_depth, min_size, ) poly_bboxes = cuspatial.polyline_bounding_boxes( small_ring_offsets, poly_points_x, poly_points_y, expansion_radius, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth, ) p2np_result = cuspatial.quadtree_point_to_nearest_polyline( intersections, quadtree, point_indices, points_x, points_y, small_ring_offsets, poly_points_x, poly_points_y, ) cudf.testing.assert_frame_equal( p2np_result, cudf.DataFrame({ "point_index": cudf.Series( [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, ], dtype=np.uint32, ), "polyline_index": cudf.Series( [ 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], dtype=np.uint32, ), "distance": cudf.Series(expected_distances, dtype=dtype), }), )
def test_quadtree_point_in_polygon_small(dtype): x_min = 0 x_max = 8 y_min = 0 y_max = 8 scale = 1 max_depth = 3 min_size = 12 points_x = small_points_x.astype(dtype) points_y = small_points_y.astype(dtype) poly_points_x = small_poly_xs.astype(dtype) poly_points_y = small_poly_ys.astype(dtype) point_indices, quadtree = cuspatial.quadtree_on_points( points_x, points_y, x_min, x_max, y_min, y_max, scale, max_depth, min_size, ) poly_bboxes = cuspatial.polygon_bounding_boxes( small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth, ) polygons_and_points = cuspatial.quadtree_point_in_polygon( intersections, quadtree, point_indices, points_x, points_y, small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y, ) cudf.testing.assert_frame_equal( polygons_and_points, cudf.DataFrame({ "polygon_index": cudf.Series( [3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 3], dtype=np.uint32, ), "point_index": cudf.Series( [ 28, 29, 30, 31, 32, 33, 34, 35, 45, 46, 47, 48, 49, 50, 51, 52, 54, 62, 60, ], dtype=np.uint32, ), }), )
def test_small_number_of_points(dtype): order, quadtree = cuspatial.quadtree_on_points( cudf.Series([ 1.9804558865545805, 0.1895259128530169, 1.2591725716781235, 0.8178039499335275, 0.48171647380517046, 1.3890664414691907, 0.2536015260915061, 3.1907684812039956, 3.028362149164369, 3.918090468102582, 3.710910700915217, 3.0706987088385853, 3.572744183805594, 3.7080407833612004, 3.70669993057843, 3.3588457228653024, 2.0697434332621234, 2.5322042870739683, 2.175448214220591, 2.113652420701984, 2.520755151373394, 2.9909779614491687, 2.4613232527836137, 4.975578758530645, 4.07037627210835, 4.300706849071861, 4.5584381091040616, 4.822583857757069, 4.849847745942472, 4.75489831780737, 4.529792124514895, 4.732546857961497, 3.7622247877537456, 3.2648444465931474, 3.01954722322135, 3.7164018490892348, 3.7002781846945347, 2.493975723955388, 2.1807636574967466, 2.566986568683904, 2.2006520196663066, 2.5104987015171574, 2.8222482218882474, 2.241538022180476, 2.3007438625108882, 6.0821276168848994, 6.291790729917634, 6.109985464455084, 6.101327777646798, 6.325158445513714, 6.6793884701899, 6.4274219368674315, 6.444584786789386, 7.897735998643542, 7.079453687660189, 7.430677191305505, 7.5085184104988, 7.886010001346151, 7.250745898479374, 7.769497359206111, 1.8703303641352362, 1.7015273093278767, 2.7456295127617385, 2.2065031771469, 3.86008672302403, 1.9143371250907073, 3.7176098065039747, 0.059011873032214, 3.1162712022943757, 2.4264509160270813, 3.154282922203257, ]).astype(dtype), # x cudf.Series([ 1.3472225743317712, 0.5431061133894604, 0.1448705855995005, 0.8138440641113271, 1.9022922214961997, 1.5177694304735412, 1.8762161698642947, 0.2621847215928189, 0.027638405909631958, 0.3338651960183463, 0.9937713340192049, 0.9376313558467103, 0.33184908855075124, 0.09804238103130436, 0.7485845679979923, 0.2346381514128677, 1.1809465376402173, 1.419555755682142, 1.2372448404986038, 1.2774712415624014, 1.902015274420646, 1.2420487904041893, 1.0484414482621331, 0.9606291981013242, 1.9486902798139454, 0.021365525588281198, 1.8996548860019926, 0.3234041700489503, 1.9531893897409585, 0.7800065259479418, 1.942673409259531, 0.5659923375279095, 2.8709552313924487, 2.693039435509084, 2.57810040095543, 2.4612194182614333, 2.3345952955903906, 3.3999020934055837, 3.2296461832828114, 3.6607732238530897, 3.7672478678985257, 3.0668114607133137, 3.8159308233351266, 3.8812819070357545, 3.6045900851589048, 2.5470532680258002, 2.983311357415729, 2.2235950639628523, 2.5239201807166616, 2.8765450351723674, 2.5605928243991434, 2.9754616970668213, 2.174562817047202, 3.380784914178574, 3.063690547962938, 3.380489849365283, 3.623862886287816, 3.538128217886674, 3.4154469467473447, 3.253257011908445, 4.209727933188015, 7.478882372510933, 7.474216636277054, 6.896038613284851, 7.513564222799629, 6.885401350515916, 6.194330707468438, 5.823535317960799, 6.789029097334483, 5.188939408363776, 5.788316610960881, ]).astype(dtype), # y 0, # x_min 8, # x_max 0, # y_min 8, # y_max 1, # scale 3, # max_depth 12, # min_size ) assert_eq( quadtree, cudf.DataFrame({ "key": cudf.Series( [0, 1, 2, 0, 1, 3, 4, 7, 5, 6, 13, 14, 28, 31], dtype=np.int32, ), "level": cudf.Series([0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], dtype=np.int8), "is_quad": cudf.Series([1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0], dtype=np.bool_), "length": cudf.Series([3, 2, 11, 7, 2, 2, 9, 2, 9, 7, 5, 8, 8, 7], dtype=np.int32), "offset": cudf.Series( [3, 6, 60, 0, 8, 10, 36, 12, 7, 16, 23, 28, 45, 53], dtype=np.int32, ), }), )
def _createIndex(self, df, colName): out = cuspatial.quadtree_on_points(df[colName + 'X'], df[colName + 'Y'], 0, 1, 0, 1, 1, 15, 20) return out
def test_polyline_join_small(dtype): x_min = 0 x_max = 8 y_min = 0 y_max = 8 scale = 1 max_depth = 3 min_size = 12 expansion_radius = 2.0 points_x = small_points_x.astype(dtype) points_y = small_points_y.astype(dtype) poly_points_x = small_poly_xs.astype(dtype) poly_points_y = small_poly_ys.astype(dtype) point_indices, quadtree = cuspatial.quadtree_on_points( points_x, points_y, x_min, x_max, y_min, y_max, scale, max_depth, min_size, ) poly_bboxes = cuspatial.polyline_bounding_boxes( small_ring_offsets, poly_points_x, poly_points_y, expansion_radius, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth, ) assert_eq( intersections, cudf.DataFrame({ "poly_offset": cudf.Series( [ 3, 1, 2, 3, 3, 0, 1, 2, 3, 0, 3, 1, 2, 3, 1, 2, 1, 2, 0, 1, 3, ], dtype=np.uint32, ), "quad_offset": cudf.Series( [ 3, 8, 8, 8, 9, 10, 10, 10, 10, 11, 11, 6, 6, 6, 12, 12, 13, 13, 2, 2, 2, ], dtype=np.uint32, ), }), )