Esempio n. 1
0
 def test_layout_empty_subplots(self):
     layout = Curve(range(10)) + NdOverlay() + HoloMap() + HoloMap(
         {1: Image(np.random.rand(10, 10))})
     plot = bokeh_renderer.get_plot(layout)
     self.assertEqual(len(plot.subplots.values()), 2)
     self.log_handler.assertContains('WARNING', 'skipping subplot')
     self.log_handler.assertContains('WARNING', 'skipping subplot')
Esempio n. 2
0
class DimensionedSelectionTest(ComparisonTestCase):

    def setUp(self):
        self.img_fn = lambda: Image(np.random.rand(10, 10))
        self.contour_fn = lambda: Contours([np.random.rand(10, 2)
                                            for i in range(2)])
        params = [list(range(3)) for i in range(2)]
        self.img_map = HoloMap({(i, j): self.img_fn()
                                for i, j in product(*params)},
                               key_dimensions=['a', 'b'])
        self.contour_map = HoloMap({(i, j): self.contour_fn()
                                    for i, j in product(*params)},
                                   key_dimensions=['a', 'b'])
        self.ndoverlay_map = self.img_map.overlay('b')
        self.overlay_map = self.img_map * self.contour_map
        self.layout_map = self.ndoverlay_map + self.contour_map
        self.duplicate_map = self.img_map.clone(key_dimensions=['x', 'y'])


    def test_simple_holoselect(self):
        self.assertEqual(self.img_map.select(a=0, b=1),
                         self.img_map[0, 1])


    def test_simple_holoslice(self):
        self.assertEqual(self.img_map.select(a=(1, 3), b=(1, 3)),
                         self.img_map[1:3, 1:3])


    def test_simple_holo_ndoverlay_slice(self):
        self.assertEqual(self.ndoverlay_map.select(a=(1, 3), b=(1, 3)),
                         self.ndoverlay_map[1:3, 1:3])


    def test_deep_holoslice(self):
        selection = self.img_map.select(a=(1,3), b=(1, 3), x=(None, 0), y=(None, 0))
        self.assertEqual(selection, self.img_map[1:3, 1:3, :0, :0])


    def test_deep_holooverlay_slice(self):
        map_slc = self.overlay_map[1:3, 1:3]
        img_slc = map_slc.map(lambda x: x[0:0.5, 0:0.5], [Image, Contours])
        selection = self.overlay_map.select(a=(1,3), b=(1, 3), x=(0, 0.5), y=(0, 0.5))
        self.assertEqual(selection, img_slc)


    def test_deep_layout_nesting_slice(self):
        hmap1 = self.layout_map.HoloMap.I[1:3, 1:3, 0:0.5, 0:0.5]
        hmap2 = self.layout_map.HoloMap.II[1:3, 1:3, 0:0.5, 0:0.5]
        selection = self.layout_map.select(a=(1,3), b=(1, 3), x=(0, 0.5), y=(0, 0.5))
        self.assertEqual(selection, hmap1 + hmap2)

    def test_spec_duplicate_dim_select(self):
        selection = self.duplicate_map.select((HoloMap,), x=(0, 1), y=(1, 3))
        self.assertEqual(selection, self.duplicate_map[0:1, 1:3])

    def test_duplicate_dim_select(self):
        selection = self.duplicate_map.select(x=(None, 0.5), y=(None, 0.5))
        self.assertEqual(selection, self.duplicate_map[:.5, :.5, :.5, :.5])
Esempio n. 3
0
 def test_layout_title(self):
     hmap1 = HoloMap({a: Image(np.random.rand(10,10)) for a in range(3)})
     hmap2 = HoloMap({a: Image(np.random.rand(10,10)) for a in range(3)})
     plot = bokeh_renderer.get_plot(hmap1+hmap2)
     title = plot.handles['title']
     self.assertIsInstance(title, Div)
     text = "<span style='font-size: 16pt'><b>Default: 0</b></font>"
     self.assertEqual(title.text, text)
Esempio n. 4
0
 def test_layout_title(self):
     hmap1 = HoloMap({a: Image(np.random.rand(10, 10)) for a in range(3)})
     hmap2 = HoloMap({a: Image(np.random.rand(10, 10)) for a in range(3)})
     plot = bokeh_renderer.get_plot(hmap1 + hmap2)
     title = plot.handles['title']
     self.assertIsInstance(title, Div)
     text = ('<span style="color:black;font-family:Arial;font-style:bold;'
             'font-weight:bold;font-size:12pt">Default: 0</span>')
     self.assertEqual(title.text, text)
