Exemple #1
0
    def test_different_radius_not_square_image(self):
        x, y, r, px, py, iX, iY = 40, 55, 20, 6, 5, 120, 100
        kwrds = {
            "probe_size_x": px,
            "probe_size_y": py,
            "image_size_x": iX,
            "image_size_y": iY,
            "disk_I": 0,
            "ring_x": x,
            "ring_y": y,
            "ring_r": r,
            "ring_I": 5,
            "blur": True,
            "downscale": False,
        }
        r0, r1, r2, r3 = 20, 25, 30, 27
        kwrds["ring_r"] = r0
        s = mdtd.generate_4d_data(**kwrds)
        kwrds["ring_r"] = r1
        s1 = mdtd.generate_4d_data(**kwrds)
        kwrds["ring_r"] = r2
        s2 = mdtd.generate_4d_data(**kwrds)
        kwrds["ring_r"] = r3
        s3 = mdtd.generate_4d_data(**kwrds)

        s.data[:, :, :y, x:] = s1.data[:, :, :y, x:]
        s.data[:, :, y:, x:] = s2.data[:, :, y:, x:]
        s.data[:, :, y:, :x] = s3.data[:, :, y:, :x]

        s_ar = s.angular_slice_radial_average(centre_x=x, centre_y=y, angleN=4)
        assert (s_ar.inav[:, :, 0].data.argmax(axis=-1) == r0).all()
        assert (s_ar.inav[:, :, 1].data.argmax(axis=-1) == r1).all()
        assert (s_ar.inav[:, :, 2].data.argmax(axis=-1) == r2).all()
        assert (s_ar.inav[:, :, 3].data.argmax(axis=-1) == r3).all()
 def test_disk_position_array(self):
     ps_x, ps_y, intensity = 4, 7, 30
     disk_x = np.random.randint(5, 35, size=(ps_y, ps_x))
     disk_y = np.random.randint(5, 45, size=(ps_y, ps_x))
     s = mdtd.generate_4d_data(
         probe_size_x=ps_x,
         probe_size_y=ps_y,
         image_size_x=40,
         image_size_y=50,
         ring_x=None,
         ring_e_x=None,
         disk_x=disk_x,
         disk_y=disk_y,
         disk_r=1,
         disk_I=intensity,
         blur=False,
         downscale=False,
     )
     for x in range(ps_x):
         for y in range(ps_y):
             cX, cY = disk_x[y, x], disk_y[y, x]
             sl = np.s_[cY - 1:cY + 2, cX - 1:cX + 2]
             im = s.inav[x, y].data[:]
             assert (im[sl] == intensity).all()
             im[sl] = 0
             assert not im.any()
Exemple #3
0
 def test_center_of_mass_different_shapes2(self):
     psX, psY = 11, 9
     s = mdtd.generate_4d_data(probe_size_x=psX,
                               probe_size_y=psY,
                               ring_x=None)
     s_com = s.center_of_mass()
     assert s_com.axes_manager.shape == (2, psX, psY)
Exemple #4
0
    def test_threshold(self):
        x, y = 60, 50
        s = mdtd.generate_4d_data(
            probe_size_x=4,
            probe_size_y=3,
            ring_x=None,
            image_size_x=120,
            image_size_y=100,
            disk_x=x,
            disk_y=y,
            disk_r=20,
            disk_I=20,
            blur=False,
            blur_sigma=1,
            downscale=False,
        )
        s.data[:, :, 0:30, 0:30] = 5

        # The extra values are ignored due to thresholding
        s_com0 = s.center_of_mass(threshold=2)
        assert (s_com0.inav[0].data == x).all()
        assert (s_com0.inav[1].data == y).all()

        # The extra values are not ignored
        s_com1 = s.center_of_mass(threshold=1)
        assert not (s_com1.inav[0].data == x).all()
        assert not (s_com1.inav[1].data == y).all()

        # The extra values are not ignored
        s_com2 = s.center_of_mass()
        assert not (s_com2.inav[0].data == x).all()
        assert not (s_com2.inav[1].data == y).all()
