mod_xscale module

Xscale is a python package created by Guillaume Sérazin and available at https://github.com/serazing/xscale.

Xscale is a collection of signal processing and statistical tools initially designed for the analysis of the spatio-temporal scales of geophysical data. It is part of the pangeo-data project and works with xarray and dask objects.

Due to some deprecations of the package, only parts of it are used here in mod_xscale.py and mod_utils.py.

mod_xscale.amplitude(spectrum)

Return the amplitude spectrum from the Fourier Transform

Parameters:
  • spectrum (DataArray) – A DataArray spectrum computed using xscale.spectral.fft.fft

  • deg (bool, optional) – If True, return the phase spectrum in degrees. Default is to return the phase spectrum in radians

Returns:

res – The phase spectrum

Return type:

DataArray

mod_xscale.fft(array, nfft=None, dim=None, dx=None, detrend=None, tapering=False, shift=True, sym=False, chunks=None)

Compute the spectrum on several dimensions of xarray.DataArray objects using the Fast Fourrier Transform parrallelized with dask.

Parameters:
  • array (xarray.DataArray) – Array from which compute the spectrum

  • dim (str or sequence) – Dimensions along which to compute the spectrum

  • dx (float or sequence, optional) – Define the resolution of the dimensions. If not precised, the resolution is computed directly from the coordinates associated to the dimensions.

  • detrend ({None, 'mean', 'linear'}, optional) – Remove the mean or a linear trend before the spectrum computation

  • tapering (bool, optional) – If True, tapper the data with a Tukey window

  • shift (bool, optional) – If True, the frequency axes are shifted to center the 0 frequency, otherwise negative frequencies follow positive frequencies as in numpy.fft.ftt

  • sym (bool, optional) – If True, force the spectrum to be symmetrical even if the input data is real

  • chunks (int, tuple or dict, optional) – Chunk sizes along each dimension, e.g., 5, (5, 5) or {'x': 5, 'y': 5}

Returns:

res – A multi-dimensional complex DataArray with the corresponding dimensions transformed in the Fourier space.

Return type:

DataArray

Notes

If the input data is real, a real fft is performed over the first dimension, which is faster. Then the transform over the remaining dimensions are computed with the classic fft.

mod_xscale.phase(spectrum, deg=False)

Return the phase spectrum from the Fourier Transform

Parameters:
  • spectrum (DataArray) – A DataArray spectrum computed using xscale.spectral.fft.fft

  • deg (bool, optional) – If True, return the phase spectrum in degrees. Default is to return the phase spectrum in radians

Returns:

res – The phase spectrum

Return type:

DataArray

mod_xscale.ps(spectrum)

Return the Power Spectrum (PS) from the Fourier Transform

Parameters:

spectrum (DataArray) – A DataArray spectrum computed using xscale.spectral.fft.fft

Returns:

power_spectrum – The PS spectrum

Return type:

DataArray

mod_xscale.psd(spectrum)

Return the Power Spectrum density (PSD) from the Fourier Transform

Parameters:

spectrum (DataArray) – A DataArray spectrum computed using xscale.spectral.fft.fft

Returns:

power_spectrum_density – The PSD spectrum

Return type:

DataArray