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 component getComplexCoherentFlux method is called. It checks if the backend is ready to perform the FFT

  • pepare : is called only if the check method returned False.It prepares the backends and the return various data relative to the preparation

  • compute : is finally called when the backend is ready to compute the FFT and return the complexCoherentFlux.

Classes:

numpyFFTBackend()

Default FFT backend using the numpy np.fft.fft2 function.

FFTWBackend()

FFT backend based on the python implementation of FFTW library.

class oimodeler.oimFTBackends.numpyFFTBackend

Default FFT backend using the numpy np.fft.fft2 function.

Empty check and prepare methods. interpolation of the FFT done with scipy.interpolate.interpn in the compute method.

static check(backendPreparation: bool, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], vcoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], wl: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], t: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) 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

static prepare(im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], vcoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], wl: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], t: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) 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

static compute(backendPreparation: bool, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], vcoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], wl: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], t: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) 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 prepare method create three FFTW objects: The IN and OUT arrays, at the format pyfftw.empty_aligned, and the pyfftw.FFTW object for the transformation.

The check method only check the size of the arrays in x and y (dim) and also in wavelength and time

After the FFT computation in the compute method, 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).

static check(backendPreparation: bool, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], vcoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], wl: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], t: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) 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

static prepare(im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], vcoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], wl: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], t: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) 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

static compute(backendPreparation: Tuple, im: ndarray, pix: float, wlin: ndarray, tin: ndarray, ucoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], vcoord: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], wl: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], t: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) 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)