Esempio n. 1
0
 def tearDown(self):
     Store._weakrefs = {}
     Store._options.pop('backend_1')
     Store._options.pop('backend_2')
     Store._custom_options.pop('backend_1')
     Store._custom_options.pop('backend_2')
     Store.set_current_backend(self.current_backend)
Esempio n. 2
0
 def test_apply_options_when_backend_switched(self):
     obj = TestObj([])
     Store.current_backend = 'backend_2'
     obj.opts(style_opt1='A', plot_opt1='B')
     Store.current_backend = 'backend_1'
     obj.opts(style_opt1='C', plot_opt1='D', backend='backend_2')
     plot_opts = Store.lookup_options('backend_2', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'D'}
     style_opts = Store.lookup_options('backend_2', obj, 'style')
     assert style_opts.options == {'style_opt1': 'C'}
    def test_overlay_options_complete(self):
        """
        Complete specification style.
        """
        data = [zip(range(10), range(10)), zip(range(5), range(5))]
        o = Overlay([Curve(c) for c in data])({"Curve.Curve": {"plot": {"show_grid": True}, "style": {"color": "b"}}})

        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.I, "plot").kwargs["show_grid"], True)
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.II, "plot").kwargs["show_grid"], True)
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.I, "style").kwargs["color"], "b")
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.II, "style").kwargs["color"], "b")
Esempio n. 4
0
    def test_cell_opts_style(self):

        self.cell("mat1 = Image(np.random.rand(5,5), name='mat1')")

        self.assertEqual(self.get_object('mat1').id, None)
        self.cell_magic('opts', " Image (cmap='hot')", 'mat1')
        self.assertEqual(self.get_object('mat1').id, 0)

        assert 0 in Store.custom_options(), "Custom OptionTree creation failed"
        self.assertEqual(
            Store.lookup_options('matplotlib',
                                 self.get_object('mat1'), 'style').options.get('cmap',None),'hot')
Esempio n. 5
0
    def test_cell_opts_norm(self):

        self.cell("mat1 = Image(np.random.rand(5,5), name='mat1')")

        self.assertEqual(self.get_object('mat1').id, None)
        self.cell_magic('opts', " Image {+axiswise}", 'mat1')
        self.assertEqual(self.get_object('mat1').id, 0)

        assert 0 in Store.custom_options(), "Custom OptionTree creation failed"
        self.assertEqual(
            Store.lookup_options('matplotlib',
                                 self.get_object('mat1'), 'norm').options.get('axiswise',True), True)
Esempio n. 6
0
    def test_cell_opts_plot_dynamic(self):

        self.cell("dmap = DynamicMap(lambda X: Image(np.random.rand(5,5), name='dmap'), kdims=['x'])"
                  ".redim.range(x=(0, 10)).opts(plot={'Image': dict(xaxis='top', xticks=3)})")

        self.assertEqual(self.get_object('dmap').id, None)
        self.cell_magic('opts', " Image [xaxis=None yaxis='right']", 'dmap')
        self.assertEqual(self.get_object('dmap').id, 0)

        assert 0 in Store.custom_options(), "Custom OptionTree creation failed"
        opts = Store.lookup_options('matplotlib', self.get_object('dmap')[0], 'plot').options
        self.assertEqual(opts, {'xticks': 3, 'xaxis': None, 'yaxis': 'right'})
Esempio n. 7
0
    def test_cell_opts_plot_float_division(self):

        self.cell("mat1 = Image(np.random.rand(5,5), name='mat1')")

        self.assertEqual(self.get_object('mat1').id, None)
        self.cell_magic('opts', " Image [aspect=3/4]", 'mat1')
        self.assertEqual(self.get_object('mat1').id, 0)

        assert 0 in Store.custom_options(), "Custom OptionTree creation failed"
        self.assertEqual(
            Store.lookup_options('matplotlib',
                                 self.get_object('mat1'), 'plot').options.get('aspect',False), 3/4.0)
Esempio n. 8
0
    def test_cell_opts_style_dynamic(self):

        self.cell("dmap = DynamicMap(lambda X: Curve(np.random.rand(5,2), name='dmap'), kdims=['x'])"
                  ".redim.range(x=(0, 10)).opts(style={'Curve': dict(linewidth=2, color='black')})")

        self.assertEqual(self.get_object('dmap').id, None)
        self.cell_magic('opts', " Curve (linewidth=3 alpha=0.5)", 'dmap')
        self.assertEqual(self.get_object('dmap').id, 0)

        assert 0 in Store.custom_options(), "Custom OptionTree creation failed"
        opts = Store.lookup_options('matplotlib', self.get_object('dmap')[0], 'style').options
        self.assertEqual(opts, {'linewidth': 3, 'alpha': 0.5, 'color': 'black'})
Esempio n. 9
0
 def test_apply_options_explicit_backend_persists_other_backend_inverted(self):
     obj = TestObj([])
     obj.opts(style_opt1='A', plot_opt1='B', backend='backend_2')
     obj.opts(style_opt1='C', plot_opt1='D', backend='backend_1')
     plot_opts = Store.lookup_options('backend_1', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'D'}
     style_opts = Store.lookup_options('backend_1', obj, 'style')
     assert style_opts.options == {'style_opt1': 'C'}
     plot_opts = Store.lookup_options('backend_2', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'B'}
     style_opts = Store.lookup_options('backend_2', obj, 'style')
     assert style_opts.options == {'style_opt1': 'A'}
Esempio n. 10
0
    def test_cell_opts_plot(self):

        self.cell("mat1 = Image(np.random.rand(5,5), name='mat1')")

        self.assertEqual(self.get_object('mat1').id, None)
        self.cell_magic('opts', " Image [show_title=False]", 'mat1')
        self.assertEqual(self.get_object('mat1').id, 0)

        assert 0 in Store.custom_options(), "Custom OptionTree creation failed"
        self.assertEqual(
            Store.lookup_options('matplotlib',
                                 self.get_object('mat1'), 'plot').options.get('show_title',True),False)
    def test_overlay_options_partitioned(self):
        """
        The new style introduced in #73
        """
        data = [zip(range(10), range(10)), zip(range(5), range(5))]
        o = Overlay([Curve(c) for c in data])(
            dict(plot={"Curve.Curve": {"show_grid": False}}, style={"Curve.Curve": {"color": "k"}})
        )

        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.I, "plot").kwargs["show_grid"], False)
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.II, "plot").kwargs["show_grid"], False)
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.I, "style").kwargs["color"], "k")
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.II, "style").kwargs["color"], "k")
Esempio n. 12
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])
Esempio n. 13
0
 def _set_style(self, feature, map_type):
     fname = feature.name.capitalize()
     style_path = ('Image', fname + map_type.capitalize())
     options = Store.options(backend='matplotlib')
     if style_path not in options.data:
         cyclic = True if feature.cyclic and not map_type == 'selectivity' else False
         options[style_path] = Options('style', **(dict(cmap='hsv') if cyclic else dict()))
 def test_layout_options_short_style(self):
     """
     Short __call__ syntax.
     """
     im = Image(np.random.rand(10, 10))
     layout = (im + im)({"Layout": dict(plot={"hspace": 5})})
     self.assertEqual(Store.lookup_options("matplotlib", layout, "plot").kwargs["hspace"], 5)
 def test_layout_options_long_style(self):
     """
     The old (longer) syntax in __call__
     """
     im = Image(np.random.rand(10, 10))
     layout = (im + im)({"Layout": dict(plot={"hspace": 10})})
     self.assertEqual(Store.lookup_options("matplotlib", layout, "plot").kwargs["hspace"], 10)
Esempio n. 16
0
    def test_overlay_options_complete(self):
        """
        Complete specification style.
        """
        data = [zip(range(10),range(10)), zip(range(5),range(5))]
        o = Overlay([Curve(c) for c in data])(
            {'Curve.Curve':{'plot':{'show_grid':True},
                            'style':{'color':'b'}}})

        self.assertEqual(Store.lookup_options(
            o.Curve.I, 'plot').kwargs['show_grid'], True)
        self.assertEqual(Store.lookup_options(
            o.Curve.II, 'plot').kwargs['show_grid'], True)
        self.assertEqual(Store.lookup_options(
            o.Curve.I, 'style').kwargs['color'], 'b')
        self.assertEqual(Store.lookup_options(
            o.Curve.II, 'style').kwargs['color'], 'b')
