Skip to content

Commit

Permalink
Added great_circle example
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jan 15, 2018
1 parent c729af7 commit f73b484
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 0 deletions.
94 changes: 94 additions & 0 deletions notebooks/gallery/bokeh/great_circle.ipynb
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
}
95 changes: 95 additions & 0 deletions notebooks/gallery/matplotlib/great_circle.ipynb
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
}

0 comments on commit f73b484

Please sign in to comment.