蓝色曲线是原始数据,绿色曲线是仅第二个最大值的高斯拟合,黄色曲线是两个最大值的高斯组合。上下文:
yraw
是列表中的原始数据,xpixel
是x轴(500-1250)
这是我的高斯方法:
def Gauss(x, amp, mu, sigma):
return amp*np.exp(-((x-mu)/(np.sqrt(2)*sigma))**2)
def bimode(x, amp1, mu1, sigma1, amp2, mu2, sigma2):
return Gauss(x, amp1, mu1, sigma1) + Gauss(x, amp2, mu2, sigma2)
ypg1 = np.asarray(yraw) #make np array from raw data list
parameters, covarience = curve_fit(bimode, xpixel, ypg1, p0 = (78, 805, 15, 8, 950, 15)) #does a curve fit for our gauss function. we give it an initial guess of amplitude, mean value (95,000)
#parameters returns amp, mu, sig, amp, mu, sig
print(parameters)
ygauss = bimode(xpixel, parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5])
我期待从双高斯曲线拟合出一个很好的曲线来包络两个最大值。
让我们创建一些数据集:
import numpy as np
import matplotlib.pyplot as plt
from scipy import optimize, stats
from pybaselines import Baseline, utils
p0 = (78, 810, 20, 8, 940, 20)
np.random.seed(12345)
x = np.linspace(500, 1250, 300)
y = model(x, *p0)
n = stats.gamma.rvs(a=1, size=y.size)
baseline = peak(x, 10, 850, 100)
yn = y + n + baseline
现在删除基线:
fitter = Baseline(x)
background = fitter.noise_median(yn)[0]
ynb = yn - background
并且适合:
popt, pcov = optimize.curve_fit(
model, x, ynb, p0=(100, 800, 10, 10, 950, 10)
)
两个峰值都可以找到: