def test_add_image_noise_random_seed(self): test_data0 = tt.MakeTestData(100, 100) test_data0.add_image_noise(random_seed=0) s0 = test_data0.signal test_data1 = tt.MakeTestData(100, 100) test_data1.add_image_noise(random_seed=0) s1 = test_data1.signal assert (s0.data == s1.data).all()
def test_get_signal(self): imX0, imY0 = 100, 100 test_data0 = tt.MakeTestData(imX0, imY0) assert (imX0, imY0) == test_data0.data_extent assert test_data0.signal.axes_manager.shape == (imX0, imY0) assert not test_data0.signal.data.any() imX1, imY1 = 100, 39 test_data1 = tt.MakeTestData(imX1, imY1) assert (imX1, imY1) == test_data1.data_extent assert test_data1.signal.axes_manager.shape == (imX1, imY1) imX2, imY2 = 34, 65 test_data2 = tt.MakeTestData(imX2, imY2) assert (imX2, imY2) == test_data2.data_extent assert test_data2.signal.axes_manager.shape == (imX2, imY2)
def setup_method(self): t1 = tt.MakeTestData(20, 10) t1.add_atom_list([5, 15], [5, 5]) sublattice = t1.sublattice self.mask_list = sublattice._get_sublattice_atom_list_mask() s = sublattice.mask_image_around_sublattice(sublattice.image, radius=1) self.s_i = np.asarray(np.nonzero(s.data))
def test_atom_plane_tolerance(self): # 10 times 10 atoms test_data = tt.MakeTestData(240, 240) x, y = np.mgrid[30:212:40, 30:222:20] x, y = x.flatten(), y.flatten() test_data.add_atom_list(x, y) x, y = np.mgrid[50:212:40, 30.0:111:20] x, y = x.flatten(), y.flatten() test_data.add_atom_list(x, y) x, y = np.mgrid[50:212:40, 135:222:20] x, y = x.flatten(), y.flatten() test_data.add_atom_list(x, y) # Distortion is too big, so the default construct_zone_axes will not # correctly construct the atomic planes sublattice = test_data.sublattice sublattice.construct_zone_axes() planes0 = sublattice.atom_planes_by_zone_vector[ sublattice.zones_axis_average_distances[0]] planes1 = sublattice.atom_planes_by_zone_vector[ sublattice.zones_axis_average_distances[1]] assert len(planes0) != 10 assert len(planes1) != 10 # Increase atom_plane_tolerance sublattice = test_data.sublattice sublattice.construct_zone_axes(atom_plane_tolerance=0.8) planes0 = sublattice.atom_planes_by_zone_vector[ sublattice.zones_axis_average_distances[0]] planes1 = sublattice.atom_planes_by_zone_vector[ sublattice.zones_axis_average_distances[1]] assert len(planes0) == 10 assert len(planes1) == 10
def setup_method(self): test_data = tt.MakeTestData(700, 700) x, y = np.mgrid[100:600:10j, 100:600:10j] x, y = x.flatten(), y.flatten() test_data.add_atom_list(x, y, sigma_x=10, sigma_y=10, amplitude=50) self.sublattice = test_data.sublattice self.sublattice.construct_zone_axes()
def setup_method(self): test_data = tt.MakeTestData(540, 540) x, y = np.mgrid[20:520:8j, 20:520:8j] x, y = x.flatten(), y.flatten() test_data.add_atom_list(x, y, sigma_x=10, sigma_y=10, amplitude=50) self.image_data = test_data.signal.data self.xy = np.dstack((x, y))[0]
def setup_method(self): test_data = tt.MakeTestData(100, 100) x, y = np.mgrid[5:95:10j, 5:95:10j] x, y = x.flatten(), y.flatten() test_data.add_atom_list(x, y) self.sublattice = test_data.sublattice self.sublattice.construct_zone_axes()
def setup_method(self): test_data = tt.MakeTestData(100, 100) x, y = np.mgrid[5:95:10j, 5:95:10j] x, y = x.flatten(), y.flatten() test_data.add_atom_list(x, y) self.s = test_data.signal self.peaks = np.array((x, y)).swapaxes(0, 1)
def setup_method(self): t = tt.MakeTestData(30, 30) x, y = np.mgrid[5:30:5, 5:30:5] x, y = x.flatten(), y.flatten() t.add_atom_list(x, y) self.sublattice = t.sublattice self.z_list = np.full_like(t.sublattice.x_position, 1).tolist()
def test_sublattice_generate_image(self): testdata = tt.MakeTestData(1000, 1000, sublattice_generate_image=False) x, y = np.mgrid[0:1000:150j, 0:1000:150j] x, y = x.flatten(), y.flatten() testdata.add_atom_list(x, y) sublattice = testdata.sublattice assert (sublattice.image == 0).all() assert len(sublattice.atom_list) == 150 * 150
def setup_method(self): x, y = 10, 12 test_data = tt.MakeTestData(20, 20) test_data.add_atom(x, y) self.signal = test_data.signal self.atom_position_list = [ [x, y], ]
def setup_method(self): test_data = tt.MakeTestData(520, 520) x, y = np.mgrid[10:510:8j, 10:510:8j] x, y = x.flatten(), y.flatten() test_data.add_atom_list(x, y) sublattice = test_data.sublattice sublattice.find_nearest_neighbors() self.sublattice = sublattice
def setup_method(self): x, y = np.mgrid[5:50:5, 5:50:5] x, y = x.flatten(), y.flatten() tV = tt.MakeTestData(50, 50) tV.add_atom_list(x, y) sublatticeV = tV.sublattice sublatticeV.construct_zone_axes() self.sublatticeV = sublatticeV tH = tt.MakeTestData(50, 50) tH.add_atom_list(y, x) sublatticeH = tH.sublattice sublatticeH.construct_zone_axes() self.sublatticeH = sublatticeH z_list = np.full_like(sublatticeV.x_position, 0) z_list[36:] = 1 self.property_list = z_list
def test_cubic_simple(self): vX, vY = 10, 10 x, y = np.mgrid[5:95:vX, 5:95:vY] test_data = tt.MakeTestData(100, 100) test_data.add_atom_list(x.flatten(), y.flatten(), sigma_x=2, sigma_y=2) sublattice = test_data.sublattice sublattice.construct_zone_axes() zone_vectors = sublattice.zones_axis_average_distances assert zone_vectors[0] == (0, vY) assert zone_vectors[1] == (vX, 0) assert zone_vectors[2] == (vX, vY) assert zone_vectors[3] == (vX, -vY)
def test_add_image_noise(self): test_data0 = tt.MakeTestData(1000, 1000) mu0, sigma0 = 0, 0.005 test_data0.add_image_noise(mu=mu0, sigma=sigma0, only_positive=False) s0 = test_data0.signal assert approx(s0.data.mean(), abs=1e-5) == mu0 assert approx(s0.data.std(), abs=1e-2) == sigma0 test_data1 = tt.MakeTestData(1000, 1000) mu1, sigma1 = 10, 0.5 test_data1.add_image_noise(mu=mu1, sigma=sigma1, only_positive=False) s1 = test_data1.signal assert approx(s1.data.mean(), rel=1e-4) == mu1 assert approx(s1.data.std(), abs=1e-2) == sigma1 test_data2 = tt.MakeTestData(1000, 1000) mu2, sigma2 = 154.2, 1.98 test_data2.add_image_noise(mu=mu2, sigma=sigma2, only_positive=False) s2 = test_data2.signal assert approx(s2.data.mean(), rel=1e-4) == mu2 assert approx(s2.data.std(), rel=1e-2) == sigma2
def test_add_atom(self): x, y, sx, sy, A, r = 10, 5, 5, 9, 10, 2 td = tt.MakeTestData(50, 50) td.add_atom(x, y, sigma_x=sx, sigma_y=sy, amplitude=A, rotation=r) assert len(td.sublattice.atom_list) == 1 atom = td.sublattice.atom_list[0] assert atom.pixel_x == x assert atom.pixel_y == y assert atom.sigma_x == sx assert atom.sigma_y == sy assert atom.amplitude_gaussian == A assert atom.rotation == r
def test_two_atoms(self): test_data = tt.MakeTestData(50, 100) x, y, A = [25, 25], [25, 75], [5, 10] test_data.add_atom_list(x=x, y=y, amplitude=A) s = test_data.signal i_points, i_record, p_record = integrate(s, x, y, max_radius=500) assert approx(i_points) == A assert i_record.axes_manager.signal_shape == (50, 100) assert (i_record.isig[:, :51].data == i_points[0]).all() assert (i_record.isig[:, 51:].data == i_points[1]).all() assert (p_record[:51] == 0).all() assert (p_record[51:] == 1).all()
def test_max_radius_1(self): test_data = tt.MakeTestData(60, 100) x, y, A = [30, 30], [25, 75], [5, 10] test_data.add_atom_list( x=x, y=y, amplitude=A, sigma_x=0.1, sigma_y=0.1) s = test_data.signal i_points, i_record, p_record = integrate(s, x, y, max_radius=1) assert (i_points[1] / i_points[0]) == 2. assert i_record.data[y[0], x[0]] == i_points[0] assert i_record.data[y[1], x[1]] == i_points[1] i_record.data[y[0], x[0]] = 0 i_record.data[y[1], x[1]] = 0 assert not i_record.data.any()
def test_rectangle_simple(self): vX, vY = 10, 15 x, y = np.mgrid[5:95:vX, 5:95:vY] test_data = tt.MakeTestData(100, 100) test_data.add_atom_list(x.flatten(), y.flatten(), sigma_x=2, sigma_y=2) sublattice = test_data.sublattice sublattice._pixel_separation = sublattice._get_pixel_separation() sublattice._make_translation_symmetry() zone_vectors = sublattice.zones_axis_average_distances assert zone_vectors[0] == (vX, 0) assert zone_vectors[1] == (0, vY) assert zone_vectors[2] == (vX, vY) assert zone_vectors[3] == (-vX, vY) assert zone_vectors[4] == (2 * vX, vY) assert zone_vectors[5] == (2 * vX, -vY)
def test_add_atom_list_simple(self): x, y = np.mgrid[10:90:10, 10:90:10] x, y = x.flatten(), y.flatten() sx, sy, A, r = 2.1, 1.3, 9.5, 1.4 td = tt.MakeTestData(100, 100) td.add_atom_list( x=x, y=y, sigma_x=sx, sigma_y=sy, amplitude=A, rotation=r) atom_list = td.sublattice.atom_list assert len(atom_list) == len(x) for tx, ty, atom in zip(x, y, atom_list): assert atom.pixel_x == tx assert atom.pixel_y == ty assert atom.sigma_x == sx assert atom.sigma_y == sy assert atom.amplitude_gaussian == A assert atom.rotation == r
def setup_method(self): test_data = tt.MakeTestData(520, 520) x, y = np.mgrid[10:510:20j, 10:510:20j] x, y = x.flatten(), y.flatten() test_data.add_atom_list(x, y) s = test_data.signal atom_positions = afr.get_atom_positions( signal=s, separation=10, threshold_rel=0.02, ) sublattice = Sublattice(atom_position_list=atom_positions, image=s.data) sublattice.find_nearest_neighbors() self.sublattice = sublattice
def test_four_atoms(self): test_data = tt.MakeTestData(60, 100) x, y, A = [20, 20, 40, 40], [25, 75, 25, 75], [5, 10, 15, 20] test_data.add_atom_list(x=x, y=y, amplitude=A) s = test_data.signal i_points, i_record, p_record = integrate(s, x, y, max_radius=500) assert approx(i_points) == A assert (i_record.isig[:31, :51].data == i_points[0]).all() assert (i_record.isig[:31, 51:].data == i_points[1]).all() assert (i_record.isig[31:, :51].data == i_points[2]).all() assert (i_record.isig[31:, 51:].data == i_points[3]).all() assert (p_record[:51, :31] == 0).all() assert (p_record[51:, :31] == 1).all() assert (p_record[:51, 31:] == 2).all() assert (p_record[51:, 31:] == 3).all()
def test_add_atom_list_all_lists(self): x, y = np.mgrid[10:90:10, 10:90:10] x, y = x.flatten(), y.flatten() sx = np.random.random_sample(size=len(x)) sy = np.random.random_sample(size=len(x)) A = np.random.random_sample(size=len(x)) r = np.random.random_sample(size=len(x)) td = tt.MakeTestData(100, 100) td.add_atom_list( x=x, y=y, sigma_x=sx, sigma_y=sy, amplitude=A, rotation=r) atom_list = td.sublattice.atom_list assert len(atom_list) == len(x) iterator = zip(x, y, sx, sy, A, r, atom_list) for tx, ty, tsx, tsy, tA, tr, atom in iterator: assert atom.pixel_x == tx assert atom.pixel_y == ty assert atom.sigma_x == tsx assert atom.sigma_y == tsy assert atom.amplitude_gaussian == tA assert atom.rotation == tr
def test_gaussian_list(self): x, y = np.mgrid[10:90:10, 10:90:10] x, y = x.flatten(), y.flatten() sx = np.random.random_sample(size=len(x)) sy = np.random.random_sample(size=len(x)) A = np.random.random_sample(size=len(x)) r = np.random.random_sample(size=len(x)) td = tt.MakeTestData(100, 100) td.add_atom_list( x=x, y=y, sigma_x=sx, sigma_y=sy, amplitude=A, rotation=r) gaussian_list = td.gaussian_list assert len(gaussian_list) == len(x) iterator = zip(x, y, sx, sy, A, r, gaussian_list) for tx, ty, tsx, tsy, tA, tr, gaussian in iterator: assert gaussian.centre_x.value == tx assert gaussian.centre_y.value == ty assert gaussian.sigma_x.value == tsx assert gaussian.sigma_y.value == tsy assert gaussian.A.value == tA assert gaussian.rotation.value == tr
def setup_method(self): t = tt.MakeTestData(50, 50) x, y = np.mgrid[5:50:5, 5:50:5] x, y = x.flatten(), y.flatten() t.add_atom_list(x, y) sublattice = t.sublattice sublattice.construct_zone_axes() self.sublattice = sublattice x0, x1, idx = 1, 8, [] for j in range(1, 9): span = np.arange(x0, x0 + x1, 1) x0 += 10 x1 -= 1 idx.extend(span) idx = np.asarray(idx) z_list = np.full_like(sublattice.x_position, 0) z_list[idx] = 1 self.property_list = z_list
def test_add_atom_list_wrong_input(self): x, y = np.mgrid[10:90:10, 10:90:10] x, y = x.flatten(), y.flatten() td = tt.MakeTestData(100, 100) with pytest.raises(ValueError): td.add_atom_list(x, y[10:]) sx = np.arange(10) with pytest.raises(ValueError): td.add_atom_list(x, y, sigma_x=sx) sy = np.arange(20) with pytest.raises(ValueError): td.add_atom_list(x, y, sigma_y=sy) A = np.arange(30) with pytest.raises(ValueError): td.add_atom_list(x, y, amplitude=A) r = np.arange(5) with pytest.raises(ValueError): td.add_atom_list(x, y, rotation=r)
def test_simple_init(self): tt.MakeTestData(100, 100)
def test_watershed_method_running(self): test_data = tt.MakeTestData(60, 100) x, y, A = [20, 20, 40, 40], [25, 75, 25, 75], [5, 10, 15, 20] test_data.add_atom_list(x=x, y=y, amplitude=A) s = test_data.signal i_points, i_record, p_record = integrate(s, x, y, method='Watershed')
def test_add_image_noise_only_positive(self): test_data0 = tt.MakeTestData(1000, 1000) test_data0.add_image_noise(mu=0, sigma=0.005, only_positive=True) s0 = test_data0.signal assert (s0.data > 0).all()
def setup_method(self): test_data = tt.MakeTestData(50, 50) test_data.add_atom_list(np.arange(5, 45, 5), np.arange(5, 45, 5)) self.atom_lattice = test_data.atom_lattice