Exemple #1
0
 def test_set_mask_radius_atom(self):
     atom_list = [Atom_Position(2, 2), Atom_Position(4, 4)]
     image = np.random.random((20, 20))
     model, mask = afr._make_model_from_atom_list(atom_list=atom_list,
                                                  image_data=image,
                                                  mask_radius=3)
     assert len(model) == 2
Exemple #2
0
 def test_mask_radius(self):
     atom_position0 = Atom_Position(15, 20)
     atom_position1 = Atom_Position(15, 20)
     image = np.random.randint(1000, size=(30, 30))
     x0, y0 = atom_position0._get_center_position_com(image, mask_radius=5)
     x1, y1 = atom_position1._get_center_position_com(image, mask_radius=10)
     assert x0 != x1
     assert y0 != y1
Exemple #3
0
 def test_create_atom_plane_object(self):
     atom_list = [
             Atom_Position(1, 2),
             Atom_Position(2, 4),
             ]
     zone_vector = (1, 2)
     atom_list[0]._start_atom = [zone_vector]
     atom_list[1]._end_atom = [zone_vector]
     atom_lattice = Atom_Lattice()
     Atom_Plane(atom_list, zone_vector, atom_lattice)
Exemple #4
0
    def test_sigma(self):
        sigma_x, sigma_y = 2, 3
        atom_position = Atom_Position(1, 2, sigma_x=sigma_x, sigma_y=sigma_y)
        assert atom_position.sigma_x == sigma_x
        assert atom_position.sigma_y == sigma_y

        sigma_x, sigma_y = -5, -6
        atom_position = Atom_Position(1, 2, sigma_x=sigma_x, sigma_y=sigma_y)
        assert atom_position.sigma_x == abs(sigma_x)
        assert atom_position.sigma_y == abs(sigma_y)
Exemple #5
0
 def setup_method(self):
     atom_lattice = Atom_Lattice()
     atom_plane_list = []
     for i in range(2):
         atom_list = [
                 Atom_Position(1, 2),
                 Atom_Position(2, 4),
                 ]
         zone_vector = (1, 2)
         atom_list[0]._start_atom = [zone_vector]
         atom_list[1]._end_atom = [zone_vector]
         atom_plane = Atom_Plane(
                 atom_list, (1, 2), atom_lattice)
         atom_plane_list.append(atom_plane)
     self.atom_plane_list = atom_plane_list
Exemple #6
0
    def add_atom(self, x, y, sigma_x=1, sigma_y=1, amplitude=1, rotation=0):
        """
        Add a single atom to the test data.

        Parameters
        ----------
        x, y : numbers
            Position of the atom.
        sigma_x, sigma_y : numbers, default 1
        amplitude : number, default 1
        rotation : number, default 0

        Examples
        --------
        >>> from atomap.testing_tools import MakeTestData
        >>> test_data = MakeTestData(200, 200)
        >>> test_data.add_atom(x=10, y=20)
        >>> test_data.signal.plot()
        """
        atom = Atom_Position(x=x,
                             y=y,
                             sigma_x=sigma_x,
                             sigma_y=sigma_y,
                             rotation=rotation,
                             amplitude=amplitude)
        self.__sublattice.atom_list.append(atom)
Exemple #7
0
 def test_flat_image(self):
     image_data = np.ones((100, 100)) * 10
     atom = Atom_Position(20, 10)
     distortion_x, distortion_y = atom.estimate_local_scanning_distortion(
         image_data, radius=6, edge_skip=2)
     assert approx(distortion_x, 0)
     assert approx(distortion_y, 0)
Exemple #8
0
 def test_value(self):
     image_data = np.zeros((100, 100))
     x, y, distance, value = 20, 49, 4, 10
     image_data[y, x] = value
     atom = Atom_Position(x, y)
     image_slice, x0, y0 = atom._get_image_slice_around_atom(
         image_data, distance)
     assert image_slice[distance, distance] == value
Exemple #9
0
 def test_close_to_edge_corner(self):
     image_data = np.random.random((50, 60))
     x, y, distance = 0, 0, 9
     atom = Atom_Position(x, y)
     image_slice, x0, y0 = atom._get_image_slice_around_atom(
         image_data, distance)
     assert image_slice.shape == (10, 10)
     assert x0 == 0
     assert y0 == 0
Exemple #10
0
 def test_close_to_edge_y1(self):
     image_data = np.random.random((50, 50))
     x, y, distance = 20, 49, 4
     atom = Atom_Position(x, y)
     image_slice, x0, y0 = atom._get_image_slice_around_atom(
         image_data, distance)
     assert image_slice.shape == (5, 9)
     assert x0 == (x - distance)
     assert y0 == (y - distance)
Exemple #11
0
 def test_image_border_y_max(self, im_y):
     x, y, sigma, sigma_quantile = 50, 95, 3, 3
     atom_position = Atom_Position(x, y, sigma_x=sigma, sigma_y=sigma)
     slice_y, slice_x = atom_position._get_atom_slice(
         100, im_y, sigma_quantile=sigma_quantile)
     assert slice_x.start == x - sigma * sigma_quantile
     assert slice_x.stop == x + sigma * sigma_quantile
     assert slice_y.start == y - sigma * sigma_quantile
     assert slice_y.stop == im_y
Exemple #12
0
 def test_image_border_y_0(self):
     x, y, sigma, sigma_quantile = 50, 0, 3, 3
     atom_position = Atom_Position(x, y, sigma_x=sigma, sigma_y=sigma)
     slice_y, slice_x = atom_position._get_atom_slice(
         100, 100, sigma_quantile=sigma_quantile)
     assert slice_x.start == x - sigma * sigma_quantile
     assert slice_x.stop == x + sigma * sigma_quantile
     assert slice_y.start == 0
     assert slice_y.stop == y + sigma * sigma_quantile
Exemple #13
0
 def test_simple(self):
     image_data = np.random.random((50, 50))
     x, y, distance = 10, 15, 4
     atom = Atom_Position(x, y)
     distance = 4
     image_slice, x0, y0 = atom._get_image_slice_around_atom(
         image_data, distance)
     assert image_slice.shape == (9, 9)
     assert x0 == (x - distance)
     assert y0 == (y - distance)
Exemple #14
0
 def test_sigma_quantile(self, quantile):
     x, y, sx, sy, sigma_quantile = 25, 30, 2, 4, quantile
     atom_position = Atom_Position(x=x, y=y, sigma_x=sx, sigma_y=sy)
     slice_y, slice_x = atom_position._get_atom_slice(
         100, 100, sigma_quantile=sigma_quantile)
     smax = max(sx, sy)
     assert slice_x.start == x - smax * sigma_quantile
     assert slice_x.stop == x + smax * sigma_quantile
     assert slice_y.start == y - smax * sigma_quantile
     assert slice_y.stop == y + smax * sigma_quantile
Exemple #15
0
 def test_values(self):
     image_data = np.zeros((100, 100))
     image_data[77, 20] = 10
     image_data[76, 21] = 10
     image_data[75, 20] = 10
     image_data[74, 21] = 10
     image_data[73, 20] = 10
     atom = Atom_Position(20.5, 75)
     distortion_x, distortion_y = atom.estimate_local_scanning_distortion(
         image_data, radius=4, edge_skip=2)
     assert approx(distortion_y, np.std((20, 21, 20, 21, 20)))
Exemple #16
0
    def test_rotation(self):
        rotation0 = 0.0
        atom_position = Atom_Position(1, 2, rotation=rotation0)
        assert atom_position.rotation == rotation0

        rotation1 = math.pi / 2
        atom_position = Atom_Position(1, 2, rotation=rotation1)
        assert atom_position.rotation == rotation1

        rotation2 = math.pi
        atom_position = Atom_Position(1, 2, rotation=rotation2)
        assert atom_position.rotation == 0

        rotation3 = math.pi * 3 / 2
        atom_position = Atom_Position(1, 2, rotation=rotation3)
        assert atom_position.rotation == math.pi / 2

        rotation4 = math.pi * 2
        atom_position = Atom_Position(1, 2, rotation=rotation4)
        assert atom_position.rotation == 0
Exemple #17
0
 def test_elliptical_atom(self):
     image = np.zeros((100, 100))
     atom = Atom_Position(17, 75)
     image[77, 15] = 10
     image[76, 16] = 10
     image[75, 17] = 10
     image[74, 18] = 10
     image[73, 19] = 10
     scanning_distortions = atom.estimate_local_scanning_distortion(
         image, radius=4, edge_skip=2)
     assert approx(scanning_distortions) == (0.0, 0.0)
Exemple #18
0
    def test_get_atom_angle(self):
        atom_position0 = Atom_Position(1, 2)
        atom_position1 = Atom_Position(3, 1)
        atom_position2 = Atom_Position(1, 0)
        atom_position3 = Atom_Position(5, 1)
        atom_position4 = Atom_Position(2, 2)

        angle90 = self.atom_position.get_angle_between_atoms(
            atom_position0, atom_position1)
        angle180 = self.atom_position.get_angle_between_atoms(
            atom_position0, atom_position2)
        angle0 = self.atom_position.get_angle_between_atoms(
            atom_position1, atom_position3)
        angle45 = self.atom_position.get_angle_between_atoms(
            atom_position1, atom_position4)

        assert approx(angle90) == pi / 2
        assert approx(angle180) == pi
        assert approx(angle0) == 0
        assert approx(angle45) == pi / 4
Exemple #19
0
    def setup_method(self):
        x, y = [1, 2], [2, 4]
        sX, sY, r = [3.1, 1.2], [2.2, 1.1], [0.5, 0.4]
        A_g = [10.2, 5.2]

        atom_list = [
                Atom_Position(x[0], y[0], sX[0], sY[0], r[0]),
                Atom_Position(x[1], y[1], sX[1], sY[1], r[1]),
                ]
        atom_list[0].amplitude_gaussian = A_g[0]
        atom_list[1].amplitude_gaussian = A_g[1]
        zone_vector = (1, 2)
        atom_list[0]._start_atom = [zone_vector]
        atom_list[1]._end_atom = [zone_vector]
        self.atom_plane = Atom_Plane(
                atom_list,
                zone_vector,
                Atom_Lattice())
        self.x, self.y, self.sX, self.sY, self.r = x, y, sX, sY, r
        self.A_g = A_g
Exemple #20
0
 def test_make_atom_position_marker_list(self):
     atom_position_list = []
     for i in range(20):
         atom_position = Atom_Position(i, i)
         atom_position_list.append(atom_position)
     marker_list = pl._make_atom_position_marker_list(
             atom_position_list,
             scale=0.2,
             markersize=30,
             color='black',
             add_numbers=True)
     assert len(marker_list) == 40
Exemple #21
0
 def test_simple(self):
     x, y, sX, sY, r = 7.1, 2.8, 2.1, 3.3, 1.9
     atom_position = Atom_Position(x=x,
                                   y=y,
                                   sigma_x=sX,
                                   sigma_y=sY,
                                   rotation=r)
     gaussian = afr._atom_to_gaussian_component(atom_position)
     assert x == gaussian.centre_x.value
     assert y == gaussian.centre_y.value
     assert sX == gaussian.sigma_x.value
     assert sY == gaussian.sigma_y.value
     assert r == gaussian.rotation.value
