且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Python中将多个高斯曲线拟合到质谱数据?

更新时间:2022-03-17 03:49:28

您可能会找到lmfit模块( https://lmfit.github.io/lmfit-py/)很有帮助.这提供了一个预先构建的GaussianModel类,用于将峰拟合到单个Gaussian,并支持将多个Model(不一定是Gaussians,而且还包括其他峰模型和其他可能对背景有用的函数)添加到可以合并的复合模型中.立刻适应.

You may find the lmfit module (https://lmfit.github.io/lmfit-py/) helpful. This provides a pre-built GaussianModel class for fitting a peak to a single Gaussian and supports adding multiple Models (not necessarily Gaussians, but also other peak models and other functions that might be useful for backgrounds and so for) into a composite model that can be fit at once.

Lmfit支持固定或给某些参数指定范围,因此您可以将模型建立为具有固定位置的高斯之和,从而将质心的值限制为在一定范围内变化(这样就不会混淆峰).此外,您可以对参数值施加简单的数学约束,以便可能要求所有峰宽均具有相同的大小(或以某种简单形式相关).

Lmfit supports fixing or giving a range to some Parameters, so that you could build a model as a sum of Gaussians with fixed positions, limiting the value for the centroid to vary with some range (so the peaks cannot get confused). In addition, you can impose simple mathematical constraints on parameter values, so that you might require that all peak widths are the same size (or related in some simple form).

尤其是,您可能会想到 https://lmfit.github.io/lmfit-py/builtin_models.html#example-3-fitting-multiple-peaks-and-using-prefixes 的示例,使用2高斯和背景函数.

In particular, you might look to https://lmfit.github.io/lmfit-py/builtin_models.html#example-3-fitting-multiple-peaks-and-using-prefixes for an example a fit using 2 Gaussians and a background function.

对于峰发现,我发现scipy.signal.find_peaks_cwt很好.

For peak finding, I've found scipy.signal.find_peaks_cwt to be pretty good.