lomb_scargle (pyleoclim.utils.lomb_scargle)

pyleoclim.utils.lomb_scargle(ys, ts, freq=None, freq_method='lomb-scargle', freq_kwargs=None, n50=3, window='hann', detrend=None, params=['default', 4, 0, 1], gaussianize=False, standardize=False, average='mean')[source]

Return the computed periodogram using lomb-scargle algorithm

Uses the lombscargle implementation from scipy.signal: https://scipy.github.io/devdocs/generated/scipy.signal.lombscargle.html#scipy.signal.lombscargle

Parameters
  • ys (array) – a time series

  • ts (array) – time axis of the time series

  • freq (str or array) – vector of frequency. If string, uses the following method:

  • freq_method (str) –

    Method to generate the frequency vector if not set directly. The following options are avialable:
    • log

    • lomb-scargle (default)

    • welch

    • scale

    • nfft

    See utils.wavelet.make_freq_vector for details

  • freq_kwargs (dict) – Arguments for the method chosen in freq_method. See specific functions in utils.wavelet for details By default, uses dt=median(ts), ofac=4 and hifac=1 for Lomb-Scargle

  • n50 (int) – The number of 50% overlapping segment to apply

  • window (str or tuple) –

    Desired window to use. Possible values:
    • boxcar

    • triang

    • blackman

    • hamming

    • hann (default)

    • bartlett

    • flattop

    • parzen

    • bohman

    • blackmanharris

    • nuttail

    • barthann

    • kaiser (needs beta)

    • gaussian (needs standard deviation)

    • general_gaussian (needs power, width)

    • slepian (needs width)

    • dpss (needs normalized half-bandwidth)

    • chebwin (needs attenuation)

    • exponential (needs decay scale)

    • tukey (needs taper fraction)

    If the window requires no parameters, then window can be a string. If the window requires parameters, then window must be a tuple with the first argument the string name of the window, and the next arguments the needed parameters. If window is a floating point number, it is interpreted as the beta parameter of the kaiser window.

    detrendstr
    If None, no detrending is applied. Available detrending methods:
    • None - no detrending will be applied (default);

    • linear - a linear least-squares fit to ys is subtracted;

    • constant - the mean of ys is subtracted

    • savitzy-golay - ys is filtered using the Savitzky-Golay filters and the resulting filtered series is subtracted from y.

    • emd - Empirical mode decomposition

    paramslist

    The paramters for the Savitzky-Golay filters. The first parameter corresponds to the window size (default it set to half of the data) while the second parameter correspond to the order of the filter (default is 4). The third parameter is the order of the derivative (the default is zero, which means only smoothing.)

    gaussianizebool

    If True, gaussianizes the timeseries

    standardizebool

    If True, standardizes the timeseriesprep_args : dict

    average{‘mean’,’median’}

    Method to use when averaging periodograms. Defaults to ‘mean’.

Returns

res_dict – the result dictionary, including - freq (array): the frequency vector - psd (array): the spectral density vector

Return type

dict

See also

periodogram()

Estimate power spectral density using a periodogram

mtm()

Retuns spectral density using a multi-taper method

welch()

Returns power spectral density using the Welch method

wwz_psd()

Return the psd of a timeseries using wwz method.

References

Lomb, N. R. (1976). Least-squares frequency analysis of unequally spaced data. Astrophysics and Space Science 39, 447-462.

Scargle, J. D. (1982). Studies in astronomical time series analysis. II. Statistical aspects of spectral analyis of unvenly spaced data. The Astrophysical Journal, 263(2), 835-853.

Scargle, J. D. (1982). Studies in astronomical time series analysis. II. Statistical aspects of spectral analyis of unvenly spaced data. The Astrophysical Journal, 263(2), 835-853.

Examples

>>> from pyleoclim import utils
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> # Create a signal
>>> time = np.arange(2001)
>>> f = 1/50
>>> signal = np.cos(2*np.pi*f*time)
>>> # Spectral Analysis
>>> res = utils.lomb_scargle(signal, time)
>>> # plot
>>> fig = plt.loglog(
...           res['freq'],
...           res['psd'])
>>> plt.xlabel('Frequency')
>>> plt.ylabel('PSD')
>>> plt.show()

(Source code, png)

../../_images/lombscargle-1.png