ivis.utils.fourier

Power Spectrum and Image Processing Utilities

This module provides tools to analyze the spatial frequency content of 2D images, including power spectrum estimation, cross-spectra, autocorrelation functions, and image preprocessing utilities such as apodization and padding.

Originally adapted from a package by J.-F. Robitaille.

Functions

  • powspec(image, reso=1, autocorr=False, **kwargs)

    Computes the azimuthally averaged power spectrum of a 2D image, optionally returning the autocorrelation or cross-spectrum if a second image is passed via im2.

  • cross_spec(image, image2, reso=1)

    Computes the cross-power spectrum between two 2D images.

  • kgrid(image)

    Returns a normalized radial spatial frequency grid (k) corresponding to the FFT bins for a given image shape.

  • apodize(radius, shape)

    Returns a 2D cosine taper mask to apodize the edges of an image.

  • apodize_1d(radius, shape)

    Returns a 1D cosine taper to apodize the edges of a 1D array (e.g. spectrum).

  • padding(input, fact)

    Pads a 2D image symmetrically by a given fractional amount (fact), centering the original image in a larger zero-filled array.

  • depad(input, fact)

    Crops a previously padded 2D image, removing the borders added by padding.

Author: Adapted from JF Robitaille package by Antoine Marchal (mostly added docstrings for RTD).

Functions

apodize(radius, shape)

Create a 2D cosine taper window for edge apodization.

apodize_1d(radius, shape)

Create a 1D cosine taper window for edge apodization.

cross_spec(image, image2[, reso])

Compute the 1D cross power spectrum between two 2D images.

depad(input, fact)

Crop a padded 2D image to its original size.

kgrid(image)

Compute the 2D spatial frequency grid (radius only) for a given image.

padding(input, fact)

Pad a 2D image by a given fractional amount with zeros.

powspec(image[, reso, autocorr])

Compute the azimuthally averaged 1D power spectrum or autocorrelation of a 2D image.

powspec_torch(image[, pixel_size_arcsec, ...])

ivis.utils.fourier.apodize(radius, shape)[source]

Create a 2D cosine taper window for edge apodization.

Parameters:
  • radius (float) – Fractional taper width (0 < radius < 1).

  • shape (tuple of int) – Shape of the 2D image (ny, nx).

Returns:

tapper – 2D tapering function.

Return type:

ndarray

ivis.utils.fourier.apodize_1d(radius, shape)[source]

Create a 1D cosine taper window for edge apodization.

Parameters:
  • radius (float) – Fractional taper width (0 < radius < 1).

  • shape (int) – Total length of the 1D array.

Returns:

tap1d_x – 1D tapering function.

Return type:

ndarray

ivis.utils.fourier.cross_spec(image, image2, reso=1)[source]

Compute the 1D cross power spectrum between two 2D images.

Parameters:
  • image (ndarray) – First 2D image.

  • image2 (ndarray) – Second 2D image.

  • reso (float, optional) – Pixel size in spatial units (e.g. arcmin).

Returns:

spec_k – Azimuthally averaged cross power spectrum.

Return type:

ndarray

ivis.utils.fourier.depad(input, fact)[source]

Crop a padded 2D image to its original size.

Parameters:
  • input (ndarray) – Padded 2D image.

  • fact (float) – Padding fraction used during padding.

Returns:

output – Cropped image matching original dimensions.

Return type:

ndarray

ivis.utils.fourier.kgrid(image)[source]

Compute the 2D spatial frequency grid (radius only) for a given image.

Parameters:

image (ndarray) – Input 2D image.

Returns:

kmat – 2D array of radial spatial frequencies (normalized).

Return type:

ndarray

ivis.utils.fourier.padding(input, fact)[source]

Pad a 2D image by a given fractional amount with zeros.

Parameters:
  • input (ndarray) – Original 2D image.

  • fact (float) – Padding fraction (e.g. 0.2 adds 20% on each side).

Returns:

output – Padded image.

Return type:

ndarray

ivis.utils.fourier.powspec(image, reso=1, autocorr=False, **kwargs)[source]

Compute the azimuthally averaged 1D power spectrum or autocorrelation of a 2D image.

Parameters:
  • image (ndarray) – Input 2D image.

  • reso (float, optional) – Pixel size in spatial units (e.g. arcmin).

  • autocorr (bool, optional) – If True, return the autocorrelation function instead of the power spectrum.

  • im2 (ndarray, optional (passed via kwargs)) – Second image for computing the cross-spectrum.

Returns:

  • tab_k (ndarray) – Radial spatial frequency values.

  • spec_k (ndarray) – Azimuthally averaged power spectrum.

ivis.utils.fourier.powspec_torch(image, pixel_size_arcsec=1.0, nbins=None, autocorr=False, im2=None)[source]