holoviz / geoviews

Simple, concise geographical visualization in Python
http://geoviews.org
BSD 3-Clause "New" or "Revised" License
577 stars 75 forks source link

`gv.Points` not compatible with `holoviews.operation.datashader.inspect_points` #619

Open kanglcn opened 1 year ago

kanglcn commented 1 year ago

ALL software version info

Name Version Build Channel bokeh 2.4.3 pyhd8ed1ab_3 conda-forge holoviews 1.15.4 pyhd8ed1ab_0 conda-forge datashader 0.14.4 pyh1a96a4e_0 conda-forge geoviews 1.9.6 pyhd8ed1ab_0 conda-forge geoviews-core 1.9.6 pyha770c72_0 conda-forge

Description of expected behavior and the observed behavior

holoviews.operation.datashader.inspect_points allows inspecting all vdims in DynamicMap. But when using it with gv.Points, points disappear as soon as the mouse enters the frame. holoviews.Points don't have this issue.

This issue was first found here: https://discourse.holoviz.org/t/one-dimension-missing-on-hover-after-rasterize-point-data/4049

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

import numpy as np
import pandas as pd
#import holoviews as hv
import geoviews as gv
#hv.extension('bokeh')
gv.extension('bokeh')
import holoviews.operation.datashader as hd

lon = np.array([8.75,8.76,8.77])
lat = np.array([46.1,46.2,46.3])
height = np.array([0.0,0.1,0.2])
index = np.array([0,1,2])

df = pd.DataFrame(dict(Longitude=lon,Latitude=lat,Height=height,Index=index))

gvpoints = gv.Points(df, ['Longitude','Latitude'])
#hvpoints = hv.Points(df, ['Longitude', 'Latitude'])

rasterized = hd.dynspread(hd.rasterize(gvpoints).opts(width=300, height=300))
highlight= hd.inspect_points(rasterized)
rasterized * highlight.opts(marker='o',size=10,tools=['hover'])

Stack traceback and/or browser JavaScript console output

Screenshots or screencasts of the bug in action

image

ahuang11 commented 9 months ago

I encountered this traceback:

WARNING:param.dynamic_operation: Callable raised "ValueError('Supplied Image bounds do not match the coordinates defined in the data. Bounds only have to be declared if no coordinates are supplied, otherwise they must match the data. To change the displayed extents set the range on the x- and y-dimensions.')".
Invoked as dynamic_operation(x=-20037508.342789244, y=20037508.342789248)
Traceback (most recent call last):
  File "/Users/ahuang/repos/holoviews/holoviews/plotting/util.py", line 279, in get_plot_frame
    return map_obj[key]
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 1212, in __getitem__
    val = self._execute_callback(*tuple_key)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 979, in _execute_callback
    retval = self.callback(*args, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 549, in __call__
    if not args and not kwargs and not any(kwarg_hash): return self.callable()
  File "/Users/ahuang/repos/holoviews/holoviews/util/__init__.py", line 1024, in dynamic_operation
    key, obj = resolve(key, kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/util/__init__.py", line 1013, in resolve
    return key, map_obj[key]
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 1212, in __getitem__
    val = self._execute_callback(*tuple_key)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 979, in _execute_callback
    retval = self.callback(*args, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 549, in __call__
    if not args and not kwargs and not any(kwarg_hash): return self.callable()
  File "/Users/ahuang/repos/holoviews/holoviews/util/__init__.py", line 1024, in dynamic_operation
    key, obj = resolve(key, kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/util/__init__.py", line 1013, in resolve
    return key, map_obj[key]
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 1212, in __getitem__
    val = self._execute_callback(*tuple_key)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 979, in _execute_callback
    retval = self.callback(*args, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 549, in __call__
    if not args and not kwargs and not any(kwarg_hash): return self.callable()
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 282, in dynamic_mul
    element = self[args]
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 1212, in __getitem__
    val = self._execute_callback(*tuple_key)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 979, in _execute_callback
    retval = self.callback(*args, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 549, in __call__
    if not args and not kwargs and not any(kwarg_hash): return self.callable()
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 204, in dynamic_mul
    other_el = other.select(HoloMap, **key_map) if other.kdims else other[()]
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 1212, in __getitem__
    val = self._execute_callback(*tuple_key)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 979, in _execute_callback
    retval = self.callback(*args, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/core/spaces.py", line 579, in __call__
    ret = self.callable(*args, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/util/__init__.py", line 1025, in dynamic_operation
    return apply(obj, *key, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/util/__init__.py", line 1017, in apply
    processed = self._process(element, key, kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/util/__init__.py", line 999, in _process
    return self.p.operation.process_element(element, key, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/core/operation.py", line 194, in process_element
    return self._apply(element, key)
  File "/Users/ahuang/repos/holoviews/holoviews/core/operation.py", line 141, in _apply
    ret = self._process(element, key)
  File "/Users/ahuang/repos/holoviews/holoviews/operation/datashader.py", line 1877, in _process
    val = raster[x-xdelta:x+xdelta, y-ydelta:y+ydelta].reduce(function=np.nansum)
  File "/Users/ahuang/repos/holoviews/holoviews/core/data/__init__.py", line 711, in __getitem__
    data = self.select(**selection)
  File "/Users/ahuang/repos/holoviews/holoviews/core/data/__init__.py", line 195, in pipelined_fn
    result = method_fn(*args, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/element/raster.py", line 451, in select
    return self.clone(data, xdensity=self.xdensity, datatype=datatype,
  File "/Users/ahuang/miniconda3/envs/holoviews/lib/python3.10/site-packages/geoviews/element/geo.py", line 118, in clone
    return super().clone(data, shared_data, new_type,
  File "/Users/ahuang/repos/holoviews/holoviews/element/raster.py", line 398, in clone
    return super().clone(data, shared_data, new_type, link,
  File "/Users/ahuang/repos/holoviews/holoviews/core/data/__init__.py", line 1193, in clone
    return super().clone(data, shared_data, new_type, *args, **overrides)
  File "/Users/ahuang/repos/holoviews/holoviews/core/dimension.py", line 564, in clone
    return clone_type(data, *args, **{k:v for k,v in settings.items()
  File "/Users/ahuang/miniconda3/envs/holoviews/lib/python3.10/site-packages/geoviews/element/geo.py", line 111, in __init__
    super().__init__(data, kdims=kdims, vdims=vdims, **kwargs)
  File "/Users/ahuang/repos/holoviews/holoviews/element/raster.py", line 313, in __init__
    self._validate(data_bounds, supplied_bounds)
  File "/Users/ahuang/repos/holoviews/holoviews/element/raster.py", line 379, in _validate
    raise ValueError('Supplied Image bounds do not match the coordinates defined '
ValueError: Supplied Image bounds do not match the coordinates defined in the data. Bounds only have to be declared if no coordinates are supplied, otherwise they must match the data. To change the displayed extents set the range on the x- and y-dimensions.