Exemple #22
0
    def test_outside_high_x(self):
        im_x, im_y = 90, 100
        test_data = MakeTestData(im_x, im_y)
        test_data.add_atom(100, 50, amplitude=200, sigma_x=10, sigma_y=10)

        image = test_data.signal.data
        atom_position = Atom_Position(80, 50)
        gaussian_list = afr._fit_atom_positions_with_gaussian_model(
            [atom_position], image, mask_radius=30)
        if gaussian_list is not False:
            gaussian = gaussian_list[0]
            assert gaussian.centre_x.value > 0
            assert gaussian.centre_x.value < im_x
            assert gaussian.centre_y.value > 0
            assert gaussian.centre_y.value < im_y
Exemple #23
0
 def test_as_gaussian(self):
     x, y, sx, sy, A, r = 10., 5., 2., 3.5, 9.9, 1.5
     atom_position = Atom_Position(x=x,
                                   y=y,
                                   sigma_x=sx,
                                   sigma_y=sy,
                                   amplitude=A,
                                   rotation=r)
     g = atom_position.as_gaussian()
     assert g.centre_x.value == x
     assert g.centre_y.value == y
     assert g.sigma_x.value == sx
     assert g.sigma_y.value == sy
     assert g.A.value == A
     assert g.rotation.value == r
Exemple #24
0
 def test_edge_skip_x(self):
     image = np.zeros((100, 100))
     image[75, 13] = 100
     image[77, 15] = 10
     image[76, 16] = 10
     image[75, 17] = 10
     image[74, 18] = 10
     image[73, 19] = 10
     atom = Atom_Position(17, 75)
     scanning_distortions = atom.estimate_local_scanning_distortion(
         image, radius=4, edge_skip=0)
     assert approx(scanning_distortions[0]) != 0.0
     assert approx(scanning_distortions[1]) != 0.0
     scanning_distortions = atom.estimate_local_scanning_distortion(
         image, radius=4, edge_skip=1)
     assert approx(scanning_distortions[0]) == 0.0
     assert approx(scanning_distortions[1]) != 0.0
Exemple #25
0
    def sublattice(self):
        atom_list = []
        for atom in self.__sublattice.atom_list:
            new_atom = Atom_Position(x=atom.pixel_x,
                                     y=atom.pixel_y,
                                     sigma_x=atom.sigma_x,
                                     sigma_y=atom.sigma_y,
                                     rotation=atom.rotation,
                                     amplitude=atom.amplitude_gaussian)
            atom_list.append(new_atom)

        if self._sublattice_generate_image:
            image = self.signal.data
        else:
            image = np.zeros(self.data_extent[::-1])
        sublattice = Sublattice([], image)
        sublattice.atom_list = atom_list
        return sublattice
Exemple #26
0
 def test_radius(self):
     image = np.zeros((100, 100))
     image[79, 17] = 100
     image[77, 15] = 10
     image[76, 16] = 10
     image[75, 17] = 10
     image[74, 18] = 10
     image[73, 19] = 10
     atom = Atom_Position(17, 75)
     scanning_distortions = atom.estimate_local_scanning_distortion(
         image, radius=2, edge_skip=0)
     assert approx(scanning_distortions) == (0.0, 0.0)
     scanning_distortions = atom.estimate_local_scanning_distortion(
         image, radius=3, edge_skip=0)
     assert approx(scanning_distortions) == (0.0, 0.0)
     scanning_distortions = atom.estimate_local_scanning_distortion(
         image, radius=4, edge_skip=0)
     assert approx(scanning_distortions) != (0.0, 0.0)
Exemple #27
0
 def test_position(self):
     atom_x, atom_y = 10, 20
     atom_position = Atom_Position(atom_x, atom_y)
     assert atom_position.pixel_x == 10
     assert atom_position.pixel_y == 20
Exemple #28
0
 def test_amplitude(self):
     amplitude = 30
     atom_position = Atom_Position(1, 2, amplitude=amplitude)
     assert atom_position.amplitude_gaussian == amplitude
Exemple #29
0
 def setup_method(self):
     self.atom_position = Atom_Position(1, 1)