geoviews icon indicating copy to clipboard operation
geoviews copied to clipboard

geoviews.operation.regrid.weighted_regrid() conservative interpolation results in KeyError: 'lon_b'

Open Timothy-W-Hilton opened this issue 5 years ago • 0 comments

ALL software version info (Panel, bokeh, python, notebook, OS, browser, any other relevant packages)

xesmf 0.2.1 py_0 conda-forge geoviews 1.6.5 py_0 conda-forge geoviews-core 1.6.5 py_0 conda-forge holoviews 1.12.6 py_0 conda-forge bokeh 1.3.4 py37_0 conda-forge python 3.7.3 h93065d6_1 conda-forge notebook 6.0.1 py37_0 conda-forge MacOS High Sierra 10.13.6 Safari Version 13.0.4 (13608.4.9.1.4)

Description of expected behavior and the observed behavior

I expected changing the interpolation method from the default "bilinear" to "conservative" would use the different interpolation method invisibly to the caller. Instead it results in a KeyError.

Complete, minimal, self-contained example code that reproduces the issue

adding interpolation='conservative' to the weighted_regrid() call in the final example in the GeoViews documentation Resampling Grids example reproduces the problem.

# in the GeoViews documentation "Resampling Grids" example notebook change 
weighted_regrid(quadmeshes, streams=[]) * gv.feature.coastline
# to
weighted_regrid(quadmeshes, streams=[], interpolation='conservative') * gv.feature.coastline

Stack traceback and/or browser JavaScript console output


KeyError Traceback (most recent call last) ~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/xarray/core/dataset.py in _construct_dataarray(self, name) 1018 try: -> 1019 variable = self._variables[name] 1020 except KeyError:

