envtoolkit.spectral¶
Functions/classes relative to time-series
Functions
multitaper (xdata[, deltat, nbandw, nfft]) |
Computes the power spectrum using the multi-taper method |
plot_ref_slope (fmin, fmax, yinterc[, slope]) |
Draws reference slopes on a log spectral plot. |
plot_slope (spectrum, freq[, fmin, fmax, offy]) |
Draws the slope of the spectrum. |
plot_spectra (xdata, deltat, ferror[, …]) |
Plot the power spectrum of a time-series. |
-
envtoolkit.spectral.
multitaper
(xdata, deltat=1.0, nbandw=3, nfft=None)[source]¶ Computes the power spectrum using the multi-taper method
This method uses adaptive weighting. Adapted from the ptmtPH.m script by Peter Huybers
Parameters: - xdata (numpy.array) – input data vector.
- deltat (float) – sampling interval
- nbandw (int) – time bandwidth product, acceptable values range from 0:.5:length(x)/2-1. 2*nbandw-1 dpss tapers are applied except if nbandw=0 a boxcar window is applied and if nbandw = .5 (or 1) a single dpss taper is applied.
- nfft (int) – number of frequencies to evaluate P at, default is length(x) for the two-sided transform.
Returns: a tuple (P, s, ci) with:
- P: Power spectrum computed via the multi-taper method.
- s: Frequency vector.
- ci: 95% confidence intervals.
Return type: tuple
-
envtoolkit.spectral.
plot_ref_slope
(fmin, fmax, yinterc, slope=2, **kwargs)[source]¶ Draws reference slopes on a log spectral plot.
Parameters:
-
envtoolkit.spectral.
plot_slope
(spectrum, freq, fmin=None, fmax=None, offy=0, **kwargs)[source]¶ Draws the slope of the spectrum.
Parameters: - spectrum (numpy.array) – frequency spectrum (output of the
plot_spectra()
function) - freq (numpy.array) – frequency vector (output of the
plot_spectra()
function) - ax (axes) – axes on which to draw the slope
- fmin (float) – the first frequency on which to compute the slope
- fmax (float) – the last frequency on which to compute the slope
- offy (float) – the y-offset of the slope
- **kwargs (dict) –
additional plotting arguments
Returns: the value of the slope
Return type: - spectrum (numpy.array) – frequency spectrum (output of the
-
envtoolkit.spectral.
plot_spectra
(xdata, deltat, ferror, spec_type='variance', nbandw=3, **kwargs)[source]¶ Plot the power spectrum of a time-series.
The power-spectrum is computed by using the
envtoolkit.spectra.multitaper()
function. Adapted from the JD_spectra script of Julie Deshayes.Parameters: - xdata (numpy.array) – time series whose spectrum to plot
- deltat (float) – time step of the time series in seconds
- ferror (float) – the frequency where to do draw the errorbar
- spec_type (str) – ‘variance’ for variance spectrum (spectrum, in $unit^2 cpy^{-1}$), else energy spectrum (freq*spectrim, in $unit^2$).
- nbandw (int) – time bandwidth product (multitaper used 2*nbandw-1 tapers)
- ylabel (str) – label of the yaxis
- **kwargs –
plot additional arguments
Returns: A tuple (Px,F,Pxc) with:
- Px: the spectrum vector
- F: the frequency vector
- PxC: the errorbar vector
Return type: tuple