Exemple #5
0
    def test_lazy(self):
        y, x = np.mgrid[75:83:9j, 85:95:11j]
        s = mdtd.generate_4d_data(
            probe_size_x=11,
            probe_size_y=9,
            ring_x=None,
            image_size_x=160,
            image_size_y=140,
            disk_x=x,
            disk_y=y,
            disk_r=40,
            disk_I=20,
            blur=True,
            blur_sigma=1,
            downscale=False,
        )
        s_lazy = LazyDiffraction2D(
            da.from_array(s.data, chunks=(1, 1, 140, 160)))
        s_lazy_com = s_lazy.center_of_mass()
        np.testing.assert_allclose(s_lazy_com.inav[0].data, x)
        np.testing.assert_allclose(s_lazy_com.inav[1].data, y)

        s_lazy_1d = s_lazy.inav[0]
        s_lazy_1d_com = s_lazy_1d.center_of_mass()
        np.testing.assert_allclose(s_lazy_1d_com.inav[0].data, x[:, 0])
        np.testing.assert_allclose(s_lazy_1d_com.inav[1].data, y[:, 0])

        s_lazy_0d = s_lazy.inav[0, 0]
        s_lazy_0d_com = s_lazy_0d.center_of_mass()
        np.testing.assert_allclose(s_lazy_0d_com.inav[0].data, x[0, 0])
        np.testing.assert_allclose(s_lazy_0d_com.inav[1].data, y[0, 0])
Exemple #6
0
    def test_compare_lazy_and_nonlazy(self):
        y, x = np.mgrid[75:83:9j, 85:95:11j]
        s = mdtd.generate_4d_data(
            probe_size_x=11,
            probe_size_y=9,
            ring_x=None,
            image_size_x=160,
            image_size_y=140,
            disk_x=x,
            disk_y=y,
            disk_r=40,
            disk_I=20,
            blur=True,
            blur_sigma=1,
            downscale=False,
        )
        s_lazy = LazyDiffraction2D(
            da.from_array(s.data, chunks=(1, 1, 140, 160)))
        s_com = s.center_of_mass()
        s_lazy_com = s_lazy.center_of_mass()
        np.testing.assert_equal(s_com.data, s_lazy_com.data)

        com_nav_extent = s_com.axes_manager.navigation_extent
        lazy_com_nav_extent = s_lazy_com.axes_manager.navigation_extent
        assert com_nav_extent == lazy_com_nav_extent

        com_sig_extent = s_com.axes_manager.signal_extent
        lazy_com_sig_extent = s_lazy_com.axes_manager.signal_extent
        assert com_sig_extent == lazy_com_sig_extent
Exemple #7
0
 def test_correct_disk_x_y_and_radius_random(self):
     x, y, px, py = 56, 48, 4, 5
     x, y = randint(45, 55, size=(py, px)), randint(45, 55, size=(py, px))
     r = randint(20, 40, size=(py, px))
     s = mdtd.generate_4d_data(
         probe_size_x=px,
         probe_size_y=py,
         image_size_x=120,
         image_size_y=100,
         disk_x=x,
         disk_y=y,
         disk_r=5,
         disk_I=20,
         ring_x=x,
         ring_y=y,
         ring_r=r,
         ring_I=5,
         blur=True,
         downscale=False,
     )
     dask_array = da.from_array(s.data, chunks=(4, 4, 50, 50))
     s = LazyDiffraction2D(dask_array)
     s_com = s.center_of_mass()
     s_r = s.radial_average(centre_x=s_com.inav[0].data,
                            centre_y=s_com.inav[1].data)
     s_r = s_r.isig[15:]  # Do not include the disk
     r -= 15  # Need to shift the radius, due to not including the disk
     assert (s_r.data.argmax(axis=-1) == r).all()
