【发布时间】:2017-10-11 09:40:18
【问题描述】:
我正在尝试使用 LMFIT 库进行多洛伦兹拟合, 但它不起作用,我什至明白我的语法 made 是完全错误的,但我没有任何新的想法。
我的问题是:我的光谱很长,有多组 峰值,但在这些集合中峰值的数量不是恒定的,所以 有时我只有 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 数组的数据。
【问题讨论】: