Skip to content

Commit

Permalink
Merge 97d3578 into dbf2459
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 21, 2018
2 parents dbf2459 + 97d3578 commit aff5ef4
Show file tree
Hide file tree
Showing 37 changed files with 2,330 additions and 170 deletions.
41 changes: 27 additions & 14 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ language: python

sudo: false

TODO: update when to upload to ioam-docs before merging
stages:
- test
- doc
Expand All @@ -23,11 +24,12 @@ jobs:
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
#########################
#########################
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION
- source activate test-environment
install:
- conda install -c conda-forge nose numpy matplotlib bokeh pandas scipy jupyter ipython param flake8 mock filelock iris cartopy xarray geopandas numpy shapely=1.6.3 gdal=2.2.3 libgdal=2.2.3 glib=2.55.0 gstreamer=1.8.0 datashader --quiet
- conda install nose numpy matplotlib bokeh pandas scipy jupyter ipython param flake8 mock filelock cartopy xarray geopandas numpy shapely gdal libgdal datashader --quiet
- conda install -c conda-forge iris
- pip install coveralls
- pip install git+https://github.com/ioam/holoviews.git
- python setup.py install
Expand All @@ -37,7 +39,7 @@ jobs:

- <<: *default
python: "3.6"
after_success: coveralls
after_success: coveralls