Exemple #8
0
    def test_mask_2(self):
        x, y = 60, 50
        s = mdtd.generate_4d_data(
            probe_size_x=5,
            probe_size_y=5,
            ring_x=None,
            image_size_x=120,
            image_size_y=100,
            disk_x=x,
            disk_y=y,
            disk_r=20,
            disk_I=20,
            blur=False,
            downscale=False,
        )
        # Add one large value
        s.data[:, :, 50, 30] = 200000  # Large value to the left of the disk

        # Center of mass should not be in center of the disk, due to the
        # large value.
        s_com0 = s.center_of_mass()
        assert not (s_com0.inav[0].data == x).all()
        assert (s_com0.inav[1].data == y).all()

        # Here, the large value is masked
        s_com1 = s.center_of_mass(mask=(60, 50, 25))
        assert (s_com1.inav[0].data == x).all()
        assert (s_com1.inav[1].data == y).all()

        # Here, the large value is right inside the edge of the mask
        s_com3 = s.center_of_mass(mask=(60, 50, 31))
        assert not (s_com3.inav[0].data == x).all()
        assert (s_com3.inav[1].data == y).all()

        # Here, the large value is right inside the edge of the mask
        s_com4 = s.center_of_mass(mask=(59, 50, 30))
        assert not (s_com4.inav[0].data == x).all()
        assert (s_com4.inav[1].data == y).all()

        s.data[:, :, 50, 30] = 0
        s.data[:, :, 80, 60] = 200000  # Large value under the disk

        # The large value is masked
        s_com5 = s.center_of_mass(mask=(60, 50, 25))
        assert (s_com5.inav[0].data == x).all()
        assert (s_com5.inav[1].data == y).all()

        # The large value just not masked
        s_com6 = s.center_of_mass(mask=(60, 50, 31))
        assert (s_com6.inav[0].data == x).all()
        assert not (s_com6.inav[1].data == y).all()

        # The large value just not masked
        s_com7 = s.center_of_mass(mask=(60, 55, 25))
        assert (s_com7.inav[0].data == x).all()
        assert not (s_com7.inav[1].data == y).all()
Exemple #9
0
    def test_slice_overlap(self):
        x, y, r, px, py, iX, iY = 40, 55, 20, 6, 5, 120, 100
        kwrds = {
            "probe_size_x": px,
            "probe_size_y": py,
            "image_size_x": iX,
            "image_size_y": iY,
            "disk_I": 0,
            "ring_x": x,
            "ring_y": y,
            "ring_r": r,
            "ring_I": 5,
            "blur": True,
            "downscale": False,
        }
        r0, r1 = 20, 30
        kwrds["ring_r"] = r0
        s = mdtd.generate_4d_data(**kwrds)
        kwrds["ring_r"] = r1
        kwrds["ring_I"] = 500
        s1 = mdtd.generate_4d_data(**kwrds)

        s.data[:, :, y:, :] = s1.data[:, :, y:, :]

        s_ar = s.angular_slice_radial_average(centre_x=x, centre_y=y, angleN=2)
        assert (s_ar.inav[:, :, 0].data.argmax(axis=-1) == r0).all()
        assert (s_ar.inav[:, :, 1].data.argmax(axis=-1) == r1).all()

        s_ar1 = s.angular_slice_radial_average(centre_x=x,
                                               centre_y=y,
                                               angleN=2,
                                               slice_overlap=0.1)
        assert (s_ar1.inav[:, :, 0].data.argmax(axis=-1) == r1).all()
        assert (s_ar1.inav[:, :, 1].data.argmax(axis=-1) == r1).all()

        with pytest.raises(ValueError):
            s.angular_slice_radial_average(slice_overlap=1.2)
        with pytest.raises(ValueError):
            s.angular_slice_radial_average(slice_overlap=-0.2)
 def test_disk_outside_image(self):
     s = mdtd.generate_4d_data(
         probe_size_x=6,
         probe_size_y=4,
         image_size_x=40,
         image_size_y=40,
         ring_x=None,
         ring_e_x=None,
         disk_x=1000,
         disk_y=1000,
         disk_r=5,
     )
     assert (s.data == 0).all()
    def test_input_numpy_array(self):
        size = (20, 10)
        disk_x = np.random.randint(5, 35, size=size)
        disk_y = np.random.randint(5, 45, size=size)
        disk_r = np.random.randint(5, 9, size=size)
        disk_I = np.random.randint(50, 100, size=size)
        ring_x = np.random.randint(5, 35, size=size)
        ring_y = np.random.randint(5, 45, size=size)
        ring_r = np.random.randint(10, 15, size=size)
        ring_I = np.random.randint(1, 30, size=size)
        ring_lw = np.random.randint(1, 5, size=size)
        ring_e_x = np.random.randint(20, 30, size)
        ring_e_y = np.random.randint(20, 30, size)
        ring_e_semi_len0 = np.random.randint(10, 20, size)
        ring_e_semi_len1 = np.random.randint(10, 20, size)
        ring_e_r = np.random.random(size) * np.pi
        ring_e_lw = np.random.randint(1, 3, size)

        mdtd.generate_4d_data(
            probe_size_x=10,
            probe_size_y=20,
            image_size_x=40,
            image_size_y=50,
            disk_x=disk_x,
            disk_y=disk_y,
            disk_I=disk_I,
            disk_r=disk_r,
            ring_x=ring_x,
            ring_y=ring_y,
            ring_r=ring_r,
            ring_I=ring_I,
            ring_lw=ring_lw,
            ring_e_x=ring_e_x,
            ring_e_y=ring_e_y,
            ring_e_semi_len0=ring_e_semi_len0,
            ring_e_semi_len1=ring_e_semi_len1,
            ring_e_r=ring_e_r,
            ring_e_lw=ring_e_lw,
        )
 def test_different_size(self):
     s = mdtd.generate_4d_data(
         probe_size_x=5,
         probe_size_y=7,
         ring_x=None,
         ring_e_x=None,
         image_size_x=30,
         image_size_y=50,
     )
     ax = s.axes_manager
     assert ax.navigation_dimension == 2
     assert ax.signal_dimension == 2
     assert ax.navigation_shape == (5, 7)
     assert ax.signal_shape == (30, 50)
