def test_wrong_input_none_mask_radius_percent_to_nn(self): sublattice = self.sublattice with pytest.raises(ValueError): afr.fit_atom_positions_gaussian(sublattice.atom_list, sublattice.image, percent_to_nn=None, mask_radius=None)
def test_one_atoms(self): sublattice = self.sublattice atom_index = 55 atom_list = [sublattice.atom_list[atom_index]] image_data = sublattice.image afr.fit_atom_positions_gaussian(atom_list, image_data) assert_allclose(sublattice.atom_list[atom_index].pixel_x, self.x[atom_index], rtol=1e-7) assert_allclose(sublattice.atom_list[atom_index].pixel_y, self.y[atom_index], rtol=1e-7)
def test_nine_atoms(self): sublattice = self.sublattice atom_indices = [34, 35, 36, 44, 45, 46, 54, 55, 56] atom_list = [] for index in atom_indices: atom_list.append(sublattice.atom_list[index]) image_data = sublattice.image afr.fit_atom_positions_gaussian(atom_list, image_data) for atom_index in atom_indices: assert_allclose(sublattice.atom_list[atom_index].pixel_x, self.x[atom_index], rtol=1e-7) assert_allclose(sublattice.atom_list[atom_index].pixel_y, self.y[atom_index], rtol=1e-7)
def refine_position_gaussian(self, image=None, show_progressbar=True): """ Parameters ---------- image : NumPy 2D array, optional show_progressbar : bool, default True """ if image is None: image = self.image0 n_tot = len(self.sublattice_list[0].atom_list) for i_atom in trange( n_tot, desc="Gaussian fitting", disable=not show_progressbar): atom_list = [] for sublattice in self.sublattice_list: atom_list.append(sublattice.atom_list[i_atom]) fit_atom_positions_gaussian( atom_list, image)
def refine_position_using_2d_gaussian( self, image_data, rotation_enabled=True, percent_to_nn=0.40, mask_radius=None, centre_free=True): """ Use 2D Gaussian to refine the parameters of the atom position. Parameters ---------- image_data : Numpy 2D array rotation_enabled : bool, optional If True, the Gaussian will be able to rotate. Note, this can increase the chance of fitting failure. Default True. percent_to_nn : float, optional The percent of the distance to the nearest neighbor atom in the same sub lattice. The distance times this percentage defines the mask around the atom where the Gaussian will be fitted. A smaller value can reduce the effect from neighboring atoms, but might also decrease the accuracy of the fitting due to less data to fit to. Default 0.4 (40%). mask_radius : float, optional Radius of the mask around each atom. If this is not set, the radius will be the distance to the nearest atom in the same sublattice times the `percent_to_nn` value. Note: if `mask_radius` is not specified, the Atom_Position objects must have a populated nearest_neighbor_list. centre_free : bool, default True If True, the centre parameter will be free, meaning that the Gaussian can move. """ fit_atom_positions_gaussian( [self], image_data=image_data, rotation_enabled=rotation_enabled, percent_to_nn=percent_to_nn, mask_radius=mask_radius, centre_free=centre_free)
def refine_position_gaussian(self, image=None, show_progressbar=True, percent_to_nn=0.40, mask_radius=None): """Fit several atoms at the same time. For datasets where the atoms are too close together to do the fitting individually. Parameters ---------- image : NumPy 2D array, optional show_progressbar : bool, default True percent_to_nn : scalar Default 0.4 mask_radius : float, optional Radius of the mask around each atom. If this is not set, the radius will be the distance to the nearest atom in the same sublattice times the `percent_to_nn` value. Note: if `mask_radius` is not specified, the Atom_Position objects must have a populated nearest_neighbor_list. This is normally done through the sublattice class, but can also be done manually. Examples -------- >>> dl = am.dummy_data.get_dumbbell_heterostructure_dumbbell_lattice() >>> dl.refine_position_gaussian(show_progressbar=False) """ if image is None: if self.original_image is None: image = self.image else: image = self.original_image n_tot = len(self.sublattice_list[0].atom_list) for i_atom in progressbar(range(n_tot), desc="Gaussian fitting", disable=not show_progressbar): atom_list = [] for sublattice in self.sublattice_list: atom_list.append(sublattice.atom_list[i_atom]) afr.fit_atom_positions_gaussian( atom_list, image, percent_to_nn=percent_to_nn, mask_radius=mask_radius)