def test_max_radius_bad_value(self): s = hs.signals.Signal2D(np.zeros((10, 10))) with pytest.raises(ValueError): integrate(s, [ 5, ], [ 5, ], max_radius=-1)
def test_wrong_method(self): s = hs.signals.Signal2D(np.zeros((10, 10))) with pytest.raises(NotImplementedError): integrate(s, [ 5, ], [ 5, ], method='bad_method')
def test_array_input(self): sublattice = am.dummy_data.get_simple_cubic_sublattice() x, y = sublattice.x_position, sublattice.y_position i_points0, i_record0, p_record0 = integrate(sublattice.image, x, y) signal = am.dummy_data.get_simple_cubic_signal() i_points1, i_record1, p_record1 = integrate(signal, x, y) assert (i_points0 == i_points1).all() assert (i_record0.data == i_record1.data).all() assert (p_record0 == p_record1).all()
def integrate_column_intensity( self, method='Voronoi', max_radius='Auto', data_to_integrate=None): """Integrate signal around the atoms in the atom lattice. See atomap.tools.integrate for more information about the parameters. Parameters ---------- method : string Voronoi or Watershed max_radius : int, optional data_to_integrate : NumPy array, HyperSpy signal or array-like Works with 2D, 3D and 4D arrays, so for example an EEL spectrum image can be used. Returns ------- i_points, i_record, p_record Examples -------- >>> al = am.dummy_data.get_simple_atom_lattice_two_sublattices() >>> i_points, i_record, p_record = al.integrate_column_intensity() See also -------- tools.integrate """ if data_to_integrate is None: data_to_integrate = self.image i_points, i_record, p_record = at.integrate( data_to_integrate, self.x_position, self.y_position, method=method, max_radius=max_radius) return(i_points, i_record, p_record)
def test_sum_2d_random_data(self): s = hs.signals.Signal2D(np.random.rand(100, 110)) y, x = np.mgrid[5:96:10, 5:96:10] x, y = x.flatten(), y.flatten() result = integrate(s, x, y) assert approx(np.sum(result[0])) == np.sum(s.data) assert result[2].shape == s.data.shape
def test_3d_data_running(self): s = dd.get_eels_spectrum_survey_image() s_eels = dd.get_eels_spectrum_map() peaks = am.get_atom_positions(s, separation=4) i_points, i_record, p_record = integrate(s_eels, peaks[:, 0], peaks[:, 1], max_radius=3) assert p_record.shape == (100, 100) assert s_eels.data.shape == i_record.data.shape
def test_two_atoms(self): test_data = tt.MakeTestData(50, 100, sigma_quantile=8) 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_four_atoms(self): test_data = tt.MakeTestData(60, 100, sigma_quantile=8) 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_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_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_too_few_dimensions(self): s = hs.signals.Signal1D(np.random.rand(110)) y, x = np.mgrid[5:96:10, 5:96:10] x, y = x.flatten(), y.flatten() with pytest.raises(ValueError): integrate(s, x, y)