Exemple #13
0
def get_holz_heterostructure_test_signal(lazy=False):
    """Get HyperSpy 2D signal with 2D navigation dimensions for HOLZ testing.

    The centre, radius and intensity of the ring varies as a function of probe
    position. The disk centre position varies as a function of probe position.

    Parameters
    ----------
    lazy : bool, default False

    Returns
    -------
    holz_signal : HyperSpy 2D signal

    Example
    -------
    >>> s = pxm.dummy_data.get_holz_heterostructure_test_signal()
    >>> s.plot()

    Load as lazy

    >>> s = pxm.dummy_data.get_holz_heterostructure_test_signal(lazy=True)

    """
    probe_size_x, probe_size_y = 40, 40
    px, py = np.mgrid[0:probe_size_x:1, 0:probe_size_y:1]
    x, y = np.mgrid[36:38:40j, 41:43:40j]
    disk_r = 10
    disk_I = np.ones_like(x) * 100 + np.random.random() * 20
    g_r = Gaussian(A=20, centre=25, sigma=5)
    ring_r = np.ones_like(x) * 30 + g_r.function(py)
    g_I = Gaussian(A=30, centre=25, sigma=3)
    ring_I = np.ones_like(x) * 20 + g_I.function(py)
    s = mdtd.generate_4d_data(
        probe_size_x=probe_size_x,
        probe_size_y=probe_size_y,
        image_size_x=80,
        image_size_y=80,
        disk_x=x,
        disk_y=y,
        disk_r=disk_r,
        disk_I=disk_I,
        ring_x=x,
        ring_y=y,
        ring_r=ring_r,
        ring_I=ring_I,
        add_noise=True,
        lazy=lazy,
    )
    return s
 def test_disk_cover_whole_image(self):
     s = mdtd.generate_4d_data(
         probe_size_x=6,
         probe_size_y=4,
         image_size_x=20,
         image_size_y=20,
         ring_x=None,
         ring_e_x=None,
         disk_x=10,
         disk_y=10,
         disk_r=40,
         disk_I=50,
         blur=False,
         downscale=False,
     )
     assert (s.data == 50).all()
 def test_ring_ellipse_center(self):
     x, y = 40, 51
     s = mdtd.generate_4d_data(
         probe_size_x=4,
         probe_size_y=5,
         image_size_x=120,
         image_size_y=100,
         disk_x=None,
         ring_x=None,
         ring_e_x=x,
         ring_e_y=y,
         blur=False,
         downscale=False,
     )
     s_com = s.center_of_mass()
     assert (s_com.inav[0].data == x).all()
     assert (s_com.inav[1].data == y).all()
