def iqdht(k: np.ndarray, f: np.ndarray, order: int = 0) -> Tuple[np.ndarray, np.ndarray]: """Perform a inverse quasi-discrete Hankel transform of the function ``f`` (sampled at points ``k``) and return the transformed function and its sample points in radial space. If you have the transform on a frequency axis (as opposed to a :math:`k`-axis), the :math:`k`-axis can be calculated using :math:`k = 2\\pi{}f`. .. warning:: This method is a convenience wrapper for :meth:`.HankelTransform.iqdht`, but incurs a significant overhead in calculating the :class:`.HankelTransform` object. If you are performing multiple transforms on the same grid, it will be much quicker to construct a single :class:`.HankelTransform` object and call :meth:`.HankelTransform.iqdht` multiple times. :param k: The :math:`k` coordinates at which the function is sampled :type k: :class:`numpy.ndarray` :param f: The value of the function to be transformed. :type f: :class:`numpy.ndarray` :param order: The order of the Hankel Transform to perform. Defaults to 0. :return: A tuple containing the radial coordinates of the transformed function and its values :rtype: (:class:`numpy.ndarray`, :class:`numpy.ndarray`) """ transformer = HankelTransform(order=order, k_grid=k) f_transform = transformer.to_transform_k(f) ht = transformer.iqdht(f_transform) return transformer.r, ht
def test_round_trip_k_interpolation(radius: np.ndarray, order: int, shape: Callable): k_grid = radius/10 transformer = HankelTransform(order=order, k_grid=k_grid) # the function must be smoothish for interpolation # to work. Random every point doesn't work func = shape(k_grid) transform_func = transformer.to_transform_k(func) reconstructed_func = transformer.to_original_k(transform_func) assert np.allclose(func, reconstructed_func, rtol=1e-4)
def test_round_trip_k_interpolation_2d(radius: np.ndarray, order: int, shape: Callable, axis: int): k_grid = radius / 10 transformer = HankelTransform(order=order, k_grid=k_grid) # the function must be smoothish for interpolation # to work. Random every point doesn't work dims_amplitude = np.ones(2, np.int) dims_amplitude[1 - axis] = 10 amplitude = np.random.random(dims_amplitude) dims_k = np.ones(2, np.int) dims_k[axis] = len(radius) func = np.reshape(shape(k_grid), dims_k) * np.reshape( amplitude, dims_amplitude) transform_func = transformer.to_transform_k(func, axis=axis) reconstructed_func = transformer.to_original_k(transform_func, axis=axis) assert np.allclose(func, reconstructed_func, rtol=1e-4)