holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.66k stars 396 forks source link

datashading error when zoomed on region without any points (maybe geoviews projection + responsive too) #4910

Open ahuang11 opened 3 years ago

ahuang11 commented 3 years ago

Sometimes happens:

  File "~/anaconda3/envs/wxqsee/lib/python3.7/site-packages/holoviews/core/sheetcoords.py", line 166, in __init__
    r1,r2,c1,c2 = Slice._boundsspec2slicespec(self.lbrt,self)
  File "~/anaconda3/envs/wxqsee/lib/python3.7/site-packages/holoviews/core/sheetcoords.py", line 519, in _boundsspec2slicespec
    t_idx = int(np.ceil(t_m-0.5))
ValueError: cannot convert float NaN to integer
jbednar commented 3 years ago

Any way to reproduce? Presumably t_m here is NaN, implying that the bounds are NaN, so I'd suspect an empty plot is being encountered somehow?

ahuang11 commented 3 years ago

Zoom too close on some points that are spread too far apart (thus no points within frame range triggering NaN) using geoviews + tiles I think?

jbednar commented 3 years ago

If you can find an example plot we can run and give a step-by-step guide, we can check it out!

ahuang11 commented 3 years ago

Maybe not related to datashader, maybe related to https://discourse.holoviz.org/t/show-individual-points-when-zoomed-else-datashade/2204

ahuang11 commented 3 years ago

Okay I got a reproducible example; has to do with responsive=True.

Basically go wild zooming (zoom in really fast and out) then the error should pop up eventually.

import datashader as ds
import holoviews as hv
import geoviews as gv
import numpy as np
import cartopy.crs as ccrs
import pandas as pd
import panel as pn
from holoviews.operation.datashader import rasterize
hv.extension("bokeh")

df = pd.DataFrame(np.random.rand(1000, 3), columns=["x", "y", "z"]) * 10

points = gv.Points(df, kdims=["x", "y"], vdims=["z"], crs=ccrs.PlateCarree())

def filter_points(points, x_range, y_range):
    if x_range is None or y_range is None:
        return points
    return points[x_range, y_range]

def hover_points(points, threshold=50):
    if len(points) > threshold:
        return points.iloc[:0]
    return points

range_stream = hv.streams.RangeXY(source=points)
streams=[range_stream]

filtered = points.apply(filter_points, streams=streams)
shaded = rasterize(filtered, streams=streams, aggregator="max", x_sampling=0.25, y_sampling=0.25)
hover = filtered.apply(hover_points)

dynamic_hover = (shaded * hover)

row = pn.pane.HoloViews((gv.tile_sources.ESRI() * dynamic_hover).opts(responsive=True),sizing_mode='stretch_both', height=500)
row.servable()
ahuang11 commented 3 years ago

Here's how I zoomed

https://user-images.githubusercontent.com/15331990/116149409-bae12a80-a6a7-11eb-8409-b57a05673075.mp4

jlstevens commented 3 years ago

Thanks for the reproducible example! I'll try it now and see if I can confirm this...