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
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)
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)
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
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
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
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
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
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 = _make_atom_position_marker_list(atom_position_list, scale=0.2, markersize=30, color='black', add_numbers=True) assert len(marker_list) == 40
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
class TestAtomPositionObjectTools: def setup_method(self): self.atom_position = Atom_Position(1, 1) 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 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
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
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 temul.external.atomap_devel_012.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)
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
def setup_method(self): self.atom_position = Atom_Position(1, 1)
def test_amplitude(self): amplitude = 30 atom_position = Atom_Position(1, 2, amplitude=amplitude) assert atom_position.amplitude_gaussian == amplitude