Esempio n. 17
0
 def test_layout_options_long_style(self):
     """
     The old (longer) syntax in __call__
     """
     im = Image(np.random.rand(10,10))
     layout = (im + im)({'Layout':dict(plot={'hspace':10})})
     self.assertEqual(Store.lookup_options(
         layout, 'plot').kwargs['hspace'], 10)
Esempio n. 18
0
    def test_overlay_options_partitioned(self):
        """
        The new style introduced in #73
        """
        data = [zip(range(10),range(10)), zip(range(5),range(5))]
        o = Overlay([Curve(c) for c in data])(
            dict(plot={'Curve.Curve':{'show_grid':False}},
                 style={'Curve.Curve':{'color':'k'}}))

        self.assertEqual(Store.lookup_options(
            o.Curve.I, 'plot').kwargs['show_grid'], False)
        self.assertEqual(Store.lookup_options(
            o.Curve.II, 'plot').kwargs['show_grid'], False)
        self.assertEqual(Store.lookup_options(
            o.Curve.I, 'style').kwargs['color'], 'k')
        self.assertEqual(Store.lookup_options(
            o.Curve.II, 'style').kwargs['color'], 'k')
Esempio n. 19
0
 def test_layout_options_short_style(self):
     """
     Short __call__ syntax.
     """
     im = Image(np.random.rand(10,10))
     layout = (im + im)({'Layout':dict(plot={'hspace':5})})
     self.assertEqual(Store.lookup_options(
         layout, 'plot').kwargs['hspace'], 5)
Esempio n. 20
0
def option_intersections(backend):
    intersections = []
    options = Store.options(backend)
    for k, opts in sorted(options.items()):
        if len(k) > 1: continue
        valid_options = {k: set(o.allowed_keywords)
                         for k, o in opts.groups.items()}
        for g1, g2 in combinations(Options._option_groups, 2):
            intersection = valid_options[g1] & valid_options[g2]
            if intersection:
                intersections.append((k, intersection))
    return intersections
Esempio n. 21
0
 def test_apply_options_current_backend_style(self):
     obj = ExampleElement([]).options(style_opt1='A')
     opts = Store.lookup_options('backend_1', obj, 'style')
     assert opts.options == {'style_opt1': 'A'}
Esempio n. 22
0
 def tearDown(self):
     Store.custom_options(val={})
     super(TestOptsMagic, self).tearDown()
Esempio n. 23
0
    def _update_layout(self):
        from holoviews.core.options import Store

        loc = self.widget_location
        if not len(self.widget_box):
            widgets = []
        elif loc in ('left', 'right'):
            widgets = Column(VSpacer(), self.widget_box, VSpacer())
        elif loc in ('top', 'bottom'):
            widgets = Row(HSpacer(), self.widget_box, HSpacer())
        elif loc in ('top_left', 'bottom_left'):
            widgets = Row(self.widget_box, HSpacer())
        elif loc in ('top_right', 'bottom_right'):
            widgets = Row(HSpacer(), self.widget_box)
        elif loc in ('left_top', 'right_top'):
            widgets = Column(self.widget_box, VSpacer())
        elif loc in ('left_bottom', 'right_bottom'):
            widgets = Column(VSpacer(), self.widget_box)

        # Do not center if content is responsive
        backend = self.backend or Store.current_backend
        if self.object is None:
            opts = {}
        else:
            try:
                opts = Store.lookup_options(backend, self.object,
                                            'plot').kwargs
            except KeyError:
                opts = {}
        responsive_modes = ('stretch_width', 'stretch_both', 'scale_width',
                            'scale_both')
        center = self.center
        if ((opts.get('responsive')
             and not (opts.get('width') or opts.get('frame_width')))
                or opts.get('sizing_mode') in responsive_modes):
            center = False

        self._widget_container = widgets
        if not widgets:
            if center:
                components = [HSpacer(), self, HSpacer()]
            else:
                components = [self]
        elif center:
            if loc.startswith('left'):
                components = [widgets, HSpacer(), self, HSpacer()]
            elif loc.startswith('right'):
                components = [HSpacer(), self, HSpacer(), widgets]
            elif loc.startswith('top'):
                components = [
                    HSpacer(),
                    Column(widgets, Row(HSpacer(), self, HSpacer())),
                    HSpacer()
                ]
            elif loc.startswith('bottom'):
                components = [
                    HSpacer(),
                    Column(Row(HSpacer(), self, HSpacer()), widgets),
                    HSpacer()
                ]
        else:
            if loc.startswith('left'):
                components = [widgets, self]
            elif loc.startswith('right'):
                components = [self, widgets]
            elif loc.startswith('top'):
                components = [Column(widgets, self)]
            elif loc.startswith('bottom'):
                components = [Column(self, widgets)]
        self.layout[:] = components
