Diagnostics#

diagnostics#

Profiles#

Fourier spectra#

radial_spectrum(ps, fftdim, radial_bin_width, bin_anchor='center', truncate=True, scaling='spectrum', prefix='freq_')[source]#

Isotropize a 2D power spectrum or cross spectrum by taking an “spherical” average over the specified dimensions.

\[\begin{split}\mathbb{F}_\text{iso}(k_r) &= \sum_{k_r: |k_r| \in [kr_0, kr_1]} |\mathbb{F}(\mathbf{k})|^2 * w(\mathbf{k}) \\ k_r &= \langle k \rangle_{|k| \in [kr_0, kr_1]}\end{split}\]

where \(kr\) is the radial wavenumber and the weights \(w\) are defined implicitly through the scaling. Always \(\sum_\mathbf{k} |\mathbb{F}(\mathbf{k})|^2 = \sum \mathbb{F}_\text{iso}(k_r) * w(k_r)\). This satisfies Parseval assuming \(\sum_\mathbf{k} |\mathbb{F}(\mathbf{k})|^2 = \sum real\_data^2 * dx * dy\).

Parameters:
  • ps (DataArray) – The power spectrum or cross spectrum to be isotropized.

  • fftdim (Sequence[str]) – The fft dimensions overwhich the isotropization must be performed.

  • radial_bin_width (float) – Width of radial bins in units of inverse length (or whatever the 2d power spectrum is in)

  • truncate (bool) – If True, the spectrum will be truncated for wavenumbers larger than min(max(ps[fftdim].size)).

  • bin_anchor (str) – Where to place the radial wavenumber within the bin. Choices {‘left’, ‘right’, ‘centre’, ‘com’}. If com : compute as the centre-of-mass radius : \(k_r = \sum_{|k| \in [kr_0, kr_1]} (\mathbb{F} * |\mathbf{k}|) / \mathbb{F}_\text{iso}(k_r)\) before rescaling. Default: com.

  • scaling (str) –

    Rescale the power spectrum to satisfy \(\sum ps = \sum \mathbb{F}_\text{iso} * w(k_r)\)

    • density: set \(w(k_r) = \pi * ((k_r^{top})^2 - (k_r^{bottom})^2)\), where \(k_r^{top}\) and \(k_r^{bottom}\) are the bin edges.

    • spectrum: set \(w(k_r) = 1\)

Return type:

DataArray

Returns:

an xarray.DataArray with the isotropic spectrum coordinates for the radial wavenumber ( prefix r), bin width ( prefix dr) and corresponding weigths ( prefix dA), i.e. \(w(k_r)\).

spectra_1d_radial(simulation, hdims, power_spectra_fields, cross_spectra_fields, radial_smooth_factor=2, radial_truncation=False, fillnan=0.0)[source]#

Compute a 1d directional and radial power and cross spectra of all fields in the simultation Dataset. Notes: resulting spectral cooordinates are in units of inverse length, not radians/length.

Parameters:
  • simulation (Dataset) – xarray Dataset of multidimensional fields. must contain the set of power_spectra_fields and cross_spectra_fields

  • hdims (Sequence[str]) – horizonal dimensions along which to compute linear spectra. The radial spectrum is computed along the Euclidean radius along vector spanned by these dimensions.

  • power_spectra_fields (Sequence[str]) – sequence of fields whose power spectrum to compute

  • cross_spectra_fields (Sequence[tuple[str, str]]) – sequence of tuples of fields whose cross-spectrum to compute

  • radial_smooth_factor (int) – smoothing factor for radial spectral bins. If 2 will have radial bin widht is 2*linear wavenumber.

  • radial_truncation (bool) – switch to include/exclude aliased wavenumber beyond the max. 1d freqeuncy in the radial spectrum. If True the result won’t respect Parseval exactly.

  • fillnan (float) – value to fill nans with in order to compute spectrum of dirty date. If set to a nan value (e.g. np.nan) will produce nan spectra globally. Defaults to 0.

Return type:

Dataset

Returns:

an xarray Dataset with the requested 1d and radial power and co-spectra. The number of physical-space grid size and cell size along hdims is included in the attributes along with the fourier normalization convention.

anisotropy diagnostics#