prysm.fttools

Supplimental tools for computing fourier transforms.

prysm.fttools.fftrange(n, dtype=None)

FFT-aligned coordinate grid for n samples.

prysm.fttools.pad2d(array, Q=2, value=0, mode='constant')

Symmetrically pads a 2D array with a value.

Parameters
  • array (numpy.ndarray) – source array

  • Q (float, optional) – oversampling factor; ratio of input to output array widths

  • value (float, optioanl) – value with which to pad the array

  • mode (str, optional) – mode, passed directly to np.pad

Returns

padded array

Return type

numpy.ndarray

Notes

padding will be symmetric.

prysm.fttools.forward_ft_unit(sample_spacing, samples, shift=True)

Compute the units resulting from a fourier transform.

Parameters
  • sample_spacing (float) – center-to-center spacing of samples in an array

  • samples (int) – number of samples in the data

  • shift (bool, optional) – whether to shift the output. If True, first element is a negative freq if False, first element is 0 freq.

Returns

array of sample frequencies in the output of an fft

Return type

numpy.ndarray

class prysm.fttools.MatrixDFTExecutor

Bases: object

MatrixDFTExecutor is an engine for performing matrix triple product DFTs as fast as possible.

dft2(ary, Q, samples, shift=None, norm=True)

Compute the two dimensional Discrete Fourier Transform of a matrix.

Parameters
  • ary (numpy.ndarray) – an array, 2D, real or complex. Not fftshifted.

  • Q (float) – oversampling / padding factor to mimic an FFT. If Q=2, Nyquist sampled

  • samples (int or Iterable) – number of samples in the output plane. If an int, used for both dimensions. If an iterable, used for each dim

  • shift (float, optional) – shift of the output domain, as a frequency. Same broadcast rules apply as with samples.

  • norm (bool, optional) – if True, normalize the computation such that Parseval’s theorm is not violated

Returns

2D array containing the shifted transform. Equivalent to ifftshift(fft2(fftshift(ary))) modulo output sampling/grid differences

Return type

numpy.ndarray

idft2(ary, Q, samples, shift=None, norm=True)

Compute the two dimensional inverse Discrete Fourier Transform of a matrix.

Parameters
  • ary (numpy.ndarray) – an array, 2D, real or complex. Not fftshifted.

  • Q (float) – oversampling / padding factor to mimic an FFT. If Q=2, Nyquist sampled

  • samples (int or Iterable) – number of samples in the output plane. If an int, used for both dimensions. If an iterable, used for each dim

  • shift (float, optional) – shift of the output domain, as a frequency. Same broadcast rules apply as with samples.

  • norm (bool, optional) – if True, normalize the computation such that Parseval’s theorm is not violated

Returns

2D array containing the shifted transform. Equivalent to ifftshift(ifft2(fftshift(ary))) modulo output sampling/grid differences

Return type

numpy.ndarray

clear()

Empty the internal caches to release memory.

nbytes()

Total size in memory of the cache in bytes.