I am writing a program in Python that will fit Gaussian and Lorentzian shapes to some given resonance data. I originally began using scipy.optimize.leastsq
but
The great thing about python is that you can define functions that return other functions, try currying:
def make_mix(numg):
def mix(x, *p):
ng = numg
p1 = p[:3*ng]
p2 = p[3*ng:]
a = sumarray(gaussian(x,p1),lorentzian(x,p2))
return a
return mix
and then
leastsq, covar = opt.curve_fit(make_mix(numg),energy,intensity,inputtot)