Exemple #16
0
def get_holz_simple_test_signal(lazy=False):
    """Get HyperSpy 2D signal with 2D navigation dimensions for HOLZ testing.

    Probe size x/y (20, 20), and image size x/y (50, 50).
    Contains a disk and a ring. The disk stays at x, y = 25, 25, with radius 2.
    The ring has a radius of 20, and moves from x, y = 24-26, 24-26.

    Parameters
    ----------
    lazy : bool, default False

    Returns
    -------
    holz_signal : Diffraction2D

    Examples
    --------
    >>> s = pxm.dummy_data.get_holz_simple_test_signal()
    >>> s.plot()

    Load as lazy

    >>> s = pxm.dummy_data.get_holz_simple_test_signal(lazy=True)

    """
    ring_x, ring_y = np.mgrid[24:26:20j, 24:26:20j]
    s = mdtd.generate_4d_data(
        probe_size_x=20,
        probe_size_y=20,
        image_size_x=50,
        image_size_y=50,
        disk_x=25,
        disk_y=25,
        disk_r=2,
        disk_I=20,
        ring_x=ring_x,
        ring_y=ring_y,
        ring_r=15,
        ring_I=10,
        add_noise=True,
        lazy=lazy,
    )
    return s
Exemple #17
0
 def test_0d_signal(self):
     x, y = 40, 51
     s = mdtd.generate_4d_data(
         probe_size_x=1,
         probe_size_y=1,
         ring_x=None,
         image_size_x=120,
         image_size_y=100,
         disk_x=x,
         disk_y=y,
         disk_r=20,
         disk_I=20,
         blur=False,
         blur_sigma=1,
         downscale=False,
     )
     s_com = s.inav[0, 0].center_of_mass()
     assert (s_com.inav[0].data == x).all()
     assert (s_com.inav[1].data == y).all()
 def test_all_arguments(self):
     s = mdtd.generate_4d_data(
         probe_size_x=10,
         probe_size_y=10,
         image_size_x=50,
         image_size_y=50,
         disk_x=20,
         disk_y=20,
         disk_r=5,
         disk_I=30,
         ring_x=None,
         ring_e_x=None,
         blur=True,
         blur_sigma=1,
         downscale=True,
         add_noise=True,
         noise_amplitude=2,
     )
     assert s.axes_manager.shape == (10, 10, 50, 50)
Exemple #19
0
 def test_different_shape_no_downscale(self):
     y, x = np.mgrid[75:83:9j, 85:95:11j]
     s = mdtd.generate_4d_data(
         probe_size_x=11,
         probe_size_y=9,
         ring_x=None,
         image_size_x=160,
         image_size_y=140,
         disk_x=x,
         disk_y=y,
         disk_r=40,
         disk_I=20,
         blur=True,
         blur_sigma=1,
         downscale=False,
     )
     s_com = s.center_of_mass()
     np.testing.assert_allclose(s_com.inav[0].data, x)
     np.testing.assert_allclose(s_com.inav[1].data, y)
Exemple #20
0
 def test_same_radius(self):
     x, y, r, px, py, angleN = 56, 48, 20, 4, 5, 20
     s = mdtd.generate_4d_data(
         probe_size_x=px,
         probe_size_y=py,
         image_size_x=120,
         image_size_y=100,
         disk_I=0,
         ring_x=x,
         ring_y=y,
         ring_r=r,
         ring_I=5,
         blur=True,
         downscale=False,
     )
     s_ar = s.angular_slice_radial_average(centre_x=x,
                                           centre_y=y,
                                           angleN=20)
     assert s_ar.axes_manager.navigation_shape, (x, y, angleN)
     assert (s_ar.data.argmax(-1) == r).all()