Esempio n. 24
0
 def setUp(self):
     self.current_backend = Store.current_backend
     self.register_custom(TestObj, 'backend_1', ['plot_custom1'])
     self.register_custom(TestObj, 'backend_2', ['plot_custom2'])
     Store.set_current_backend('backend_1')
Esempio n. 25
0
 def test_apply_options_explicit_backend_style_multiple(self):
     obj = TestObj([]).options(style_opt1='A',
                               style_opt2='B',
                               backend='backend_2')
     opts = Store.lookup_options('backend_2', obj, 'style')
     assert opts.options == {'style_opt1': 'A', 'style_opt2': 'B'}
Esempio n. 26
0
 def test_apply_options_current_backend_style_multiple(self):
     obj = TestObj([]).options(style_opt1='A', style_opt2='B')
     opts = Store.lookup_options('backend_1', obj, 'style')
     assert opts.options == {'style_opt1': 'A', 'style_opt2': 'B'}
Esempio n. 27
0
 def test_apply_options_not_cloned(self):
     obj1 = TestObj([])
     obj2 = obj1.options(style_opt1='A', clone=False)
     opts = Store.lookup_options('backend_1', obj1, 'style')
     assert opts.options == {'style_opt1': 'A'}
     assert obj1 is obj2
Esempio n. 28
0
        tile_service_options = quest.api.download_options(
            quest_service, fmt='param')[quest_service]
        basemap_features = quest.api.get_features(quest_service)
        collection_name = 'examples'
        if collection_name in quest.api.get_collections():
            pass
        else:
            quest.api.new_collection(collection_name)

        collection_feature = quest.api.add_features(collection_name,
                                                    basemap_features[0])

        staged_id = quest.api.stage_for_download(collection_feature,
                                                 options=options)
        download_state = quest.api.download_datasets(staged_id)
        # Fragile, needs improvement
        download_id = list(download_state.keys())[0]

        meta = quest.api.get_metadata(staged_id)
        file_path = meta[download_id].get('file_path', None)
        if not os.path.isfile(file_path):
            print('Error: No TIFF downloaded')
        return file_path


options = Store.options('bokeh')

options.Points = Options('plot', padding=0.1)
options.Path = Options('plot', padding=0.1)
options.Polygons = Options('plot', padding=0.1)
Esempio n. 29
0
 def test_bivariate_composite_transfer_opts_with_group(self):
     dist = Bivariate(np.random.rand(10, 2),
                      group='Test').opts(style=dict(cmap='Blues'))
     contours = Compositor.collapse_element(dist)
     opts = Store.lookup_options('matplotlib', contours, 'style').kwargs
     self.assertEqual(opts.get('cmap', None), 'Blues')
Esempio n. 30
0
 def test_distribution_composite_transfer_opts_with_group(self):
     dist = Distribution(np.array([0, 1, 2]),
                         group='Test').opts(style=dict(color='red'))
     area = Compositor.collapse_element(dist)
     opts = Store.lookup_options('matplotlib', area, 'style').kwargs
     self.assertEqual(opts.get('color', None), 'red')
