Ejemplo n.º 1
0
    def test_0d(self):
        data_shape = (10, 8)
        data = np.ones(data_shape) * 100.0
        s = Signal2D(data)
        mask0 = pst._get_angle_sector_mask(s, angle0=0.0, angle1=np.pi / 2)
        np.testing.assert_array_equal(mask0, np.zeros_like(mask0,
                                                           dtype=np.bool))
        assert mask0.shape == data_shape

        s.axes_manager.signal_axes[0].offset = -5
        s.axes_manager.signal_axes[1].offset = -5
        mask1 = pst._get_angle_sector_mask(s, angle0=0.0, angle1=np.pi / 2)
        assert mask1[:5, :5].all()
        mask1[:5, :5] = False
        np.testing.assert_array_equal(mask1, np.zeros_like(mask1,
                                                           dtype=np.bool))

        s.axes_manager.signal_axes[0].offset = -15
        s.axes_manager.signal_axes[1].offset = -15
        mask2 = pst._get_angle_sector_mask(s, angle0=0.0, angle1=np.pi / 2)
        assert mask2.all()

        s.axes_manager.signal_axes[0].offset = -15
        s.axes_manager.signal_axes[1].offset = -15
        mask3 = pst._get_angle_sector_mask(s,
                                           angle0=np.pi * 3 / 2,
                                           angle1=np.pi * 2)
        assert not mask3.any()
Ejemplo n.º 2
0
    def test_angles_more_than_2pi(self):
        s = Signal2D(np.zeros((100, 100)))
        s.axes_manager[0].offset, s.axes_manager[1].offset = -50, -50
        mask0 = pst._get_angle_sector_mask(s, 0.1 * np.pi, 4 * np.pi)
        assert mask0.all()

        mask1 = pst._get_angle_sector_mask(s, -1 * np.pi, 2.1 * np.pi)
        assert mask1.all()
Ejemplo n.º 3
0
 def test_0d_com(self):
     data_shape = (10, 8)
     data = np.zeros(data_shape)
     s = Diffraction2D(data)
     s.data[4, 5] = 5.0
     s_com = s.center_of_mass()
     pst._get_angle_sector_mask(
         s,
         centre_x_array=s_com.inav[0].data,
         centre_y_array=s_com.inav[1].data,
         angle0=np.pi * 3 / 2,
         angle1=np.pi * 2,
     )
Ejemplo n.º 4
0
    def test_1d(self):
        data_shape = (5, 7, 10)
        data = np.ones(data_shape) * 100.0
        s = Signal2D(data)
        mask0 = pst._get_angle_sector_mask(s, angle0=0.0, angle1=np.pi / 2)
        np.testing.assert_array_equal(mask0, np.zeros_like(mask0, dtype=bool))
        assert mask0.shape == data_shape

        s.axes_manager.signal_axes[0].offset = -5
        s.axes_manager.signal_axes[1].offset = -4
        mask1 = pst._get_angle_sector_mask(s, angle0=0.0, angle1=np.pi / 2)
        assert mask1[:, :4, :5].all()
        mask1[:, :4, :5] = False
        np.testing.assert_array_equal(mask1, np.zeros_like(mask1, dtype=bool))
Ejemplo n.º 5
0
    def test_angles_across_zero(self):
        s = Signal2D(np.zeros((100, 100)))
        s.axes_manager[0].offset, s.axes_manager[1].offset = -50, -50
        mask0 = pst._get_angle_sector_mask(s, -0.5 * np.pi, 0.5 * np.pi)
        assert mask0[:, 0:50].all()
        assert np.invert(mask0[:, 50:]).all()

        mask1 = pst._get_angle_sector_mask(s, 1.5 * np.pi, 2.5 * np.pi)
        assert mask1[:, 0:50].all()
        assert np.invert(mask1[:, 50:]).all()

        mask2 = pst._get_angle_sector_mask(s, 3.5 * np.pi, 4.5 * np.pi)
        assert mask2[:, 0:50].all()
        assert np.invert(mask2[:, 50:]).all()

        mask3 = pst._get_angle_sector_mask(s, -4.5 * np.pi, -3.5 * np.pi)
        assert mask3[:, 0:50].all()
        assert np.invert(mask3[:, 50:]).all()
