我有一些二维数据,特别是扫描的X光片。这些都有重叠点源暴露的测量。数据示例:http://i.stack.imgur.com/oawlU.png
我想通过拟合二维高斯函数和数据来找出峰值位置。我尝试过其他几种方法,也取得了一些成功,包括一种“星搜索”方法,它可以定位全局最大值,拟合高斯函数并减去它。循环这会发现所有的峰值都相当好,但它不稳定,也不太准确。我想使用star search输出作为匹配的第一个猜测,但是在实现scipy.optimize.curve_fit
时遇到了麻烦。在
我做了一个函数twoD_envelope
,它创建了从恒星搜索中找到的所有高斯人的二维包络。这将产生以下输出:http://i.stack.imgur.com/4KnpG.png
我的印象是我可以用它作为curve_fit
的初始猜测,但是我得到了以下TypeError
:
358802比数据的大小多1个,这是一个巨大的线索,但我不知道是什么问题!我是一个物理学家,有“实用”的编码知识,所以任何输入都是非常感谢的。在
代码如下。在
^{pr2}$(sq_image
是数据,是形状为(599,599)
的ndarray
)
(pars, xls, yxl
=star search的高斯拟合参数列表)
(makeGaussian
是在别处定义的函数)
你认为这是一个错误的结果。这可能会导致}(如果不能运行代码,很难判断)。根据文件,传递给曲线拟合的函数应
data
数组被解释为vars
,这将导致您看到的{您可能还需要在初始猜测之前使用一个星来将其作为元组传递,例如
pars_opt, pars_cov = opt.curve_fit(twoD_envelope, coords, data, p0=*initial_guess)
{1,可能有一个很好的高斯参数。在
一个可能解决你的问题可能是循环通过你的二维sq_图像,并使用一个单一的二维高斯拟合与每个初始参数从恒星搜索。。。在
编辑:代码适合高斯。在
在图像30155885所在的位置
请注意,只使用了图像数据的一个通道(您应该将数据数组替换为sq_image中的一个)。结果是
相关问题 更多 >
编程相关推荐