From e5ec9f6533f67f61cdb96d797685b09e568e4fd6 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Wed, 26 Dec 2018 17:11:04 +0000
Subject: [PATCH 1/4] Various example notebook updates
---
examples/Homepage.ipynb | 8 ++--
examples/user_guide/Gridded_Datasets_I.ipynb | 13 ++++--
examples/user_guide/Gridded_Datasets_II.ipynb | 46 +++++++++++--------
examples/user_guide/Resampling_Grids.ipynb | 2 +-
examples/user_guide/Working_with_Bokeh.ipynb | 8 ++--
5 files changed, 44 insertions(+), 33 deletions(-)
diff --git a/examples/Homepage.ipynb b/examples/Homepage.ipynb
index 6eaecf5c..c038c2f5 100644
--- a/examples/Homepage.ipynb
+++ b/examples/Homepage.ipynb
@@ -32,8 +32,7 @@
"outputs": [],
"source": [
"(gf.ocean + gf.land + gf.ocean * gf.land * gf.coastline * gf.borders).opts(\n",
- " 'Feature', projection=crs.Geostationary(), global_extent=True, height=325\n",
- ").cols(3)"
+ " 'Feature', projection=crs.Geostationary(), global_extent=True, height=325).cols(3)"
]
},
{
@@ -52,9 +51,10 @@
"outputs": [],
"source": [
"dataset = gv.Dataset(xr.open_dataset('./data/ensemble.nc'))\n",
- "ensemble = dataset.to(gv.Image, ['longitude', 'latitude'])\n",
+ "ensemble = dataset.to(gv.Image, ['longitude', 'latitude'], 'surface_temperature')\n",
"\n",
- "gv.output(ensemble.opts(cmap='viridis', colorbar=True, fig_size=200) * gf.coastline(), backend='matplotlib')"
+ "gv.output(ensemble.opts(cmap='viridis', colorbar=True, fig_size=200, backend='matplotlib') * gf.coastline(),\n",
+ " backend='matplotlib')"
]
},
{
diff --git a/examples/user_guide/Gridded_Datasets_I.ipynb b/examples/user_guide/Gridded_Datasets_I.ipynb
index 146bb17a..b9388958 100644
--- a/examples/user_guide/Gridded_Datasets_I.ipynb
+++ b/examples/user_guide/Gridded_Datasets_I.ipynb
@@ -19,7 +19,9 @@
"import holoviews as hv\n",
"import geoviews as gv\n",
"import geoviews.feature as gf\n",
+ "\n",
"from cartopy import crs\n",
+ "from geoviews import opts\n",
"\n",
"gv.extension('matplotlib')\n",
"\n",
@@ -190,8 +192,9 @@
"metadata": {},
"outputs": [],
"source": [
- "air_temperature = gv.Dataset(xr.open_dataset('../data/pre-industrial.nc'), kdims=['longitude', 'latitude'],\n",
- " vdims=['air_temperature'])\n",
+ "pre_industrial = xr.open_dataset('../data/pre-industrial.nc').load()\n",
+ "\n",
+ "air_temperature = gv.Dataset(pre_industrial, ['longitude', 'latitude'], 'air_temperature')\n",
"air_temperature"
]
},
@@ -225,10 +228,10 @@
"outputs": [],
"source": [
"temp_curve = hv.Curve(xr_dataset.select(longitude=0, latitude=10), kdims=['time'])\n",
- "temp_map = xr_dataset.to(gv.Image,['longitude', 'latitude']) * gv.Points([(0,10)], crs=crs.PlateCarree())\n",
+ "temp_map = xr_dataset.to(gv.Image,['longitude', 'latitude']) * gv.Points([(0,10)])\n",
"(temp_map + temp_curve).opts(\n",
" opts.Curve(aspect=2, xticks=4, xrotation=15),\n",
- " opts.Points(color='k'))"
+ " opts.Points(color='k', global_extent=True))"
]
},
{
@@ -275,7 +278,7 @@
"srfc_temps = xr_dataset.redim.range(surface_temperature=(300, max_surface_temp)).to(gv.Image,['longitude', 'latitude'])\n",
"\n",
"(srfc_temps * gf.coastline).opts(\n",
- " opts.Image(projection=crs.Geostationary(), cmap='Greens', xaxis=None yaxis=None))"
+ " opts.Image(projection=crs.Geostationary(), cmap='Greens', xaxis=None, yaxis=None))"
]
},
{
diff --git a/examples/user_guide/Gridded_Datasets_II.ipynb b/examples/user_guide/Gridded_Datasets_II.ipynb
index 28cbd95e..d64612f2 100644
--- a/examples/user_guide/Gridded_Datasets_II.ipynb
+++ b/examples/user_guide/Gridded_Datasets_II.ipynb
@@ -11,10 +11,13 @@
"import holoviews as hv\n",
"import geoviews as gv\n",
"import geoviews.feature as gf\n",
+ "\n",
+ "from geoviews import opts\n",
"from cartopy import crs as ccrs\n",
"\n",
"gv.extension('matplotlib', 'bokeh')\n",
- "%output size=200"
+ "\n",
+ "gv.output(size=200)"
]
},
{
@@ -56,7 +59,7 @@
"metadata": {},
"outputs": [],
"source": [
- "dataset = gv.Dataset(xr_ensembles, vdims='surface_temperature', crs=ccrs.PlateCarree())\n",
+ "dataset = gv.Dataset(xr_ensembles, vdims='surface_temperature')\n",
"dataset"
]
},
@@ -114,9 +117,10 @@
"metadata": {},
"outputs": [],
"source": [
- "%%opts Points [color_index=2 size_index=None] (cmap='jet')\n",
- "hv.Layout([dataset.to(el, geo_dims)[::10, ::5] * gf.coastline\n",
- " for el in [gv.FilledContours, gv.LineContours, gv.Points]]).cols(1)"
+ "layout = hv.Layout([dataset.to(el, geo_dims)[::10, ::5] * gf.coastline\n",
+ " for el in [gv.FilledContours, gv.LineContours, gv.Points]]).cols(1)\n",
+ "\n",
+ "layout.opts(opts.Points(color='surface_temperature', cmap='jet'))"
]
},
{
@@ -152,10 +156,9 @@
"metadata": {},
"outputs": [],
"source": [
- "%%opts QuadMesh [colorbar=True fig_size=300 projection=ccrs.Robinson()] (cmap='RdBu_r')\n",
- "xrds = xr.tutorial.load_dataset('rasm')\n",
- "qmesh = gv.Dataset(xrds.Tair).to(gv.QuadMesh, ['xc', 'yc'], dynamic=True)\n",
- "qmesh.redim.range(Tair=(-30, 30)) * gf.coastline"
+ "xrds = xr.tutorial.open_dataset('rasm').load()\n",
+ "qmesh = gv.Dataset(xrds.Tair).to(gv.QuadMesh, ['xc', 'yc'], dynamic=True).redim.range(Tair=(-30, 30))\n",
+ "qmesh.opts(colorbar=True, cmap='RdBu_r', projection=ccrs.Robinson()) * gf.coastline"
]
},
{
@@ -173,7 +176,7 @@
"metadata": {},
"outputs": [],
"source": [
- "%output backend='bokeh'"
+ "hv.output(backend='bokeh')"
]
},
{
@@ -189,8 +192,11 @@
"metadata": {},
"outputs": [],
"source": [
- "%%opts Curve [xrotation=25 width=600 height=400] {+framewise} NdOverlay [legend_position='right' toolbar='above']\n",
- "dataset.to(hv.Curve, 'time', dynamic=True).overlay('realization')"
+ "curves = dataset.to(hv.Curve, 'time', dynamic=True).overlay('realization')\n",
+ "\n",
+ "curves.opts(\n",
+ " opts.Curve(xrotation=25, width=600, height=400, framewise=True),\n",
+ " opts.NdOverlay(legend_position='right', toolbar='right'))"
]
},
{
@@ -208,8 +214,7 @@
"metadata": {},
"outputs": [],
"source": [
- "%%opts HeatMap [width=600 colorbar=True tools=['hover']]\n",
- "dataset.to(hv.HeatMap, ['realization', 'time'], dynamic=True)"
+ "dataset.to(hv.HeatMap, ['realization', 'time'], dynamic=True).opts(width=600, colorbar=True, tools=['hover'])"
]
},
{
@@ -227,8 +232,9 @@
"metadata": {},
"outputs": [],
"source": [
- "%%output backend='matplotlib'\n",
- "hv.Layout([dataset.to(hv.Violin, d, groupby=[], datatype=['dataframe']).options(xrotation=25)\n",
+ "hv.output(backend='matplotlib')\n",
+ "\n",
+ "hv.Layout([dataset.to(hv.Violin, d, groupby=[], datatype=['dataframe']).opts(xrotation=25)\n",
" for d in ['time', 'realization']])"
]
},
@@ -251,7 +257,6 @@
"metadata": {},
"outputs": [],
"source": [
- "%%output backend='matplotlib'\n",
"northern = dataset.select(latitude=slice(25, 75))\n",
"(northern.select(longitude=slice(260, 305)).to(gv.Image, geo_dims) *\n",
" northern.select(longitude=slice(330, 362)).to(gv.Image, geo_dims) *\n",
@@ -273,8 +278,11 @@
"metadata": {},
"outputs": [],
"source": [
- "%%opts NdOverlay [width=600 height=400 legend_position='right' toolbar='above'] Curve (color=Palette('Set1'))\n",
- "dataset.select(latitude=0, longitude=0).to(hv.Curve, ['time']).reindex().overlay()"
+ "hv.output(backend='bokeh')\n",
+ "\n",
+ "curves = dataset.select(latitude=0, longitude=0).to(hv.Curve, ['time']).reindex().overlay()\n",
+ "\n",
+ "curves.opts(width=600, height=400, legend_position='right', toolbar='above')"
]
},
{
diff --git a/examples/user_guide/Resampling_Grids.ipynb b/examples/user_guide/Resampling_Grids.ipynb
index c6b96a2b..52c0521a 100644
--- a/examples/user_guide/Resampling_Grids.ipynb
+++ b/examples/user_guide/Resampling_Grids.ipynb
@@ -307,7 +307,7 @@
"metadata": {},
"outputs": [],
"source": [
- "gv.output(quadmeshes.opts(cmap='RdBu_r') * gv.feature.coastline, backend='matplotlib')"
+ "gv.output(quadmeshes.opts(cmap='RdBu_r') * gv.feature.coastline, backend='matplotlib', size=300)"
]
},
{
diff --git a/examples/user_guide/Working_with_Bokeh.ipynb b/examples/user_guide/Working_with_Bokeh.ipynb
index 3a9a64b7..3949ffea 100644
--- a/examples/user_guide/Working_with_Bokeh.ipynb
+++ b/examples/user_guide/Working_with_Bokeh.ipynb
@@ -48,8 +48,7 @@
"import geoviews.tile_sources as gts\n",
"\n",
"gv.Layout([ts.relabel(name) for name, ts in gts.tile_sources.items()]).opts(\n",
- " 'WMTS', xaxis=None, yaxis=None, width=225, height=225\n",
- ").cols(4)"
+ " 'WMTS', xaxis=None, yaxis=None, width=225, height=225).cols(4)"
]
},
{
@@ -184,10 +183,11 @@
"metadata": {},
"outputs": [],
"source": [
- "dataset = xr.open_dataset('../data/pre-industrial.nc')\n",
+ "dataset = xr.open_dataset('../../doc/sample-data//pre-industrial.nc')\n",
"air_temperature = gv.Dataset(dataset, ['longitude', 'latitude'], 'air_temperature',\n",
" group='Pre-industrial air temperature')\n",
- "air_temperature.to.image().opts(tools=['hover'], cmap='viridis') * gf.coastline.options(line_color='black', width=600, height=500)"
+ "air_temperature.to.image().opts(tools=['hover'], cmap='viridis') *\\\n",
+ "gf.coastline().opts(line_color='black', width=600, height=500)"
]
}
],
From 3fde52d0601fa8f40177297c916400caef7f3be7 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Wed, 26 Dec 2018 17:11:27 +0000
Subject: [PATCH 2/4] Various fixes for projections
---
geoviews/operation/projection.py | 4 +---
geoviews/plotting/bokeh/plot.py | 1 +
geoviews/plotting/mpl/__init__.py | 2 +-
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/geoviews/operation/projection.py b/geoviews/operation/projection.py
index 076b08c3..a8b13020 100644
--- a/geoviews/operation/projection.py
+++ b/geoviews/operation/projection.py
@@ -49,9 +49,7 @@ class project_path(_project_operation):
supported_types = [Polygons, Path, Contours, EdgePaths]
def _process_element(self, element):
- if element.crs == self.p.projection:
- return element
- elif not len(element):
+ if not len(element):
return element.clone(crs=self.p.projection)
crs = element.crs
diff --git a/geoviews/plotting/bokeh/plot.py b/geoviews/plotting/bokeh/plot.py
index 6a3b3263..d788da27 100644
--- a/geoviews/plotting/bokeh/plot.py
+++ b/geoviews/plotting/bokeh/plot.py
@@ -91,6 +91,7 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
shape = Shape(self.projection.boundary, crs=self.projection).options(fill_alpha=0)
shapeplot = GeoShapePlot(shape, projection=self.projection,
overlaid=True, renderer=self.renderer)
+ shapeplot.geographic = False
shapeplot.initialize_plot(plot=fig)
return fig
diff --git a/geoviews/plotting/mpl/__init__.py b/geoviews/plotting/mpl/__init__.py
index 50a96582..429061e9 100644
--- a/geoviews/plotting/mpl/__init__.py
+++ b/geoviews/plotting/mpl/__init__.py
@@ -114,7 +114,7 @@ def _finalize_axis(self, *args, **kwargs):
return ret
def get_data(self, element, ranges, style):
- if self._project_operation and self.geographic and element.crs != self.projection:
+ if self._project_operation and self.geographic:
element = self._project_operation(element, projection=self.projection)
return super(GeoPlot, self).get_data(element, ranges, style)
From 3380e8c1b4c29f5aa061b73d973319f957ca4599 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Wed, 26 Dec 2018 17:13:57 +0000
Subject: [PATCH 3/4] Set matplotlib backend to agg
---
.travis.yml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index cf77cbd8..a81eba54 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -58,6 +58,8 @@ jobs:
- source activate test-environment
- doit develop_install $CHANS_DEV -o recommended
- doit env_capture
+ before-script:
+ - "echo 'backend : Agg' > $HOME/.matplotlib/matplotlibrc"
script:
- geoviews fetch-data --path=examples
- bokeh sampledata
From 6c0fc3e7c0a2a92435969345a443c5195742fb33 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Wed, 26 Dec 2018 17:15:19 +0000
Subject: [PATCH 4/4] Fixed reference data link
---
examples/user_guide/Working_with_Bokeh.ipynb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/user_guide/Working_with_Bokeh.ipynb b/examples/user_guide/Working_with_Bokeh.ipynb
index 3949ffea..100bd325 100644
--- a/examples/user_guide/Working_with_Bokeh.ipynb
+++ b/examples/user_guide/Working_with_Bokeh.ipynb
@@ -183,7 +183,7 @@
"metadata": {},
"outputs": [],
"source": [
- "dataset = xr.open_dataset('../../doc/sample-data//pre-industrial.nc')\n",
+ "dataset = xr.open_dataset('../data/pre-industrial.nc')\n",
"air_temperature = gv.Dataset(dataset, ['longitude', 'latitude'], 'air_temperature',\n",
" group='Pre-industrial air temperature')\n",
"air_temperature.to.image().opts(tools=['hover'], cmap='viridis') *\\\n",