Skip to content

Commit

Permalink
notebook should be working now
Browse files Browse the repository at this point in the history
  • Loading branch information
quasiben committed Jul 9, 2024
1 parent a5ff4eb commit 8f6e97b
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 deletions docs/source/user_guide/cuspatial_api_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"outputs": [],
"source": [
"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())"
]
Expand Down Expand Up @@ -231,8 +232,8 @@
"source": [
"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 = sorted_dataframe.to_geopandas()\n",
"sorted_dataframe['geometry'].iloc[0]"
]
},
{
Expand Down Expand Up @@ -640,16 +641,6 @@
"Using WGS 84 Pseudo-Mercator, distances are in meters."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97775b8a-fd59-4e77-9add-840f03836830",
"metadata": {},
"outputs": [],
"source": [
"host_dataframe.to_crs(3857)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -660,8 +651,8 @@
"outputs": [],
"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",
Expand Down Expand Up @@ -698,20 +689,22 @@
},
"outputs": [],
"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 = geopandas.read_file('https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_0_countries.zip')\n",
"countries = countries.to_crs(3857)\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",
"\n",
"gpu_countries[\"distance_from\"] = cities.name\n",
"gpu_countries[\"distance\"] = dist\n",
"\n",
"gpu_countries.head()"
"print(gpu_countries.head())"
]
},
{
Expand Down Expand Up @@ -807,11 +800,8 @@
"metadata": {},
"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)"
]
},
{
Expand All @@ -828,8 +818,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",
")"
]
Expand Down Expand Up @@ -858,7 +848,6 @@
},
"outputs": [],
"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",
Expand Down Expand Up @@ -915,9 +904,8 @@
"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)"
]
Expand Down Expand Up @@ -993,7 +981,6 @@
},
"outputs": [],
"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",
Expand Down Expand Up @@ -1177,10 +1164,8 @@
},
"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'])"
]
},
{
Expand Down Expand Up @@ -1240,6 +1225,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": {
Expand Down

0 comments on commit 8f6e97b

Please sign in to comment.