Skip to content

Commit

Permalink
isort, black, and flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gboeing committed Mar 20, 2021
1 parent e8b469d commit 55690f7
Show file tree
Hide file tree
Showing 18 changed files with 904 additions and 516 deletions.
77 changes: 43 additions & 34 deletions notebooks/00-osmnx-features-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
"source": [
"import networkx as nx\n",
"import osmnx as ox\n",
"import requests\n",
"import matplotlib.cm as cm\n",
"import matplotlib.colors as colors\n",
"\n",
"%matplotlib inline\n",
"ox.config(log_console=True)\n",
"ox.__version__"
Expand All @@ -59,7 +57,7 @@
"outputs": [],
"source": [
"# download/model a street network for some city then visualize it\n",
"G = ox.graph_from_place('Piedmont, California, USA', network_type='drive')\n",
"G = ox.graph_from_place(\"Piedmont, California, USA\", network_type=\"drive\")\n",
"fig, ax = ox.plot_graph(G)"
]
},
Expand Down Expand Up @@ -152,7 +150,9 @@
"outputs": [],
"source": [
"# show some basic stats about the network\n",
"ox.basic_stats(G_proj, area=graph_area_m, clean_intersects=True, circuity_dist='euclidean')"
"ox.basic_stats(\n",
" G_proj, area=graph_area_m, clean_intersects=True, circuity_dist=\"euclidean\"\n",
")"
]
},
{
Expand All @@ -169,7 +169,9 @@
"outputs": [],
"source": [
"# see more stats (mostly topological stuff) with extended_stats\n",
"more_stats = ox.extended_stats(G, ecc=True, bc=True, cc=True) #use arguments to turn other toplogical analyses on/off\n",
"more_stats = ox.extended_stats(\n",
" G, ecc=True, bc=True, cc=True\n",
") # use arguments to turn other toplogical analyses on/off\n",
"for key in sorted(more_stats.keys()):\n",
" print(key)"
]
Expand All @@ -180,7 +182,7 @@
"metadata": {},
"outputs": [],
"source": [
"more_stats['radius']"
"more_stats[\"radius\"]"
]
},
{
Expand All @@ -197,8 +199,8 @@
"outputs": [],
"source": [
"# save graph to disk as geopackage (for GIS) or graphml file (for gephi etc)\n",
"ox.save_graph_geopackage(G, filepath='./data/mynetwork.gpkg')\n",
"ox.save_graphml(G, filepath='./data/mynetwork.graphml')"
"ox.save_graph_geopackage(G, filepath=\"./data/mynetwork.gpkg\")\n",
"ox.save_graphml(G, filepath=\"./data/mynetwork.graphml\")"
]
},
{
Expand All @@ -218,7 +220,7 @@
"source": [
"# convert graph to line graph so edges become nodes and vice versa\n",
"edge_centrality = nx.closeness_centrality(nx.line_graph(G))\n",
"nx.set_edge_attributes(G, edge_centrality, 'edge_centrality')"
"nx.set_edge_attributes(G, edge_centrality, \"edge_centrality\")"
]
},
{
Expand All @@ -228,7 +230,7 @@
"outputs": [],
"source": [
"# color edges in original graph with closeness centralities from line graph\n",
"ec = ox.plot.get_edge_colors_by_attr(G, 'edge_centrality', cmap='inferno')\n",
"ec = ox.plot.get_edge_colors_by_attr(G, \"edge_centrality\", cmap=\"inferno\")\n",
"fig, ax = ox.plot_graph(G, edge_color=ec, edge_linewidth=2, node_size=0)"
]
},
Expand Down Expand Up @@ -268,7 +270,7 @@
"outputs": [],
"source": [
"# find the shortest path between these nodes, minimizing travel time, then plot it\n",
"route = ox.shortest_path(G, orig, dest, weight='travel_time')\n",
"route = ox.shortest_path(G, orig, dest, weight=\"travel_time\")\n",
"fig, ax = ox.plot_graph_route(G, route, node_size=0)"
]
},
Expand All @@ -279,7 +281,7 @@
"outputs": [],
"source": [
"# how long is our route in meters?\n",
"edge_lengths = ox.utils_graph.get_route_edge_attributes(G, route, 'length')\n",
"edge_lengths = ox.utils_graph.get_route_edge_attributes(G, route, \"length\")\n",
"sum(edge_lengths)"
]
},
Expand All @@ -290,8 +292,9 @@
"outputs": [],
"source": [
"# how far is it between these two nodes as the crow flies (haversine)?\n",
"ox.distance.great_circle_vec(G.nodes[orig]['y'], G.nodes[orig]['x'],\n",
" G.nodes[dest]['y'], G.nodes[dest]['x'])"
"ox.distance.great_circle_vec(\n",
" G.nodes[orig][\"y\"], G.nodes[orig][\"x\"], G.nodes[dest][\"y\"], G.nodes[dest][\"x\"]\n",
")"
]
},
{
Expand All @@ -304,10 +307,13 @@
"# you need a google elevation api key to run this cell!\n",
"try:\n",
" from keys import google_elevation_api_key\n",
"\n",
" G = ox.add_node_elevations(G, api_key=google_elevation_api_key)\n",
" G = ox.add_edge_grades(G)\n",
" nc = ox.plot.get_node_colors_by_attr(G, 'elevation', cmap='plasma')\n",
" fig, ax = ox.plot_graph(G, node_color=nc, node_size=20, edge_linewidth=2, edge_color='#333')\n",
" nc = ox.plot.get_node_colors_by_attr(G, \"elevation\", cmap=\"plasma\")\n",
" fig, ax = ox.plot_graph(\n",
" G, node_color=nc, node_size=20, edge_linewidth=2, edge_color=\"#333\"\n",
" )\n",
"except ImportError:\n",
" pass"
]
Expand Down Expand Up @@ -337,11 +343,11 @@
"outputs": [],
"source": [
"# you can make query an unambiguous dict to help the geocoder find it\n",
"place = {'city' : 'San Francisco',\n",
" 'state' : 'California',\n",
" 'country': 'USA'}\n",
"G = ox.graph_from_place(place, network_type='drive', truncate_by_edge=True)\n",
"fig, ax = ox.plot_graph(G, figsize=(10, 10), node_size=0, edge_color='y', edge_linewidth=0.2)"
"place = {\"city\": \"San Francisco\", \"state\": \"California\", \"country\": \"USA\"}\n",
"G = ox.graph_from_place(place, network_type=\"drive\", truncate_by_edge=True)\n",
"fig, ax = ox.plot_graph(\n",
" G, figsize=(10, 10), node_size=0, edge_color=\"y\", edge_linewidth=0.2\n",
")"
]
},
{
Expand All @@ -351,7 +357,7 @@
"outputs": [],
"source": [
"# you can get networks anywhere in the world\n",
"G = ox.graph_from_place('Sinalunga, Italy', network_type='all')\n",
"G = ox.graph_from_place(\"Sinalunga, Italy\", network_type=\"all\")\n",
"fig, ax = ox.plot_graph(G, node_size=0, edge_linewidth=0.5)"
]
},
Expand All @@ -364,8 +370,8 @@
"# or get network by address, coordinates, bounding box, or any custom polygon\n",
"# ...useful when OSM just doesn't already have a polygon for the place you want\n",
"wurster_hall = (37.870605, -122.254830)\n",
"one_mile = 1609 #meters\n",
"G = ox.graph_from_point(wurster_hall, dist=one_mile, network_type='drive')\n",
"one_mile = 1609 # meters\n",
"G = ox.graph_from_point(wurster_hall, dist=one_mile, network_type=\"drive\")\n",
"fig, ax = ox.plot_graph(G, node_size=0)"
]
},
Expand All @@ -392,11 +398,15 @@
"outputs": [],
"source": [
"# get NY subway rail network\n",
"G = ox.graph_from_place('New York City, New York',\n",
" retain_all=False, truncate_by_edge=True, simplify=True,\n",
" custom_filter='[\"railway\"~\"subway\"]')\n",
"G = ox.graph_from_place(\n",
" \"New York City, New York\",\n",
" retain_all=False,\n",
" truncate_by_edge=True,\n",
" simplify=True,\n",
" custom_filter='[\"railway\"~\"subway\"]',\n",
")\n",
"\n",
"fig, ax = ox.plot_graph(G, node_size=0, edge_color='w', edge_linewidth=0.2)"
"fig, ax = ox.plot_graph(G, node_size=0, edge_color=\"w\", edge_linewidth=0.2)"
]
},
{
Expand All @@ -415,8 +425,8 @@
"outputs": [],
"source": [
"# get all building footprints in some neighborhood\n",
"place = 'Bunker Hill, Los Angeles, California'\n",
"tags = {'building': True}\n",
"place = \"Bunker Hill, Los Angeles, California\"\n",
"tags = {\"building\": True}\n",
"gdf = ox.geometries_from_place(place, tags)\n",
"gdf.shape"
]
Expand Down Expand Up @@ -444,8 +454,7 @@
"outputs": [],
"source": [
"# get all parks and bus stops in some neighborhood\n",
"tags = {'leisure': 'park',\n",
" 'highway': 'bus_stop'}\n",
"tags = {\"leisure\": \"park\", \"highway\": \"bus_stop\"}\n",
"gdf = ox.geometries_from_place(place, tags)\n",
"gdf.shape"
]
Expand Down Expand Up @@ -474,7 +483,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.9.2"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 55690f7

Please sign in to comment.