- <<: *default
stage: doc
Expand All @@ -46,26 +48,37 @@ jobs:
# TODO: can't remember why I did this twice
- python -c "import geoviews as gv; gv.sample_data('notebooks/user_guide/sample-data')"
- python -c "import geoviews as gv; gv.sample_data('doc/sample-data')"
- conda install -c conda-forge "sphinx<1.7" beautifulsoup4 graphviz
- python -c "import bokeh; bokeh.sampledata.download()"
- conda install -c pyviz/label/dev -c conda-forge nbsite sphinx_ioam_theme
- conda install -c nesii/label/dev-esmf -c conda-forge esmpy
- pip install xesmf
- pip install nbsite
- pip install sphinx_ioam_theme
# TODO: should make this content available too rather than deleting it!
- rm notebooks/*.ipynb
- cd doc
- nbsite_nbpagebuild.py ioam geoviews ../notebooks .
# gallery notebooks depend on user guide assets
- mkdir -p _build/html/user_guide
- cp -r ../notebooks/user_guide/assets user_guide/
- cp -r ../notebooks/user_guide/assets _build/html/user_guide/
- cp -r ../notebooks/user_guide/sample-data _build/html/user_guide/
- nbsite_gallery.py .. notebooks None '.' matplotlib bokeh None
- sphinx-build -b html . ./_build/html
- nbsite_fix_links.py _build/html
- nbsite_cleandisthtml.py ./_build/html take_a_chance
- cp -r ../notebooks/user_guide/assets _build/html/user_guide/
- cp -r ../notebooks/user_guide/sample-data _build/html/user_guide/
- touch ./_build/html/.nojekyll
- cd ..
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: ./doc/_build/html
on:
tags: true
- provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: ./doc/_build/html
on:
tags: true
- provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: ./doc/_build/html
repo: ioam-docs/geoviews-master
on:
branch: gallery
# TODO: remove branch:gallery before merge
30 changes: 24 additions & 6 deletions doc/Homepage.ipynb
Expand Up @@ -6,7 +6,7 @@
"source": [
"GeoViews is a [Python](http://python.org) library that makes it easy to explore and visualize geographical, meteorological, and oceanographic datasets, such as those used in weather, climate, and remote sensing research. \n",
"\n",
"GeoViews is built on the [HoloViews](http://holoviews.org) library for building flexible visualizations of multidimensional data. GeoViews adds a family of geographic plot types based on the [Cartopy](http://scitools.org.uk/cartopy) library, plotted using either the [Matplotlib](http://matplotlib.org) or [Bokeh](http://bokeh.pydata.org) packages. Each of the new `GeoElement` plot types is a new HoloViews `Element` that has an associated geographic projection based on `cartopy.crs`. The `GeoElements` currently include `Feature`, `WMTS`, `Tiles`, `Points`, `Contours`, `Image`, and `Text` objects, each of which can easily be overlaid in the same plots. E.g. an object with temperature data can be overlaid with coastline data using an expression like ``gv.Image(temperature)*gv.Feature(cartopy.feature.COASTLINE)``. Each `GeoElement` can also be freely combined in layouts with any other HoloViews `Element`, making it simple to make even complex multi-figure layouts of overlaid objects.\n",
"GeoViews is built on the [HoloViews](http://holoviews.org) library for building flexible visualizations of multidimensional data. GeoViews adds a family of geographic plot types based on the [Cartopy](http://scitools.org.uk/cartopy) library, plotted using either the [Matplotlib](http://matplotlib.org) or [Bokeh](http://bokeh.pydata.org) packages. Each of the new `GeoElement` plot types is a new HoloViews `Element` that has an associated geographic projection based on `cartopy.crs`. The `GeoElements` currently include `Feature`, `WMTS`, `Tiles`, `Points`, `Contours`, `Image`, `QuadMesh`, `TriMesh`, `RGB`, `HSV`, `Labels`, `Graph`, `HexTiles`, `VectorField` and `Text` objects, each of which can easily be overlaid in the same plots. E.g. an object with temperature data can be overlaid with coastline data using an expression like ``gv.Image(temperature) * gv.Feature(cartopy.feature.COASTLINE)``. Each `GeoElement` can also be freely combined in layouts with any other HoloViews `Element`, making it simple to make even complex multi-figure layouts of overlaid objects.\n",
"\n",
"With GeoViews, you can now work easily and naturally with large, multidimensional geographic datasets, instantly visualizing any subset or combination of them, while always being able to access the raw data underlying any plot. Here's a simple example:"
]
Expand All @@ -25,7 +25,7 @@
"import xarray as xr\n",
"from cartopy import crs\n",
"\n",
"hv.notebook_extension()"
"hv.extension('matplotlib', 'bokeh')"
]
},
{
Expand Down Expand Up @@ -57,10 +57,28 @@
},
"outputs": [],
"source": [
"%%opts Image [colorbar=True fig_size=200] (cmap='viridis')\n",
"ensemble = xr.open_dataset('./sample-data/ensemble.nc')\n",
"dataset = gv.Dataset(ensemble, kdims=['longitude', 'latitude', 'time'], crs=crs.PlateCarree())\n",
"dataset.to(gv.Image, ['longitude', 'latitude'], ['surface_temperature'], ['time']) * gf.coastline()"
"dataset = gv.Dataset(xr.open_dataset('./sample-data/ensemble.nc'))\n",
"dataset.to(gv.Image, ['longitude', 'latitude']).options(cmap='viridis', colorbar=True, fig_size=200) * gf.coastline()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"GeoViews also natively supports geopandas datastructures allowing us to easily plot shapefiles and choropleths:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%output backend='bokeh'\n",
"import geopandas as gpd\n",
"gv.Polygons(gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')), vdims='pop_est').options(\n",
" tools=['hover'], height=500, width=500\n",
")"
]
}
],
Expand Down
Binary file modified doc/_static/favicon.ico 100755 → 100644
Binary file not shown.
1 change: 1 addition & 0 deletions doc/conf.py
Expand Up @@ -20,6 +20,7 @@

_NAV = (
('User Guide', 'user_guide/index'),
('Gallery', 'gallery/index'),
('About', 'about')
)

Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Expand Up @@ -44,4 +44,5 @@ welcome to chat with the developers on `gitter

Introduction <self>
User Guide <user_guide/index>
Gallery <gallery/index>
About <about>
5 changes: 5 additions & 0 deletions doc/user_guide/index.rst
Expand Up @@ -19,6 +19,10 @@ Contents:
* `Working with Bokeh <Working_with_Bokeh.html>`_
Using the Bokeh extension for more interactivity.

* `Resampling large grids <Resampling_Grids.html>`_
Using the datashader and xESMF libraries to regrid large meshes.


.. toctree::
:titlesonly:
:hidden:
Expand All @@ -29,3 +33,4 @@ Contents:
Gridded Datasets I <Gridded_Datasets_I>
Gridded Datasets II <Gridded_Datasets_II>
Working with Bokeh <Working_with_Bokeh>
Resampling Grids <Resampling_Grids>
8 changes: 4 additions & 4 deletions geoviews/element/geo.py
Expand Up @@ -32,7 +32,7 @@
except:
WebMapTileService = None

from ..util import path_to_geom, polygon_to_geom
from ..util import path_to_geom, polygon_to_geom, geom_to_array

geographic_types = (GoogleTiles, cFeature, BaseGeometry)

Expand Down Expand Up @@ -620,13 +620,13 @@ def from_records(cls, records, dataset=None, on=None,
return NdOverlay(data, kdims=kdims)


def dimension_values(self, dimension):
def dimension_values(self, dimension, expanded=True, flat=True):
"""
Shapes do not support convert to array values.
"""
dim = self.get_dimension(dimension)
if dim in self.vdims:
return [self.level]
return np.full(len(self), self.level) if expanded else np.array([self.level])
else:
return []

Expand Down Expand Up @@ -655,4 +655,4 @@ def geom(self):


def __len__(self):
return len(self.data)
return len(geom_to_array(self.data))
3 changes: 3 additions & 0 deletions geoviews/util.py
Expand Up @@ -124,6 +124,9 @@ def geom_to_array(geom):
if hasattr(geom, 'exterior'):
xs = np.array(geom.exterior.coords.xy[0])
ys = np.array(geom.exterior.coords.xy[1])
elif geom.geom_type == 'LineString':
arr = geom_to_arr(geom)
xs, ys = arr[:, 0], arr[:, 1]
else:
xs, ys = [], []
for g in geom:
Expand Down
88 changes: 88 additions & 0 deletions notebooks/gallery/bokeh/airport_graph.ipynb
@@ -0,0 +1,88 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\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": [
"# Count the number of connections from each airport\n",
"counts = routes.groupby('SourceID')[['Stops']].count().reset_index().rename(columns={'Stops': 'Connections'})\n",
"airports_df = pd.merge(airports, counts, left_on='AirportID', right_on='SourceID', how='left')\n",
"\n",
"# Select only US mainland airports & convert from Mercator to Latitudes/Longitudes\n",
"airport_points = gv.Points(airports_df, ['Longitude', 'Latitude']).select(Longitude=(-170, -50), Latitude=(0, 50))\n",
"\n",
"# Declare nodes, graph and tiles\n",
"nodes = gv.Nodes(airport_points, ['Longitude', 'Latitude', 'AirportID'],\n",
" ['Name', 'City', 'Connections'])\n",
"graph = gv.Graph((routes, nodes), ['SourceID', 'DestinationID'], ['Source', 'Destination'])\n",
"tiles = gv.WMTS('https://maps.wikimedia.org/osm-intl/{Z}/{X}/{Y}@2x.png')\n",
"\n",
"# Select 50 busiest airports\n",
"busiest = list(routes.groupby('SourceID').count().sort_values('Stops').iloc[-50:].index.values)\n",
"busiest_airports = graph.select(AirportID=busiest, selection_mode='nodes')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts Graph [width=800 height=600] (edge_selection_line_color='black' edge_hover_line_color='red')\n",
"%%opts Graph (edge_line_width=1 edge_line_alpha=0.01 edge_nonselection_line_alpha=0.01)\n",
"tiles * busiest_airports"
]
}
],
"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
}
75 changes: 75 additions & 0 deletions notebooks/gallery/bokeh/brexit_choropleth.ipynb
@@ -0,0 +1,75 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import geopandas as gpd\n",
"import holoviews as hv\n",
"import geoviews as gv\n",
"\n",
"hv.extension('bokeh')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Declaring data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geometries = gpd.read_file('../../user_guide/assets/boundaries/boundaries.shp')\n",
"referendum = pd.read_csv('../../user_guide/assets/referendum.csv')\n",
"gdf = gpd.GeoDataFrame(pd.merge(geometries, referendum))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot_opts = dict(tools=['hover'], width=550, height=700, color_index='leaveVoteshare',\n",
" colorbar=True, toolbar='above', xaxis=None, yaxis=None)\n",
"gv.Polygons(gdf, vdims=['name', 'leaveVoteshare'], label='Brexit Referendum Vote').opts(plot=plot_opts)"
]
}
],
"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 aff5ef4

Please sign in to comment.