Sorry for not clarifying the problem, i'm a masters student not experienced in programming.
My question is " i want to fit multi-Gaussian components to my continuum normalized data with picks at 5875, 5890, and 5896 angstrom where sigma of 5890 and 5896 has to be the same.
By setting initial parameter of amplitude and fit i get output amplitude which is measured from 0 not from 1(continuum level), i would like to know how i can fix the amplitude to be measured from 1. The attached is data.
thank you.
import matplotlib.pyplot as plt
from numpy import exp, loadtxt, pi, sqrt
from lmfit import Model, Parameters
data = loadtxt('Data.txt')
x = data[:, 0]
y = data[:, 1]
#selected region for fitting
mask = (x>= 5875) & (x <= 5910)
mask = (x>= 5850) & (x <= 5950)
xarray, yarray = x[mask], y[mask]
x=xarray
y=yarray
#defining a multi-Gaussian components function
def gaussian(x, amp1, cen1, wid1, amp2, cen2, wid2, amp3, cen3, wid3):
g1=(amp1 / (sqrt(2*pi) * wid1)) * exp(-(x-cen1)**2 / (2*wid2**2))
g2=(amp2 / (sqrt(2*pi) * wid2)) * exp(-(x-cen2)**2 / (2*wid2**2))
g3=(amp3 / (sqrt(2*pi) * wid3)) * exp(-(x-cen3)**2 / (2*wid3**2))
return g1+g2+g3
gmodel = Model(gaussian)
params = Parameters()
params.add('amp1', vale=0.8, min=0.7, max=0.3)
params.add('cen1', vale=5890, min=5887, max=5894)
params.add('wid1', vale=3.0 , min=1, max=4)
params.add('amp2', vale=0.9, min=1, max=0.7)
params.add('cen2', vale=5896, min=5891, max=5902)
params.add('wid2', vale=3.0 , min=2, max=4)
params.add('amp3', vale=1.06, min=1, max=1.7)
params.add('cen3', vale=5875, min=5870, max=5890)
params.add('wid3', vale=3.0 , min=2, max=4)
result = gmodel.fit(y, params, x=x)
print(result.fit_report())
plt.plot(x, y, 'b', label='observed')
plt.ylim(ymin=-1, ymax=1.5)
plt.plot(x, result.best_fit, 'r-', label='best fit')
plt.xlabel('wavelength[$\AA$]')
plt.ylabel('flux[erg cm-2 s-1 $\AA$ -1]')
plt.legend(loc='best')
plt.savefig('NaID-He.pdf')
plt.show()