Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
if pyplot is None:
raise SkipTest("Matplotlib required to test widgets")
self.basename = 'no-file'
self.image1 = Image(np.array([[0,1],[2,3]]), label='Image1')
self.image2 = Image(np.array([[1,0],[4,-2]]), label='Image2')
self.map1 = HoloMap({1:self.image1, 2:self.image2}, label='TestMap')
self.unicode_table = ItemTable([('β','Δ1'), ('°C', '3×4')],
label='Poincaré', group='α Festkörperphysik')
self.renderer = Store.renderer.instance()
def test_dataset_groupby(self):
group1 = {'Age':[10,16], 'Weight':[15,18], 'Height':[0.8,0.6]}
group2 = {'Age':[12], 'Weight':[10], 'Height':[0.8]}
grouped = HoloMap([('M', Dataset(group1, kdims=['Age'], vdims=self.vdims)),
('F', Dataset(group2, kdims=['Age'], vdims=self.vdims))],
kdims=['Gender'], sort=False)
print(grouped.keys())
self.assertEqual(self.table.groupby(['Gender']), grouped)
def test_dataset_groupby_second_dim(self):
group1 = {'Gender':['M'], 'Weight':[15], 'Height':[0.8]}
group2 = {'Gender':['M'], 'Weight':[18], 'Height':[0.6]}
group3 = {'Gender':['F'], 'Weight':[10], 'Height':[0.8]}
grouped = HoloMap([(10, Dataset(group1, kdims=['Gender'], vdims=self.vdims)),
(16, Dataset(group2, kdims=['Gender'], vdims=self.vdims)),
(12, Dataset(group3, kdims=['Gender'], vdims=self.vdims))],
kdims=['Age'], sort=False)
self.assertEqual(self.table.groupby(['Age']), grouped)
def test_overlay_update_visible(self):
hmap = HoloMap({i: Curve(np.arange(i), label='A') for i in range(1, 3)})
hmap2 = HoloMap({i: Curve(np.arange(i), label='B') for i in range(3, 5)})
plot = bokeh_renderer.get_plot(hmap*hmap2)
subplot1, subplot2 = plot.subplots.values()
self.assertTrue(subplot1.handles['glyph_renderer'].visible)
self.assertFalse(subplot2.handles['glyph_renderer'].visible)
plot.update((4,))
self.assertFalse(subplot1.handles['glyph_renderer'].visible)
self.assertTrue(subplot2.handles['glyph_renderer'].visible)
def setUp(self):
if 'matplotlib' not in Store.renderers:
raise SkipTest("Matplotlib required to test widgets")
self.basename = 'no-file'
self.image1 = Image(np.array([[0,1],[2,3]]), label='Image1')
self.image2 = Image(np.array([[1,0],[4,-2]]), label='Image2')
self.map1 = HoloMap({1:self.image1, 2:self.image2}, label='TestMap')
self.unicode_table = ItemTable([('β','Δ1'), ('°C', '3×4')],
label='Poincaré', group='α Festkörperphysik')
self.renderer = MPLRenderer.instance()
def test_unique_keys_no_overlap_exception(self):
hmap1 = HoloMap({i: Curve(range(10)) for i in range(5)}, kdims=['A'])
hmap2 = HoloMap({i: Curve(range(10)) for i in range(3, 10)})
exception = ('When combining HoloMaps into a composite plot '
'their dimensions must be subsets of each other.')
with self.assertRaisesRegexp(Exception, exception):
dims, keys = unique_dimkeys(hmap1+hmap2)
def generate_holo_map(rgb_images, height, width):
frame_map = {}
for i, image in enumerate(rgb_images):
# print('image type: ' + str(type(image)))
hv_rgb = hv.RGB(np.array(image))
shape = image.shape
frame_map[i] = hv_rgb
holomap = hv.HoloMap(frame_map)
holomap = holomap.options(width=int(width), height=int(height))
return holomap
cents_df = centroid(A)
hv_pts_dict[key] = (hv.Points(cents_df,
kdims=['width', 'height'],
vdims=['unit_id'])
.opts(plot=dict(tools=['hover']),
style=dict(fill_alpha=0.2,
line_alpha=0, size=8)))
hv_A_dict[key] = hv.Image(A.sum('unit_id').rename('A'),
kdims=['width', 'height'])
hv_Ab_dict[key] = hv.Image((A > 0).sum('unit_id').rename('A_bin'),
kdims=['width', 'height'])
hv_C_dict[key] = hv.Dataset(C.rename('C')).to(hv.Curve, kdims='frame')
hv_pts = hv.HoloMap(hv_pts_dict, kdims=kdims)
hv_A = hv.HoloMap(hv_A_dict, kdims=kdims)
hv_Ab = hv.HoloMap(hv_Ab_dict, kdims=kdims)
hv_C = (hv.HoloMap(hv_C_dict, kdims=kdims).collate()
.grid('unit_id').add_dimension('time', 0, 0))
if datashading:
hv_A = regrid(hv_A)
hv_Ab = regrid(hv_Ab)
hv_C = datashade(hv_C)
hv_A = hv_A.opts(frame_width=400, aspect=w/h,
colorbar=True, cmap='viridis')
hv_Ab = hv_Ab.opts(frame_width=400, aspect=w/h,
colorbar=True, cmap='viridis')
hv_C = hv_C.map(
lambda cr: cr.opts(frame_width=500, frame_height=50),
hv.RGB if datashading else hv.Curve)
return (hv.NdLayout({
'pseudo-color': (hv_pts * hv_A),
'binary': (hv_pts * hv_Ab)}, kdims='Spatial Matrix').cols(1)
+ hv_C.relabel('Temporal Components'))