Skip to content

Commit

Permalink
Added GOSTNets
Browse files Browse the repository at this point in the history
  • Loading branch information
bpstewar committed Nov 26, 2018
1 parent 370fad3 commit 9bb154c
Show file tree
Hide file tree
Showing 37 changed files with 12,590 additions and 57 deletions.
869 changes: 869 additions & 0 deletions GOSTNets/GOSTNets/GOSTnet.py

Large diffs are not rendered by default.

Empty file added GOSTNets/GOSTNets/__init__.py
Empty file.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2,291 changes: 2,291 additions & 0 deletions GOSTNets/Notebooks/.ipynb_checkpoints/GOSTNets_Library-checkpoint.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os, sys\n",
"\n",
"gostNetsFolder = os.path.dirname(os.getcwd())\n",
"sys.path.insert(0, gostNetsFolder)\n",
"\n",
"from GOSTNets import GOSTNets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# GOSTNets\n",
"With constant advances in network analysis, the GOST team at the WBG have shifted focus from traditional GIS solutions to network analysis (ie - ESRI) to open-source python solutions (ie - osmnx, networkx, peartree). This notebook starts by importing the GOSTNets functions, which serve as a backbone for the network analyses listed below. This is a work in progress, so please check back, or head to the GOSTNets Github page for more information.\n",
"\n",
"### Network Analyses\n",
"All of these network analyses are able to be run with various modifications:\n",
"\n",
"1. Occlusions - part of the network can be removed through a geospatial occlusion. An example would be running a market access from all locations in a city to all the hospitals, and then running it again with the introduction of a flood\n",
"\n",
"2. Multi-modal analysis - while the majority of our analysis focuses on single modes of transport (walking or driving), there is often a need to combine multiple modes of travel (walking and transit).\n",
"\n",
"Based on the optional modifications above, GOSTNets is designed to answer the following analyses\n",
"\n",
"1. Market Access - measure travel time from all origins to all destinations\n",
"2. Isochrones - create travel time isochrones from origins along the network\n",
"3. Criticality - identify the key edges in the network that, when removed, have the largest effect on the measured travel time\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"import geopandas as gpd\n",
"import osmnx as ox\n",
"import networkx as nx\n",
"\n",
"inputAOI = os.path.join(gostNetsFolder, \"SampleData\", \"AOI.shp\")\n",
"inputOrigins = os.path.join(gostNetsFolder, \"SampleData\", \"origins.shp\")\n",
"inputDestinations = os.path.join(gostNetsFolder, \"SampleData\", \"destinations.shp\")\n",
"\n",
"inAOI = gpd.read_file(inputAOI)\n",
"inO = gpd.read_file(inputOrigins)\n",
"inD = gpd.read_file(inputDestinations)\n",
"networkType = 'walk'"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"#Get walking network for AOI\n",
"gWalk = ox.graph_from_polygon(inAOI.unary_union, network_type='walk')\n",
"#Add time to dataset\n",
"gWalk = GOSTNets.convert_network_to_time(gWalk, \"length\", graph_type=networkType)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"###Market Analysis\n",
"#Get network nodes of origins and destinations\n",
"inO = GOSTNets.snap_points_to_graph(inO, gWalk)\n",
"inD = GOSTNets.snap_points_to_graph(inD, gWalk)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5726318544, 5871191267: 595.616 - 476.49280000000005\n",
"5726318544, 5098477148: 920.2840000000001 - 736.2272000000002\n",
"5726318544, 2625591872: 937.887 - 750.3095999999998\n",
"5726318544, 5982278990: 1609.3220000000003 - 1279.816\n",
"5726318544, 5314175304: 1911.5829999999996 - 1529.1144\n",
"3107767222, 5871191267: 345.8 - 276.64\n",
"3107767222, 5098477148: 1138.692 - 839.3064\n",
"3107767222, 2625591872: 480.774 - 384.61920000000003\n",
"3107767222, 5982278990: 1350.191 - 1080.1528\n",
"3107767222, 5314175304: 1454.4699999999998 - 1142.6336000000001\n",
"5520542032, 5871191267: 1039.1770000000001 - 821.8711999999999\n",
"5520542032, 5098477148: 1378.2660000000003 - 1102.6127999999999\n",
"5520542032, 2625591872: 328.026 - 262.4208\n",
"5520542032, 5982278990: 1306.9110000000003 - 1045.5288\n",
"5520542032, 5314175304: 989.5379999999999 - 791.6304\n",
"30757798, 5871191267: 1907.5900000000001 - 1518.4303999999997\n",
"30757798, 5098477148: 1513.2810000000002 - 1210.6248\n",
"30757798, 2625591872: 1242.42 - 993.9359999999999\n",
"30757798, 5982278990: 327.52 - 262.01599999999996\n",
"30757798, 5314175304: 1330.164 - 1000.1992\n",
"5726082201, 5871191267: 1057.2730000000001 - 845.8184000000001\n",
"5726082201, 5098477148: 729.3 - 583.44\n",
"5726082201, 2625591872: 434.87500000000006 - 347.9\n",
"5726082201, 5982278990: 631.64 - 505.312\n",
"5726082201, 5314175304: 1330.558 - 1064.4464\n"
]
}
],
"source": [
"for oID in inO.Nearest_node:\n",
" for dID in inD.Nearest_node:\n",
" walkdist = nx.shortest_path_length(gWalk, oID, dID, weight=\"length\")\n",
" walktime = nx.shortest_path_length(gWalk, oID, dID, weight=\"time\")\n",
" print (\"%s, %s: %s - %s\" % (oID,dID,walkdist,walktime))"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.2\n",
" id geometry Nearest_node\n",
"0 1 POINT (-63.59431806196039 44.65133356316481) 5726318544\n",
"1 2 POINT (-63.58916915341164 44.6527942848499) 3107767222\n",
"2 3 POINT (-63.58360024325922 44.65176514385551) 5520542032\n",
"3 4 POINT (-63.57627354861734 44.6442839572668) 30757798\n",
"4 5 POINT (-63.58487580368518 44.64749346022605) 5726082201\n",
" id geometry Nearest_node\n",
"0 1 POINT (-63.59231138763172 44.65362422396232) 5871191267\n",
"1 2 POINT (-63.59172027426359 44.64523575942496) 5098477148\n",
"2 3 POINT (-63.58496913737489 44.65039292745496) 2625591872\n",
"3 4 POINT (-63.58014689674011 44.64417328158375) 5982278990\n",
"4 5 POINT (-63.57621132615753 44.65238484384609) 5314175304\n"
]
}
],
"source": [
"print(nx.__version__)\n",
"print(inO.head())\n",
"print(inD.head())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 9bb154c

Please sign in to comment.