Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_batched_curve_subscribers_correctly_linked(self):
# Checks if a stream callback is created to link batched plot
# to the stream
posx = PointerX()
opts = {'NdOverlay': dict(plot=dict(legend_limit=0)),
'Curve': dict(style=dict(line_color=Cycle(values=['red', 'blue'])))}
overlay = DynamicMap(lambda x: NdOverlay({i: Curve([(i, j) for j in range(2)])
for i in range(2)}).opts(opts), kdims=[],
streams=[posx])
plot = bokeh_renderer.get_plot(overlay)
self.assertEqual(len(Callback._callbacks), 1)
key = list(Callback._callbacks.keys())[0]
self.assertEqual(key, (id(plot.handles['plot']), id(PointerXCallback)))
def panel(self):
helper = self.draw_helper
mesh_dmap = DynamicMap(Callable(self.gen_mesh, memoize=False), streams=[self])
return pn.Column(self.param, pn.Row(helper.map_view() * mesh_dmap, helper.table_view()))
def _get_objs(self):
opts = {
'plot': {'height': self.hh, 'width': self.ww, 'colorbar': True},
'style': {'cmap': 'Viridis'}}
im0 = (regrid(hv.DynamicMap(self._temp0, streams=[self.str_sel]))
.opts(**opts))
ims = (regrid(hv.DynamicMap(self._temps, streams=[self.str_sel]))
.opts(**opts))
re = (regrid(hv.DynamicMap(self._re, streams=[self.str_sel]))
.opts(**opts))
return ((im0 * self.box).relabel("Template")
+ (ims * self.box.clone(link_inputs=False)).relabel("Target")
+ re.relabel("Shifted Target"))
if not cmin: # if user left blank or initial values are empty
self.control.style.lower_limit.value = str(round(c_lim_lower, 5))
self.control.style.upper_limit.value = str(round(c_lim_upper, 5))
if use_all_data: # do the selection later
sel_data = sel_data.sel(**selection, drop=True)
assign_opts = {dim: self.data[dim] for dim in sel_data.dims}
graph = sel_data.assign_coords(
**assign_opts).hvplot.quadmesh(**graph_opts).redim.range(
**color_range).opts(active_tools=['wheel_zoom', 'pan'])
self.graph = graph
if len(self.data[self.var].dims) > 2 and self.kwargs['extract along']:
self.tap_stream.source = graph
self.taps_graph = hv.DynamicMap(
self.create_taps_graph,
streams=[self.tap_stream, self.clear_points])
self.output[0] = self.graph * self.taps_graph
self.clear_series_button.disabled = False
else:
self.output[0] = self.graph
self.clear_series_button.disabled = True
if x and y:
pattern = np.array(shapes[pattern])
r, c = pattern.shape
y, x = img.sheet2matrixidx(x,y)
img.data[y:y+r,x:x+c] = pattern[::-1]
else:
img.data = step(img.data)
return hv.Image(img)
title = 'Game of Life - Tap to place pattern, Doubletap to clear'
img_opts = opts.Image(cmap='gray', toolbar=None, height=400, width=800,
title=title, xaxis=None, yaxis=None)
img = hv.Image(np.zeros((100, 200), dtype=np.uint8))
counter, tap = Counter(transient=True), Tap(transient=True)
pattern_dim = hv.Dimension('Pattern', values=sorted(shapes.keys()))
dmap = hv.DynamicMap(update, kdims=[pattern_dim], streams=[counter, tap])
doc = renderer.server_doc(dmap.redim.range(z=(0, 1)).opts(img_opts))
dmap.periodic(0.05, None)
doc.title = 'Game of Life'
mdict = {k: v for k, v in zip(list(self.meta_dicts.keys()), meta)}
im_dict[meta] = get_im_ovly(mdict)
ims = hv.NdLayout(im_dict, kdims=list(self.meta_dicts.keys()))
else:
ims = get_im_ovly(self.cur_metas)
if self.summary is not None:
hvsum = (hv.Dataset(self.sum_sub)
.to(hv.Curve, kdims=['frame'])
.overlay('sum_var'))
if self._datashade:
hvsum = datashade_ndcurve(hvsum, kdim='sum_var')
try:
hvsum = hvsum.layout(list(self.meta_dicts.keys()))
except:
pass
vl = (hv.DynamicMap(lambda f: hv.VLine(f), streams=[self.strm_f])
.opts(style=dict(color='red')))
summ = ((hvsum * vl).map(
lambda p: p.opts(frame_width=500, aspect=3),
[hv.RGB, hv.Curve]))
else:
summ = hv.Div('')
hvobj = (ims + summ).cols(1)
return hvobj
The app can be served using:
bokeh serve --show selection_stream.py
"""
import numpy as np
import holoviews as hv
from holoviews.streams import Selection1D
renderer = hv.renderer('bokeh')
hv.opts("Points [tools=['box_select']]")
data = np.random.multivariate_normal((0, 0), [[1, 0.1], [0.1, 1]], (1000,))
points = hv.Points(data)
sel = Selection1D(source=points)
mean_sel = hv.DynamicMap(lambda index: hv.HLine(points.iloc[index]['y'].mean()
if index else -10),
kdims=[], streams=[sel])
doc = renderer.server_doc(points * mean_sel)
doc.title = 'HoloViews Selection Stream'
style=dict(cmap='Viridis')))
cents = (hv.Dataset(
self.cents_sub.drop(list(self.meta_dicts.keys()), axis='columns'),
kdims=['width', 'height', 'unit_id'])
.to(hv.Points, ['width', 'height'])
.opts(style=dict(alpha=0.1,
line_alpha=0,
size=5,
nonselection_alpha=0.1,
selection_alpha=0.9))
.collate()
.overlay('unit_id')
.opts(plot=dict(tools=['hover', 'box_select'])))
self.strm_uid.source = cents
fim = fct.partial(hv.Image, kdims=['width', 'height'])
AC = (regrid(hv.DynamicMap(fim, streams=[self.pipAC]),
precompute=True)
.opts(plot=dict(
frame_height=len(self._h),
frame_width=len(self._w)),
style=dict(cmap='Viridis')))
mov = (regrid(hv.DynamicMap(fim, streams=[self.pipmov]),
precompute=True)
.opts(plot=dict(
frame_height=len(self._h),
frame_width=len(self._w)),
style=dict(cmap='Viridis')))
lab = fct.partial(hv.Labels, kdims=['width', 'height'], vdims=['unit_id'])
ulab = (hv.DynamicMap(lab, streams=[self.pipusub])
.opts(style=dict(text_color='red')))
return pn.panel(Asum * cents + AC * ulab + mov)
def view(self):
points = hv.DynamicMap(hv.Points(df, kdims=['x', 'y']))
raster = rasterize(points, x_sampling=1, y_sampling=1, width=900, height=600)
return hv.DynamicMap(self.tiles) * shade(raster, streams=[hv.streams.Params(self, ['cmap'])])
pnr: ndarray
peak-to-noise image created with caiman.summary_images.correlation_pnr
"""
hv_corr = hv.Image(corr, vdims='corr', label='correlation')
hv_pnr = hv.Image(pnr, vdims='pnr', label='pnr')
def hist(im, rx, ry):
obj = im.select(x=rx, y=ry) if rx and ry else im
return hv.operation.histogram(obj)
str_corr = (hv.streams.RangeXY(source=hv_corr)
.rename(x_range='rx', y_range='ry'))
str_pnr = (hv.streams.RangeXY(source=hv_pnr)
.rename(x_range='rx', y_range='ry'))
hist_corr = hv.DynamicMap(
fct.partial(hist, im=hv_corr), streams=[str_corr])
hist_pnr = hv.DynamicMap(
fct.partial(hist, im=hv_pnr), streams=[str_pnr])
return (hv_corr << hist_corr) + (hv_pnr << hist_pnr)