KeyError: 'lon_b'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last) ~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/IPython/core/formatters.py in call(self, obj, include, exclude) 968 969 if method is not None: --> 970 return method(include=include, exclude=exclude) 971 return None 972 else:

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/dimension.py in repr_mimebundle(self, include, exclude) 1292 combined and returned. 1293 """ -> 1294 return Store.render(self) 1295 1296

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/options.py in render(cls, obj) 1366 data, metadata = {}, {} 1367 for hook in hooks: -> 1368 ret = hook(obj) 1369 if ret is None: 1370 continue

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in pprint_display(obj) 279 if not ip.display_formatter.formatters['text/plain'].pprint: 280 return None --> 281 return display(obj, raw_output=True) 282 283

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw_output, **kwargs) 255 elif isinstance(obj, (HoloMap, DynamicMap)): 256 with option_state(obj): --> 257 output = map_display(obj) 258 elif isinstance(obj, Plot): 259 output = render(obj)

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in wrapped(element) 144 try: 145 max_frames = OutputSettings.options['max_frames'] --> 146 mimebundle = fn(element, max_frames=max_frames) 147 if mimebundle is None: 148 return {}, {}

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in map_display(vmap, max_frames) 204 return None 205 --> 206 return render(vmap) 207 208

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in render(obj, **kwargs) 66 renderer = renderer.instance(fig='png') 67 ---> 68 return renderer.components(obj, **kwargs) 69 70

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/plotting/bokeh/renderer.py in components(self, obj, fmt, comm, **kwargs) 248 # Bokeh has to handle comms directly in <0.12.15 249 comm = False if bokeh_version < '0.12.15' else comm --> 250 return super(BokehRenderer, self).components(obj,fmt, comm, **kwargs) 251 252

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/plotting/renderer.py in components(self, obj, fmt, comm, **kwargs) 319 plot = obj 320 else: --> 321 plot, fmt = self._validate(obj, fmt) 322 323 data, metadata = {}, {}

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/plotting/renderer.py in _validate(self, obj, fmt, **kwargs) 218 if isinstance(obj, tuple(self.widgets.values())): 219 return obj, 'html' --> 220 plot = self.get_plot(obj, renderer=self, **kwargs) 221 222 fig_formats = self.mode_formats['fig'][self.mode]

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/plotting/bokeh/renderer.py in get_plot(self_or_cls, obj, doc, renderer, **kwargs) 133 curdoc().theme = self_or_cls.theme 134 doc.theme = self_or_cls.theme --> 135 plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer, **kwargs) 136 plot.document = doc 137 return plot

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj, renderer, **kwargs) 184 185 # Initialize DynamicMaps with first data item --> 186 initialize_dynamic(obj) 187 188 if not isinstance(obj, Plot):

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/plotting/util.py in initialize_dynamic(obj) 248 continue 249 if not len(dmap): --> 250 dmap[dmap._initial_key()] 251 252

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/spaces.py in getitem(self, key) 1325 # Not a cross product and nothing cached so compute element. 1326 if cache is not None: return cache -> 1327 val = self._execute_callback(*tuple_key) 1328 if data_slice: 1329 val = self._dataslice(val, data_slice)

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/spaces.py in _execute_callback(self, *args) 1098 1099 with dynamicmap_memoization(self.callback, self.streams): -> 1100 retval = self.callback(*args, **kwargs) 1101 return self._style(retval) 1102

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/spaces.py in call(self, *args, **kwargs) 732 733 try: --> 734 ret = self.callable(*args, **kwargs) 735 except KeyError: 736 # KeyError is caught separately because it is used to signal

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/spaces.py in dynamic_mul(*args, **kwargs) 290 if isinstance(self, DynamicMap): 291 def dynamic_mul(*args, **kwargs): --> 292 element = self[args] 293 if reverse: 294 return other * element

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/spaces.py in getitem(self, key) 1325 # Not a cross product and nothing cached so compute element. 1326 if cache is not None: return cache -> 1327 val = self._execute_callback(*tuple_key) 1328 if data_slice: 1329 val = self._dataslice(val, data_slice)

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/spaces.py in _execute_callback(self, *args) 1098 1099 with dynamicmap_memoization(self.callback, self.streams): -> 1100 retval = self.callback(*args, **kwargs) 1101 return self._style(retval) 1102

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/spaces.py in call(self, *args, **kwargs) 732 733 try: --> 734 ret = self.callable(*args, **kwargs) 735 except KeyError: 736 # KeyError is caught separately because it is used to signal

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/util/init.py in dynamic_operation(*key, **kwargs) 943 if map_obj._posarg_keys and not key: 944 key = tuple(kwargs[k] for k in map_obj._posarg_keys) --> 945 return self._process(map_obj[key], key, kwargs) 946 if isinstance(self.p.operation, Operation): 947 return OperationCallable(dynamic_operation, inputs=[map_obj],

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/util/init.py in _process(self, element, key, kwargs) 924 elif isinstance(self.p.operation, Operation): 925 kwargs = {k: v for k, v in kwargs.items() if k in self.p.operation.param} --> 926 return self.p.operation.process_element(element, key, **kwargs) 927 else: 928 return self.p.operation(element, **kwargs)

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/operation.py in process_element(self, element, key, **params) 141 """ 142 self.p = param.ParamOverrides(self, params) --> 143 return self._apply(element, key) 144 145

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/holoviews/core/operation.py in _apply(self, element, key) 119 for hook in self._preprocess_hooks: 120 kwargs.update(hook(self, element)) --> 121 ret = self._process(element, key) 122 for hook in self._postprocess_hooks: 123 ret = hook(self, ret, **kwargs)

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/geoviews/operation/regrid.py in _process(self, element, key) 98 99 def _process(self, element, key=None): --> 100 regridder, arrays = self._get_regridder(element) 101 x, y = element.kdims 102 ds = xr.Dataset({vd: regridder(arr) for vd, arr in arrays.items()})

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/geoviews/operation/regrid.py in _get_regridder(self, element) 93 regridder = xe.Regridder(ds, ds_out, self.p.interpolation, 94 reuse_weights=self.p.reuse_weights, ---> 95 filename=filename) 96 return regridder, arrays 97

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/xesmf/frontend.py in init(self, ds_in, ds_out, method, periodic, filename, reuse_weights) 135 self._grid_in, shape_in = ds_to_ESMFgrid(ds_in, 136 need_bounds=self.need_bounds, --> 137 periodic=periodic 138 ) 139 self._grid_out, shape_out = ds_to_ESMFgrid(ds_out,

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/xesmf/frontend.py in ds_to_ESMFgrid(ds, need_bounds, periodic, append) 65 66 if need_bounds: ---> 67 lon_b = np.asarray(ds['lon_b']) 68 lat_b = np.asarray(ds['lat_b']) 69 lon_b, lat_b = as_2d_mesh(lon_b, lat_b)

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/xarray/core/dataset.py in getitem(self, key) 1101 1102 if hashable(key): -> 1103 return self._construct_dataarray(key) 1104 else: 1105 return self._copy_listed(np.asarray(key))

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/xarray/core/dataset.py in _construct_dataarray(self, name) 1020 except KeyError: 1021 _, name, variable = _get_virtual_variable( -> 1022 self._variables, name, self._level_coords, self.dims) 1023 1024 needed_dims = set(variable.dims)

~/anaconda3/envs/d34Shv/lib/python3.7/site-packages/xarray/core/dataset.py in _get_virtual_variable(variables, key, level_vars, dim_sizes) 89 ref_var = dim_var.to_index_variable().get_level_variable(ref_name) 90 else: ---> 91 ref_var = variables[ref_name] 92 93 if var_name is None:

KeyError: 'lon_b'

Screenshots or screencasts of the bug in action

Timothy-W-Hilton avatar Dec 12 '19 17:12 Timothy-W-Hilton