我正在尝试使用 LMFIT 库进行多洛伦兹拟合,但它不起作用,我什至明白我所做的语法完全错误,但我没有任何新想法。
我的问题是:我的光谱很长,有多组峰,但这些组中的峰数不是恒定的,所以有时我只有 1 个峰,但有时我可能有 8 个甚至 20 个。
#function definition:
def Lorentzian(x, amp, cen, wid, n):
f = 0
for i in range( int(n) ):
"lorentzian function: wid = half-width at half-max"
f += (amp[i]/(1 + ((x-cen[i])/wid[i])**2))
return f
#library import and model definition:
import lmfit as lf
lmodel = lf.Model(Lorentzian)
#The initial parameters for the model:
peaks_in_interval = np.array([2378, 2493, 2525, 2630, 2769])
number_of_peaks = len(peaks_in_interval)
amplitude = width = np.zeros( number_of_peaks ) + 1
center = x[peaks_in_interval]
params = lmodel.make_params(x = x, amp = amplitude, cen = center, wid = width, n = number_of_peaks)
#This is the line that doesn't work:
result = lmodel.fit( y, params, x = x )
我已经开始尝试制作一个返回多洛伦兹函数的通用函数,但我正在努力解决如何使其工作......
我也在发送 x, y 数组的数据。