Hankel-Like Transforms (transforms)#

Added in version 0.4.6.

Perform Hankel-like transforms in 1- and 2-d.

SphericalBesselTransform(degree, bias, ...)

Spherical Bessel Transform.

DoubleSphericalBesselTransform(degrees, ...)

Double spherical Bessel Transform.

resample_lglin(sampts, samples[, size, spline])

Resample at logarithmically spaced sample points in 1- or 2-d.

resample_lin(sampts, samples[, size, spline])

Resample at linearly spaced sample points in 1- or 2-d.

class triumvirate.transforms.SphericalBesselTransform(degree, bias, sample_pts, pivot=1.0, lowring=True, extrap=0, extrap_exp=2.0, extrap_layer='outer', threaded=False)[source]#

Bases: object

Spherical Bessel Transform.

Parameters:
  • degree (int) – Degree of the spherical Bessel transform.

  • bias (int) – Power-law bias index.

  • sample_pts (array of float) – Pre-transform sample points in 1-d. Must be logarithmically spaced. Must be even in length if extrapolation is used.

  • pivot (float, optional) – Pivot value (default is 1.). When lowring is True, this is adjusted if it is non-zero, or otherwise directly calculated.

  • lowring (bool, optional) – Low-ringing condition (default is True).

  • extrap (int, optional) – Extrapolation method (default is 0) with the following options:

    • 0: none;

    • 1: extrapolate by zero padding;

    • 2: extrapolate by constant padding;

    • 3: extrapolate linearly;

    • 4: extrapolate log-linearly;

    • 5: extrapolate log-linearly with oscillatory behaviour.

    Any extrapolation results in a sample size for the transform that is the smallest power of 2 greater than or equal to extrap_exp times the original number of sample points; the pre-transform samples are assumed to be real.

  • extrap_exp (float, optional) – Sample size expansion factor (default is 2.) for extrapolation. The smallest power of 2 greater than or equal to this times the original number of sample points is used as the sample size for the transform.

  • extrap_layer ({‘native’, ‘outer’}, optional) – Extrapolation layer:

    • ‘native’: extrapolate the samples, including any pre-factors, within the underlying FFTLog algorithm;

    • ‘outer’ (default): extrapolate the samples, excluding any pre-factors, before passing them to the underlying FFTLog algorithm.

  • threaded (bool, optional) – If True (default is False), use the multi-threaded FFTLog algorithm.

Variables:
  • degree (int) – Degree of the spherical Bessel transform.

  • bias (int) – Power-law bias index.

  • size (int) – Sample size.

  • pivot (float) – Pivot value used.

Raises:
  • ValueError – When extrap is not a supported option.

  • ValueError – When the input sample size is not even and extrapolation is used.

property size#

Sample size of the transform.

Return type:

int

property pivot#

Pivot value.

Return type:

float

transform(pre_samples)[source]#

Transform samples at initialised sample points.

Parameters:

pre_samples (array_like) – Pre-transform samples in 1-d. Assumed to be real if extrapolation is used.

Returns:

post_sampts, post_samples – Post-transform sample points and samples.

Return type:

array_like

transform_cosmo_multipoles(direction, pre_samples)[source]#

Transform cosmological multipoles between configuration and Fourier spaces.

Parameters:
  • direction ({‘forward’, ‘backward’, 1, -1}) – Transform direction: ‘forward’ or 1 from configuration to Fourier space, ‘backward’ or -1 from Fourier to configuration space.

  • pre_samples (array of float) – Pre-transform samples in 1-d. Assumed to be real if extrapolation is used.

Returns:

post_sampts, post_samples – Post-transform sample points and samples.

Return type:

array of float

class triumvirate.transforms.DoubleSphericalBesselTransform(degrees, biases, sample_pts, pivot=1.0, lowring=True, extrap=0, extrap_exp=2.0, extrap2d=False, threaded=False)[source]#

Bases: object

Double spherical Bessel Transform.

Parameters:
  • degrees ((int, int)) – Degrees of the double spherical Bessel transform.

  • biases ((int, int)) – Power-law bias indices.

  • sample_pts (array of float) – Pre-transform sample points in 1-d for both dimensions. Must be logarithmically spaced. Must be even in length if extrapolation is used.

  • pivot (float, optional) – Pivot value (default is 1.). When lowring is True, this is adjusted if it is non-zero, or otherwise directly calculated.

  • lowring (bool, optional) – Low-ringing condition (default is True).

  • extrap (int or tuple of int, optional) – Extrapolation method for both or each dimension(s) (default is 0) with the following options:

    • 0: none;

    • 1: extrapolate by zero padding;

    • 2: extrapolate by constant padding;

    • 3: extrapolate linearly;

    • 4: extrapolate log-linearly;

    • 5: extrapolate log-linearly with oscillatory behaviour.

    Any extrapolation results in a sample size for the transform that is the smallest power of 2 greater than or equal to extrap_exp times the original number of sample points; the pre-transform samples are assumed to be real.

  • extrap_exp (float, optional) – Sample size expansion factor (default is 2.) for extrapolation. The smallest power of 2 greater than or equal to this times the original number of sample points is used as the sample size for the transform.

  • extrap2d (bool, optional) – If True (default is False), perform 2-d extrapolation pre-transform excluding any pre-factors; otherwise, perform 1-d extrapolation including any pre-factors within the underlying FFTLog algorithm.

  • threaded (bool, optional) – If True (default is False), use the multi-threaded FFTLog algorithm.