Exemple #21
0
 def test_correct_radius_random(self):
     x, y, px, py = 56, 48, 4, 5
     r = np.random.randint(20, 40, size=(py, px))
     s = mdtd.generate_4d_data(
         probe_size_x=px,
         probe_size_y=py,
         image_size_x=120,
         image_size_y=100,
         disk_I=0,
         ring_x=x,
         ring_y=y,
         ring_r=r,
         ring_I=5,
         blur=True,
         downscale=False,
     )
     s.axes_manager.signal_axes[0].offset = -x
     s.axes_manager.signal_axes[1].offset = -y
     s_r = s.radial_average()
     assert (s_r.data.argmax(axis=-1) == r).all()
Exemple #22
0
 def test_correct_radius_simple(self):
     x, y, r, px, py = 40, 51, 30, 4, 5
     s = mdtd.generate_4d_data(
         probe_size_x=px,
         probe_size_y=py,
         image_size_x=120,
         image_size_y=100,
         disk_I=0,
         ring_x=x,
         ring_y=y,
         ring_r=r,
         ring_I=5,
         blur=True,
         downscale=False,
     )
     s.axes_manager.signal_axes[0].offset = -x
     s.axes_manager.signal_axes[1].offset = -y
     s_r = s.radial_average()
     assert s_r.axes_manager.navigation_shape == (px, py)
     assert (s_r.data.argmax(axis=-1) == 30).all()
Exemple #23
0
 def test_1d_signal(self):
     x = np.arange(45, 45 + 9).reshape((1, 9))
     y = np.arange(55, 55 + 9).reshape((1, 9))
     s = mdtd.generate_4d_data(
         probe_size_x=9,
         probe_size_y=1,
         ring_x=None,
         image_size_x=120,
         image_size_y=100,
         disk_x=x,
         disk_y=y,
         disk_r=20,
         disk_I=20,
         blur=False,
         blur_sigma=1,
         downscale=False,
     )
     s_com = s.inav[:, 0].center_of_mass()
     assert (s_com.inav[0].data == x).all()
     assert (s_com.inav[1].data == y).all()
Exemple #24
0
 def test_random_shifts(self, centre_x, centre_y):
     y, x = np.mgrid[20:30:7j, 20:30:5j]
     s = mdtd.generate_4d_data(
         probe_size_x=5,
         probe_size_y=7,
         disk_x=x,
         disk_y=y,
         disk_r=1,
         blur=True,
         ring_x=None,
     )
     s_com = s.center_of_mass()
     s_com.data[0] -= centre_x
     s_com.data[1] -= centre_y
     s_shift = s.shift_diffraction(shift_x=s_com.inav[0].data,
                                   shift_y=s_com.inav[1].data)
     s_shift_c = s_shift.center_of_mass()
     np.testing.assert_allclose(s_shift_c.data[0],
                                np.ones_like(s_shift_c.data[0]) * centre_x)
     np.testing.assert_allclose(s_shift_c.data[1],
                                np.ones_like(s_shift_c.data[1]) * centre_y)
Exemple #25
0
def get_disk_shift_simple_test_signal(lazy=False):
    """Get HyperSpy 2D signal with 2D navigation dimensions for DPC testing.

    Probe size x/y (20, 20), and image size x/y (50, 50).
    Disk moves from 22-28 x/y.

    Parameters
    ----------
    lazy : bool, default False

    Returns
    -------
    disk_shift_signal : Diffraction2D

    Examples
    --------
    >>> s = pxm.dummy_data.get_disk_shift_simple_test_signal()
    >>> s.plot()

    Load as lazy

    >>> s = pxm.dummy_data.get_disk_shift_simple_test_signal(lazy=True)

    """
    disk_x, disk_y = np.mgrid[22:28:20j, 22:28:20j]
    s = mdtd.generate_4d_data(
        probe_size_x=20,
        probe_size_y=20,
        image_size_x=50,
        image_size_y=50,
        disk_x=disk_x,
        disk_y=disk_y,
        disk_r=2,
        ring_x=None,
        add_noise=True,
        lazy=lazy,
    )
    return s
