Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Gallery #121

Merged
merged 36 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
04b14de
WIP: beginning to add gallery.
ceball Jan 14, 2018
8c10a38
Syntax fixup
ceball Jan 14, 2018
551d0f3
Added missing dependencies for bokeh png export.
ceball Jan 14, 2018
7d39e35
Upload website to preview location.
ceball Jan 14, 2018
b63b395
Whitespace fix
ceball Jan 14, 2018
9ba8fca
Syntax fixup.
ceball Jan 14, 2018
17ebe30
Added initial gallery examples
philippjfr Jan 14, 2018
c9f5a26
Added and fixed gallery examples
philippjfr Jan 14, 2018
de22dc7
Generate only matplotlib and bokeh galleries. Also, newer nbsite_gall…
ceball Jan 14, 2018
995567a
Allow us to see gallery during this PR.
ceball Jan 14, 2018
54ddfd9
Fix syntax.
ceball Jan 14, 2018
2355dd6
Fixed katrina_track example legend
philippjfr Jan 14, 2018
8e891a8
Download bokeh sampledata
philippjfr Jan 14, 2018
99ade65
Skip apps for now.
ceball Jan 14, 2018
4748161
One or more gallery notebooks depend on user guide assets.
ceball Jan 15, 2018
b3bb13e
Add world_population gallery example
philippjfr Jan 15, 2018
327f427
Add transparent favicon
philippjfr Jan 15, 2018
7898716
Set orthographic_vectorfield example options
philippjfr Jan 15, 2018
a4e2312
Add xarray Image example
philippjfr Jan 15, 2018
38ac20c
Cropped favicon
philippjfr Jan 15, 2018
b3cc3c6
Added great_circle example
philippjfr Jan 15, 2018
b2fe65d
Fixed bad merge
philippjfr Apr 19, 2018
2d21e67
Use nbsite conda package.
ceball Apr 19, 2018
8e54f32
Fixed fixed bad merge.
ceball Apr 19, 2018
79f35e3
Fixed bugs in Shape
philippjfr Apr 20, 2018
1ee32b4
Simplified orthographic_vectorfield example
philippjfr Apr 20, 2018
251cc6c
Minor fix for bokeh filled_contours example
philippjfr Apr 21, 2018
ec23e5c
Added Resampling Grids notebook to user guide
philippjfr Apr 21, 2018
2003ae0
Rewrote projection user guide
philippjfr Apr 21, 2018
b0832ca
Updated Homepage
philippjfr Apr 21, 2018
d42035d
Move assets to correct location on travis
philippjfr Apr 21, 2018
3c90ba4
Fixed Gridded dataset notebooks
philippjfr Apr 21, 2018
c9fd070
Removed TriMesh resampling section
philippjfr Apr 21, 2018
54a3baa
Attempt to simplify travis.yml
philippjfr Apr 21, 2018
97d3578
Simplified Gridded Datasets notebook
philippjfr Apr 21, 2018
de77ee5
Build docs on commits to master
philippjfr Apr 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: python

sudo: false

TODO: update when to upload to ioam-docs before merging
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something went wrong for you in a rebase and/or merge? This should be a comment (# TODO: ...).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bizarre, no idea how that could possibly happen. That said, master seem to have been building okay. Will fix it some time today.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably manual error during merge? Anyway, I like the idea of travis having a TODO key, which you use to tell it what to do in the future. But evidently they haven't implemented that yet...

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,29 @@ 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:
branch: master
30 changes: 24 additions & 6 deletions doc/Homepage.ipynb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}
Loading