如何在python(numpy/scipy)中的嘈杂数据集中找到峰的FWHM? [英] How can I find the FWHM of a peak in a noisy data set in python (numpy/scipy)?
问题描述
我正在分析两条交叉线(如+号)的图像,并提取与其中一条线垂直的像素线(nx1
numpy数组).这给了我一个可以绘制的浮点值数组(代表颜色).我正在使用matplotlib绘制数据,得到了180至200之间的一堆嘈杂数据,中间有一个明显的峰值,峰值下降到100左右.
I am analyzing an image of two crossing lines (like a + sign) and I am extracting a line of pixels (an nx1
numpy array) perpendicular to one of the lines. This gives me an array of floating point values (representing colors) that I can then plot. I am plotting the data with matplotlib and I get a bunch of noisy data between 180 and 200 with a distinct peak in the middle that spikes down to around 100.
我需要找到此数据的FWHM.我认为我需要首先过滤噪声,所以我使用了高斯滤波器,可以平滑我的数据,但是它的顶部仍然不是超级平坦.
I need to find FWHM of this data. I figured I needed to filter the noise first, so I used a gaussian filter, which smoothed out my data, but its still not super flat at the top.
-
我想知道是否有更好的方法来过滤数据.
I was wondering if there is a better way to filter the data.
如何找到此数据的FWHM?
How can I find the FWHM of this data?
如果可能的话,我只想使用numpy,scipy和matplotlib.
I would like to only use numpy, scipy, and matplotlib if possible.
以下是原始数据:
以下是过滤后的数据:
Here is the filtered data:
推荐答案
我最终没有使用任何过滤器,而是使用了原始数据. 我使用的过程是:
I ended up not using any filter, but rather used the original data. The procedure I used was:
- 找到最小和最大点并计算
difference = max(arr_y) - min(arr_y)
- 找到最大半数(在我的情况下是最小半个数)
HM = difference / 2
- 找到了距HM最近的数据点:
nearest = (np.abs(arr_y - HM)).argmin()
- 计算了最接近距离和最小值之间的距离(这给了我HWHM)
- 然后简单地乘以2即可得到FWHM
- Found the minimum and maximum points and calculated
difference = max(arr_y) - min(arr_y)
- Found the half max (in my case it is half min)
HM = difference / 2
- Found the nearest data point to HM:
nearest = (np.abs(arr_y - HM)).argmin()
- Calculated the distance between nearest and min (this gives me the HWHM)
- Then simply multiplied by 2 to get the FWHM
我不知道(或认为)这是最好的方法,但是它可以工作,并且根据比较似乎相当准确.
I don't know (or think) this is the best way, but it works and seems to be fairly accurate based on comparison.
这篇关于如何在python(numpy/scipy)中的嘈杂数据集中找到峰的FWHM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!