Exemple #26
0
 def test_mask(self):
     y, x = np.mgrid[75:83:9j, 85:95:11j]
     s = mdtd.generate_4d_data(
         probe_size_x=11,
         probe_size_y=9,
         ring_x=None,
         image_size_x=160,
         image_size_y=140,
         disk_x=x,
         disk_y=y,
         disk_r=40,
         disk_I=20,
         blur=False,
         blur_sigma=1,
         downscale=False,
     )
     s.data[:, :, 15, 10] = 1000000
     s_com0 = s.center_of_mass()
     s_com1 = s.center_of_mass(mask=(90, 79, 60))
     assert not (s_com0.inav[0].data == x).all()
     assert not (s_com0.inav[1].data == y).all()
     assert (s_com1.inav[0].data == x).all()
     assert (s_com1.inav[1].data == y).all()
Exemple #27
0
def get_simple_fem_signal(lazy=False):
    """2D signal approximating a very small fluctuation electron microscopy (FEM) dataset.

    Parameters
    ----------
    lazy : bool, default False
        If True, resulting signal will be lazy.

    Returns
    -------
    fem_signal : Diffraction2D

    Examples
    --------
    >>> s = pxm.dummy_data.get_simple_fem_signal()
    >>> s.plot()

    """

    radii1 = 10 * np.random.randint(0, 2, size=(2, 2))
    intensities1 = np.random.randint(0, 5, size=(2, 2))

    radii2 = 20 * np.random.randint(0, 2, size=(2, 2))
    intensities2 = np.random.randint(0, 15, size=(2, 2))

    test1 = mdtd.generate_4d_data(
        probe_size_x=2,
        probe_size_y=2,
        image_size_x=50,
        image_size_y=50,
        disk_x=25,
        disk_y=25,
        disk_r=5,
        disk_I=100,
        ring_x=25,
        ring_y=25,
        ring_r=radii1,
        ring_I=intensities1,
        ring_lw=0,
        blur=True,
        blur_sigma=1,
        downscale=True,
        add_noise=True,
        show_progressbar=False,
        lazy=lazy,
    )

    test2 = mdtd.generate_4d_data(
        probe_size_x=2,
        probe_size_y=2,
        image_size_x=50,
        image_size_y=50,
        disk_x=25,
        disk_y=25,
        disk_r=5,
        disk_I=100,
        ring_x=25,
        ring_y=25,
        ring_r=radii2,
        ring_I=intensities2,
        ring_lw=0,
        blur=True,
        blur_sigma=1,
        downscale=True,
        add_noise=True,
        show_progressbar=False,
        lazy=lazy,
    )

    fem_signal = test1 + test2

    fem_signal.axes_manager.navigation_axes[0].name = "Probe position x"
    fem_signal.axes_manager.navigation_axes[0].units = "nm"
    fem_signal.axes_manager.navigation_axes[0].scale = 1.0
    fem_signal.axes_manager.navigation_axes[0].offset = 0

    fem_signal.axes_manager.navigation_axes[1].name = "Probe position y"
    fem_signal.axes_manager.navigation_axes[1].units = "nm"
    fem_signal.axes_manager.navigation_axes[1].scale = 1.0
    fem_signal.axes_manager.navigation_axes[1].offset = 0

    fem_signal.axes_manager.signal_axes[0].name = "Signal x"
    fem_signal.axes_manager.signal_axes[0].units = "mrads"
    fem_signal.axes_manager.signal_axes[0].scale = 0.25
    fem_signal.axes_manager.signal_axes[0].offset = 0

    fem_signal.axes_manager.signal_axes[1].name = "Signal y"
    fem_signal.axes_manager.signal_axes[1].units = "mrads"
    fem_signal.axes_manager.signal_axes[1].scale = 0.25
    fem_signal.axes_manager.signal_axes[1].offset = 0

    return fem_signal