Esempio n. 31
0
    def __init__(self,
                 data,
                 x,
                 y,
                 kind=None,
                 by=None,
                 use_index=True,
                 group_label='Variable',
                 value_label='value',
                 backlog=1000,
                 persist=False,
                 use_dask=False,
                 crs=None,
                 fields={},
                 groupby=None,
                 dynamic=True,
                 width=700,
                 height=300,
                 shared_axes=True,
                 grid=False,
                 legend=True,
                 rot=None,
                 title=None,
                 xlim=None,
                 ylim=None,
                 xticks=None,
                 yticks=None,
                 logx=False,
                 logy=False,
                 loglog=False,
                 hover=True,
                 subplots=False,
                 label=None,
                 invert=False,
                 stacked=False,
                 colorbar=None,
                 fontsize=None,
                 colormap=None,
                 datashade=False,
                 rasterize=False,
                 row=None,
                 col=None,
                 figsize=None,
                 debug=False,
                 xaxis=True,
                 yaxis=True,
                 framewise=True,
                 aggregator=None,
                 projection=None,
                 global_extent=False,
                 **kwds):

        # Process data and related options
        self._process_data(kind, data, x, y, by, groupby, row, col, use_dask,
                           persist, backlog, label, value_label, kwds)
        self.use_index = use_index
        self.value_label = value_label
        self.group_label = group_label
        self.dynamic = dynamic
        self.crs = process_crs(crs)
        self.row = row
        self.col = col

        # Operations
        self.datashade = datashade
        self.rasterize = rasterize
        self.aggregator = aggregator

        # By type
        self.subplots = subplots
        self._by_type = NdLayout if subplots else NdOverlay

        # Process options
        style_opts, plot_opts, kwds = self._process_style(kind, colormap, kwds)
        self.stacked = stacked
        self.invert = invert
        plot_opts['logx'] = logx or loglog
        plot_opts['logy'] = logy or loglog
        plot_opts['show_grid'] = grid
        plot_opts['shared_axes'] = shared_axes
        plot_opts['show_legend'] = legend
        if xticks:
            plot_opts['xticks'] = xticks
        if yticks:
            plot_opts['yticks'] = yticks
        if not xaxis:
            plot_opts['xaxis'] = None
        if not yaxis:
            plot_opts['yaxis'] = None
        if width:
            plot_opts['width'] = width
        if height:
            plot_opts['height'] = height
        if fontsize:
            plot_opts['fontsize'] = fontsize
        if isinstance(colorbar, bool):
            plot_opts['colorbar'] = colorbar
        elif self.kind in self._colorbar_types:
            plot_opts['colorbar'] = True
        if invert:
            plot_opts['invert_axes'] = kind != 'barh'
        if rot:
            axis = 'yrotation' if invert else 'xrotation'
            plot_opts[axis] = rot
        if hover:
            plot_opts['tools'] = ['hover']

        if self.crs and global_extent:
            plot_opts['global_extent'] = global_extent
        if projection:
            plot_opts['projection'] = process_crs(projection)
        plot_opts['legend_position'] = 'right'
        if title is not None:
            plot_opts['title_format'] = title
        self._plot_opts = plot_opts
        options = Store.options(backend='bokeh')
        el_type = self._kind_mapping[self.kind].__name__
        style = options[el_type].groups['style']
        cycled_opts = [
            k for k, v in style.kwargs.items() if isinstance(v, Cycle)
        ]
        for opt in cycled_opts:
            color = style_opts.get('color', None)
            if color is None:
                cycle = process_cmap(colormap or 'Category10',
                                     categorical=True)
            elif not isinstance(color, (Cycle, list)):
                continue
            style_opts[opt] = Cycle(
                values=cycle) if isinstance(cycle, list) else cycle
        self._style_opts = style_opts
        self._norm_opts = {'framewise': framewise, 'axiswise': not shared_axes}
        self.kwds = kwds

        # Process dimensions and labels
        self.label = label
        self._relabel = {'label': label} if label else {}
        self._dim_ranges = {
            'x': xlim or (None, None),
            'y': ylim or (None, None)
        }
        self._redim = fields

        # High-level options
        self._validate_kwds(kwds)
        if debug:
            kwds = dict(x=self.x,
                        y=self.y,
                        by=self.by,
                        kind=self.kind,
                        groupby=self.groupby)
            self.warning('Plotting {kind} plot with parameters x: {x}, '
                         'y: {y}, by: {by}, groupby: {groupby}'.format(**kwds))
