我想用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数组的数据。在
dataset for x and y
您应该能够使用内置模型并使用manual中描述的前缀。此外,最近有一个关于mailinglist的非常相似的话题的讨论。在
你可以做如下所示的事情。它还不能很好地适应上一个峰值,但是你可以稍微改变一下起始值之类的。此外,由于基线不是完全平坦的,使用
LinearModel
代替ConstantModel
可能会有所改善,但我没有尝试过。在相关问题 更多 >
编程相关推荐