diff --git a/docs/source/user_guide/cuspatial_api_examples.ipynb b/docs/source/user_guide/cuspatial_api_examples.ipynb index f5b207541..073a2776e 100644 --- a/docs/source/user_guide/cuspatial_api_examples.ipynb +++ b/docs/source/user_guide/cuspatial_api_examples.ipynb @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "7265f9d2-9203-4da2-bbb2-b35c7f933641", "metadata": {}, "outputs": [], @@ -162,40 +162,54 @@ "tags": [] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/3038749724.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] - }, { "name": "stdout", "output_type": "stream", "text": [ - " pop_est continent name iso_a3 gdp_md_est \\\n", - "0 889953.0 Oceania Fiji FJI 5496 \n", - "1 58005463.0 Africa Tanzania TZA 63177 \n", - "2 603253.0 Africa W. Sahara ESH 907 \n", - "3 37589262.0 North America Canada CAN 1736425 \n", - "4 328239523.0 North America United States of America USA 21433226 \n", + " featurecla scalerank LABELRANK SOVEREIGNT SOV_A3 \\\n", + "0 Admin-0 country 1 6 Fiji FJI \n", + "1 Admin-0 country 1 3 United Republic of Tanzania TZA \n", + "2 Admin-0 country 1 7 Western Sahara SAH \n", + "3 Admin-0 country 1 2 Canada CAN \n", + "4 Admin-0 country 1 2 United States of America US1 \n", + "\n", + " ADM0_DIF LEVEL TYPE TLC ADMIN ... \\\n", + "0 0 2 Sovereign country 1 Fiji ... \n", + "1 0 2 Sovereign country 1 United Republic of Tanzania ... \n", + "2 0 2 Indeterminate 1 Western Sahara ... \n", + "3 0 2 Sovereign country 1 Canada ... \n", + "4 1 2 Country 1 United States of America ... \n", + "\n", + " FCLASS_TR FCLASS_ID FCLASS_PL FCLASS_GR FCLASS_IT \\\n", + "0 None None None None None \n", + "1 None None None None None \n", + "2 Unrecognized Unrecognized Unrecognized None None \n", + "3 None None None None None \n", + "4 None None None None None \n", + "\n", + " FCLASS_NL FCLASS_SE FCLASS_BD FCLASS_UA \\\n", + "0 None None None None \n", + "1 None None None None \n", + "2 Unrecognized None None None \n", + "3 None None None None \n", + "4 None None None None \n", "\n", " geometry \n", - "0 MULTIPOLYGON (((180.00000 -16.06713, 180.00000... \n", - "1 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... \n", + "0 MULTIPOLYGON (((180 -16.06713, 180 -16.55522, ... \n", + "1 POLYGON ((33.90371 -0.95, 34.07262 -1.05982, 3... \n", "2 POLYGON ((-8.66559 27.65643, -8.66512 27.58948... \n", - "3 MULTIPOLYGON (((-122.84000 49.00000, -122.9742... \n", - "4 MULTIPOLYGON (((-122.84000 49.00000, -120.0000... \n", + "3 MULTIPOLYGON (((-122.84 49, -122.97421 49.0025... \n", + "4 MULTIPOLYGON (((-122.84 49, -120 49, -117.0312... \n", + "\n", + "[5 rows x 169 columns]\n", "(GPU)\n", "\n" ] } ], "source": [ - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\n", - " \"naturalearth_lowres\"\n", - "))\n", + "host_dataframe = geopandas.read_file('https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_0_countries.zip')\n", + "host_dataframe = host_dataframe.set_crs(4326)\n", "gpu_dataframe = cuspatial.from_geopandas(host_dataframe)\n", "print(gpu_dataframe.head())" ] @@ -235,51 +249,44 @@ "name": "stdout", "output_type": "stream", "text": [ - " pop_est continent name iso_a3 gdp_md_est \\\n", - "103 38041754.0 Asia Afghanistan AFG 19291 \n", - "125 2854191.0 Europe Albania ALB 15279 \n", - "82 43053054.0 Africa Algeria DZA 171091 \n", - "74 31825295.0 Africa Angola AGO 88815 \n", - "159 4490.0 Antarctica Antarctica ATA 898 \n", - ".. ... ... ... ... ... \n", - "2 603253.0 Africa W. Sahara ESH 907 \n", - "157 29161922.0 Asia Yemen YEM 22581 \n", - "70 17861030.0 Africa Zambia ZMB 23309 \n", - "48 14645468.0 Africa Zimbabwe ZWE 21440 \n", - "73 1148130.0 Africa eSwatini SWZ 4471 \n", + " featurecla scalerank LABELRANK SOVEREIGNT SOV_A3 ADM0_DIF \\\n", + "103 Admin-0 country 1 3 Afghanistan AFG 0 \n", + "125 Admin-0 country 1 6 Albania ALB 0 \n", + "82 Admin-0 country 1 3 Algeria DZA 0 \n", + "74 Admin-0 country 1 3 Angola AGO 0 \n", + "159 Admin-0 country 1 4 Antarctica ATA 0 \n", + "\n", + " LEVEL TYPE TLC ADMIN ... FCLASS_TR FCLASS_ID \\\n", + "103 2 Sovereign country 1 Afghanistan ... None None \n", + "125 2 Sovereign country 1 Albania ... None None \n", + "82 2 Sovereign country 1 Algeria ... None None \n", + "74 2 Sovereign country 1 Angola ... None None \n", + "159 2 Indeterminate 1 Antarctica ... None None \n", + "\n", + " FCLASS_PL FCLASS_GR FCLASS_IT FCLASS_NL FCLASS_SE FCLASS_BD FCLASS_UA \\\n", + "103 None None None None None None None \n", + "125 None None None None None None None \n", + "82 None None None None None None None \n", + "74 None None None None None None None \n", + "159 None None None None None None None \n", "\n", " geometry \n", "103 POLYGON ((66.51861 37.36278, 67.07578 37.35614... \n", - "125 POLYGON ((21.02004 40.84273, 20.99999 40.58000... \n", - "82 POLYGON ((-8.68440 27.39574, -8.66512 27.58948... \n", - "74 MULTIPOLYGON (((12.99552 -4.78110, 12.63161 -4... \n", - "159 MULTIPOLYGON (((-48.66062 -78.04702, -48.15140... \n", - ".. ... \n", - "2 POLYGON ((-8.66559 27.65643, -8.66512 27.58948... \n", - "157 POLYGON ((52.00001 19.00000, 52.78218 17.34974... \n", - "70 POLYGON ((30.74001 -8.34001, 31.15775 -8.59458... \n", - "48 POLYGON ((31.19141 -22.25151, 30.65987 -22.151... \n", - "73 POLYGON ((32.07167 -26.73382, 31.86806 -27.177... \n", + "125 POLYGON ((21.02004 40.84273, 20.99999 40.58, 2... \n", + "82 POLYGON ((-8.6844 27.39574, -8.66512 27.58948,... \n", + "74 MULTIPOLYGON (((12.99552 -4.7811, 12.63161 -4.... \n", + "159 MULTIPOLYGON (((-48.66062 -78.04702, -48.1514 ... \n", "\n", - "[177 rows x 6 columns]\n", + "[5 rows x 169 columns]\n", "(GPU)\n", "\n" ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/567044009.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] } ], "source": [ - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", "gpu_dataframe = cuspatial.from_geopandas(host_dataframe)\n", - "continents_dataframe = gpu_dataframe.sort_values(\"name\")\n", - "print(continents_dataframe)" + "continents_dataframe = gpu_dataframe.sort_values(\"NAME\")\n", + "print(continents_dataframe.head())" ] }, { @@ -304,14 +311,6 @@ "tags": [] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/1940355512.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] - }, { "data": { "image/svg+xml": [ @@ -327,11 +326,10 @@ } ], "source": [ - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", "gpu_dataframe = cuspatial.from_geopandas(host_dataframe)\n", - "sorted_dataframe = gpu_dataframe.sort_values(\"name\")\n", - "host_dataframe = sorted_dataframe.to_geopandas()\n", - "host_dataframe['geometry'].iloc[0]" + "sorted_dataframe = gpu_dataframe.sort_values(\"NAME\")\n", + "sorted_dataframe = sorted_dataframe.to_geopandas()\n", + "sorted_dataframe['geometry'].iloc[0]" ] }, { @@ -542,18 +540,9 @@ "3 55.928917 37.144994 73.055417 45.586804\n", "4 12.182337 -13.257227 31.174149 5.256088\n" ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/1016569337.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] } ], "source": [ - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", "single_polygons = cuspatial.from_geopandas(\n", " host_dataframe['geometry'][host_dataframe['geometry'].type == \"Polygon\"]\n", ")\n", @@ -635,27 +624,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "0 POINT (112.174 -281.590)\n", + "0 POINT (112.174 -281.59)\n", "1 POINT (62.152 -280.852)\n", "2 POINT (-5.573 -257.391)\n", "3 POINT (-33.071 -243.849)\n", - "4 POINT (-98.002 -279.540)\n", + "4 POINT (-98.002 -279.54)\n", "dtype: geometry\n" ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/2658722012.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] } ], "source": [ - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", "gpu_dataframe = cuspatial.from_geopandas(host_dataframe)\n", - "afghanistan = gpu_dataframe['geometry'][gpu_dataframe['name'] == 'Afghanistan']\n", + "afghanistan = gpu_dataframe['geometry'][gpu_dataframe['NAME'] == 'Afghanistan']\n", "points = cuspatial.GeoSeries.from_points_xy(afghanistan.polygons.xy)\n", "projected = cuspatial.sinusoidal_projection(\n", " afghanistan.polygons.x.mean(),\n", @@ -764,14 +744,6 @@ "tags": [] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/491857862.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] - }, { "data": { "text/plain": [ @@ -789,10 +761,9 @@ } ], "source": [ - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", "gpu_dataframe = cuspatial.from_geopandas(host_dataframe)\n", "polygons_first = gpu_dataframe['geometry'][0:10]\n", - "polygons_second = gpu_dataframe['geometry'][10:20]\n", + "polygons_second = gpu_dataframe['geometry'][10:30]\n", "\n", "points_first = polygons_first.polygons.xy[0:1000]\n", "points_second = polygons_second.polygons.xy[0:1000]\n", @@ -826,27 +797,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " latitude longitude atlanta_lat atlanta_lng atlanta_dist\n", - "0 17.1167 -61.7833 33.749 -84.388 11961.556540\n", - "1 17.1333 -61.7833 33.749 -84.388 11963.392729\n", - "2 25.3330 55.5170 33.749 -84.388 12243.126130\n", - "3 25.2550 55.3640 33.749 -84.388 12233.867463\n", - "4 24.4330 54.6510 33.749 -84.388 12139.822218\n", - "5 24.2620 55.6090 33.749 -84.388 12124.483127\n", - "6 35.3170 69.0170 33.749 -84.388 13418.538383\n", - "7 34.2100 62.2280 33.749 -84.388 13258.725239\n", - "8 34.5660 69.2120 33.749 -84.388 13336.375942\n", - "9 31.5000 65.8500 33.749 -84.388 12976.749248\n", - "10 36.7167 3.2500 33.749 -84.388 13547.245294\n", - "11 30.5667 2.8667 33.749 -84.388 12866.528267\n", - "12 28.0500 9.6331 33.749 -84.388 12554.544289\n", - "13 22.8000 5.4331 33.749 -84.388 11990.825098\n", - "14 35.7297 0.6500 33.749 -84.388 13451.775999\n", - "15 36.9700 7.7900 33.749 -84.388 13553.372737\n", - "16 36.7800 3.0700 33.749 -84.388 13555.211584\n", - "17 36.8000 3.0300 33.749 -84.388 13557.641136\n", - "18 36.8000 3.0400 33.749 -84.388 13557.588738\n", - "19 36.7200 4.0500 33.749 -84.388 13543.496327\n" + " latitude longitude atlanta_lat atlanta_lng atlanta_dist\n", + "0 17.1167 -61.7833 33.749 -84.388 11961.556540\n", + "1 17.1333 -61.7833 33.749 -84.388 11963.392729\n", + "2 25.3330 55.5170 33.749 -84.388 12243.126130\n", + "3 25.2550 55.3640 33.749 -84.388 12233.867463\n", + "4 24.4330 54.6510 33.749 -84.388 12139.822218\n" ] } ], @@ -900,14 +856,6 @@ "tags": [] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/1097934054.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] - }, { "name": "stdout", "output_type": "stream", @@ -928,8 +876,6 @@ } ], "source": [ - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", - "\n", "gpu_boundaries = cuspatial.from_geopandas(host_dataframe.geometry.boundary)\n", "zeros = cuspatial.pairwise_linestring_distance(\n", " gpu_boundaries[0:50],\n", @@ -967,31 +913,46 @@ "tags": [] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/2846028812.py:2: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\")).to_crs(3857)\n" - ] - }, { "name": "stdout", "output_type": "stream", "text": [ - " pop_est continent name iso_a3 gdp_md_est \\\n", - "1 58005463.0 Africa Tanzania TZA 63177 \n", - "2 603253.0 Africa W. Sahara ESH 907 \n", - "5 18513930.0 Asia Kazakhstan KAZ 181665 \n", - "6 33580650.0 Asia Uzbekistan UZB 57921 \n", - "11 86790567.0 Africa Dem. Rep. Congo COD 50400 \n", + " featurecla scalerank LABELRANK SOVEREIGNT \\\n", + "1 Admin-0 country 1 3 United Republic of Tanzania \n", + "2 Admin-0 country 1 7 Western Sahara \n", + "5 Admin-0 country 1 3 Kazakhstan \n", + "6 Admin-0 country 1 3 Uzbekistan \n", + "11 Admin-0 country 1 2 Democratic Republic of the Congo \n", + "\n", + " SOV_A3 ADM0_DIF LEVEL TYPE TLC \\\n", + "1 TZA 0 2 Sovereign country 1 \n", + "2 SAH 0 2 Indeterminate 1 \n", + "5 KA1 1 1 Sovereignty 1 \n", + "6 UZB 0 2 Sovereign country 1 \n", + "11 COD 0 2 Sovereign country 1 \n", + "\n", + " ADMIN ... FCLASS_ID FCLASS_PL \\\n", + "1 United Republic of Tanzania ... None None \n", + "2 Western Sahara ... Unrecognized Unrecognized \n", + "5 Kazakhstan ... None None \n", + "6 Uzbekistan ... None None \n", + "11 Democratic Republic of the Congo ... None None \n", "\n", - " geometry border_distance \n", - "1 POLYGON ((3774143.866 -105758.362, 3792946.708... 8047.288391 \n", - "2 POLYGON ((-964649.018 3205725.605, -964597.245... 593137.492497 \n", - "5 POLYGON ((9724867.413 6311418.173, 9640131.701... 37091.213890 \n", - "6 POLYGON ((6230350.563 5057973.384, 6225978.591... 278633.467299 \n", - "11 POLYGON ((3266113.592 -501451.658, 3286149.877... 35812.988244 \n", + " FCLASS_GR FCLASS_IT FCLASS_NL FCLASS_SE FCLASS_BD FCLASS_UA \\\n", + "1 None None None None None None \n", + "2 None None Unrecognized None None None \n", + "5 None None None None None None \n", + "6 None None None None None None \n", + "11 None None None None None None \n", + "\n", + " geometry border_distance \n", + "1 POLYGON ((3774143.866 -105758.362, 3792946.708... 8047.288391 \n", + "2 POLYGON ((-964649.018 3205725.605, -964597.245... 593137.492497 \n", + "5 POLYGON ((9724867.413 6311418.173, 9640131.701... 37091.213890 \n", + "6 POLYGON ((6230350.563 5057973.384, 6225978.591... 278633.467299 \n", + "11 POLYGON ((3266113.592 -501451.658, 3286149.877... 35812.988244 \n", + "\n", + "[5 rows x 170 columns]\n", "(GPU)\n", "\n" ] @@ -999,8 +960,8 @@ ], "source": [ "# Convert input dataframe to Pseudo-Mercator projection.\n", - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\")).to_crs(3857)\n", - "polygons = host_dataframe[host_dataframe['geometry'].type == \"Polygon\"]\n", + "host_dataframe3857 = host_dataframe.to_crs(3857)\n", + "polygons = host_dataframe3857[host_dataframe3857['geometry'].type == \"Polygon\"]\n", "gpu_polygons = cuspatial.from_geopandas(polygons)\n", "# Extract mean_x and mean_y from each country\n", "mean_x = [gpu_polygons['geometry'].iloc[[ix]].polygons.x.mean() for ix in range(len(gpu_polygons))]\n", @@ -1037,142 +998,58 @@ }, "outputs": [ { - "name": "stderr", + "name": "stdout", "output_type": "stream", "text": [ - "/tmp/ipykernel_5364/3261459244.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_cities' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " cities = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_cities\")).to_crs(3857)\n", - "/tmp/ipykernel_5364/3261459244.py:2: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " countries = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\")).to_crs(3857)\n" + " featurecla scalerank LABELRANK SOVEREIGNT SOV_A3 \\\n", + "0 Admin-0 country 1 6 Fiji FJI \n", + "1 Admin-0 country 1 3 United Republic of Tanzania TZA \n", + "2 Admin-0 country 1 7 Western Sahara SAH \n", + "3 Admin-0 country 1 2 Canada CAN \n", + "4 Admin-0 country 1 2 United States of America US1 \n", + "\n", + " ADM0_DIF LEVEL TYPE TLC ADMIN ... \\\n", + "0 0 2 Sovereign country 1 Fiji ... \n", + "1 0 2 Sovereign country 1 United Republic of Tanzania ... \n", + "2 0 2 Indeterminate 1 Western Sahara ... \n", + "3 0 2 Sovereign country 1 Canada ... \n", + "4 1 2 Country 1 United States of America ... \n", + "\n", + " FCLASS_PL FCLASS_GR FCLASS_IT FCLASS_NL FCLASS_SE FCLASS_BD \\\n", + "0 None None None None None None \n", + "1 None None None None None None \n", + "2 Unrecognized None None Unrecognized None None \n", + "3 None None None None None None \n", + "4 None None None None None None \n", + "\n", + " FCLASS_UA geometry distance_from \\\n", + "0 None MULTIPOLYGON (((20037508.343 -1812498.413, 200... Vatican City \n", + "1 None POLYGON ((3774143.866 -105758.362, 3792946.708... San Marino \n", + "2 None POLYGON ((-964649.018 3205725.605, -964597.245... Vaduz \n", + "3 None MULTIPOLYGON (((-13674486.249 6274861.394, -13... Lobamba \n", + "4 None MULTIPOLYGON (((-13674486.249 6274861.394, -13... Luxembourg \n", + "\n", + " distance \n", + "0 1.969350e+07 \n", + "1 5.929777e+06 \n", + "2 3.421172e+06 \n", + "3 1.296059e+07 \n", + "4 8.174897e+06 \n", + "\n", + "[5 rows x 171 columns]\n", + "(GPU)\n", + "\n" ] - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
pop_estcontinentnameiso_a3gdp_md_estgeometrydistance_fromdistance
0889953.0OceaniaFijiFJI5496MULTIPOLYGON (((20037508.343 -1812498.413, 200...Vatican City1.969350e+07
158005463.0AfricaTanzaniaTZA63177POLYGON ((3774143.866 -105758.362, 3792946.708...San Marino5.929777e+06
2603253.0AfricaW. SaharaESH907POLYGON ((-964649.018 3205725.605, -964597.245...Vaduz3.421172e+06
337589262.0North AmericaCanadaCAN1736425MULTIPOLYGON (((-13674486.249 6274861.394, -13...Lobamba1.296059e+07
4328239523.0North AmericaUnited States of AmericaUSA21433226MULTIPOLYGON (((-13674486.249 6274861.394, -13...Luxembourg8.174897e+06
\n", - "
" - ], - "text/plain": [ - " pop_est continent name iso_a3 gdp_md_est \\\n", - "0 889953.0 Oceania Fiji FJI 5496 \n", - "1 58005463.0 Africa Tanzania TZA 63177 \n", - "2 603253.0 Africa W. Sahara ESH 907 \n", - "3 37589262.0 North America Canada CAN 1736425 \n", - "4 328239523.0 North America United States of America USA 21433226 \n", - "\n", - " geometry distance_from \\\n", - "0 MULTIPOLYGON (((20037508.343 -1812498.413, 200... Vatican City \n", - "1 POLYGON ((3774143.866 -105758.362, 3792946.708... San Marino \n", - "2 POLYGON ((-964649.018 3205725.605, -964597.245... Vaduz \n", - "3 MULTIPOLYGON (((-13674486.249 6274861.394, -13... Lobamba \n", - "4 MULTIPOLYGON (((-13674486.249 6274861.394, -13... Luxembourg \n", - "\n", - " distance \n", - "0 1.969350e+07 \n", - "1 5.929777e+06 \n", - "2 3.421172e+06 \n", - "3 1.296059e+07 \n", - "4 8.174897e+06 \n", - "(GPU)" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ - "cities = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_cities\")).to_crs(3857)\n", - "countries = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\")).to_crs(3857)\n", + "countries = host_dataframe\n", + "\n", + "cities = geopandas.read_file('https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_populated_places_simple.zip')\n", + "cities = cities.to_crs(3857)\n", "\n", "gpu_cities = cuspatial.from_geopandas(cities)\n", "gpu_countries = cuspatial.from_geopandas(countries)\n", - "\n", "dist = cuspatial.pairwise_point_polygon_distance(\n", " gpu_cities.geometry[:len(gpu_countries)], gpu_countries.geometry\n", ")\n", @@ -1180,7 +1057,7 @@ "gpu_countries[\"distance_from\"] = cities.name\n", "gpu_countries[\"distance\"] = dist\n", "\n", - "gpu_countries.head()" + "print(gpu_countries.head())" ] }, { @@ -1196,7 +1073,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 22, "id": "5863871e", "metadata": {}, "outputs": [ @@ -1270,7 +1147,7 @@ "4 Broadway LINESTRING (-8235369.475 4980617.398, -8235373..." ] }, - "execution_count": 19, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -1296,7 +1173,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 24, "id": "f4c67464", "metadata": {}, "outputs": [ @@ -1363,7 +1240,7 @@ "0 POLYGON ((-8236139.639 4975314.625, -8235990.3..." ] }, - "execution_count": 20, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -1388,7 +1265,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 25, "id": "d4e68e87", "metadata": {}, "outputs": [ @@ -1495,7 +1372,7 @@ "[1864 rows x 2 columns]" ] }, - "execution_count": 21, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -1522,30 +1399,18 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 26, "id": "951625da", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/3213563529.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " countries = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\")).to_crs(3857)\n" - ] - } - ], + "outputs": [], "source": [ - "countries = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\")).to_crs(3857)\n", - "gpu_countries = cuspatial.from_geopandas(countries)\n", - "\n", - "african_countries = gpu_countries[gpu_countries.continent == \"Africa\"].sort_values(\"pop_est\", ascending=False)\n", - "asian_countries = gpu_countries[gpu_countries.continent == \"Asia\"].sort_values(\"pop_est\", ascending=False)" + "african_countries = gpu_countries[gpu_countries.CONTINENT == \"Africa\"].sort_values(\"POP_EST\", ascending=False)\n", + "asian_countries = gpu_countries[gpu_countries.CONTINENT == \"Asia\"].sort_values(\"POP_EST\", ascending=False)" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 27, "id": "2f0e1118", "metadata": {}, "outputs": [ @@ -1654,7 +1519,7 @@ "9 Sudan Iran 1.625828e+06" ] }, - "execution_count": 23, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -1667,8 +1532,8 @@ " population_top10_africa.geometry, population_top10_asia.geometry)\n", "\n", "cudf.concat([\n", - " population_top10_africa[\"name\"].rename(\"Africa\"),\n", - " population_top10_asia[\"name\"].rename(\"Asia\"), \n", + " population_top10_africa[\"NAME\"].rename(\"Africa\"),\n", + " population_top10_asia[\"NAME\"].rename(\"Asia\"), \n", " dist.rename(\"dist\")], axis=1\n", ")" ] @@ -1690,35 +1555,26 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 28, "id": "d1ade9da-c9e2-45c4-9685-dffeda3fd358", "metadata": { "tags": [] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/3414785716.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] - }, { "name": "stdout", "output_type": "stream", "text": [ - "0 POINT (33.90371 -0.95000)\n", + "0 POINT (33.90371 -0.95)\n", "1 POINT (34.07262 -1.05982)\n", "2 POINT (37.69869 -3.09699)\n", - "3 POINT (37.76690 -3.67712)\n", + "3 POINT (37.7669 -3.67712)\n", "4 POINT (39.20222 -4.67677)\n", "dtype: geometry\n" ] } ], "source": [ - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", "gpu_dataframe = cuspatial.from_geopandas(host_dataframe)\n", "geometry = gpu_dataframe['geometry']\n", "points = cuspatial.GeoSeries.from_points_xy(geometry.polygons.xy)\n", @@ -1766,34 +1622,24 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 29, "id": "cc72a44d-a9bf-4432-9898-de899ac45869", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/199363072.py:3: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] - } - ], + "outputs": [], "source": [ "from cuspatial.core.binops.intersection import pairwise_linestring_intersection\n", "\n", - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", - "usa_boundary = cuspatial.from_geopandas(host_dataframe[host_dataframe.name == \"United States of America\"].geometry.boundary)\n", - "canada_boundary = cuspatial.from_geopandas(host_dataframe[host_dataframe.name == \"Canada\"].geometry.boundary)\n", + "usa_boundary = cuspatial.from_geopandas(host_dataframe[host_dataframe.NAME == \"United States of America\"].geometry.boundary)\n", + "canada_boundary = cuspatial.from_geopandas(host_dataframe[host_dataframe.NAME == \"Canada\"].geometry.boundary)\n", "\n", "list_offsets, geometries, look_back_ids = pairwise_linestring_intersection(usa_boundary, canada_boundary)" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 30, "id": "1125fd17-afe1-4b9c-b48d-8842dd3700b3", "metadata": { "tags": [] @@ -1802,7 +1648,7 @@ { "data": { "text/plain": [ - "\n", + "\n", "[\n", " 0,\n", " 142\n", @@ -1810,7 +1656,7 @@ "dtype: int32" ] }, - "execution_count": 26, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -1823,7 +1669,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 31, "id": "b281e3bb-42d4-4d60-9cb2-b7dcc20b4776", "metadata": { "tags": [] @@ -1835,18 +1681,18 @@ "0 POINT (-130.53611 54.80275)\n", "1 POINT (-130.53611 54.80278)\n", "2 POINT (-130.53611 54.80275)\n", - "3 POINT (-129.98000 55.28500)\n", + "3 POINT (-129.98 55.285)\n", "4 POINT (-130.53611 54.80278)\n", " ... \n", - "137 LINESTRING (-120.00000 49.00000, -117.03121 49...\n", - "138 LINESTRING (-122.84000 49.00000, -120.00000 49...\n", - "139 LINESTRING (-117.03121 49.00000, -107.05000 49...\n", + "137 LINESTRING (-120 49, -117.03121 49)\n", + "138 LINESTRING (-122.84 49, -120 49)\n", + "139 LINESTRING (-117.03121 49, -107.05 49)\n", "140 LINESTRING (-83.89077 46.11693, -83.61613 46.1...\n", "141 LINESTRING (-82.69009 41.67511, -82.43928 41.6...\n", "Length: 142, dtype: geometry" ] }, - "execution_count": 27, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -1858,7 +1704,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 32, "id": "e19873b9-2614-4242-ad67-caa47f807d04", "metadata": { "tags": [] @@ -1895,9 +1741,9 @@ " \n", " 0\n", " [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ...\n", - " [18, 16, 18, 15, 17, 14, 16, 13, 15, 14, 11, 1...\n", + " [18, 16, 18, 15, 17, 14, 16, 137, 13, 15, 14, ...\n", " [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...\n", - " [9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15...\n", + " [9, 10, 10, 11, 11, 12, 12, 28, 13, 13, 14, 15...\n", " \n", " \n", "\n", @@ -1908,16 +1754,16 @@ "0 [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ... \n", "\n", " lhs_segment_id \\\n", - "0 [18, 16, 18, 15, 17, 14, 16, 13, 15, 14, 11, 1... \n", + "0 [18, 16, 18, 15, 17, 14, 16, 137, 13, 15, 14, ... \n", "\n", " rhs_linestring_id \\\n", "0 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... \n", "\n", " rhs_segment_id \n", - "0 [9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15... " + "0 [9, 10, 10, 11, 11, 12, 12, 28, 13, 13, 14, 15... " ] }, - "execution_count": 28, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -1951,20 +1797,12 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 33, "id": "bf7b2256", "metadata": { "tags": [] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/1271339229.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n" - ] - }, { "data": { "text/plain": [ @@ -1976,13 +1814,12 @@ "dtype: int64" ] }, - "execution_count": 29, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", "single_polygons = host_dataframe[host_dataframe['geometry'].type == \"Polygon\"]\n", "gpu_dataframe = cuspatial.from_geopandas(single_polygons)\n", "x_points = (cupy.random.random(10000000) - 0.5) * 360\n", @@ -2063,7 +1900,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 34, "id": "e3a0a9a3-0bdd-4f05-bcb5-7db4b99a44a3", "metadata": { "tags": [] @@ -2128,7 +1965,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 35, "id": "023bd25a-35be-435d-ab0b-ecbd7a47e147", "metadata": { "tags": [] @@ -2188,33 +2025,20 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 36, "id": "784aff8e-c9ed-4a81-aa87-bf301b3b90af", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_5364/2951982051.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_countries = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", - "/tmp/ipykernel_5364/2951982051.py:2: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_cities' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.\n", - " host_cities = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_cities\"))\n" - ] - } - ], + "outputs": [], "source": [ - "host_countries = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", - "host_cities = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_cities\"))\n", - "gpu_countries = cuspatial.from_geopandas(host_countries[host_countries['geometry'].type == \"Polygon\"])\n", - "gpu_cities = cuspatial.from_geopandas(host_cities[host_cities['geometry'].type == 'Point'])" + "gpu_countries = cuspatial.from_geopandas(countries[countries['geometry'].type == \"Polygon\"])\n", + "gpu_cities = cuspatial.from_geopandas(cities[cities['geometry'].type == 'Point'])" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 37, "id": "fea24c78-cf5c-45c6-b860-338238e61323", "metadata": { "tags": [] @@ -2224,12 +2048,22 @@ "name": "stdout", "output_type": "stream", "text": [ - " point_index linestring_index distance\n", - "0 0 21 10.857363\n", - "1 1 21 10.937690\n", - "2 2 19 0.522859\n", - "3 3 19 0.050204\n", - "4 4 129 0.104261\n" + " point_index linestring_index distance\n", + "0 0 19 1.362153e+06\n", + "1 1 21 1.352434e+06\n", + "2 2 19 6.406228e+04\n", + "3 3 19 6.750845e+03\n", + "4 4 21 3.473671e+05\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/coder/cuspatial/python/cuspatial/cuspatial/core/spatial/indexing.py:174: UserWarning: scale 5 is less than required minimum scale 243402.43980382645. Clamping to minimum scale\n", + " warnings.warn(\n", + "/home/coder/cuspatial/python/cuspatial/cuspatial/core/spatial/join.py:146: UserWarning: scale 5 is less than required minimum scale 243402.43980382645. Clamping to minimum scale\n", + " warnings.warn(\n" ] } ], @@ -2282,6 +2116,14 @@ "source": [ "_Images used with permission from Wikipedia Creative Commons_" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c3c504d6-a908-455d-9d35-58521f70c5e2", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -2300,7 +2142,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.11.9" }, "vscode": { "interpreter": {