Esempio n. 1
0
    def test_circle_spec(self):
        s = self.s_s
        s.data = np.ones_like(s.data)
        r = CircleROI(20, 25, 20)
        r_ann = CircleROI(20, 25, 20, 15)
        sr = r(s)
        sr_ann = r_ann(s)
        scale = s.axes_manager[0].scale
        n = int(round(40 / scale))
        assert sr.axes_manager.navigation_shape == (n, n)
        assert sr_ann.axes_manager.navigation_shape == (n, n)
        # Check that mask is same for all images:
        for i in range(n):
            for j in range(n):
                assert (np.all(sr.data.mask[j, i, :] == True)
                        or np.all(sr.data.mask[j, i, :] == False))
                assert (np.all(sr_ann.data.mask[j, i, :] == True)
                        or np.all(sr_ann.data.mask[j, i, :] == False))
        # Check that the correct elements has been masked out:
        mask = sr.data.mask[:, :, 0]
        print(mask)  # To help debugging, this shows the shape of the mask
        np.testing.assert_array_equal(
            np.where(mask.flatten())[0],
            [0, 1, 6, 7, 8, 15, 48, 55, 56, 57, 62, 63])
        mask_ann = sr_ann.data.mask[:, :, 0]
        print(mask_ann)  # To help debugging, this shows the shape of the mask
        np.testing.assert_array_equal(
            np.where(mask_ann.flatten())[0], [
                0, 1, 6, 7, 8, 10, 11, 12, 13, 15, 17, 18, 19, 20, 21, 22, 25,
                26, 27, 28, 29, 30, 33, 34, 35, 36, 37, 38, 41, 42, 43, 44, 45,
                46, 48, 50, 51, 52, 53, 55, 56, 57, 62, 63
            ])
        # Check that mask works for sum
        assert np.sum(sr.data) == (n**2 - 3 * 4) * 4
        assert np.sum(sr_ann.data) == 4 * 5 * 4

        s.plot()
        r_signal = r.interactive(signal=s)
        r_ann_signal = r_ann.interactive(signal=s)

        assert np.sum(r_signal.sum().data) == (n**2 - 3 * 4) * 4
        assert np.sum(r_ann_signal.sum().data) == 4 * 5 * 4
Esempio n. 2
0
    def test_circle_spec(self):
        s = self.s_s
        s.data = np.ones_like(s.data)
        r = CircleROI(20, 25, 20)
        r_ann = CircleROI(20, 25, 20, 15)
        sr = r(s)
        sr_ann = r_ann(s)
        scale = s.axes_manager[0].scale
        n = int(round(40 / scale))
        assert sr.axes_manager.navigation_shape == (n, n)
        assert sr_ann.axes_manager.navigation_shape == (n, n)
        # Check that mask is same for all images:
        for i in range(n):
            for j in range(n):
                assert (np.all(sr.data.mask[j, i, :] == True) or
                        np.all(sr.data.mask[j, i, :] == False))
                assert (np.all(sr_ann.data.mask[j, i, :] == True) or
                        np.all(sr_ann.data.mask[j, i, :] == False))
        # Check that the correct elements has been masked out:
        mask = sr.data.mask[:, :, 0]
        print(mask)   # To help debugging, this shows the shape of the mask
        np.testing.assert_array_equal(
            np.where(mask.flatten())[0],
            [0, 1, 6, 7, 8, 15, 48, 55, 56, 57, 62, 63])
        mask_ann = sr_ann.data.mask[:, :, 0]
        print(mask_ann)   # To help debugging, this shows the shape of the mask
        np.testing.assert_array_equal(
            np.where(mask_ann.flatten())[0],
            [0, 1, 6, 7, 8, 10, 11, 12, 13, 15, 17, 18, 19, 20, 21, 22, 25,
             26, 27, 28, 29, 30, 33, 34, 35, 36, 37, 38, 41, 42, 43, 44, 45, 46,
             48, 50, 51, 52, 53, 55, 56, 57, 62, 63])
        # Check that mask works for sum
        assert np.sum(sr.data) == (n**2 - 3 * 4) * 4
        assert np.sum(sr_ann.data) == 4 * 5 * 4

        s.plot()
        r_signal = r.interactive(signal=s)
        r_ann_signal = r_ann.interactive(signal=s)

        assert np.sum(r_signal.sum().data) == (n**2 - 3 * 4) * 4
        assert np.sum(r_ann_signal.sum().data) == 4 * 5 * 4
Esempio n. 3
0
 def test_interactive_special_case(self):
     s = self.s.inav[0]
     r = CircleROI(3, 5, 2)
     sr = r.interactive(s, None, color="blue")
     np.testing.assert_array_equal(
         np.where(sr.data.mask.flatten())[0], [0, 3, 12, 15])
     r.r_inner = 1
     r.cy = 16
     sr2 = r(s)
     np.testing.assert_array_equal(
         np.where(sr.data.mask.flatten())[0], [0, 3, 5, 6, 9, 10, 12, 15])
     np.testing.assert_array_equal(sr2.data, sr.data)
Esempio n. 4
0
 def test_interactive_special_case(self):
     s = self.s.inav[0]
     r = CircleROI(3, 5, 2)
     sr = r.interactive(s, None)
     np.testing.assert_array_equal(np.where(sr.data.mask.flatten())[0],
                                   [0, 3, 12, 15])
     r.r_inner = 1
     r.cy = 16
     sr2 = r(s)
     np.testing.assert_array_equal(np.where(sr.data.mask.flatten())[0],
                                   [0, 3, 5, 6, 9, 10, 12, 15])
     np.testing.assert_array_equal(sr2.data, sr.data)