Esempio n. 5
0
 def test_layout_title_fontsize(self):
     hmap1 = HoloMap({a: Image(np.random.rand(10,10)) for a in range(3)})
     hmap2 = HoloMap({a: Image(np.random.rand(10,10)) for a in range(3)})
     layout = Layout([hmap1, hmap2]).opts(plot=dict(fontsize={'title': '12pt'}))
     plot = bokeh_renderer.get_plot(layout)
     title = plot.handles['title']
     self.assertIsInstance(title, Div)
     text = "<span style='font-size: 12pt'><b>Default: 0</b></font>"
     self.assertEqual(title.text, text)
 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)
Esempio n. 7
0
 def test_layout_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 = [p for k, p in sorted(plot.subplots.items())]
     subplot1 = subplot1.subplots['main']
     subplot2 = subplot2.subplots['main']
     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)
Esempio n. 8
0
 def setUp(self):
     alphas, betas, deltas = 2, 2, 2
     Bs = list(range(100))
     coords = itertools.product(*(range(n) for n in [alphas, betas, deltas]))
     mus=np.random.rand(alphas, betas, 100, 10)
     self.phase_boundaries = {(a, b, d): Curve(zip(Bs, mus[a, b, :, i]*a+b))
                              for i in range(10) for a, b, d in coords}
     self.dimensions = ['alpha', 'beta', 'delta']
     self.nesting_hmap = HoloMap(self.phase_boundaries, kdims=self.dimensions)
     self.nested_hmap = self.nesting_hmap.groupby(['alpha'])
     self.nested_overlay = self.nesting_hmap.overlay(['delta'])
     self.nested_grid = self.nested_overlay.grid(['alpha', 'beta'])
     self.nested_layout = self.nested_overlay.layout(['alpha', 'beta'])
Esempio n. 9
0
    def setUp(self):
        self.img_fn = lambda: Image(np.random.rand(10, 10))
        self.contour_fn = lambda: Contours(
            [np.random.rand(10, 2) for i in range(2)])
        self.datetime_fn = lambda: Curve(([
            dt.datetime(2000, 1, 1),
            dt.datetime(2000, 1, 2),
            dt.datetime(2000, 1, 3)
        ], np.random.rand(3)), 'time', 'x')
        params = [list(range(3)) for i in range(2)]
        self.sanitized_map = HoloMap(
            {i: Image(i * np.random.rand(10, 10))
             for i in range(1, 10)},
            kdims=['A B'])
        self.img_map = HoloMap(
            {(i, j): self.img_fn()
             for i, j in product(*params)},
            kdims=['a', 'b'])
        self.contour_map = HoloMap(
            {(i, j): self.contour_fn()
             for i, j in product(*params)},
            kdims=['a', 'b'])
        self.ndoverlay_map = self.img_map.overlay('b')
        self.overlay_map = self.img_map * self.contour_map
        self.layout_map = self.ndoverlay_map + self.contour_map
        self.duplicate_map = self.img_map.clone(kdims=['x', 'y'])

        self.overlap1 = HoloMap({i: self.img_fn() for i in range(5)})
        self.overlap2 = HoloMap({i: self.img_fn() for i in range(10)})
        self.overlap_layout = self.overlap1 + self.overlap2
Esempio n. 10
0
 def test_holomap_cftime_slider(self):
     try:
         import cftime
     except:
         raise SkipTest('Test requires cftime library')
     dates = [
         cftime.DatetimeGregorian(2000, 2, 28),
         cftime.DatetimeGregorian(2000, 3, 1),
         cftime.DatetimeGregorian(2000, 3, 2)
     ]
     hmap = HoloMap({d: Curve([1, 2, i])
                     for i, d in enumerate(dates)}, 'Date')
     widgets = bokeh_renderer.get_widget(hmap, 'widgets')
     widgets, dimensions, init_dim_vals = widgets.get_widgets()
     self.assertEqual(len(widgets), 1)
     slider = widgets[0]
     self.assertEqual(slider['type'], 'slider')
     self.assertEqual(slider['dim'], 'Date')
     self.assertEqual(slider['dim_idx'], 0)
     self.assertEqual(slider['vals'], repr([str(d) for d in dates]))
     self.assertEqual(slider['labels'], repr([str(d) for d in dates]))
     self.assertEqual(slider['step'], 1)
     self.assertEqual(slider['default'], 0)
     self.assertIs(slider['next_dim'], None)
     self.assertEqual(dimensions, ['Date'])
     self.assertEqual(init_dim_vals, ['2000-02-28 00:00:00'])
Esempio n. 11
0
 def test_polygons_no_holes_with_draw_tool(self):
     if bokeh_version < '1.0':
         raise SkipTest(
             'Plotting Polygons with holes requires bokeh >= 1.0')
     from bokeh.models import Patches
     xs = [1, 2, 3, np.nan, 6, 7, 3]
     ys = [2, 0, 7, np.nan, 7, 5, 2]
     holes = [[[(1.5, 2), (2, 3), (1.6, 1.6)],
               [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]], []]
     poly = HoloMap({
         0: Polygons([{
             'x': xs,
             'y': ys,
             'holes': holes
         }]),
         1: Polygons([{
             'x': xs,
             'y': ys
         }])
     })
     PolyDraw(source=poly)
     plot = bokeh_renderer.get_plot(poly)
     glyph = plot.handles['glyph']
     self.assertFalse(plot._has_holes)
     self.assertIsInstance(glyph, Patches)
Esempio n. 12
0
    def test_holomap_slider_and_dropdown(self):
        hmap = HoloMap({(i, chr(65 + i)): Curve([1, 2, 3])
                        for i in range(10)}, ['X', 'Y'])
        widgets = bokeh_renderer.get_widget(hmap, 'widgets')
        widgets, dimensions, init_dim_vals = widgets.get_widgets()
        self.assertEqual(len(widgets), 2)

        slider = widgets[0]
        self.assertEqual(slider['type'], 'slider')
        self.assertEqual(slider['dim'], 'X')
        self.assertEqual(slider['dim_idx'], 0)
        self.assertEqual(slider['vals'],
                         repr([repr(float(v)) for v in range(10)]))
        self.assertEqual(slider['labels'], repr([str(v) for v in range(10)]))
        self.assertEqual(slider['step'], 1)
        self.assertEqual(slider['default'], 0)
        self.assertEqual(slider['next_dim'], Dimension('Y'))
        self.assertEqual(eval(slider['next_vals']),
                         {str(float(i)): [chr(65 + i)]
                          for i in range(10)})

        dropdown = widgets[1]
        self.assertEqual(dropdown['type'], 'dropdown')
        self.assertEqual(dropdown['dim'], 'Y')
        self.assertEqual(dropdown['dim_idx'], 1)
        self.assertEqual(dropdown['vals'],
                         repr([chr(65 + v) for v in range(10)]))
        self.assertEqual(dropdown['labels'],
                         repr([chr(65 + v) for v in range(10)]))
        self.assertEqual(dropdown['step'], 1)
        self.assertEqual(dropdown['default'], 0)
        self.assertIs(dropdown['next_dim'], None)

        self.assertEqual(dimensions, ['X', 'Y'])
        self.assertEqual(init_dim_vals, repr(['0.0', 'A']))
Esempio n. 13
0
    def test_holomap_datetime_widgets(self):
        hmap = HoloMap({
            np.datetime64(dt.datetime(2017, 1, i)): Curve([i])
            for i in range(1, 3)
        })
        widgets = mpl_renderer.get_widget(hmap, 'widgets')

        key_data = json.loads(widgets.get_key_data())
        widget_data, dimensions, init_vals = widgets.get_widgets()

        expected = {
            'type': 'slider',
            'vals':
            "['2017-01-01T00:00:00.000000000', '2017-01-02T00:00:00.000000000']",
            'labels':
            "['2017-01-01T00:00:00.000000000', '2017-01-02T00:00:00.000000000']",
            'step': 1,
            'default': 0,
            'next_vals': '{}',
            'next_dim': None,
            'init_val': '2017-01-01T00:00:00.000000000',
            'visible': True,
            'dim': 'Default',
            'dim_label': 'Default',
            'dim_idx': 0,
            'visibility': '',
            'value': np.datetime64(dt.datetime(2017, 1, 1))
        }
        self.assertEqual(widget_data[0], expected)

        expected_keys = {
            "('2017-01-01T00:00:00.000000000',)": 0,
            "('2017-01-02T00:00:00.000000000',)": 1
        }
        self.assertEqual(key_data, expected_keys)
Esempio n. 14
0
 def test_holomap_slider_default(self):
     dim = Dimension('X', default=3)
     hmap = HoloMap({i: Curve([1, 2, 3]) for i in range(1, 9)}, dim)
     widgets = bokeh_renderer.get_widget(hmap, 'widgets')
     widgets, dimensions, init_dim_vals = widgets.get_widgets()
     self.assertEqual(widgets[0]['default'], '2')
     self.assertEqual(init_dim_vals, "['3.0']")
Esempio n. 15
0
 def test_holomap_dropdown_default(self):
     dim = Dimension('X', default='C')
     hmap = HoloMap({chr(65 + i): Curve([1, 2, 3]) for i in range(10)}, dim)
     widgets = bokeh_renderer.get_widget(hmap, 'widgets')
     widgets, dimensions, init_dim_vals = widgets.get_widgets()
     self.assertEqual(widgets[0]['default'], '2')
     self.assertEqual(init_dim_vals, "['C']")
Esempio n. 16
0
 def test_hover_tooltip_update(self):
     hmap = HoloMap({'a': Curve([1, 2, 3], vdims='a'), 'b': Curve([1, 2, 3], vdims='b')}).opts(
         tools=['hover'])
     plot = bokeh_renderer.get_plot(hmap)
     self.assertEqual(plot.handles['hover'].tooltips, [('x', '@{x}'), ('a', '@{a}')])
     plot.update(('b',))
     self.assertEqual(plot.handles['hover'].tooltips, [('x', '@{x}'), ('b', '@{b}')])
Esempio n. 17
0
 def test_batched_empty_update_invisible(self):
     hmap = HoloMap({i: NdOverlay({j: Curve(np.arange(i), label='A') for j in range(i%2)})
                     for i in range(1, 4)})
     opts = {'NdOverlay': {'legend_limit': 0}}
     plot = list(bokeh_renderer.get_plot(hmap(plot=opts)).subplots.values())[0]
     self.assertTrue(plot.handles['glyph_renderer'].visible)
     plot.update((2,))
     self.assertFalse(plot.handles['glyph_renderer'].visible)
Esempio n. 18
0
 def test_overlay_update_plot_opts_inherited(self):
     hmap = HoloMap({
         0: (Curve([]).options(title='A') * Curve([])),
         1: (Curve([]).options(title='B') * Curve([]))
     })
     plot = mpl_renderer.get_plot(hmap)
     self.assertEqual(plot.handles['title'].get_text(), 'A')
     plot.update((1, ))
     self.assertEqual(plot.handles['title'].get_text(), 'B')
Esempio n. 19
0
 def test_grid_title(self):
     grid = GridSpace({(i, j): HoloMap({a: Image(np.random.rand(10,10))
                                        for a in range(3)}, kdims=['X'])
                       for i in range(2) for j in range(3)})
     plot = bokeh_renderer.get_plot(grid)
     title = plot.handles['title']
     self.assertIsInstance(title, Div)
     text = "<span style='font-size: 16pt'><b>X: 0</b></font>"
     self.assertEqual(title.text, text)
Esempio n. 20
0
 def test_holomap_slider_unsorted_initialization(self):
     data = [(3, Curve([3, 2, 1])), (1, Curve([1, 2, 3]))]
     hmap = HoloMap(data, ['X'], sort=False)
     widgets = bokeh_renderer.get_widget(hmap, 'widgets')
     widgets, dimensions, init_dim_vals = widgets.get_widgets()
     self.assertEqual(len(widgets), 1)
     slider = widgets[0]
     self.assertEqual(slider['vals'], "['1.0', '3.0']")
     self.assertEqual(slider['labels'], "['1', '3']")
 def test_overlay_update_plot_opts_inherited(self):
     hmap = HoloMap(
         {0: (Curve([]).options(title='A') * Curve([])),
          1: (Curve([]).options(title='B') * Curve([]))}
     )
     plot = bokeh_renderer.get_plot(hmap)
     self.assertEqual(plot.state.title.text, 'A')
     plot.update((1,))
     self.assertEqual(plot.state.title.text, 'B')
 def test_overlay_update_sources(self):
     hmap = HoloMap({i: (Curve(np.arange(i), label='A') *
                         Curve(np.arange(i)*2, label='B'))
                     for i in range(10, 13)})
     plot = bokeh_renderer.get_plot(hmap)
     plot.update((12,))
     subplot1, subplot2 = plot.subplots.values()
     self.assertEqual(subplot1.handles['source'].data['y'], np.arange(12))
     self.assertEqual(subplot2.handles['source'].data['y'], np.arange(12)*2)
Esempio n. 23
0
    def test_grid_shared_source_synced_update(self):
        hmap = HoloMap({
            i: Dataset({chr(65 + j): np.random.rand(i + 2)
                        for j in range(4)},
                       kdims=['A', 'B', 'C', 'D'])
            for i in range(3)
        })

        # Create two holomaps of points sharing the same data source
        hmap1 = hmap.map(lambda x: Points(x.clone(kdims=['A', 'B'])), Dataset)
        hmap2 = hmap.map(lambda x: Points(x.clone(kdims=['D', 'C'])), Dataset)

        # Pop key (1,) for one of the HoloMaps and make GridSpace
        hmap2.pop(1)
        grid = GridSpace({
            0: hmap1,
            2: hmap2
        }, kdims=['X']).opts(plot=dict(shared_datasource=True))

        # Get plot
        plot = bokeh_renderer.get_plot(grid)

        # Check plot created shared data source and recorded expected columns
        sources = plot.handles.get('shared_sources', [])
        source_cols = plot.handles.get('source_cols', {})
        self.assertEqual(len(sources), 1)
        source = sources[0]
        data = source.data
        cols = source_cols[id(source)]
        self.assertEqual(set(cols), {'A', 'B', 'C', 'D'})

        # Ensure the source contains the expected columns
        self.assertEqual(set(data.keys()), {'A', 'B', 'C', 'D'})

        # Update to key (1,) and check the source contains data
        # corresponding to hmap1 and filled in NaNs for hmap2,
        # which was popped above
        plot.update((1, ))
        self.assertEqual(data['A'], hmap1[1].dimension_values(0))
        self.assertEqual(data['B'], hmap1[1].dimension_values(1))
        self.assertEqual(data['C'],
                         np.full_like(hmap1[1].dimension_values(0), np.NaN))
        self.assertEqual(data['D'],
                         np.full_like(hmap1[1].dimension_values(0), np.NaN))
Esempio n. 24
0
 def test_holomap_slider_unsorted_datetime_values_initialization(self):
     hmap = HoloMap([(np.datetime64(10005, 'D'), Curve([1, 2, 3])),
                     (np.datetime64(10000, 'D'), Curve([1, 2, 4]))],
                    sort=False)
     widgets = plotly_renderer.get_widget(hmap, 'widgets')
     widgets()
     self.assertEqual(widgets.plot.current_key,
                      (np.datetime64(10000, 'D'), ))
     self.assertEqual(widgets.plot.current_frame,
                      hmap[np.datetime64(10000, 'D')])
Esempio n. 25
0
 def test_holomap_slider_unsorted(self):
     data = {(i, j): Curve([1, 2, 3]) for i in range(3) for j in range(3)}
     del data[2, 2]
     hmap = HoloMap(data, ['X', 'Y'])
     widgets = bokeh_renderer.get_widget(hmap, 'widgets')
     widgets, dimensions, init_dim_vals =  widgets.get_widgets()
     self.assertEqual(len(widgets), 2)
     slider = widgets[1]
     self.assertEqual(slider['vals'], repr([repr(float(v)) for v in range(3)]))
     self.assertEqual(slider['labels'], repr([str(v) for v in range(3)]))
Esempio n. 26
0
    def setUp(self):
        self.img_fn = lambda: Image(np.random.rand(10, 10))
        self.contour_fn = lambda: Contours([np.random.rand(10, 2)
                                            for i in range(2)])
        params = [list(range(3)) for i in range(2)]
        self.img_map = HoloMap({(i, j): self.img_fn()
                                for i, j in product(*params)},
                               kdims=['a', 'b'])
        self.contour_map = HoloMap({(i, j): self.contour_fn()
                                    for i, j in product(*params)},
                                   kdims=['a', 'b'])
        self.ndoverlay_map = self.img_map.overlay('b')
        self.overlay_map = self.img_map * self.contour_map
        self.layout_map = self.ndoverlay_map + self.contour_map
        self.duplicate_map = self.img_map.clone(kdims=['x', 'y'])

        self.overlap1 = HoloMap({i: self.img_fn() for i in range(5)})
        self.overlap2 = HoloMap({i: self.img_fn() for i in range(10)})
        self.overlap_layout = self.overlap1 + self.overlap2
Esempio n. 27
0
 def test_cyclic_palette_curves(self):
     palette = Palette('Set1')
     opts = dict(color=palette)
     hmap = HoloMap({i: NdOverlay({j: Curve(np.random.rand(3)).opts(style=opts)
                                   for j in range(3)})
                     for i in range(3)})
     colors = palette[3].values
     plot = bokeh_renderer.get_plot(hmap)
     for subp, color in zip(plot.subplots.values(), colors):
         color = color if isinstance(color, basestring) else rgb2hex(color)
         self.assertEqual(subp.handles['glyph'].line_color, color)
 def test_holomap_legend_updates_varying_lengths(self):
     hmap = HoloMap({i: Overlay([Curve([1, 2, j], label=chr(65+j)) for j in range(i)]) for i in range(1, 4)})
     plot = bokeh_renderer.get_plot(hmap)
     legend_labels = [item.label for item in plot.state.legend[0].items]
     self.assertEqual(legend_labels, [{'value': 'A'}])
     plot.update((2,))
     legend_labels = [item.label for item in plot.state.legend[0].items]
     self.assertEqual(legend_labels, [{'value': 'A'}, {'value': 'B'}])
     plot.update((3,))
     legend_labels = [item.label for item in plot.state.legend[0].items]
     self.assertEqual(legend_labels, [{'value': 'A'}, {'value': 'B'}, {'value': 'C'}])
 def test_holomap_legend_updates(self):
     hmap = HoloMap({i: Curve([1, 2, 3], label=chr(65+i+2)) * Curve([1, 2, 3], label='B')
                     for i in range(3)})
     plot = bokeh_renderer.get_plot(hmap)
     legend_labels = [item.label for item in plot.state.legend[0].items]
     self.assertEqual(legend_labels, [{'value': 'C'}, {'value': 'B'}])
     plot.update((1,))
     legend_labels = [item.label for item in plot.state.legend[0].items]
     self.assertEqual(legend_labels, [{'value': 'B'}, {'value': 'D'}])
     plot.update((2,))
     legend_labels = [item.label for item in plot.state.legend[0].items]
     self.assertEqual(legend_labels, [{'value': 'B'}, {'value': 'E'}])
Esempio n. 30
0
 def setUp(self):
     alphas, betas, deltas = 2, 2, 2
     Bs = list(range(100))
     coords = itertools.product(*(range(n) for n in [alphas, betas, deltas]))
     mus=np.random.rand(alphas, betas, 100, 10)
     self.phase_boundaries = {(a, b, d): Curve(zip(Bs, mus[a, b, :, i]*a+b))
                              for i in range(10) for a, b, d in coords}
     self.dimensions = ['alpha', 'beta', 'delta']
     self.nesting_hmap = HoloMap(self.phase_boundaries, kdims=self.dimensions)
     self.nested_hmap = self.nesting_hmap.groupby(['alpha'])
     self.nested_overlay = self.nesting_hmap.overlay(['delta'])
     self.nested_grid = self.nested_overlay.grid(['alpha', 'beta'])
     self.nested_layout = self.nested_overlay.layout(['alpha', 'beta'])
