Beispiel #1
0
 def test_point1d_spectrum_ronded_coord(self):
     s = self.s_s
     r = Point1DROI(37.)
     sr = r(s)
     scale = s.axes_manager[0].scale
     np.testing.assert_equal(sr.data, s.data[:,
                                             int(round(37 / scale)), ...])
     r = Point1DROI(39.)
     sr = r(s)
     np.testing.assert_equal(sr.data, s.data[:,
                                             int(round(39 / scale)), ...])
Beispiel #2
0
 def test_point1d_image(self):
     s = self.s_i
     r = Point1DROI(35)
     sr = r(s)
     scale = s.axes_manager[0].scale
     nt.assert_equal(sr.axes_manager.navigation_shape,
                     s.axes_manager.navigation_shape[1:])
     np.testing.assert_equal(sr.data, s.data[:, int(35 / scale), ...])
Beispiel #3
0
 def test_repr_vals(self):
     repr(Point1DROI(1.1))
     repr(Point2DROI(1.1, 2.1))
     repr(Line2DROI(0, 0, 1, 1, 0.1))
     repr(RectangularROI(0, 0, 1, 1))
     repr(SpanROI(3., 5.))
     repr(CircleROI(5, 5, 3))
     repr(CircleROI(5, 5, 3, 1))
Beispiel #4
0
 def test_point1d_image(self):
     s = self.s_i
     r = Point1DROI(35)
     sr = r(s)
     scale = s.axes_manager[0].scale
     assert (sr.axes_manager.navigation_shape ==
             s.axes_manager.navigation_shape[1:])
     if s._lazy:
         s.compute()
         sr.compute()
     np.testing.assert_equal(
         sr.data, s.data[:, int(35 / scale), ...])
Beispiel #5
0
 def _get_rois(self, signal):
     rois = []
     if self.have_selection(signal):
         if self.ndim(signal) == 1:
             if self.ranged:
                 roi_template = SpanROI(0, 1)
             else:
                 roi_template = Point1DROI(0)
         elif self.ndim(signal) > 1:
             if self.ranged:
                 roi_template = RectangularROI(0, 0, 1, 1)
             else:
                 roi_template = Point2DROI(0, 0)
         for w in self.widgets[signal]:
             roi = copy.deepcopy(roi_template)
             # ROI gets coords from widget:
             roi._on_widget_change(w)
             rois.append(roi)
     return rois
Beispiel #6
0
 def accept(self):
     if self.is_on():
         if self.ndim == 1:
             if self.ranged:
                 roi = SpanROI(0, 1)
             else:
                 roi = Point1DROI(0)
         elif self.ndim > 1:
             if self.ranged:
                 roi = RectangularROI(0, 0, 1, 1)
             else:
                 roi = Point2DROI(0, 0)
         else:
             raise RuntimeWarning("No figure could be found.")
             return
         roi._on_widget_change(self.widget)  # ROI gets coords from widget
         self.accepted[BaseInteractiveROI].emit(roi)
         self.accepted[BaseInteractiveROI, SignalFigureTool].emit(roi, self)
     if self.cancel_on_accept:
         self.cancel()
Beispiel #7
0
 def test_point1d_getitem(self):
     r = Point1DROI(35)
     assert (35, ) == tuple(r)
Beispiel #8
0
    def test_interactive_snap(self, snap):
        kwargs = {}
        if snap != 'default':
            kwargs['snap'] = snap
        else:
            # default is True
            snap = True
        s = self.s
        r = RectangularROI(left=3, right=7, top=2, bottom=5)
        s.plot()
        _ = r.interactive(s, **kwargs)
        for w in r.widgets:
            old_position = w.position
            new_position = (3.25, 2.2)
            w.position = new_position
            assert w.position == old_position if snap else new_position
            assert w.snap_all == snap
            assert w.snap_position == snap
            assert w.snap_size == snap

        p1 = Point1DROI(4)
        _ = p1.interactive(s, **kwargs)
        for w in p1.widgets:
            old_position = w.position
            new_position = (4.2, )
            w.position = new_position
            assert w.position == old_position if snap else new_position
            assert w.snap_position == snap

        p2 = Point2DROI(4, 5)
        _ = p2.interactive(s, **kwargs)
        for w in p2.widgets:
            old_position = w.position
            new_position = (4.3, 5.3)
            w.position = new_position
            assert w.position == old_position if snap else new_position
            assert w.snap_position == snap

        span = SpanROI(4.01, 5)
        _ = span.interactive(s, **kwargs)
        for w in span.widgets:
            old_position = w.position
            new_position = (4.2, )
            w.position = new_position
            assert w.position == old_position if snap else new_position
            assert w.snap_all == snap
            assert w.snap_position == snap
            assert w.snap_size == snap

            # check that changing snap is working fine
            new_snap = not snap
            w.snap_all = new_snap
            old_position = w.position
            new_position = (4.2, )
            w.position = new_position
            assert w.position == old_position if new_snap else new_position

        line2d = Line2DROI(4, 5, 6, 6, 1)
        _ = line2d.interactive(s, **kwargs)
        for w in line2d.widgets:
            old_position = w.position
            new_position = ([4.3, 5.3], [6.0, 6.0])
            w.position = new_position
            assert w.position == old_position if snap else new_position
            assert w.snap_all == snap
            assert w.snap_position == snap
            assert w.snap_size == snap