Variables:
  • degrees ((int, int)) – Degrees of the spherical Bessel transform.

  • biases ((int, int)) – Power-law bias indices.

  • size (int) – Sample size for either dimension.

  • pivot ((float, float)) – Pivot values used for both dimensions.

Raises:
  • ValueError – When extrap is not a supported option.

  • ValueError – When the input sample size is not even and extrapolation is used.

property size#

Sample size of the transform for either dimension.

Return type:

int

property pivot#

Pivot values for both dimensions.

Return type:

tuple of float

transform(pre_samples)[source]#

Transform samples at initialised sample points.

Parameters:

pre_samples (array_like) – Pre-transform samples in 2-d. Assumed to be real if extrapolation is used.

Returns:

post_sampts, post_samples – Post-transform sample points and samples in 2-d, with post_sampts in numpy.meshgrid() ‘ij’-indexing format.

Return type:

array_like

transform_cosmo_multipoles(direction, pre_samples)[source]#

Transform cosmological multipoles between configuration and Fourier spaces.

Parameters:
  • direction ({‘forward’, ‘backward’, 1, -1}) – Transform direction: ‘forward’ or 1 from configuration to Fourier space, ‘backward’ or -1 from Fourier to configuration space.

  • pre_samples (array of float) – Pre-transform samples in 2-d. Assumed to be real if extrapolation is used.

Returns:

post_sampts, post_samples – Post-transform sample points and samples in 2-d, with post_sampts in numpy.meshgrid() ‘ij’-indexing format.

Return type:

array of float

triumvirate.transforms.resample_lglin(sampts, samples, size=None, spline=3)[source]#

Resample at logarithmically spaced sample points in 1- or 2-d.

Parameters:
  • sampts (array_like or sequence of array_like) – Original sample points (1-d in each dimension).

  • samples (array_like) – Original samples in 1-d or 2-d.

  • size (int or sequence of int, optional) – Size of the interpolated samples. If None (default), the size is kept the same as the original samples.

  • spline (int, optional) – Degree of the interpolation spline (default is 3).

Returns:

  • resampts ((2-tuple of) numpy.ndarray) – Logarithmically spaced sample points (1-d for each dimension) in the original range(s).

  • resamples (numpy.ndarray) – Interpolated samples.

Examples

Resample a 2-d function:

>>> def f(x, y): return np.exp(-x*np.sqrt(y))
>>> sampts = 1.e-3 * np.arange(1., 51.)
>>> samples = f(*np.meshgrid(sampts, sampts, indexing='ij'))
>>> resampts, resamples = resample_lglin(sampts, samples, size=10)

Check that the resampling is accurate:

>>> resamples_expected = f(
...     *np.meshgrid(resampts[0], resampts[-1], indexing='ij')
... )
>>> print(
...     "Resampling is accurate:",
...     np.allclose(resamples, resamples_expected)
... )
Resampling is accurate: True
triumvirate.transforms.resample_lin(sampts, samples, size=None, spline=3)[source]#

Resample at linearly spaced sample points in 1- or 2-d.

Parameters:
  • sampts (array_like or sequence of array_like) – Original sample points (1-d in each dimension).

  • samples (array_like) – Original samples in 1-d or 2-d.

  • size (int or sequence of int, optional) – Size of the interpolated samples. If None (default), the size is kept the same as the original samples.

  • spline (int, optional) – Degree of the interpolation spline (default is 3).

Returns:

  • resampts ((2-tuple of) numpy.ndarray) – Linearly spaced sample points (1-d for each dimension) in the original range(s).

  • resamples (numpy.ndarray) – Interpolated samples.

Examples

Resample a 2-d function:

>>> def f(x, y): return np.exp(-x*np.sqrt(y))
>>> sampts = 1.e-3 * np.arange(1., 51.)
>>> samples = f(*np.meshgrid(sampts, sampts, indexing='ij'))
>>> resampts, resamples = resample_lin(sampts, samples, size=10)

Check that the resampling is accurate:

>>> resamples_expected = f(
...     *np.meshgrid(resampts[0], resampts[-1], indexing='ij')
... )
>>> print(
...     "Resampling is accurate:",
...     np.allclose(resamples, resamples_expected)
... )
Resampling is accurate: True