epygram.spectra — Class and functions for spectra

This module contains:

  • a class to handle variance spectrum;

  • a function to compute DCT spectrum from a 2D field;

  • a function to sort spectra with regards to their name;

  • a function to plot a series of spectra.

  • a function to read a dumped spectrum.

Classes

class epygram.spectra.Spectrum(variances, name=None, resolution=None, mean2=None, **kwargs)[source]

Bases: epygram.util.RecursiveObject

A spectrum can be seen as a quantification of a signal’s variance with regards to scale. If the signal is defined in physical space on N points, its spectral representation will be a squared mean value (wavenumber 0) and variances for N-1 wavenumbers. For details and documentation, see

Denis et al. (2002) : ‘Spectral Decomposition of Two-Dimensional Atmospheric Fields on Limited-Area Domains Using the Discrete Cosine Transform (DCT)’

Parameters
  • variances – variances of the spectrum, from wavenumber 1 to N-1.

  • name – an optional name for the spectrum.

  • resolution – an optional resolution for the field represented by the spectrum. It is used to compute the according wavelengths. Resolution unit is arbitrary, to the will of the user.

  • mean2 – the optional mean^2 of the field, i.e. variance of wavenumber 0 of the spectrum.

dump(filename)[source]

Writes the spectrum with formatted output in filename.

plotspectrum(together_with=[], over=(None, None), slopes=[{'exp': - 3, 'offset': 1, 'label': '-3'}, {'exp': - 1.6666666666666667, 'offset': 1, 'label': '-5/3'}], zoom=None, unit='SI', title=None, figsize=None)[source]

Plot the spectrum.

Parameters

together_with – another spectrum or list of spectra to plot on the same ax.

Cf. function plotspectra() of this module for other arguments.

property wavelengths

Gets the wavelengths of the spectrum.

property wavenumbers

Gets the wavenumbers of the spectrum.

write(out)[source]

Writes the spectrum with formatted output in out.

Parameters

out – must be an output open file-like object.


Functions

epygram.spectra.read_Spectrum(filename)[source]

Read a Spectrum written in file and return it.

epygram.spectra.dctspectrum(x, verbose=False, log=None)[source]

Function dctspectrum takes a 2D-array as argument and returns its 1D DCT ellipse spectrum.

For details and documentation, see

Denis et al. (2002) : ‘Spectral Decomposition of Two-Dimensional Atmospheric Fields on Limited-Area Domains Using the Discrete Cosine Transform (DCT).’

Parameters
  • verbose – verbose mode

  • log – an optional logging.Logger instance to which print info in verbose case.

epygram.spectra.sort(spectra)[source]

Sort a list of spectra with regards to their name.

epygram.spectra.plotspectra(spectra, over=(None, None), slopes=[{'exp': - 3, 'offset': 1, 'label': '-3'}, {'exp': - 1.6666666666666667, 'offset': 1, 'label': '-5/3'}], zoom=None, unit='SI', title=None, figsize=None)[source]

To plot a series of spectra.

Parameters
  • over – any existing figure and/or ax to be used for the plot, given as a tuple (fig, ax), with None for missing objects. fig is the frame of the matplotlib figure, containing eventually several subplots (axes); ax is the matplotlib axes on which the drawing is done. When given (is not None), these objects must be coherent, i.e. ax being one of the fig axes.

  • spectra – a Spectrum instance or a list of.

  • unit – string accepting LaTeX-mathematical syntaxes

  • slopes

    list of dict( - exp=x where x is exposant of a A*k**-x slope - offset=A where A is logscale offset in a A*k**-x slope;

    a offset=1 is fitted to intercept the first spectra at wavenumber = 2

    • label=(optional label) appearing ‘k = label’ in legend)

  • zoom – dict(xmin=,xmax=,ymin=,ymax=)

  • title – title for the plot

  • figsize – figure sizes in inches, e.g. (5, 8.5). Default figsize is config.plotsizes.