Handle poor Gaussian fitting
I have an imag that I have run the following code on:
seperation = 15
A_positions = am.get_atom_positions(seg, separation=seperation, pca=True)
sublattice_A = am.Sublattice(A_positions, image=seg.data, color='r')
sublattice_A.find_nearest_neighbors()
sublattice_A.refine_atom_positions_using_center_of_mass()
sublattice_A.refine_atom_positions_using_2d_gaussian()
Now if I image_without_A = remove_atoms_from_image_using_2d_gaussian(sublattice_A.image, sublattice_A, percent_to_nn=0.06)
or re-run sublattice_A.refine_atom_positions_using_2d_gaussian()
then I get the following error
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-14-ac1403da166b> in <module>()
----> 1 sublattice_A.refine_atom_positions_using_2d_gaussian()
~\Programs\Anaconda\envs\data-analysis\lib\site-packages\atomap\sublattice.py in refine_atom_positions_using_2d_gaussian(self, image_data, percent_to_nn, rotation_enabled, show_progressbar)
880 image_data,
881 rotation_enabled=rotation_enabled,
--> 882 percent_to_nn=percent_to_nn)
883
884 def refine_atom_positions_using_center_of_mass(
~\Programs\Anaconda\envs\data-analysis\lib\site-packages\atomap\atom_position.py in refine_position_using_2d_gaussian(self, image_data, rotation_enabled, percent_to_nn, centre_free)
356 rotation_enabled=True,
357 percent_to_nn=0.40,
--> 358 centre_free=True)
359
360 def get_center_position_com(
~\Programs\Anaconda\envs\data-analysis\lib\site-packages\atomap\atom_finding_refining.py in fit_atom_positions_gaussian(atom_list, image_data, rotation_enabled, percent_to_nn, mask_radius, centre_free)
800 mask_radius=mask_radius,
801 percent_to_nn=percent_to_nn,
--> 802 centre_free=centre_free)
803 if g_list is False:
804 if i == 9:
~\Programs\Anaconda\envs\data-analysis\lib\site-packages\atomap\atom_finding_refining.py in _fit_atom_positions_with_gaussian_model(atom_list, image_data, rotation_enabled, percent_to_nn, mask_radius, centre_free)
685 # If the Gaussian centre is located outside the masked region,
686 # return False
--> 687 inside_mask = mask[int(g.centre_y.value)][int(g.centre_x.value)]
688 if not inside_mask:
689 return(False)
IndexError: index 745 is out of bounds for axis 0 with size 682
A few other comments and I am not sure if they are related. Running image_without_A = remove_atoms_from_image_using_2d_gaussian(sublattice_A.image, sublattice_A, percent_to_nn=0.04)
with ercent_to_nn<0.05 leads to
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-0229f9c39d4d> in <module>()
1 from atomap.tools import remove_atoms_from_image_using_2d_gaussian
----> 2 image_without_A = remove_atoms_from_image_using_2d_gaussian(sublattice_A.image, sublattice_A, percent_to_nn=0.04)
~\Programs\Anaconda\envs\data-analysis\lib\site-packages\atomap\tools.py in remove_atoms_from_image_using_2d_gaussian(image, sublattice, percent_to_nn, show_progressbar)
97 image,
98 rotation_enabled=True,
---> 99 percent_to_nn=percent_distance)
100 if g_list is False:
101 if i == 9:
~\Programs\Anaconda\envs\data-analysis\lib\site-packages\atomap\atom_finding_refining.py in _fit_atom_positions_with_gaussian_model(atom_list, image_data, rotation_enabled, percent_to_nn, mask_radius, centre_free)
679 g.rotation.free = False
680
--> 681 model.fit()
682
683 gaussian_list = []
c:\users\owner\documents\github\hyperspy\hyperspy\model.py in fit(self, fitter, method, grad, bounded, ext_bounding, update_plot, **kwargs)
1079 leastsq(self._errfunc, self.p0[:], Dfun=jacobian,
1080 col_deriv=1, args=args, full_output=True,
-> 1081 **kwargs)
1082 self.p0, pcov = output[0:2]
1083
~\Programs\Anaconda\envs\data-analysis\lib\site-packages\scipy\optimize\minpack.py in leastsq(func, x0, args, Dfun, full_output, col_deriv, ftol, xtol, gtol, maxfev, epsfcn, factor, diag)
384 m = shape[0]
385 if n > m:
--> 386 raise TypeError('Improper input: N=%s must not exceed M=%s' % (n, m))
387 if epsfcn is None:
388 epsfcn = finfo(dtype).eps
TypeError: Improper input: N=6 must not exceed M=4