Esempio n. 31
0
class TestCollation(unittest.TestCase):
    def setUp(self):
        alphas, betas, deltas = 2, 2, 2
        Bs = list(range(100))
        coords = itertools.product(*(range(n) for n in [alphas, betas, deltas]))
        mus = np.random.rand(alphas, betas, 100, 10)
        self.phase_boundaries = {
            (a, b, d): Curve(zip(Bs, mus[a, b, :, i] * a + b)) for i in range(10) for a, b, d in coords
        }
        self.dimensions = ["alpha", "beta", "delta"]
        self.nesting_hmap = HoloMap(self.phase_boundaries, kdims=self.dimensions)
        self.nested_hmap = self.nesting_hmap.groupby(["alpha"])
        self.nested_overlay = self.nesting_hmap.overlay(["delta"])
        self.nested_grid = self.nested_overlay.grid(["alpha", "beta"])
        self.nested_layout = self.nested_overlay.layout(["alpha", "beta"])

    def test_collate_hmap(self):
        collated = self.nested_hmap.collate()
        self.assertEqual(collated.kdims, self.nesting_hmap.kdims)
        self.assertEqual(collated.keys(), self.nesting_hmap.keys())
        self.assertEqual(collated.type, self.nesting_hmap.type)
        self.assertEqual(repr(collated), repr(self.nesting_hmap))

    def test_collate_ndoverlay(self):
        collated = self.nested_overlay.collate(NdOverlay)
        ndoverlay = NdOverlay(self.phase_boundaries, kdims=self.dimensions)
        self.assertEqual(collated.kdims, ndoverlay.kdims)
        self.assertEqual(collated.keys(), ndoverlay.keys())
        self.assertEqual(repr(collated), repr(ndoverlay))

    def test_collate_gridspace_ndoverlay(self):
        grid = self.nesting_hmap.groupby(["delta"]).collate(NdOverlay).grid(["alpha", "beta"])
        self.assertEqual(grid.dimensions(), self.nested_grid.dimensions())
        self.assertEqual(grid.keys(), self.nested_grid.keys())
        self.assertEqual(repr(grid), repr(self.nested_grid))

    def test_collate_ndlayout_ndoverlay(self):
        layout = self.nesting_hmap.groupby(["delta"]).collate(NdOverlay).layout(["alpha", "beta"])
        self.assertEqual(layout.dimensions(), self.nested_layout.dimensions())
        self.assertEqual(layout.keys(), self.nested_layout.keys())
        self.assertEqual(repr(layout), repr(self.nested_layout))

    def test_collate_layout_overlay(self):
        layout = self.nested_overlay + self.nested_overlay
        collated = Collator(kdims=["alpha", "beta"])
        for k, v in self.nested_overlay.items():
            collated[k] = v + v
        collated = collated()
        self.assertEqual(collated.dimensions(), layout.dimensions())

    def test_collate_layout_hmap(self):
        layout = self.nested_overlay + self.nested_overlay
        collated = Collator(kdims=["delta"], merge_type=NdOverlay)
        for k, v in self.nesting_hmap.groupby(["delta"]).items():
            collated[k] = v + v
        collated = collated()
        self.assertEqual(repr(collated), repr(layout))
        self.assertEqual(collated.dimensions(), layout.dimensions())
Esempio n. 32
0
 def test_grid_title(self):
     grid = GridSpace({
         (i, j):
         HoloMap({a: Image(np.random.rand(10, 10))
                  for a in range(3)},
                 kdims=['X'])
         for i in range(2) for j in range(3)
     })
     plot = bokeh_renderer.get_plot(grid)
     title = plot.handles['title']
     self.assertIsInstance(title, Div)
     text = ('<span style="color:black;font-family:Arial;'
             'font-style:bold;font-weight:bold;font-size:16pt">X: 0</span>')
     self.assertEqual(title.text, text)
Esempio n. 33
0
 def test_polygons_holes_initialize(self):
     from bokeh.models import MultiPolygons
     xs = [1, 2, 3, np.nan, 6, 7, 3]
     ys = [2, 0, 7, np.nan, 7, 5, 2]
     holes = [
         [[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]],
         []
     ]
     poly = HoloMap({0: Polygons([{'x': xs, 'y': ys, 'holes': holes}]),
                     1: Polygons([{'x': xs, 'y': ys}])})
     plot = bokeh_renderer.get_plot(poly)
     glyph = plot.handles['glyph']
     self.assertTrue(plot._has_holes)
     self.assertIsInstance(glyph, MultiPolygons)
