使用插值找出2D峰的x和y全角半最大值

时间:2018-08-21 17:23:39

标签: python python-3.x numpy interpolation spline

给定一个二维的numpy数据数组,我编写了在x和y方向上计算FWHM的代码。但是,我的方法非常简单,并且仅针对这些宽度返回整数值。如果可能的话,我想实现某种插值,以便获得宽度的精确浮点值。我已经看到了一些在1D中使用scipy样条插值的示例,但是我不确定如何将其扩展到2D。我对样条线的总体工作方式仍然有些困惑。下面是我的代码,其中包含一个简单的数据示例(尽管我的真实数据要大得多)。

import numpy as np

data = np.array([[1, 2, 5, 91, 27], [5, 41, 80, 66, 52], [56, 101, 122, 115, 9], [21, 55, 81, 5, 7], [90, 22, 37, 24, 2]])
amp = np.max(data)
ypix, xpix = np.where(data==amp)
x_range = np.take(data, ypix[0], axis=0)
print(x_range)
>>> [ 56 101 122 115   9]
y_range = np.take(data, xpix[0], axis=1)
print(y_range)
>>> [  5  80 122  81  37]

half_max = amp/2.0
d_x = x_range - half_max
d_y = y_range - half_max
indices_x = np.where(d_x>0)[0]
indices_y = np.where(d_y>0)[0]

# FMHM in x and y - simply counts how many pixels are within half the max in both directions
width_x = len(indices_x)
width_y = len(indices_y)

如何添加插值方法以使这些宽度更精确?任何帮助表示赞赏。谢谢!

0 个答案:

没有答案