Example #1
0
 def update_brush_y(self, *ignore):
     with self.output_widget:
         if not self.brush_y.brushing:  # only select when we ended
             y = self.brush_y.selected
             if y is not None and len(y):
                 roi = RangeROI(min=min(y), max=max(y), orientation='y')
                 self.apply_roi(roi)
Example #2
0
 def update_selection(self, *args):
     with self.viewer._output_widget:
         if self.interact.selected is not None:
             y = self.interact.selected
             if y is not None and len(y):
                 roi = RangeROI(min=min(y), max=max(y), orientation='y')
                 self.viewer.apply_roi(roi)
Example #3
0
 def update_brush_x(self, *ignore):
     with self.output_widget:
         if not self.brush_x.brushing:  # only select when we ended
             x = self.brush_x.selected
             if x is not None and len(x):
                 roi = RangeROI(min=min(x), max=max(x), orientation='x')
                 self.apply_roi(roi)
Example #4
0
    def apply_roi(self, roi, override_mode=None):

        # Force redraw to get rid of ROI. We do this because applying the
        # subset state below might end up not having an effect on the viewer,
        # for example there may not be any layers, or the active subset may not
        # be one of the layers. So we just explicitly redraw here to make sure
        # a redraw will happen after this method is called.
        self.redraw()

        if len(self.layers) == 0:
            return

        x_date = 'datetime' in self.state.x_kinds

        if x_date:
            roi = roi.transformed(xfunc=mpl_to_datetime64 if x_date else None)

        bins = self.state.bins

        x = roi.to_polygon()[0]
        lo, hi = min(x), max(x)

        if lo >= bins.min():
            lo = bins[bins <= lo].max()
        if hi <= bins.max():
            hi = bins[bins >= hi].min()

        roi_new = RangeROI(min=lo, max=hi, orientation='x')

        subset_state = roi_to_subset_state(
            roi_new,
            x_att=self.state.x_att,
            x_categories=self.state.x_categories)

        self.apply_subset_state(subset_state, override_mode=override_mode)
Example #5
0
    def apply_roi(self, roi):

        # TODO: move this to state class?

        # TODO: add back command stack here so as to be able to undo?
        # cmd = command.ApplyROI(client=self.client, roi=roi)
        # self._session.command_stack.do(cmd)

        # TODO Does subset get applied to all data or just visible data?

        bins = self.state.bins

        x = roi.to_polygon()[0]
        lo, hi = min(x), max(x)

        if lo >= bins.min():
            lo = bins[bins <= lo].max()
        if hi <= bins.max():
            hi = bins[bins >= hi].min()

        roi_new = RangeROI(min=lo, max=hi, orientation='x')

        for layer_artist in self._layer_artist_container:

            if not isinstance(layer_artist.layer, Data):
                continue

            x_comp = layer_artist.layer.get_component(self.state.x_att)

            subset_state = x_comp.subset_from_roi(self.state.x_att, roi_new,
                                                  coord='x')

            mode = EditSubsetMode()
            mode.update(self._data, subset_state, focus_data=layer_artist.layer)
Example #6
0
    def apply_roi(self, roi, use_current=False):

        if len(self.layers) == 0:  # Force redraw to get rid of ROI
            return self.redraw()

        x_date = any(comp.datetime for comp in self.state._get_x_components())

        if x_date:
            roi = roi.transformed(xfunc=mpl_to_datetime64 if x_date else None)

        bins = self.state.bins

        x = roi.to_polygon()[0]
        lo, hi = min(x), max(x)

        if lo >= bins.min():
            lo = bins[bins <= lo].max()
        if hi <= bins.max():
            hi = bins[bins >= hi].min()

        roi_new = RangeROI(min=lo, max=hi, orientation='x')

        x_comp = self.state.x_att.parent.get_component(self.state.x_att)

        subset_state = roi_to_subset_state(roi_new,
                                           x_att=self.state.x_att,
                                           x_comp=x_comp)

        self.apply_subset_state(subset_state, use_current=use_current)
Example #7
0
    def _roi_to_subset_state(self, roi):

        x = roi.to_polygon()[0]
        lo, hi = min(x), max(x)

        roi_new = RangeROI(min=lo, max=hi, orientation='x')

        return roi_to_subset_state(roi_new, x_att=self.state.x_att)
Example #8
0
    def _roi_to_subset_state(self, roi):
        # TODO: copy paste from glue/viewers/histogram/qt/data_viewer.py
        # TODO Does subset get applied to all data or just visible data?

        bins = self.state.bins

        x = roi.to_polygon()[0]
        lo, hi = min(x), max(x)

        if lo >= bins.min():
            lo = bins[bins <= lo].max()
        if hi <= bins.max():
            hi = bins[bins >= hi].min()

        roi_new = RangeROI(min=lo, max=hi, orientation='x')

        return roi_to_subset_state(roi_new, x_att=self.state.x_att)
Example #9
0
    def _roi_to_subset_state(self, roi):

        # TODO Does subset get applied to all data or just visible data?

        bins = self.state.bins

        x = roi.to_polygon()[0]
        lo, hi = min(x), max(x)

        if lo >= bins.min():
            lo = bins[bins <= lo].max()
        if hi <= bins.max():
            hi = bins[bins >= hi].min()

        roi_new = RangeROI(min=lo, max=hi, orientation='x')

        x_comp = self.state.x_att.parent.get_component(self.state.x_att)

        return x_comp.subset_from_roi(self.state.x_att, roi_new, coord='x')
Example #10
0
    def _roi_to_subset_state(self, roi):

        # TODO Does subset get applied to all data or just visible data?

        x_date = any(comp.datetime for comp in self.state._get_x_components())

        if x_date:
            roi = roi.transformed(xfunc=mpl_to_datetime64 if x_date else None)

        bins = self.state.bins

        x = roi.to_polygon()[0]
        lo, hi = min(x), max(x)

        if lo >= bins.min():
            lo = bins[bins <= lo].max()
        if hi <= bins.max():
            hi = bins[bins >= hi].min()

        roi_new = RangeROI(min=lo, max=hi, orientation='x')

        x_comp = self.state.x_att.parent.get_component(self.state.x_att)

        return x_comp.subset_from_roi(self.state.x_att, roi_new, coord='x')
Example #11
0
    def apply_roi(self, roi):
        x, _ = roi.to_polygon()
        lo = min(x)
        hi = max(x)

        # expand roi to match bin edges
        bins = self.bins

        if lo >= bins.min():
            lo = bins[bins <= lo].max()
        if hi <= bins.max():
            hi = bins[bins >= hi].min()

        if self.xlog:
            lo = 10**lo
            hi = 10**hi

        nroi = RangeROI(min=lo, max=hi, orientation='x')
        for comp in self._get_data_components('x'):
            state = comp.subset_from_roi(self.component, nroi, coord='x')
            mode = EditSubsetMode()
            visible = [d for d in self.data if self.is_layer_visible(d)]
            focus = visible[0] if len(visible) > 0 else None
            mode.update(self.data, state, focus_data=focus)