Python基线校正库 [英] Python baseline correction library

查看:388
本文介绍了Python基线校正库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在处理一些拉曼光谱数据,并且试图纠正由于荧光偏斜引起的数据.看看下面的图:

I am currently working with some Raman Spectra data, and I am trying to correct my data caused by florescence skewing. Take a look at the graph below:

我非常接近实现自己想要的目标.如您所见,我正在尝试在所有数据中拟合多项式,而实际上我应该只在局部极小值处拟合多项式.

I am pretty close to achieving what I want. As you can see, I am trying to fit a polynomial in all my data whereas I should really just be fitting a polynomial at the local minimas.

理想情况下,我希望有一个多项式拟合,当从原始数据中减去该多项式拟合时,结果将是这样的:

Ideally I would want to have a polynomial fitting which when subtracted from my original data would result in something like this:

是否已经有内置库执行此操作?

Are there any built in libs that does this already?

如果没有,可以给我推荐一种简单的算法吗?

If not, any simple algorithm one can recommend for me?

推荐答案

我找到了我的问题的答案,只是分享给那些偶然发现此问题的人.

I found an answer to my question, just sharing for everyone who stumbles upon this.

P.Eilers和H. Boelens在2005年提出了一种称为非对称最小二乘平滑"的算法.该论文是免费的,您可以在Google上找到它.

There is an algorithm called "Asymmetric Least Squares Smoothing" by P. Eilers and H. Boelens in 2005. The paper is free and you can find it on google.

def baseline_als(y, lam, p, niter=10):
  L = len(y)
  D = sparse.csc_matrix(np.diff(np.eye(L), 2))
  w = np.ones(L)
  for i in xrange(niter):
    W = sparse.spdiags(w, 0, L, L)
    Z = W + lam * D.dot(D.transpose())
    z = spsolve(Z, w*y)
    w = p * (y > z) + (1-p) * (y < z)
  return z

这篇关于Python基线校正库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