geoviews.feature extents
See original GitHub issueIt would be nice if the extents given to the geoviews.feature determine the extent of data that is extracted/used, rather than just determing the viewable window size.
Below is an example that plots some fake data over a small region. Here the window extent is chosen by a) the dataset used and b) the extents given to the geoviews.feature.coastline
However, if you zoom out you can see that the coastline data is actually available for the entire globe rather than just the subdomain I have chosen.
This has implications for the size of files generated (HoloMaps) or data downloaded (DynamicMaps). This is especially noticiable when using high resolution data. If you turn on the use of 10m coastline resolution, you will see that the file size goes from ~approximately 150k to 8.8M. It is my suspiciion that the majority of the increased data comes from the highresolution data in regions on the world we don’t actually care about.
import numpy as np
import xarray as xr
import holoviews as hv
import geoviews as gv
import geoviews.feature as gf
from cartopy import crs as ccrs
def create_data():
"""
create fake example data
"""
times = [np.datetime64('2018-02-22 00:00:00')]
lons = np.arange(144, 150, 1)
lats = np.arange(-45, -39, 1)
dims = ('time', 'latitude', 'longitude')
shape = (len(times), len(lats), len(lons))
coords = {'latitude':lats, 'longitude':lons, 'time':times}
pres = np.zeros(shape)
pres[0, :, :] = 10
pres_xr = xr.DataArray(pres, dims=dims, coords=coords)
xr_ds = xr.Dataset({'time': times, 'latitude': lats,
'longitude': lons, 'pres': (dims, pres)})
return xr_ds
hv.extension('bokeh')
renderer = hv.renderer('bokeh')
hv.output('size=200')
hv.opts("Image (cmap='Spectral_r')")
xr_ds = create_data()
vdims = ['pres']
kdims= ['time', 'latitude', 'longitude']
gv_ds = gv.Dataset(xr_ds, kdims=kdims, vdims=vdims, crs=ccrs.PlateCarree())
hv.Dimension.type_formatters[np.datetime64] = '%Y-%m-%d %H'
geo_dims = ['longitude', 'latitude']
extents = (144.0, -45.0, 149.0, -40.0)
# using extents on the geo feature sets the plot window extents,
# however, all the data is still extracted/used
#hv.opts("Feature [scale='10m']")
coast = gf.coastline.clone(extents=extents)
img = gv_ds.to(gv.Image, geo_dims) * coast
renderer.save(img, 'test_gf')
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:18 (3 by maintainers)
Top GitHub Comments
http://geopandas.org/indexing.html I just discovered there’s a
.cx
method which might be useful here.I would like to help make a PR for this, but I don’t know where/how to start.
I was thinking of adding a
subset
orcrop
kwarg like this:gv.feature.coastline(subset=(x1, x2, y1, y2))
sort of similar to thescale
kwarggv.feature.coastline(scale='50m')
so I tried searching for thescale
kwarg in the code, but I only found it in https://github.com/holoviz/geoviews/blob/master/geoviews/element/geo.py#L152 which is only called when doinggv.feature.coastline(scale='50m').geoms
Any ideas appreciated!