Esempio n. 32
0
 def test_apply_options_current_backend_plot_multiple(self):
     obj = TestObj([]).options(plot_opt1='A', plot_opt2='B')
     opts = Store.lookup_options('backend_1', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A', 'plot_opt2': 'B'}
Esempio n. 33
0
 def test_apply_options_current_backend_plot_and_style(self):
     obj = TestObj([]).options(style_opt1='A', plot_opt1='B')
     plot_opts = Store.lookup_options('backend_1', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'B'}
     style_opts = Store.lookup_options('backend_1', obj, 'style')
     assert style_opts.options == {'style_opt1': 'A'}
Esempio n. 34
0
        The situated bounds can be set to embed the CFView in a larger
        bounded region.""")

    input_sheet_slice = param.NumericTuple(default=(0, 0, 0, 0), doc="""
        Slice indices of the embedded view into the situated matrix.""")

    @property
    def situated(self):
        if self.bounds.lbrt() == self.situated_bounds.lbrt():
            self.warning("CFView is already situated.")
            return self
        l, b, r, t = self.bounds.lbrt()
        xd = int(np.round(self.data.shape[1] / (r-l)))
        yd = int(np.round(self.data.shape[0] / (t-b)))

        scs = SheetCoordinateSystem(self.situated_bounds, xd, yd)

        data = np.zeros(scs.shape, dtype=np.float64)
        r1, r2, c1, c2 = self.input_sheet_slice
        data[r1:r2, c1:c2] = self.data

        return CFView(data, self.situated_bounds, roi_bounds=self.bounds,
                      situated_bounds=self.situated_bounds,
                      label=self.label, group=self.group)


Store.register({CFView: RasterPlot}, 'matplotlib')

options = Store.options(backend='matplotlib')
options.CFView = Options('style', cmap='gray', interpolation='nearest')
Esempio n. 35
0
 def test_apply_options_explicit_backend_plot(self):
     obj = TestObj([]).options(plot_opt1='A', backend='backend_2')
     opts = Store.lookup_options('backend_2', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A'}
Esempio n. 36
0
 def test_apply_options_explicit_backend_plot_and_style(self):
     obj = TestObj([]).options(style_opt1='A', plot_opt1='B', backend='backend_2')
     plot_opts = Store.lookup_options('backend_2', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'B'}
     style_opts = Store.lookup_options('backend_2', obj, 'style')
     assert style_opts.options == {'style_opt1': 'A'}
Esempio n. 37
0
        for (in_label, out_label), view in grids.items():
            results.set_path(('%s_Reverse_Correlation' % in_label, out_label), view)
            if p.store_responses:
                info = (p.pattern_generator.__class__.__name__,
                        pattern_dim_label, 'Response')
                results.set_path(('%s_%s_%s' % info, in_label),
                                 responses[in_label])
                results.set_path(('%s_%s_%s' % info, out_label),
                                 responses[out_label])
        return results

from holoviews.core.options import Compositor
from .analysis import toHCS

#Default styles
options = Store.options(backend='matplotlib')
options.Image.Preference = Options('style', cmap='hsv')
options.Image.Selectivity = Options('style', cmap='gray')
options.Image.Activity = Options('style', cmap='gray')
options.Image.Response = Options('style', cmap='gray')
options.Image.FFT_Power = Options('style', cmap='gray')

# Default channel definitions
Compositor.register(
    Compositor('Image.Orientation_Preference * Image.Orientation_Selectivity',
               toHCS, 'OR PrefSel', mode='display', flipSC=True))

Compositor.register(
    Compositor('Image.Direction_Preference * Image.Direction_Selectivity',
               toHCS, 'DR PrefSel', mode='display', flipSC=True))
Esempio n. 38
0
 def test_dynamic_options_no_clone(self):
     dmap = DynamicMap(lambda X: TestObj(None),
                       kdims=['X']).redim.range(X=(0, 10))
     dmap.options(plot_opt1='red', clone=False)
     opts = Store.lookup_options('backend_1', dmap[0], 'plot')
     self.assertEqual(opts.options, {'plot_opt1': 'red'})
Esempio n. 39
0
                                           doc="""
        Slice indices of the embedded view into the situated matrix.""")

    @property
    def situated(self):
        if self.bounds.lbrt() == self.situated_bounds.lbrt():
            self.warning("CFView is already situated.")
            return self
        l, b, r, t = self.bounds.lbrt()
        xd = int(np.round(self.data.shape[1] / (r - l)))
        yd = int(np.round(self.data.shape[0] / (t - b)))

        scs = SheetCoordinateSystem(self.situated_bounds, xd, yd)

        data = np.zeros(scs.shape, dtype=np.float64)
        r1, r2, c1, c2 = self.input_sheet_slice
        data[r1:r2, c1:c2] = self.data

        return CFView(data,
                      self.situated_bounds,
                      roi_bounds=self.bounds,
                      situated_bounds=self.situated_bounds,
                      label=self.label,
                      group=self.group)


Store.register({CFView: RasterPlot}, 'matplotlib')

options = Store.options(backend='matplotlib')
options.CFView = Options('style', cmap='gray', interpolation='nearest')
Esempio n. 40
0
 def test_apply_options_current_backend_plot(self):
     obj = ExampleElement([]).options(plot_opt1='A')
     opts = Store.lookup_options('backend_1', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A'}
Esempio n. 41
0
 def test_apply_options_explicit_backend_plot_multiple(self):
     obj = TestObj([]).options(plot_opt1='A', plot_opt2='B', backend='backend_2')
     opts = Store.lookup_options('backend_2', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A', 'plot_opt2': 'B'}
Esempio n. 42
0
 def test_apply_options_explicit_backend_plot_multiple(self):
     obj = ExampleElement([]).options(plot_opt1='A',
                                      plot_opt2='B',
                                      backend='backend_2')
     opts = Store.lookup_options('backend_2', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A', 'plot_opt2': 'B'}
Esempio n. 43
0
 def test_apply_options_cloned(self):
     obj1 = TestObj([])
     obj2 = obj1.options(style_opt1='A')
     opts = Store.lookup_options('backend_1', obj2, 'style')
     assert opts.options == {'style_opt1': 'A'}
     assert obj1 is not obj2
Esempio n. 44
0
 def test_apply_options_cloned(self):
     obj1 = ExampleElement([])
     obj2 = obj1.options(style_opt1='A')
     opts = Store.lookup_options('backend_1', obj2, 'style')
     assert opts.options == {'style_opt1': 'A'}
     assert obj1 is not obj2
Esempio n. 45
0
                           extents=sheet.bounds.lbrt(),
                           label=proj.name,
                           group='Center of Gravity')

        xcog_map = HoloMap((timestamp, xsv), kdims=[features.Time])
        xcog_map.metadata = metadata
        ycog_map = HoloMap((timestamp, ysv), kdims=[features.Time])
        ycog_map.metadata = metadata

        contour_map = HoloMap((timestamp, cogmesh), kdims=[features.Time])
        contour_map.metadata = metadata

        return {'XCoG': xcog_map, 'YCoG': ycog_map, 'CoG': contour_map}


options = Store.options(backend='matplotlib')
options.Contours.Gravity = Options('style', linewidth=1.0)
options.Image.X_CoG = Options('style', cmap='gray')
options.Image.Y_CoG = Options('style', cmap='gray')
options.CFView.OnOff_CFs = Options('style',
                                   cmap='RdYlBu_r',
                                   interpolation='nearest')

import types

__all__ = list(
    set([
        k for k, v in locals().items() if isinstance(v, types.FunctionType) or
        (isinstance(v, type) and issubclass(v, ParameterizedFunction))
        and not v.__name__.startswith('_')
    ]))
Esempio n. 46
0
 def setUp(self):
     super().setUp()
     self.current_backend = Store.current_backend
     self.register_custom(ExampleElement, 'backend_1', ['plot_custom1'])
     self.register_custom(ExampleElement, 'backend_2', ['plot_custom2'])
     Store.set_current_backend('backend_1')
Esempio n. 47
0
 def setUp(self):
     self.current_backend = Store.current_backend
     self.register_custom(TestObj, 'backend_1', ['plot_custom1'])
     self.register_custom(TestObj, 'backend_2', ['plot_custom2'])
     Store.set_current_backend('backend_1')
Esempio n. 48
0
 def test_holomap_options(self):
     hmap = HoloMap({0: Image(np.random.rand(10, 10))}).options(xaxis=None)
     opts = Store.lookup_options('matplotlib', hmap.last, 'plot')
     self.assertIs(opts.kwargs['xaxis'], None)
Esempio n. 49
0
 def test_apply_options_current_backend_plot(self):
     obj = TestObj([]).options(plot_opt1='A')
     opts = Store.lookup_options('backend_1', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A'}
    input_sheet_slice = param.NumericTuple(default=(0, 0, 0, 0), doc="""
        Slice indices of the embedded view into the situated matrix.""")

    @property
    def situated(self):
        if self.bounds.lbrt() == self.situated_bounds.lbrt():
            self.warning("CFView is already situated.")
            return self
        l, b, r, t = self.bounds.lbrt()
        xd = int(np.round(self.data.shape[1] / (r-l)))
        yd = int(np.round(self.data.shape[0] / (t-b)))

        scs = SheetCoordinateSystem(self.situated_bounds, xd, yd)

        data = np.zeros(scs.shape, dtype=np.float64)
        r1, r2, c1, c2 = self.input_sheet_slice
        data[r1:r2, c1:c2] = self.data

        return CFView(data, self.situated_bounds, roi_bounds=self.bounds,
                      situated_bounds=self.situated_bounds,
                      label=self.label, group=self.group)


Store.registry.update({CFView: RasterPlot})

def topo_options(options):
    options.CFView = Options('style', cmap='gray', interpolation='nearest')

Store.option_setters.append(topo_options)
Store.register_plots(style_aliases=style_aliases)
Esempio n. 51
0
        for vind in range(vlines)[:: p.stride]:
            lines.append(np.vstack([xsv.data[:, vind].T, ysv.data[:, vind]]).T)
        cogmesh = Contours(lines, extents=sheet.bounds.lbrt(), label=proj.name, group="Center of Gravity")

        xcog_map = HoloMap((timestamp, xsv), kdims=[features.Time])
        xcog_map.metadata = metadata
        ycog_map = HoloMap((timestamp, ysv), kdims=[features.Time])
        ycog_map.metadata = metadata

        contour_map = HoloMap((timestamp, cogmesh), kdims=[features.Time])
        contour_map.metadata = metadata

        return {"XCoG": xcog_map, "YCoG": ycog_map, "CoG": contour_map}


options = Store.options(backend="matplotlib")
options.Contours.Gravity = Options("style", linewidth=1.0)
options.Image.X_CoG = Options("style", cmap="gray")
options.Image.Y_CoG = Options("style", cmap="gray")
options.CFView.OnOff_CFs = Options("style", cmap="RdYlBu_r", interpolation="nearest")

import types

__all__ = list(
    set(
        [
            k
            for k, v in locals().items()
            if isinstance(v, types.FunctionType)
            or (isinstance(v, type) and issubclass(v, ParameterizedFunction))
            and not v.__name__.startswith("_")
Esempio n. 52
0
 def test_dynamic_options(self):
     dmap = DynamicMap(lambda X: ExampleElement(None), kdims=['X']).redim.range(X=(0,10))
     dmap = dmap.options(plot_opt1='red')
     opts = Store.lookup_options('backend_1', dmap[0], 'plot')
     self.assertEqual(opts.options, {'plot_opt1': 'red'})