繁体   English   中英

将数据拟合到高斯轮廓

[英]Fitting data to a gaussian profile

我一直在尝试将高斯拟合到我的光谱中。 (强度v/s速度谱)

光谱

新的拟合谱

我使用以下代码将数据拟合到高斯轮廓。 但是,从结果中可以看出,拟合中仅包含一个数据点。 有什么我可以做的,以便我可以在高斯中包含更多点。

from numpy import exp, linspace, random
import matplotlib.pyplot as plt
def gaussian(x, amp, cen, wid):
    return amp * exp(-(x-cen)**2 / wid)

from scipy.optimize import curve_fit
x = velocity
y = data
print(x)
print(y)

init_vals = [0.00950554, 60000, 35]  # for [amp, cen, wid]
best_vals, covar = curve_fit(gaussian, x, y, p0=init_vals)
print(best_vals)
print(repr(covar))

ym = gaussian(x, best_vals[0], best_vals[1], best_vals[2])
fig = plt.figure()
ax = fig.add_subplot(211)
ax.plot(x,y)
ax = fig.add_subplot(212)
ax.plot(x, y, c='k', label='Function')
ax.plot(x, ym, c='r', label='Best fit')
plt.legend()
plt.show()

数据点:

x: [-5.99999993e+04 -4.99999993e+04 -3.99999993e+04 -2.99999993e+04
 -1.99999993e+04 -9.99999934e+03  6.65010004e-04  1.00000007e+04
  2.00000007e+04  3.00000007e+04  4.00000007e+04  5.00000007e+04
  6.00000007e+04  7.00000007e+04  8.00000007e+04  9.00000007e+04
  1.00000001e+05  1.10000001e+05  1.20000001e+05  1.30000001e+05
  1.40000001e+05]

y: [ 0.00056511 -0.00098584 -0.00325616 -0.00101042  0.00168894 -0.00097406
 -0.00134408  0.00128847 -0.00111633 -0.00151621  0.00299326  0.00916455
  0.00960554  0.00317363  0.00311124 -0.00080881  0.00215932  0.00596419
 -0.00192256 -0.00190138 -0.00013216]

这些是光谱的数据点。 任何人都可以帮助我更好地拟合数据。 我一直在尽我所能。

非常感谢。

第一步始终是 plot 数据,您已经这样做了。 接下来是猜测初始值。 如果与 plot 相比,用于ampcen的那些看起来很合理。 但是wid呢? 它是 SQUARED 分布宽度的 2 倍。 从 plot 开始,宽度本身必须在几千以上。 如果平方,它可能达到 10^7,乘以 2 得到 2*10^7 作为初始值。 离你的35很远!

一种可能的解决方案:

安培 = 0.0106283
岑 = 55784
宽度 = 1.92911e+08

Plot:

itting函数图

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM