Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add viewport downsample algorithm #6017

Merged
merged 33 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
043f7fc
Add viewport downsample algorithm
hoxbro Dec 8, 2023
bf42891
pop non relevant stream ranges in RangeX and RangeY
hoxbro Dec 19, 2023
9141979
Rough implementation of finding first value outside of range
hoxbro Dec 19, 2023
0943eea
Remove unnessary 0
hoxbro Dec 19, 2023
45d89da
Add hack to work with xlim
hoxbro Dec 19, 2023
b2311b6
Use slice instead of np.arange for nth
hoxbro Dec 19, 2023
3417c3d
Merge branch 'main' into viewport_downsample
hoxbro Dec 19, 2023
e0ffefd
Improve detection first values outside of viewport
hoxbro Dec 19, 2023
d033ca0
Use boolean logic instead
hoxbro Dec 20, 2023
fef1b73
Add select_mask_neighbor
hoxbro Dec 20, 2023
d226e6f
Add _select_mask_neighbor to dask interface
hoxbro Dec 20, 2023
ae35f9e
Add error message to logging
hoxbro Dec 20, 2023
3ceaf73
Correct if statement in dask interface
hoxbro Dec 20, 2023
7ef8c6c
Remove xlim hack
hoxbro Dec 20, 2023
5fc5e73
Nit change
hoxbro Dec 20, 2023
662cc90
Move x_range check down
hoxbro Dec 20, 2023
8111966
Send empty plot for real this time
hoxbro Dec 20, 2023
3c9d2f6
Add viewport-xlim as workaround for now
hoxbro Dec 22, 2023
6ba3b6f
Add width points to get a better approximation of the data in the y-d…
hoxbro Dec 22, 2023
06436c5
Add unit test
hoxbro Dec 22, 2023
9d6adc8
Add viewport options to docstring
hoxbro Dec 22, 2023
ee457ae
Update comment
hoxbro Dec 22, 2023
3e5eb01
Merge branch 'main' into viewport_downsample
hoxbro Jan 17, 2024
257e5fb
Only send the needed data during the initial rendering
hoxbro Jan 17, 2024
4b738d0
Merge branch 'main' into viewport_downsample
hoxbro Jan 17, 2024
aa477f4
Discard change callbacks until plot is fully initialized
philippjfr Jan 24, 2024
a44cc54
Update holoviews/plotting/bokeh/callbacks.py
hoxbro Jan 24, 2024
fda8958
Merge branch 'main' into viewport_downsample
hoxbro Jan 29, 2024
3ddb49c
Update tests
hoxbro Jan 29, 2024
2a64d0e
Small fixes
hoxbro Jan 30, 2024
d6b654f
Extract compute mask from _process and make it an options
hoxbro Jan 30, 2024
0e9ca5d
Ignore cuDF test
hoxbro Jan 30, 2024
1de1336
Merge branch 'main' into viewport_downsample
hoxbro Jan 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions holoviews/operation/downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,19 @@ def _nth_point(x, y, n_out):
y (np.ndarray): The y-values of the data.
n_out (int): The number of output points.
Returns:
np.array: The indexes of the selected datapoints.
slice: The slice of selected datapoints.
"""
n_samples = len(x)
return np.arange(0, n_samples, max(1, math.ceil(n_samples / n_out)))
return slice(0, n_samples, max(1, math.ceil(n_samples / n_out)))

def _viewport(x, y, n_out):
return slice(len(x))


_ALGORITHMS = {
'lttb': _lttb,
'nth': _nth_point
'nth': _nth_point,
'viewport': _viewport,
}


Expand All @@ -164,9 +168,10 @@ class downsample1d(ResampleOperation1D):
- `nth`: Selects every n-th point.
"""

algorithm = param.Selector(default='lttb', objects=['lttb', 'nth'])
algorithm = param.Selector(default='lttb', objects=list(_ALGORITHMS))

def _process(self, element, key=None):
self.p.x_range = self.p.x_range or element.opts.get().kwargs.get("xlim") # hack
if isinstance(element, (Overlay, NdOverlay)):
_process = partial(self._process, key=key)
if isinstance(element, Overlay):
Expand All @@ -176,7 +181,9 @@ def _process(self, element, key=None):
return element.clone(elements)

if self.p.x_range:
element = element[slice(*self.p.x_range)]
xs = element.dimension_values(0)
x0, x1 = (np.argmin(np.abs(xs-coord)) for coord in self.p.x_range)
element = element.iloc[max(x0 - 1, 0):(x1 + 2)]
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
if len(element) <= self.p.width:
return element
xs, ys = (element.dimension_values(i) for i in range(2))
Expand Down
8 changes: 8 additions & 0 deletions holoviews/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,10 @@ class RangeX(LinkedStream):
x_range = param.Tuple(default=None, length=2, constant=True, doc="""
Range of the x-axis of a plot in data coordinates""")

def _set_stream_parameters(self, **kwargs):
kwargs.pop("y_range", None)
super()._set_stream_parameters(**kwargs)


class RangeY(LinkedStream):
"""
Expand All @@ -1489,6 +1493,10 @@ class RangeY(LinkedStream):
y_range = param.Tuple(default=None, length=2, constant=True, doc="""
Range of the y-axis of a plot in data coordinates""")

def _set_stream_parameters(self, **kwargs):
kwargs.pop("x_range", None)
super()._set_stream_parameters(**kwargs)


class BoundsXY(LinkedStream):
"""
Expand Down