Python:一维数组的快速汉克尔变换
Python: Fast Hankel Transform for 1d array
我正在尝试在 Python 中找到 Hankel 变换的任何现有实现(实际上我更喜欢两个 2d 径向对称函数的对称傅立叶变换,但它可以很容易地简化为 hankel 变换)。
我知道 hankel
python 模块,但它需要 lambda 函数作为输入,而我只有一维数组。
有什么想法吗?
如果您阅读 Hankel all the way through the Transforms section you will see that to perform the transformation you call hankel.transform(function, array, ret_err=bool)
so you just need the function for whatever form of the transformation you require. I believe there is a list of transformation functions in the Wikipedia entry for Hankel Transformation 的文档。
我是 hankel 的作者。虽然我不建议在这种情况下使用我的代码(因为正如你提到的,它需要一个可调用的输入函数,其目的是准确计算积分,而不是做 DHT),我会说它 是可能的。
您需要做的就是对输入的一维数组进行插值。如何做到这一点取决于您,但通常像下面这样的东西效果很好:
from scipy.interpolate import InterpolatedUnivariateSpline as Spline
import numpy as np
x, y = # Import/create data vectors
# Do this if y is both negative and positive
fnc = Spline(x,y, k=1) #I usually choose k=1 in case anything gets extrapolated.
# Otherwise do this
spl = Spline(np.log(x), np.log(y), k=1)
fnc = lambda x : np.exp(spl(np.log(x)))
# Continue as normal with hankel.transform(fnc, kvec)
这样做的一个大问题是选择参数 N
和 h
,这样变换就可以很好地近似于 kvec
中 k
的所有值。如果 kvec
跨越宽动态范围,那么 hankel
效率非常低,因为它对转换中的每个 k
使用相同的底层数组(长度 N
),这意味着最困难 k
设置性能级别。
所以,简而言之,我不会推荐 hankel
,但如果您找不到其他任何东西,它仍然可以工作 ;-)
我的一个朋友在 Python 中寻找 Hankel 变换,在确定没有可用的东西之后 - 部分是基于这个问题的答案 - 找我分享我的。
这个包执行 Quasi-discrete Hankel 变换,按照原始问题的要求(如果几年太晚了!)但希望这个答案能将发现这个问题的未来用户(比如我的朋友)引导到正确的地方。
我正在尝试在 Python 中找到 Hankel 变换的任何现有实现(实际上我更喜欢两个 2d 径向对称函数的对称傅立叶变换,但它可以很容易地简化为 hankel 变换)。
我知道 hankel
python 模块,但它需要 lambda 函数作为输入,而我只有一维数组。
有什么想法吗?
如果您阅读 Hankel all the way through the Transforms section you will see that to perform the transformation you call hankel.transform(function, array, ret_err=bool)
so you just need the function for whatever form of the transformation you require. I believe there is a list of transformation functions in the Wikipedia entry for Hankel Transformation 的文档。
我是 hankel 的作者。虽然我不建议在这种情况下使用我的代码(因为正如你提到的,它需要一个可调用的输入函数,其目的是准确计算积分,而不是做 DHT),我会说它 是可能的。
您需要做的就是对输入的一维数组进行插值。如何做到这一点取决于您,但通常像下面这样的东西效果很好:
from scipy.interpolate import InterpolatedUnivariateSpline as Spline
import numpy as np
x, y = # Import/create data vectors
# Do this if y is both negative and positive
fnc = Spline(x,y, k=1) #I usually choose k=1 in case anything gets extrapolated.
# Otherwise do this
spl = Spline(np.log(x), np.log(y), k=1)
fnc = lambda x : np.exp(spl(np.log(x)))
# Continue as normal with hankel.transform(fnc, kvec)
这样做的一个大问题是选择参数 N
和 h
,这样变换就可以很好地近似于 kvec
中 k
的所有值。如果 kvec
跨越宽动态范围,那么 hankel
效率非常低,因为它对转换中的每个 k
使用相同的底层数组(长度 N
),这意味着最困难 k
设置性能级别。
所以,简而言之,我不会推荐 hankel
,但如果您找不到其他任何东西,它仍然可以工作 ;-)
我的一个朋友在 Python 中寻找 Hankel 变换,在确定没有可用的东西之后 - 部分是基于这个问题的答案 - 找我分享我的。
这个包执行 Quasi-discrete Hankel 变换,按照原始问题的要求(如果几年太晚了!)但希望这个答案能将发现这个问题的未来用户(比如我的朋友)引导到正确的地方。