Exemple #28
0
def get_generic_fem_signal(probe_x=2, probe_y=2, image_x=50, image_y=50, lazy=False):
    """2D signal approximating a fluctuation electron microscopy (FEM) dataset with user defined dimensions.

    Parameters
    ----------
    probe_x : int, default 2
        Horizontal dimension of the navigation axes
    probe_y : int, default 2
        Vertical dimension of the navigation axes
    image_x : int, default 2
        Horizontal dimension of the signal axes
    image_y : int, default 2
        Vertical dimension of the signal axes
    lazy : bool, default False
        If True, resulting signal will be lazy.

    Returns
    -------
    fem_signal : Diffraction2D

    Examples
    --------
    >>> s = pxm.dummy_data.get_generic_fem_signal(probe_x=5, probe_y=10,
    ...     image_x=25, image_y=30, lazy=False)
    >>> s.plot()

    """
    image_center = [np.int(image_x / 2), np.int(image_y / 2)]

    radii1 = 10 * np.random.randint(0, 2, size=(probe_y, probe_x))
    intensities1 = np.random.randint(0, 5, size=(probe_y, probe_x))

    radii2 = 20 * np.random.randint(0, 2, size=(probe_y, probe_x))
    intensities2 = np.random.randint(0, 15, size=(probe_y, probe_x))

    test1 = mdtd.generate_4d_data(
        probe_size_x=probe_x,
        probe_size_y=probe_y,
        image_size_x=image_x,
        image_size_y=image_y,
        disk_x=image_center[0],
        disk_y=image_center[1],
        disk_r=5,
        disk_I=100,
        ring_x=image_center[0],
        ring_y=image_center[1],
        ring_r=radii1,
        ring_I=intensities1,
        ring_lw=0,
        blur=True,
        blur_sigma=1,
        downscale=True,
        add_noise=True,
        show_progressbar=False,
        lazy=lazy,
    )

    test2 = mdtd.generate_4d_data(
        probe_size_x=probe_x,
        probe_size_y=probe_y,
        image_size_x=image_x,
        image_size_y=image_y,
        disk_x=image_center[0],
        disk_y=image_center[1],
        disk_r=5,
        disk_I=100,
        ring_x=image_center[0],
        ring_y=image_center[1],
        ring_r=radii2,
        ring_I=intensities2,
        ring_lw=0,
        blur=True,
        blur_sigma=1,
        downscale=True,
        add_noise=True,
        show_progressbar=False,
        lazy=lazy,
    )

    fem_signal = test1 + test2

    fem_signal.axes_manager.navigation_axes[0].name = "Probe position x"
    fem_signal.axes_manager.navigation_axes[0].units = "nm"
    fem_signal.axes_manager.navigation_axes[0].scale = 1.0
    fem_signal.axes_manager.navigation_axes[0].offset = 0

    fem_signal.axes_manager.navigation_axes[1].name = "Probe position y"
    fem_signal.axes_manager.navigation_axes[1].units = "nm"
    fem_signal.axes_manager.navigation_axes[1].scale = 1.0
    fem_signal.axes_manager.navigation_axes[1].offset = 0

    fem_signal.axes_manager.signal_axes[0].name = "Signal x"
    fem_signal.axes_manager.signal_axes[0].units = "mrads"
    fem_signal.axes_manager.signal_axes[0].scale = 0.25
    fem_signal.axes_manager.signal_axes[0].offset = 0

    fem_signal.axes_manager.signal_axes[1].name = "Signal y"
    fem_signal.axes_manager.signal_axes[1].units = "mrads"
    fem_signal.axes_manager.signal_axes[1].scale = 0.25
    fem_signal.axes_manager.signal_axes[1].offset = 0
    return fem_signal
 def test_simple0(self):
     mdtd.generate_4d_data()