Ejemplo n.º 6
0
 def test_centre_xy(self):
     data_shape = (3, 5, 7, 10)
     data = np.ones(data_shape) * 100.0
     s = Signal2D(data)
     nav_shape = s.axes_manager.navigation_shape
     centre_x, centre_y = np.ones(nav_shape[::-1]) * 5, np.ones(nav_shape[::-1]) * 9
     mask0 = pst._get_angle_sector_mask(
         s,
         angle0=np.pi,
         angle1=2 * np.pi,
         centre_x_array=centre_x,
         centre_y_array=centre_y,
     )
     assert mask0.shape == data_shape
Ejemplo n.º 7
0
def get_angle_image_comparison(s0, s1, angleN=12, mask_radius=None):
    """Compare two images by overlaying one on the other in slices.

    This function takes two images, extracts different angular slices
    and combines them into one image.

    Useful for comparing two diffraction images, to see if the rings
    have the same radius.

    Parameters
    ----------
    s0, s1 : HyperSpy 2D Signal
        Both signals need to have the same shape, and no navigation
        dimensions.
    angleN : int, default 12
        Number of angular slices.
    mask_radius : int, optional
        Mask the centre of the image. The default is not to mask anything.
        Useful to mask the most intense parts of the diffraction pattern,
        so the less intense parts can be visualized.

    Returns
    -------
    comparison_signal : HyperSpy 2D

    Examples
    --------
    >>> from pyxem.dummy_data import MakeTestData
    >>> test_data0 = MakeTestData(300, 300)
    >>> test_data0.add_ring(150, 150, 40)
    >>> test_data1 = MakeTestData(300, 300)
    >>> test_data1.add_ring(150, 150, 60)
    >>> s0 = test_data0.signal
    >>> s1 = test_data1.signal
    >>> s0.axes_manager[0].offset, s0.axes_manager[1].offset = -150, -150
    >>> s1.axes_manager[0].offset, s1.axes_manager[1].offset = -150, -150
    >>> import pyxem.utils.radial_utils as ra
    >>> s = ra.get_angle_image_comparison(s0, s1)
    >>> s.plot()

    Mask the inner parts

    >>> s = ra.get_angle_image_comparison(s0, s1, mask_radius=10)

    """
    if s0.axes_manager.shape != s1.axes_manager.shape:
        raise ValueError("s0 and s1 need to have the same shape")
    s = s0.deepcopy()
    angle_array = np.ogrid[0:2 * np.pi:(1 + angleN) * 1j]
    for i in range(len(angle_array[:-1])):
        if i % 2:
            angle0, angle1 = angle_array[i:i + 2]
            bool_array = pst._get_angle_sector_mask(s, angle0, angle1)
            s.data[bool_array] = s1.data[bool_array]

    if mask_radius is not None:
        am = s.axes_manager
        mask = pst._make_circular_mask(
            am[0].value2index(0.0),
            am[1].value2index(0.0),
            am[0].size,
            am[1].size,
            mask_radius,
        )
        mask = np.invert(mask)
        s.data *= mask
    return s
Ejemplo n.º 8
0
 def test_bad_angles(self):
     s = Signal2D(np.zeros((100, 100)))
     with pytest.raises(ValueError):
         pst._get_angle_sector_mask(s, angle0=2, angle1=-1)
Ejemplo n.º 9
0
 def test_3d(self):
     data_shape = (5, 3, 5, 7, 10)
     data = np.ones(data_shape) * 100.0
     s = Signal2D(data)
     mask0 = pst._get_angle_sector_mask(s, angle0=np.pi, angle1=2 * np.pi)
     assert mask0.shape == data_shape