Skip to content

Commit 42998ef

Browse files
Only after PR#349: Test NBs onJupyterLab (#370)
* edit sentinel mosaic and fix pathfinding * remove unnecessary imports * test all user_guide nb's to work in jupyterlab edits for clarity and for bugs * edit 6 and 7 and pharmacy deserts and datasets.yml * edit user_guide nbs * edit focal nb * edit pharmacy deserts for functionality; change natural breaks to quantile * add austin streets in datasets * edit pharmacy deserts * mv test_examples_cli for appveyer tests ignore * Revert "mv test_examples_cli for appveyer tests ignore" This reverts commit 43be8db. revert * revert non-related * Revert "revert non-related" This reverts commit 88a7a42. * move test_examples * add pytest skip for appveyor in github * add import pytest * flake8 test_examples * move files and edit manifest to match vcs and sdist * remove fxn call in test_cli * add pharmacy deserts and remove tiling * suppress warning * edit ms Co-authored-by: Brendan Collins <brendan@makepath.com>
1 parent 4eee5cb commit 42998ef

16 files changed

+975
-823
lines changed

MANIFEST.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ prune conda.recipe
1313
prune img
1414
prune .idea
1515

16+
exclude xrspatial/.DS_Store
17+
exclude xrspatial/.version
1618
exclude examples/.ipynb_checkpoints/*
1719
exclude examples/user_guide/.ipynb_checkpoints/*
1820
exclude xrspatial/_version.py
1921
exclude xrspatial/.DS_Store
2022
exclude xrspatial/.version
2123
exclude xrspatial/__pycache__/*
24+
25+
exclude xrspatial/examples/user_guide_idea/*
26+
exclude xrspatial/tests/.DS_Store
27+
exclude xrspatial/tests/__pycache__/*
28+
2229
exclude xrspatial/tests/__pycache__/*
2330
exclude xrspatial/tests/.DS_Store
31+
2432
exclude xrspatial/tests/_qgis_results/__pycache__/*
2533
exclude tile_idea.py
2634
exclude *.enc

examples/Path-finding_City-of-Austin-Road-Network.ipynb

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Path Finding in the City of Austin\n",
8+
"\n",
9+
"This notebook demonstrates pathfinding along the city of Austin street network using Xarray-spatial's `pathfinding` module.\n",
10+
"The a_star_search function provides the shortest path between any two points."
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"metadata": {},
16+
"source": [
17+
"#### Setup:\n",
18+
"\n",
19+
"First, we'll need to import some packages: these include the basic array manipulation ones, \n",
20+
"as well as some geospatial-focused ones.\n",
21+
"We'll also grab a few datashader functions for easy rendering."
22+
]
23+
},
324
{
425
"cell_type": "code",
526
"execution_count": null,
@@ -10,6 +31,7 @@
1031
"import numpy as np\n",
1132
"import pandas as pd\n",
1233
"import geopandas\n",
34+
"import spatialpandas\n",
1335
"\n",
1436
"import datashader as ds\n",
1537
"from datashader.transfer_functions import shade, stack, dynspread, set_background\n",
@@ -21,36 +43,22 @@
2143
"cell_type": "markdown",
2244
"metadata": {},
2345
"source": [
24-
"## Load data\n",
46+
"### Load data\n",
2547
"\n",
48+
"Now, we're ready to load up the data and transform it into a format we ccan work with.\n",
2649
"The road network used in this example notebook can be downloaded from:\n",
2750
"\n",
2851
"https://data.austintexas.gov/Locations-and-Maps/Street-Centerline/m5w3-uea6"
2952
]
3053
},
3154
{
32-
"cell_type": "code",
33-
"execution_count": null,
55+
"cell_type": "markdown",
3456
"metadata": {},
35-
"outputs": [],
3657
"source": [
37-
"streets = geopandas.read_file('zip://./data/Street_Centerline.zip')\n",
38-
"streets = streets.to_crs({'init': 'epsg:4326'})\n",
39-
"\n",
40-
"xs = []\n",
41-
"ys = []\n",
42-
"for s in streets.geometry.values:\n",
43-
" try:\n",
44-
" coords = s.coords.xy\n",
45-
" xs += coords[0].tolist()\n",
46-
" ys += coords[1].tolist()\n",
47-
" \n",
48-
" xs.append(np.nan)\n",
49-
" ys.append(np.nan)\n",
50-
" except:\n",
51-
" continue\n",
52-
" \n",
53-
"street_df = pd.DataFrame(dict(x=xs, y=ys))"
58+
"We'll start by opening the shapefile, transforming the crs (coordinate reference system) to the commonly-used longitude/latitude, \n",
59+
"and, after a quick clean-up, transforming it to a spatialpandas GeoDataFrame.\n",
60+
"\n",
61+
"Now our data is ready to be aggregated to an xarray DataArray raster."
5462
]
5563
},
5664
{
@@ -59,14 +67,26 @@
5967
"metadata": {},
6068
"outputs": [],
6169
"source": [
62-
"street_df"
70+
"streets = geopandas.read_file('./data/Street_Centerline.zip')\n",
71+
"streets = streets.to_crs('EPSG:4326')\n",
72+
"streets = streets.explode('geometry').reset_index(drop=True)\n",
73+
"streets_spd = spatialpandas.GeoDataFrame(streets, geometry='geometry')"
6374
]
6475
},
6576
{
6677
"cell_type": "markdown",
6778
"metadata": {},
6879
"source": [
69-
"## Define study area (find range of x and y)"
80+
"### Define study area (find range of x and y) and aggregate:\n",
81+
"\n",
82+
"To finish off our set-up:\n",
83+
"- We'll define a study area, with xmin, xmax, ymin, and ymax; this set the x, y coordinates we'll be using in our aggregate.\n",
84+
"- We'll set up a datashader Canvas object, which provides an easy frame for setting up a new raster and aggregating data to it.\n",
85+
"- Finally, we'll aggregate the streets data into a lines raster with Canvas.line.\n",
86+
"\n",
87+
"- We also set up the start and goal point (x, y) coordinates, and set up a DataFrame and aggregation for visualization.\n",
88+
"\n",
89+
"Some shading and stacking of all of this displays our complete setup below."
7090
]
7191
},
7292
{
@@ -94,7 +114,7 @@
94114
"cvs = ds.Canvas(plot_width=W, plot_height=H,\n",
95115
" x_range=xrange, y_range=yrange)\n",
96116
"\n",
97-
"street_agg = cvs.line(street_df, x='x', y='y').astype(int)\n",
117+
"street_agg = cvs.line(streets_spd, geometry='geometry')\n",
98118
"street_shaded = dynspread(shade(street_agg, cmap=['salmon']))\n",
99119
"\n",
100120
"# Pick two locations\n",
@@ -112,7 +132,17 @@
112132
"cell_type": "markdown",
113133
"metadata": {},
114134
"source": [
115-
"## Shortest path using A* from start location to goal location"
135+
"### Shortest path using A* from start location to goal location\n",
136+
"\n",
137+
"Now, we can do some pathfinding:\n",
138+
"\n",
139+
"In `a_star_search`, we'll input the Austin city streets lines aggregate we built above, the start and goal point coordinates, and barriers:\n",
140+
" - Barriers defines all non-crossable points in the raster: for our streets raster, this includes all non-street areas, all of which have 0 set as their value. \n",
141+
"\n",
142+
"We've also set `snap-start` and `snap-goal` to `True`: this helps ensure the start and goal points are set correctly.\n",
143+
"\n",
144+
"The result is a the shortest path al\n",
145+
" "
116146
]
117147
},
118148
{

0 commit comments

Comments
 (0)