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', out_shape=None)¶ 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
out_shape (tuple) – output shape for the array. Overrides Q if given. in_shape * Q ~= out_shape (up to integer rounding)
- Returns
padded array, may share memory with input array
- Return type
numpy.ndarray
Notes
padding will be symmetric.
-
prysm.fttools.
crop_center
(img, out_shape)¶ Crop the central (out_shape) of an image, with FFT alignment.
As an example, if img=512x512 and out_shape=200 out_shape => 200x200 and the returned array is 200x200, 156 elements from the [0,0]th pixel
This function is the adjoint of pad2d.
- Parameters
img (numpy.ndarray) – ndarray of shape (m, n)
out_shape (int or iterable of int) – shape to crop out, either a scalar or pair of values
-
prysm.fttools.
forward_ft_unit
(dx, samples, shift=True)¶ Compute the units resulting from a fourier transform.
- Parameters
dx (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)¶ 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.
- 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)¶ 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.
- 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.
-