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_dataset_element_allowing_two_kdims_with_one_default_kdim(self):
df = pd.DataFrame({'x': [1, 2, 3], 'y': [1, 2, 3], 'z': [1, 2, 3]},
columns=['x', 'y', 'z'])
ds = Scatter(df)
self.assertEqual(ds.kdims, [Dimension('x')])
self.assertEqual(ds.vdims, [Dimension('y'), Dimension('z')])
def setUp(self):
"Variations on the constructors in the Elements notebook"
key_dims1=[Dimension('Car occupants')]
key_dims2=[Dimension('Cyclists')]
value_dims1=['Count']
self.bars1 = Bars([('one',8),('two', 10), ('three', 16)],
kdims=key_dims1, vdims=value_dims1)
self.bars2 = Bars([('one',8),('two', 10), ('three', 17)],
kdims=key_dims1, vdims=value_dims1)
self.bars3 = Bars([('one',8),('two', 10), ('three', 16)],
kdims=key_dims2, vdims=value_dims1)
def test_shade_categorical_images_xarray(self):
xs, ys = [0.25, 0.75], [0.25, 0.75]
data = NdOverlay({'A': Image((xs, ys, [[1, 0], [0, 0]]), datatype=['xarray'], vdims='z Count'),
'B': Image((xs, ys, [[0, 0], [1, 0]]), datatype=['xarray'], vdims='z Count'),
'C': Image((xs, ys, [[0, 0], [1, 0]]), datatype=['xarray'], vdims='z Count')},
kdims=['z'])
shaded = shade(data)
r = [[228, 255], [66, 255]]
g = [[26, 255], [150, 255]]
b = [[28, 255], [129, 255]]
a = [[40, 0], [255, 0]]
expected = RGB((xs, ys, r, g, b, a), datatype=['grid'],
vdims=RGB.vdims+[Dimension('A', range=(0, 1))])
self.assertEqual(shaded, expected)
def test_raster_string_signature(self):
raster = Raster(np.array([[0]]), ['a', 'b'], 'c')
self.assertEqual(raster.kdims, [Dimension('a'), Dimension('b')])
self.assertEqual(raster.vdims, [Dimension('c')])
def test_dynamic_values_partial_overlap(self):
kdims = [Dimension('File', range=(0.01, 1)),
Dimension('SliceDimension', values=['x', 'y', 'z']),
Dimension('Coordinates', range=(0.01, 1))]
dmap1 = DynamicMap(lambda x, y, z: Image(np.random.rand(10,10)), kdims=kdims)
dmap2 = DynamicMap(lambda x: Curve(np.random.rand(10,2))*VLine(x),
kdims=kdims[:1])
mpl_renderer.get_widget(dmap1 + dmap2, 'selection')
def test_rgb_string_signature(self):
img = RGB(np.zeros((2, 2, 3)), ['a', 'b'], ['R', 'G', 'B'])
self.assertEqual(img.kdims, [Dimension('a'), Dimension('b')])
self.assertEqual(img.vdims, [Dimension('R'), Dimension('G'), Dimension('B')])
def test_dataset_process_index(self):
df = pd.DataFrame({'x': [1, 2, 3], 'y': [1, 2, 3], 'z': [1, 2, 3]},
columns=['x', 'y', 'z'])
ds = Dataset(df, 'index')
self.assertEqual(ds.kdims, [Dimension('index')])
self.assertEqual(ds.vdims, [Dimension('x'), Dimension('y'), Dimension('z')])
def test_dataset_range_with_dimension_range(self):
dt64 = np.array([np.datetime64(datetime.datetime(2017, 1, i)) for i in range(1, 4)])
ds = Dataset(dt64, [Dimension('Date', range=(dt64[0], dt64[-1]))])
self.assertEqual(ds.range('Date'), (dt64[0], dt64[-1]))
'Fitted Spikes': hvobjs[2], 'Fitted Signal': hvobjs[3]}
hv_pul = {'Simulated Calcium': hvobjs[4], 'Simulated Spike': hvobjs[5]}
hv_unit = hv.HoloMap(hv_unit, kdims='traces').collate().overlay('traces')
hv_pul = hv.HoloMap(hv_pul, kdims='traces').collate().overlay('traces')
hv_A = hvobjs[6]
if datashading:
hv_unit = datashade_ndcurve(hv_unit, 'traces')
hv_A = regrid(hv_A)
else:
hv_unit = Dynamic(hv_unit)
hv_A = Dynamic(hv_A)
hv_pul = Dynamic(hv_pul)
hv_unit = hv_unit.map(
lambda p: p.opts(plot=dict(frame_height=400, frame_width=1000)))
hv_pul = (hv_pul.opts(plot=dict(frame_width=500, aspect=w/h))
.redim(t=hv.Dimension('t', soft_range=pul_range)))
hv_A = hv_A.opts(plot=dict(frame_width=500, aspect=w/h), style=dict(cmap='Viridis'))
return (hv_unit.relabel("Current Unit: Temporal Traces")
+ hv.NdLayout({
'Simulated Pulse Response': hv_pul,
'Spatial Footprint': hv_A}, kdims='Current Unit')).cols(1)
def update(pattern, counter, x, y):
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'