oimFTBackends
The oimBackends.py module contains the backends for Fast-Fourier Transform computation used in all model components derived from the oimImageComponent semi-abstract component. This include most of the 2D-image-defined component. The varoius FFT backends are static classes with three methods:
check: is called each time the componentgetComplexCoherentFluxmethod is called. It checks if the backend is ready to perform the FFTpepare: is called only if the check method returned False.It prepares the backends and the return various data relative to the preparationcompute: is finally called when the backend is ready to compute the FFT and return the complexCoherentFlux.
Classes:
Default FFT backend using the numpy np.fft.fft2 function. |
|
FFT backend based on the python implementation of FFTW library. |
|
DFT backend using the numpy |
- class oimodeler.oimFTBackends.numpyFFTBackend
Default FFT backend using the numpy np.fft.fft2 function.
Empty
checkandpreparemethods. interpolation of the FFT done with scipy.interpolate.interpn in thecomputemethod.- check(backendPreparation: bool, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) bool
Checks if the backend is ready to compute the FFT.
In the case of the simple numpy FFT backend no preparation are needed. Always return True
- Parameters:
backendPreparation (bool) – The FFTBackendPreparation structure. Always True for the numpy backend.
im (numpy.ndarray) – 4D image (t,wl,x,y) to be FFTed.
pix (float) – pixel size of the image in rad.
wlin (numpy.ndarray) – the input wavelength vector of the image.
tin (numpy.ndarray) – the input time vector of the image.
ucoord (array_like) – the u coordinate of the baselines.
vcoord (array_like) – the v coordinate of the baselines.
wl (array_like) – the wl coordinate of the baselines.
t (array_like) – the t coordinate of the baselines.
- Returns:
In the case of the numpy FFT backend it is always equal to True.
- Return type:
bool
- prepare(im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) bool
Prepares the backend to compute the FFT if not ready.
In the case of the simple numpy FFT backend no preparation are needed. Always return True.
- Parameters:
im (numpy.ndarray) – 4D image (t,wl,x,y) to be FFTed.
pix (float) – pixel size of the image in rad.
wlin (numpy.ndarray) – the input wavelength vector of the image.
tin (numpy.ndarray) – the input time vector of the image.
ucoord (array_like) – the u coordinate of the baselines.
vcoord (array_like) – the v coordinate of the baselines.
wl (array_like) – the wl coordinate of the baselines.
t (array_like) – the t coordinate of the baselines.
- Returns:
The FFTBackendPreparation structure. Always True for the numpy backend.
- Return type:
bool
- compute(backendPreparation: bool, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) ndarray
Computes the FFT and interpolate the results at the required coordinates.
It computes the FFT of the 4D image (t,wl,x,y) using the numpy.fft.fft2 function and interpolate the results at the proper spatial, spectral and temporal coordinates using the scipy.interpolate.interpn function.
- Parameters:
backendPreparation (bool) – The FFTBackendPreparation structure. Always True for the numpy backend.
im (numpy.ndarray) – 4D image (t,wl,x,y) to be FFTed.
pix (float) – pixel size of the image in rad.
wlin (numpy.ndarray) – the input wavelength vector of the image.
tin (numpy.ndarry) – the input time vector of the image.
ucoord (array_like) – the u coordinate of the baselines.
vcoord (array_like) – the v coordinate of the baselines.
wl (array_like) – the wl coordinate of the baselines.
t (array_like) – the t coordinate of the baselines.
- Returns:
The computed and interpolated complex FFT of the image at the the proper spatial, spectral and temporal coordinates.
- Return type:
numpy.ndarray (complex)
- class oimodeler.oimFTBackends.FFTWBackend
FFT backend based on the python implementation of FFTW library.
The
preparemethod create three FFTW objects: The IN and OUT arrays, at the format pyfftw.empty_aligned, and the pyfftw.FFTW object for the transformation.The
checkmethod only check the size of the arrays in x and y (dim) and also in wavelength and timeAfter the FFT computation in the
computemethod, interpolation to the proper coordinates are done with the scipy.interpolate.interpn method.The backendPreparation contains the following six elements: fft_in, (pyfftw.empty_aligned), fft_out (pyfftw.empty_aligned), fft_object (pyfftw.FFTW), dim (int), nwl (int), nt (int).
- property initialized: bool
Checks if the FFTW library is properly initialized.
- check(backendPreparation: bool, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) bool
Checks if the backend is ready to compute the FFT.
- Parameters:
backendPreparation (bool) – The FFTBackendPreparation structure. Always True for the numpy backend.
im (numpy.ndarray) – 4D image (t,wl,x,y) to be FFTed.
pix (float) – pixel size of the image in rad.
wlin (numpy.ndarray) – the input wavelength vector of the image.
tin (numpy.ndarray) – the input time vector of the image.
ucoord (array_like) – the u coordinate of the baselines.
vcoord (array_like) – the v coordinate of the baselines.
wl (array_like) – the wl coordinate of the baselines.
t (array_like) – the t coordinate of the baselines.
- Returns:
In the case of the numpy FFT backend it is always equal to True.
- Return type:
bool
- prepare(im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) Tuple
Prepares the backend to compute the FFT if not ready.
The preparation is done by initializing two pyfftw.empty_aligned arrays and one pyfftw.FFTW on these arrays.
- Parameters:
im (numpy.ndarray) – 4D image (t,wl,x,y) to be FFTed.
pix (float) – pixel size of the image in rad.
wlin (numpy.ndarray) – the input wavelength vector of the image.
tin (numpy.ndarray) – the input time vector of the image.
ucoord (array_like) – the u coordinate of the baselines.
vcoord (array_like) – the v coordinate of the baselines.
wl (array_like) – the wl coordinate of the baselines.
t (array_like) – the t coordinate of the baselines.
- Returns:
A tuple of six elements containing the dimension of the image, the number of wavelength and time, and three FFTW objects: IN and OUT arrays at pyfftw.empty_aligned and its transform as pyfftw.FFTW.
- Return type:
tuple
- compute(backendPreparation: Tuple, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) ndarray
Computes the FFT and interpolate the results at the required coordinates.
It computes the FFT of the 4D image (t,wl,x,y) using FFTW function and interpolate the results at the proper spatial, spectral and temporal coordinates using the scipy.interpolate.interpn function.
- Returns:
The computed and interpolated complex FFT of the image at the proper spatial, spectral and temporal coordinates.
- Return type:
numpy.ndarray (complex)
- class oimodeler.oimFTBackends.DFTBackend
DFT backend using the numpy
Empty
checkandpreparemethods.- check(backendPreparation: bool, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) bool
Checks if the backend is ready to compute the FFT.
In the case of the simple numpy FFT backend no preparation are needed. Always return True
- Parameters:
backendPreparation (bool) – The FFTBackendPreparation structure. Always True for the numpy backend.
im (numpy.ndarray) – 4D image (t,wl,x,y) to be FFTed.
pix (float) – pixel size of the image in rad.
wlin (numpy.ndarray) – the input wavelength vector of the image.
tin (numpy.ndarray) – the input time vector of the image.
ucoord (array_like) – the u coordinate of the baselines.
vcoord (array_like) – the v coordinate of the baselines.
wl (array_like) – the wl coordinate of the baselines.
t (array_like) – the t coordinate of the baselines.
- Returns:
In the case of the numpy FFT backend it is always equal to True.
- Return type:
bool
- prepare(im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) bool
Prepares the backend to compute the FFT if not ready.
In the case of the simple numpy FFT backend no preparation are needed. Always return True.
- Parameters:
im (numpy.ndarray) – 4D image (t,wl,x,y) to be FFTed.
pix (float) – pixel size of the image in rad.
wlin (numpy.ndarray) – the input wavelength vector of the image.
tin (numpy.ndarray) – the input time vector of the image.
ucoord (array_like) – the u coordinate of the baselines.
vcoord (array_like) – the v coordinate of the baselines.
wl (array_like) – the wl coordinate of the baselines.
t (array_like) – the t coordinate of the baselines.
- Returns:
The FFTBackendPreparation structure. Always True for the numpy backend.
- Return type:
bool
- compute_old(backendPreparation: Tuple, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) ndarray
Computes the DFT
- Returns:
The computed and interpolated complex FFT of the image at the proper spatial, spectral and temporal coordinates.
- Return type:
numpy.ndarray (complex)
- compute_old2(backendPreparation: Tuple, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) ndarray
Computes the DFT
- Returns:
The computed and interpolated complex FFT of the image at the proper spatial, spectral and temporal coordinates.
- Return type:
numpy.ndarray (complex)
- compute(backendPreparation: Tuple, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], vcoord: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], wl: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], t: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) ndarray
Computes the DFT
- Returns:
The computed and interpolated complex FFT of the image at the proper spatial, spectral and temporal coordinates.
- Return type:
numpy.ndarray (complex)