Esempio n. 34
0
class TestCollation(unittest.TestCase):
    def setUp(self):
        alphas, betas, deltas = 2, 2, 2
        Bs = list(range(100))
        coords = itertools.product(*(range(n) for n in [alphas, betas, deltas]))
        mus=np.random.rand(alphas, betas, 100, 10)
        self.phase_boundaries = {(a, b, d): Curve(zip(Bs, mus[a, b, :, i]*a+b))
                                 for i in range(10) for a, b, d in coords}
        self.dimensions = ['alpha', 'beta', 'delta']
        self.nesting_hmap = HoloMap(self.phase_boundaries, kdims=self.dimensions)
        self.nested_hmap = self.nesting_hmap.groupby(['alpha'])
        self.nested_overlay = self.nesting_hmap.overlay(['delta'])
        self.nested_grid = self.nested_overlay.grid(['alpha', 'beta'])
        self.nested_layout = self.nested_overlay.layout(['alpha', 'beta'])

    def test_collate_hmap(self):
        collated = self.nested_hmap.collate()
        self.assertEqual(collated.kdims, self.nesting_hmap.kdims)
        self.assertEqual(collated.keys(), self.nesting_hmap.keys())
        self.assertEqual(collated.type, self.nesting_hmap.type)
        self.assertEqual(repr(collated), repr(self.nesting_hmap))

    def test_collate_ndoverlay(self):
        collated = self.nested_overlay.collate(NdOverlay)
        ndoverlay = NdOverlay(self.phase_boundaries, kdims=self.dimensions)
        self.assertEqual(collated.kdims, ndoverlay.kdims)
        self.assertEqual(collated.keys(), ndoverlay.keys())
        self.assertEqual(repr(collated), repr(ndoverlay))

    def test_collate_gridspace_ndoverlay(self):
        grid = self.nesting_hmap.groupby(['delta']).collate(NdOverlay).grid(['alpha', 'beta'])
        self.assertEqual(grid.dimensions(), self.nested_grid.dimensions())
        self.assertEqual(grid.keys(), self.nested_grid.keys())
        self.assertEqual(repr(grid), repr(self.nested_grid))

    def test_collate_ndlayout_ndoverlay(self):
        layout = self.nesting_hmap.groupby(['delta']).collate(NdOverlay).layout(['alpha', 'beta'])
        self.assertEqual(layout.dimensions(), self.nested_layout.dimensions())
        self.assertEqual(layout.keys(), self.nested_layout.keys())
        self.assertEqual(repr(layout), repr(self.nested_layout))

    def test_collate_layout_overlay(self):
        layout = self.nested_overlay + self.nested_overlay
        collated = Collator(kdims=['alpha', 'beta'])
        for k, v in self.nested_overlay.items():
            collated[k] = v + v
        collated = collated()
        self.assertEqual(collated.dimensions(), layout.dimensions())

    def test_collate_layout_hmap(self):
        layout = self.nested_overlay + self.nested_overlay
        collated = Collator(kdims=['delta'], merge_type=NdOverlay)
        for k, v in self.nesting_hmap.groupby(['delta']).items():
            collated[k] = v + v
        collated = collated()
        self.assertEqual(repr(collated), repr(layout))
        self.assertEqual(collated.dimensions(), layout.dimensions())
Esempio n. 35
0
    def test_grid_shared_source_synced_update(self):
        hmap = HoloMap({i: Dataset({chr(65+j): np.random.rand(i+2)
                                    for j in range(4)}, kdims=['A', 'B', 'C', 'D'])
                        for i in range(3)})

        # Create two holomaps of points sharing the same data source
        hmap1=  hmap.map(lambda x: Points(x.clone(kdims=['A', 'B'])), Dataset)
        hmap2 = hmap.map(lambda x: Points(x.clone(kdims=['D', 'C'])), Dataset)

        # Pop key (1,) for one of the HoloMaps and make GridSpace
        hmap2.pop(1)
        grid = GridSpace({0: hmap1, 2: hmap2}, kdims=['X']).opts(plot=dict(shared_datasource=True))

        # Get plot
        plot = bokeh_renderer.get_plot(grid)

        # Check plot created shared data source and recorded expected columns
        sources = plot.handles.get('shared_sources', [])
        source_cols = plot.handles.get('source_cols', {})
        self.assertEqual(len(sources), 1)
        source = sources[0]
        data = source.data
        cols = source_cols[id(source)]
        self.assertEqual(set(cols), {'A', 'B', 'C', 'D'})

        # Ensure the source contains the expected columns
        self.assertEqual(set(data.keys()), {'A', 'B', 'C', 'D'})

        # Update to key (1,) and check the source contains data
        # corresponding to hmap1 and filled in NaNs for hmap2,
        # which was popped above
        plot.update((1,))
        self.assertEqual(data['A'], hmap1[1].dimension_values(0))
        self.assertEqual(data['B'], hmap1[1].dimension_values(1))
        self.assertEqual(data['C'], np.full_like(hmap1[1].dimension_values(0), np.NaN))
        self.assertEqual(data['D'], np.full_like(hmap1[1].dimension_values(0), np.NaN))