0

I am trying to fit a Voigt profile to emission line spectrum using scipy.optimize.curve_fit.

  1. I don't understand how to define initial guesses
  2. The data contains more than one emission lines merged together. I also want to deconvolute the data.

Can anyone tell me how to define the initial guesses and how to deconvolute the emission lines. I am interested in the middle one.

the data fitted with voigt

Here's my code for single Voigt profile fitting

#initial guesses
amp1 = max(y)
amp2 = max(y)
cen1 = 6565
cen2 = 6565
sigma = 10
wid = max(x) - min(x)
def voigt(x, amp1, cen1, sigma, amp2, cen2, wid):
    return (amp1*(1/(sigma*(np.sqrt(2*np.pi))))*(np.exp(-((x-cen1)**2)/((2*sigma)**2)))) +\
              ((amp2*wid**2/((x-cen2)**2+wid**2)) )
              
popt_voigt,pcov_voigt=scipy.optimize.curve_fit(voigt, x, y, p0 = [amp1,cen1,sigma,amp2,cen2,wid])
perr_voigt = np.sqrt(np.diag(pcov_voigt))
  • Note that there is `scipy.special.voigt_profile`, so you do not need an approximation. (if not available in your version yo can go via the Faddeeva function) Second, as there are multiple peaks you need a wrapper that can handle more than one peak ( is it fix, n=3 or variable?). Finally, you should start with `scipy.signal.find_peaks` to get the peak positions. It also helps to get a guess for the height. – mikuszefski Sep 23 '20 at 08:15
  • You might want to look [here](https://stackoverflow.com/q/61657107/803359) as well. – mikuszefski Sep 24 '20 at 06:54
  • I realized later it had more peaks. therefore the code wasn't performing the fit properly. Thanks for pointing it out. – Adnan Mirza Sep 25 '20 at 15:18

1 Answers1

1

Generally, this is good idea to fix the maximum width of your Voigt profiles, specially when you have overlap between them. To do that, use the parameter "bounds" for example. Bonus: To help scipy in fitting process, you can try to normalize your data and reduce the background here.

JohnB
  • 71
  • 2