-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c729af7
commit f73b484
Showing
2 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pyproj\n", | ||
"import numpy as np\n", | ||
"import holoviews as hv\n", | ||
"import geoviews as gv\n", | ||
"from bokeh.sampledata.airport_routes import airports, routes\n", | ||
"\n", | ||
"hv.extension('bokeh')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_circle_path(start, end, samples=200):\n", | ||
" sx, sy = start\n", | ||
" ex, ey = end\n", | ||
" g = pyproj.Geod(ellps='WGS84')\n", | ||
" (az12, az21, dist) = g.inv(sx, sy, ex, ey)\n", | ||
" lonlats = g.npts(sx, sy, ex, ey, 200)\n", | ||
" return np.array([(sx, sy)]+lonlats+[(ex, ey)])\n", | ||
"\n", | ||
"# Compute great-circle paths for all US flight routes from Honolulu\n", | ||
"paths = []\n", | ||
"honolulu = (-157.9219970703125, 21.318700790405273)\n", | ||
"routes = routes[routes.SourceID==3728]\n", | ||
"airports = airports[airports.AirportID.isin(list(routes.DestinationID)+[3728])]\n", | ||
"for i, route in routes.iterrows():\n", | ||
" airport = airports[airports.AirportID==route.DestinationID].iloc[0]\n", | ||
" paths.append(get_circle_path(honolulu, (airport.Longitude, airport.Latitude)))\n", | ||
"tiles = gv.WMTS('https://maps.wikimedia.org/osm-intl/{Z}/{X}/{Y}@2x.png')\n", | ||
"\n", | ||
"# Define Graph from Nodes and EdgePaths\n", | ||
"path = gv.EdgePaths(paths)\n", | ||
"points = gv.Nodes(airports, ['Longitude', 'Latitude', 'AirportID'], ['Name', 'City'])\n", | ||
"graph = gv.Graph((routes, points, path), ['SourceID', 'DestinationID'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%opts Graph [width=600 height=400 tools=['hover']] (node_color='black')\n", | ||
"(tiles * graph).redim.range(Longitude=(-170, -62))" | ||
] | ||
} | ||
], | ||
"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.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pyproj\n", | ||
"import numpy as np\n", | ||
"import holoviews as hv\n", | ||
"import geoviews as gv\n", | ||
"import geoviews.feature as gf\n", | ||
"from bokeh.sampledata.airport_routes import airports, routes\n", | ||
"\n", | ||
"hv.extension('matplotlib')\n", | ||
"%output fig='svg' size=250" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_circle_path(start, end, samples=200):\n", | ||
" sx, sy = start\n", | ||
" ex, ey = end\n", | ||
" g = pyproj.Geod(ellps='WGS84')\n", | ||
" (az12, az21, dist) = g.inv(sx, sy, ex, ey)\n", | ||
" lonlats = g.npts(sx, sy, ex, ey, 200)\n", | ||
" return np.array([(sx, sy)]+lonlats+[(ex, ey)])\n", | ||
"\n", | ||
"# Compute great-circle paths for all US flight routes from Honolulu\n", | ||
"paths = []\n", | ||
"honolulu = (-157.9219970703125, 21.318700790405273)\n", | ||
"routes = routes[routes.SourceID==3728]\n", | ||
"airports = airports[airports.AirportID.isin(list(routes.DestinationID)+[3728])]\n", | ||
"for i, route in routes.iterrows():\n", | ||
" airport = airports[airports.AirportID==route.DestinationID].iloc[0]\n", | ||
" paths.append(get_circle_path(honolulu, (airport.Longitude, airport.Latitude)))\n", | ||
"\n", | ||
"# Define Graph from Nodes and EdgePaths\n", | ||
"path = gv.EdgePaths(paths)\n", | ||
"points = gv.Nodes(airports, ['Longitude', 'Latitude', 'AirportID'], ['Name', 'City'])\n", | ||
"graph = gv.Graph((routes, points, path), ['SourceID', 'DestinationID'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%opts Graph [width=600 height=400 tools=['hover']] (node_color='black' node_size=8)\n", | ||
"(gf.ocean * gf.land * gf.lakes * graph * gf.coastline).redim.range(Longitude=(-170, -62), Latitude=(10, 75))" | ||
] | ||
} | ||
], | ||
"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.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |