Exemplo n.º 1
0
 def test_redim_dimension_values_cache_reset_1D(self):
     # Setting the values should drop mismatching keys from the cache
     fn = lambda i: Curve([i,i])
     dmap = DynamicMap(fn, kdims=['i'])[{0,1,2,3,4,5}]
     self.assertEqual(dmap.keys(), [0,1,2,3,4,5])
     redimmed = dmap.redim.values(i=[2,3,5,6,8])
     self.assertEqual(redimmed.keys(), [2,3,5])
Exemplo n.º 2
0
 def test_dynamic_collate_ndlayout(self):
     def callback():
         return NdLayout({i: Image(np.array([[i, 1], [2, 3]])) for i in range(1, 3)})
     dmap = DynamicMap(callback, kdims=[])
     layout = dmap.collate()
     self.assertEqual(list(layout.keys()), [1, 2])
     self.assertEqual(layout[1][()], Image(np.array([[1, 1], [2, 3]])))
Exemplo n.º 3
0
 def test_deep_apply_transform_element_type(self):
     fn = lambda i: Curve(np.arange(i))
     dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
     dmap[10]
     mapped = dmap.apply(lambda x: Scatter(x))
     area = mapped[11]
     self.assertEqual(area, Scatter(fn(11)))
Exemplo n.º 4
0
 def test_dynamic_collate_layout(self):
     def callback():
         return Image(np.array([[0, 1], [2, 3]])) + Text(0, 0, 'Test')
     dmap = DynamicMap(callback, kdims=[])
     layout = dmap.collate()
     self.assertEqual(list(layout.keys()), [('Image', 'I'), ('Text', 'I')])
     self.assertEqual(layout.Image.I[()], Image(np.array([[0, 1], [2, 3]])))
Exemplo n.º 5
0
 def test_redim_dimension_values_cache_reset_2D_multi(self):
     # Setting the values should drop mismatching keys from the cache
     fn = lambda i,j: Curve([i,j])
     keys = [(0,1),(1,0),(2,2),(2,5), (3,3)]
     dmap = DynamicMap(fn, kdims=['i','j'])[keys]
     self.assertEqual(dmap.keys(), keys)
     redimmed = dmap.redim.values(i=[2,10,50], j=[5,50,100])
     self.assertEqual(redimmed.keys(), [(2,5)])
Exemplo n.º 6
0
 def test_periodic_param_fn_blocking(self):
     def callback(x): return Curve([1,2,3])
     xval = Stream.define('x',x=0)()
     dmap = DynamicMap(callback, streams=[xval])
     # Add stream subscriber mocking plot
     xval.add_subscriber(lambda **kwargs: dmap[()])
     dmap.periodic(0.01, 100, param_fn=lambda i: {'x':i})
     self.assertEqual(xval.x, 100)
Exemplo n.º 7
0
 def test_dynamic_split_overlays_on_ndoverlay(self):
     dmap = DynamicMap(lambda: NdOverlay({i: Points([i]) for i in range(3)}))
     initialize_dynamic(dmap)
     keys, dmaps = dmap._split_overlays()
     self.assertEqual(keys, [(0,), (1,), (2,)])
     self.assertEqual(dmaps[0][()], Points([0]))
     self.assertEqual(dmaps[1][()], Points([1]))
     self.assertEqual(dmaps[2][()], Points([2]))
Exemplo n.º 8
0
 def test_dynamic_reindex_reorder(self):
     def history_callback(x, y, history=deque(maxlen=10)):
         history.append((x, y))
         return Points(list(history))
     dmap = DynamicMap(history_callback, kdims=['x', 'y'])
     reindexed = dmap.reindex(['y', 'x'])
     points = reindexed[2, 1]
     self.assertEqual(points, Points([(1, 2)]))
Exemplo n.º 9
0
 def test_dynamic_collate_layout_raise_no_remapping_error(self):
     def callback(x, y):
         return Image(np.array([[0, 1], [2, 3]])) + Text(0, 0, 'Test')
     stream = PointerXY()
     cb_callable = Callable(callback)
     dmap = DynamicMap(cb_callable, kdims=[], streams=[stream])
     with self.assertRaisesRegexp(ValueError, 'The following streams are set to be automatically linked'):
         dmap.collate()
Exemplo n.º 10
0
 def test_dynamic_collate_layout_raise_ambiguous_remapping_error(self):
     def callback(x, y):
         return Image(np.array([[0, 1], [2, 3]])) + Image(np.array([[0, 1], [2, 3]]))
     stream = PointerXY()
     cb_callable = Callable(callback, stream_mapping={'Image': [stream]})
     dmap = DynamicMap(cb_callable, kdims=[], streams=[stream])
     with self.assertRaisesRegexp(ValueError, 'The stream_mapping supplied on the Callable is ambiguous'):
         dmap.collate()
Exemplo n.º 11
0
    def test_dynamic_event_renaming_valid(self):

        def fn(x1, y1):
            return Scatter([(x1, y1)])

        xy = PointerXY(rename={'x':'x1','y':'y1'})
        dmap = DynamicMap(fn, kdims=[], streams=[xy])
        dmap.event(x1=1, y1=2)
Exemplo n.º 12
0
 def test_dynamic_collate_gridspace_with_changing_items_raises(self):
     def callback(i):
         return GridSpace({j: Curve([], label=str(j)) for j in range(i)}, 'X')
     dmap = DynamicMap(callback, kdims=['i']).redim.range(i=(2, 10))
     layout = dmap.collate()
     dmap1, dmap2 = layout.values()
     err = 'Collated DynamicMaps must return GridSpace with consistent number of items.'
     with self.assertRaisesRegexp(ValueError, err):
         dmap1[4]
Exemplo n.º 13
0
 def test_dynamic_collate_layout_with_spec_stream_mapping(self):
     def callback(x, y):
         return Image(np.array([[0, 1], [2, 3]])) + Text(0, 0, 'Test')
     stream = PointerXY()
     cb_callable = Callable(callback, stream_mapping={'Image': [stream]})
     dmap = DynamicMap(cb_callable, kdims=[], streams=[stream])
     layout = dmap.collate()
     self.assertEqual(list(layout.keys()), [('Image', 'I'), ('Text', 'I')])
     self.assertIs(stream.source, layout.Image.I)
Exemplo n.º 14
0
 def test_dynamic_collate_ndlayout_with_key_stream_mapping(self):
     def callback(x, y):
         return NdLayout({i: Image(np.array([[i, 1], [2, 3]])) for i in range(1, 3)})
     stream = PointerXY()
     cb_callable = Callable(callback, stream_mapping={(1,): [stream]})
     dmap = DynamicMap(cb_callable, kdims=[], streams=[stream])
     layout = dmap.collate()
     self.assertEqual(list(layout.keys()), [1, 2])
     self.assertIs(stream.source, layout[1])
Exemplo n.º 15
0
 def test_dynamic_collate_grid(self):
     def callback():
         return GridSpace({(i, j): Image(np.array([[i, j], [2, 3]]))
                           for i in range(1, 3) for j in range(1, 3)})
     dmap = DynamicMap(callback, kdims=[])
     grid = dmap.collate()
     self.assertEqual(list(grid.keys()), [(i, j) for i in range(1, 3)
                                          for j in range(1, 3)])
     self.assertEqual(grid[(0, 1)][()], Image(np.array([[1, 1], [2, 3]])))
Exemplo n.º 16
0
 def test_dynamic_reindex_drop_raises_exception(self):
     def history_callback(x, y, history=deque(maxlen=10)):
         history.append((x, y))
         return Points(list(history))
     dmap = DynamicMap(history_callback, kdims=['x', 'y'])
     exception = ("DynamicMap does not allow dropping dimensions, "
                  "reindex may only be used to reorder dimensions.")
     with self.assertRaisesRegexp(ValueError, exception):
         dmap.reindex(['x'])
Exemplo n.º 17
0
 def test_dynamic_collate_layout_with_changing_label(self):
     def callback(i):
         return Layout([Curve([], label=str(j)) for j in range(i, i+2)])
     dmap = DynamicMap(callback, kdims=['i']).redim.range(i=(0, 10))
     layout = dmap.collate()
     dmap1, dmap2 = layout.values()
     el1, el2 = dmap1[2], dmap2[2]
     self.assertEqual(el1.label, '2')
     self.assertEqual(el2.label, '3')
Exemplo n.º 18
0
    def test_dynamic_event_renaming_invalid(self):
        def fn(x1, y1):
            return Scatter([(x1, y1)])

        xy = PointerXY(rename={'x':'x1','y':'y1'})
        dmap = DynamicMap(fn, kdims=[], streams=[xy])

        regexp = '(.+?)do not correspond to stream parameters'
        with self.assertRaisesRegexp(KeyError, regexp):
            dmap.event(x=1, y=2)
Exemplo n.º 19
0
 def test_dynamic_collate_grid_with_key_stream_mapping(self):
     def callback():
         return GridSpace({(i, j): Image(np.array([[i, j], [2, 3]]))
                           for i in range(1, 3) for j in range(1, 3)})
     stream = PointerXY()
     cb_callable = Callable(callback, stream_mapping={(1, 2): [stream]})
     dmap = DynamicMap(cb_callable, kdims=[])
     grid = dmap.collate()
     self.assertEqual(list(grid.keys()), [(i, j) for i in range(1, 3)
                                          for j in range(1, 3)])
     self.assertEqual(stream.source, grid[(1, 2)])
Exemplo n.º 20
0
 def test_periodic_param_fn_blocking_timeout(self):
     def callback(x):
         return Curve([1,2,3])
     xval = Stream.define('x',x=0)()
     dmap = DynamicMap(callback, streams=[xval])
     # Add stream subscriber mocking plot
     xval.add_subscriber(lambda **kwargs: dmap[()])
     start = time.time()
     dmap.periodic(0.5, 100, param_fn=lambda i: {'x':i}, timeout=3)
     end = time.time()
     self.assertEqual((end - start) < 5, True)
Exemplo n.º 21
0
class DynamicTransferStreams(ComparisonTestCase):

    def setUp(self):
        self.dimstream = PointerX(x=0)
        self.stream = PointerY(y=0)
        self.dmap = DynamicMap(lambda x, y, z: Curve([x, y, z]),
                               kdims=['x', 'z'], streams=[self.stream, self.dimstream])

    def test_dynamic_redim_inherits_streams(self):
        redimmed = self.dmap.redim.range(z=(0, 5))
        self.assertEqual(redimmed.streams, self.dmap.streams)

    def test_dynamic_relabel_inherits_streams(self):
        relabelled = self.dmap.relabel(label='Test')
        self.assertEqual(relabelled.streams, self.dmap.streams)

    def test_dynamic_map_inherits_streams(self):
        mapped = self.dmap.map(lambda x: x, Curve)
        self.assertEqual(mapped.streams, self.dmap.streams)

    def test_dynamic_select_inherits_streams(self):
        selected = self.dmap.select(Curve, x=(0, 5))
        self.assertEqual(selected.streams, self.dmap.streams)

    def test_dynamic_hist_inherits_streams(self):
        hist = self.dmap.hist(adjoin=False)
        self.assertEqual(hist.streams, self.dmap.streams)

    def test_dynamic_mul_inherits_dim_streams(self):
        hist = self.dmap * self.dmap
        self.assertEqual(hist.streams, self.dmap.streams[1:])

    def test_dynamic_util_inherits_dim_streams(self):
        hist = Dynamic(self.dmap)
        self.assertEqual(hist.streams, self.dmap.streams[1:])

    def test_dynamic_util_parameterized_method(self):
        class Test(param.Parameterized):
            label = param.String(default='test')

            @param.depends('label')
            def apply_label(self, obj):
                return obj.relabel(self.label)

        test = Test()
        dmap = Dynamic(self.dmap, operation=test.apply_label)
        test.label = 'custom label'
        self.assertEqual(dmap[(0, 3)].label, 'custom label')

    def test_dynamic_util_inherits_dim_streams_clash(self):
        exception = ("The supplied stream objects PointerX\(x=None\) and "
                     "PointerX\(x=0\) clash on the following parameters: \['x'\]")
        with self.assertRaisesRegexp(Exception, exception):
            Dynamic(self.dmap, streams=[PointerX])
Exemplo n.º 22
0
 def test_dynamic_collate_gridspace_with_changing_item_types_raises(self):
     def callback(i):
         eltype = Image if i%2 else Curve
         return GridSpace({j: eltype([], label=str(j)) for j in range(i, i+2)}, 'X')
     dmap = DynamicMap(callback, kdims=['i']).redim.range(i=(2, 10))
     layout = dmap.collate()
     dmap1, dmap2 = layout.values()
     err = ('The objects in a GridSpace returned by a DynamicMap must '
            'consistently return the same number of items of the same type.')
     with self.assertRaisesRegexp(ValueError, err):
         dmap1[3]
Exemplo n.º 23
0
    def test_dynamic_groupby_kdims_and_streams(self):
        def plot_function(mydim, data):
            return Scatter(data[data[:, 2]==mydim])

        buff = Buffer(data=np.empty((0, 3)))
        dmap = DynamicMap(plot_function, streams=[buff], kdims='mydim').redim.values(mydim=[0, 1, 2])
        ndlayout = dmap.groupby('mydim', container_type=NdLayout)
        self.assertIsInstance(ndlayout[0], DynamicMap)
        data = np.array([(0, 0, 0), (1, 1, 1), (2, 2, 2)])
        buff.send(data)
        self.assertEqual(ndlayout[0][()], Scatter([(0, 0)]))
        self.assertEqual(ndlayout[1][()], Scatter([(1, 1)]))
        self.assertEqual(ndlayout[2][()], Scatter([(2, 2)]))
Exemplo n.º 24
0
    def test_periodic_param_fn_non_blocking(self):
        def callback(x): return Curve([1,2,3])
        xval = Stream.define('x',x=0)()
        dmap = DynamicMap(callback, streams=[xval])
        # Add stream subscriber mocking plot
        xval.add_subscriber(lambda **kwargs: dmap[()])

        self.assertNotEqual(xval.x, 100)
        dmap.periodic(0.0001, 100, param_fn=lambda i: {'x': i}, block=False)
        time.sleep(2)
        if not dmap.periodic.instance.completed:
            raise RuntimeError('Periodic callback timed out.')
        dmap.periodic.stop()
        self.assertEqual(xval.x, 100)
Exemplo n.º 25
0
 def test_dynamic_split_overlays_on_varying_order_overlay(self):
     def cb(i):
         if i%2 == 0:
             return Curve([]) * Points([])
         else:
             return Points([]) * Curve([])
     dmap = DynamicMap(cb, kdims='i').redim.range(i=(0, 4))
     initialize_dynamic(dmap)
     keys, dmaps = dmap._split_overlays()
     self.assertEqual(keys, [('Curve', 'I'), ('Points', 'I')])
     self.assertEqual(dmaps[0][0], Curve([]))
     self.assertEqual(dmaps[0][1], Curve([]))
     self.assertEqual(dmaps[1][0], Points([]))
     self.assertEqual(dmaps[1][1], Points([]))
Exemplo n.º 26
0
    def test_periodic_param_fn_non_blocking(self):
        def callback(x): return Curve([1,2,3])
        xval = Stream.define('x',x=0)()
        dmap = DynamicMap(callback, streams=[xval])
        # Add stream subscriber mocking plot
        xval.add_subscriber(lambda **kwargs: dmap[()])

        dmap.periodic(0.0001, 1000, param_fn=lambda i: {'x':i}, block=False)
        self.assertNotEqual(xval.x, 1000)
        for i in range(1000):
            time.sleep(0.01)
            if dmap.periodic.instance.completed:
                break
        dmap.periodic.stop()
        self.assertEqual(xval.x, 1000)
Exemplo n.º 27
0
 def test_dynamic_split_overlays_on_missing_item_in_overlay(self):
     def cb(i):
         if i%2 == 0:
             return Curve([]) * Points([])
         else:
             return Scatter([]) * Curve([])
     dmap = DynamicMap(cb, kdims='i').redim.range(i=(0, 4))
     initialize_dynamic(dmap)
     keys, dmaps = dmap._split_overlays()
     self.assertEqual(keys, [('Curve', 'I'), ('Points', 'I')])
     self.assertEqual(dmaps[0][0], Curve([]))
     self.assertEqual(dmaps[0][1], Curve([]))
     self.assertEqual(dmaps[1][0], Points([]))
     with self.assertRaises(KeyError):
         dmaps[1][1]
Exemplo n.º 28
0
 def test_dynamic_opts_link_inputs(self):
     stream = LinkedStream()
     inputs = [DynamicMap(lambda: None, streams=[stream])]
     dmap = DynamicMap(Callable(lambda X: TestObj(None), inputs=inputs),
                       kdims=['X']).redim.range(X=(0,10))
     styled_dmap = dmap.options(plot_opt1='red', clone=False)
     opts = Store.lookup_options('backend_1', dmap[0], 'plot')
     self.assertEqual(opts.options, {'plot_opt1': 'red'})
     self.assertIs(styled_dmap, dmap)
     self.assertTrue(dmap.callback.link_inputs)
     unstyled_dmap = dmap.callback.inputs[0].callback.inputs[0]
     opts = Store.lookup_options('backend_1', unstyled_dmap[0], 'plot')
     self.assertEqual(opts.options, {})
     original_dmap = unstyled_dmap.callback.inputs[0]
     self.assertIs(stream, original_dmap.streams[0])
Exemplo n.º 29
0
    def test_periodic_counter_blocking(self):
        class Counter(object):
            def __init__(self):
                self.count = 0
            def __call__(self):
                self.count += 1
                return Curve([1,2,3])

        next_stream = Stream.define('Next')()
        counter = Counter()
        dmap = DynamicMap(counter, streams=[next_stream])
        # Add stream subscriber mocking plot
        next_stream.add_subscriber(lambda **kwargs: dmap[()])
        dmap.periodic(0.01, 100)
        self.assertEqual(counter.count, 100)
Exemplo n.º 30
0
 def test_dynamic_compute_overlayable_zorders_two_deep_dynamic_layers(self):
     area = DynamicMap(lambda: Area(range(10)), kdims=[])
     curve = DynamicMap(lambda: Curve(range(10)), kdims=[])
     area_redim = area.redim(x='x2')
     curve_redim = curve.redim(x='x2')
     combined = area_redim*curve_redim
     combined[()]
     sources = compute_overlayable_zorders(combined)
     self.assertIn(area_redim, sources[0])
     self.assertIn(area, sources[0])
     self.assertNotIn(curve_redim, sources[0])
     self.assertNotIn(curve, sources[0])
     self.assertIn(curve_redim, sources[1])
     self.assertIn(curve, sources[1])
     self.assertNotIn(area_redim, sources[1])
     self.assertNotIn(area, sources[1])
Exemplo n.º 31
0
 def test_dynamic_operation_link_inputs_not_transferred_on_clone(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap=DynamicMap(fn, kdims=['i'])
     dmap_with_fn = Dynamic(dmap, link_inputs=False, operation=lambda x: x.clone(x.data*2))
     self.assertTrue(dmap_with_fn.clone().callback.link_inputs)
Exemplo n.º 32
0
 def test_dynamic_element_overlay(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap=DynamicMap(fn, kdims=['i'])
     dynamic_overlay = dmap * Image(sine_array(0,10))
     overlaid = Image(sine_array(0,5)) * Image(sine_array(0,10))
     self.assertEqual(dynamic_overlay[5], overlaid)
Exemplo n.º 33
0
 def test_deep_redim_dimension_name(self):
     fn = lambda i: Image(sine_array(0, i))
     dmap = DynamicMap(fn).redim(x='X')
     self.assertEqual(dmap[0].kdims[0].name, 'X')
Exemplo n.º 34
0
 def test_redim_dimension_unit_aux(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap = DynamicMap(fn, kdims=['i']).redim.unit(i='m/s')
     self.assertEqual(dmap.kdims[0].unit, 'm/s')
Exemplo n.º 35
0
 def test_deep_redim_dimension_name_with_spec(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap = DynamicMap(fn, kdims=['i']).redim(Image, x='X')
     self.assertEqual(dmap[0].kdims[0].name, 'X')
Exemplo n.º 36
0
 def test_deep_getitem_cross_product_and_slice(self):
     fn = lambda i: Curve(np.arange(i))
     dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
     self.assertEqual(dmap[[10, 11, 12], 5:10],
                      dmap.clone([(i, fn(i)[5:10]) for i in range(10, 13)]))
Exemplo n.º 37
0
 def test_mixed_kdim_streams_unbounded(self):
     dmap=DynamicMap(lambda x,y,z: x+y, kdims=['z'], streams=[XY()])
     self.assertEqual(dmap.unbounded, ['z'])
Exemplo n.º 38
0
 def test_mixed_kdim_streams_bounded_redim(self):
     dmap=DynamicMap(lambda x,y,z: x+y, kdims=['z'], streams=[XY()])
     self.assertEqual(dmap.redim.range(z=(-0.5,0.5)).unbounded, [])
Exemplo n.º 39
0
 def setUp(self):
     self.dimstream = PointerX(x=0)
     self.stream = PointerY(y=0)
     self.dmap = DynamicMap(lambda x, y, z: Curve([x, y, z]),
                            kdims=['x', 'z'], streams=[self.stream, self.dimstream])
Exemplo n.º 40
0
 def test_simple_constructor_kdims(self):
     DynamicMap(lambda x: x, kdims=['test'])
Exemplo n.º 41
0
 def test_simple_constructor_invalid_no_kdims(self):
     regexp = ("Callable '<lambda>' accepts more positional arguments than there are "
               "kdims and stream parameters")
     with self.assertRaisesRegexp(KeyError, regexp):
         DynamicMap(lambda x: x)
Exemplo n.º 42
0
 def test_sampled_bounded_init(self):
     fn = lambda i: Image(sine_array(0, i))
     dmap = DynamicMap(fn, sampled=True)
Exemplo n.º 43
0
 def test_deep_select_slice_kdim_and_vdims(self):
     fn = lambda i: Curve(np.arange(i))
     dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
     self.assertEqual(dmap.select(x=(5, 10), y=(0, 5))[10], fn(10)[5:10, 0:5])
Exemplo n.º 44
0
 def test_sampled_unbounded_resample(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap=DynamicMap(fn, kdims=['i'])
     self.assertEqual(dmap[{0, 1, 2}].keys(), [0, 1, 2])
     self.assertEqual(dmap.unbounded, ['i'])
Exemplo n.º 45
0
 def test_deep_getitem_cache_sliced(self):
     fn = lambda i: Curve(np.arange(i))
     dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
     dmap[10] # Add item to cache
     self.assertEqual(dmap[:, 5:10][10], fn(10)[5:10])
Exemplo n.º 46
0
 def test_sampled_unbounded_init(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap=DynamicMap(fn, kdims=['i'])
     self.assertEqual(dmap.unbounded, ['i'])
Exemplo n.º 47
0
 def test_deep_getitem_index_and_slice(self):
     fn = lambda i: Curve(np.arange(i))
     dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
     self.assertEqual(dmap[10, 5:10], fn(10)[5:10])
Exemplo n.º 48
0
 def test_callable_bounded_clone(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap=DynamicMap(fn, kdims=[Dimension('dim', range=(0,10))])
     self.assertEqual(dmap, dmap.clone())
     self.assertEqual(dmap.unbounded, [])
Exemplo n.º 49
0
 def test_deep_getitem_bounded_kdims_and_vdims(self):
     fn = lambda i: Curve(np.arange(i))
     dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
     self.assertEqual(dmap[:, 5:10, 0:5][10], fn(10)[5:10, 0:5])
Exemplo n.º 50
0
 def test_deep_map_apply_element_function(self):
     fn = lambda i: Curve(np.arange(i))
     dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
     mapped = dmap.map(lambda x: x.clone(x.data*2), Curve)
     curve = fn(10)
     self.assertEqual(mapped[10], curve.clone(curve.data*2))
Exemplo n.º 51
0
 def test_redim_dimension_type_aux(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap = DynamicMap(fn, kdims=['i']).redim.type(i=int)
     self.assertEqual(dmap.kdims[0].type, int)
Exemplo n.º 52
0
 def test_deep_relabel_group(self):
     fn = lambda i: Image(sine_array(0, i))
     dmap = DynamicMap(fn).relabel(group='Test')
     self.assertEqual(dmap[0].group, 'Test')
Exemplo n.º 53
0
 def test_callable_bounded_init(self):
     fn = lambda i: Image(sine_array(0, i))
     dmap = DynamicMap(fn, kdims=[Dimension('dim', range=(0, 10))])
Exemplo n.º 54
0
 def test_sampled_bounded_resample(self):
     fn = lambda i: Image(sine_array(0, i))
     dmap = DynamicMap(fn, sampled=True)
     self.assertEqual(dmap[{0, 1, 2}].keys(), [0, 1, 2])
Exemplo n.º 55
0
 def test_redim_dimension_name(self):
     fn = lambda i: Image(sine_array(0, i))
     dmap = DynamicMap(fn).redim(Default='New')
     self.assertEqual(dmap.kdims[0].name, 'New')
Exemplo n.º 56
0
 def test_simple_constructor_invalid(self):
     regexp = ("Callback '<lambda>' signature over \['x'\] does not accommodate "
               "required kdims \['x', 'y'\]")
     with self.assertRaisesRegexp(KeyError, regexp):
         DynamicMap(lambda x: x, kdims=['x','y'])
Exemplo n.º 57
0
 def test_dynamic_element_underlay(self):
     fn = lambda i: Image(sine_array(0, i))
     dmap = DynamicMap(fn, sampled=True)
     dynamic_overlay = Image(sine_array(0, 10)) * dmap
     overlaid = Image(sine_array(0, 10)) * Image(sine_array(0, 5))
     self.assertEqual(dynamic_overlay[5], overlaid)
Exemplo n.º 58
0
 def test_deep_select_slice_kdim_no_match(self):
     fn = lambda i: Curve(np.arange(i))
     dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
     self.assertEqual(dmap.select(DynamicMap, x=(5, 10))[10], fn(10))
Exemplo n.º 59
0
 def test_redim_dimension_range_aux(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap = DynamicMap(fn, kdims=['i']).redim.range(i=(0,1))
     self.assertEqual(dmap.kdims[0].range, (0,1))
Exemplo n.º 60
0
 def test_dynamic_operation(self):
     fn = lambda i: Image(sine_array(0,i))
     dmap=DynamicMap(fn, kdims=['i'])
     dmap_with_fn = Dynamic(dmap, operation=lambda x: x.clone(x.data*2))
     self.assertEqual(dmap_with_fn[5], Image(sine_array(0,5)*2))