Dear all,I have an absorption line data which I thought could be easily fitted with a simple 1D Gaussian function. For some reason, the lmfit does not seem to give any meaningful result. The initial values for the fit are being guessed from the data, but I feel that the guess that lmfit makes is incorrect. Here, the question that really puzzles me is when is it that lmfit can make a correct initial guess and in what circumstances it fails? I also tried setting the parameters manually closer to expected values but that too seems to fail. But that again begs the question as to how close should the initial guess be ?
I am attaching my python code as well as the figure and the data used in this example.I'll really appreciate it if someone could tell me what I am doing wrong....
#--------------------------------------------------------------
from lmfit.models import GaussianModel
import numpy as np
data = np.loadtxt('test.dat') # Load the test data
xx = data[:, 0] # read the x-column
yy = data[:, 1] # read the y-columns
model = GaussianModel () # initiate the Gaussian Model
params = model.guess(yy, x=xx) # guess the initial parameters
result = model.fit(yy, params, x=xx) # fit a 1D Gaussian to data
result.plot_fit() # display the data and the fit
#----------------------------------------------------------------------------------------------------
print (params)
Parameters([('amplitude', <Parameter 'amplitude', value=27.216, bounds=[-inf:inf]>), ('center', <Parameter 'center', value=5141.315789473684, bounds=[-inf:inf]>), ('sigma', <Parameter 'sigma', value=15.0, bounds=[0.0:inf]>), ('fwhm', <Parameter 'fwhm', value=35.3223, bounds=[-inf:inf], expr='2.3548200*sigma'>), ('height', <Parameter 'height', value=0.7238409091200001, bounds=[-inf:inf], expr='0.3989423*amplitude/max(2.220446049250313e-16, sigma)'>)])
-------------------------------------------------------------------------------------------------------------------
Thanks
With Best Wishes
Steve