rednoisefit

rednoisefit(dt, a, /, maxlag=None, imaxlag=None, maxlag_fit=None, imaxlag_fit=None, axis=0)[source]

Return the \(e\)-folding autocorrelation timescale for the input autocorrelation spectra along an arbitrary axis. Depending on the length of axis, the timescale is obtained with either of the following two approaches:

  1. Find the \(e\)-folding timescale(s) for the pure red noise autocorrelation spectra \(\exp(-x\Delta t / \tau)\) with the least-squares best fit to the provided spectra.

  2. Assume the process is pure red noise and invert the red noise autocorrelation spectrum at lag 1 to solve for \(\tau = \Delta t / \log a_1\).

Approach 2 is used if axis is singleton or the data is scalar. In these cases, the data is assumed to represent just the lag-1 autocorrelation.

Parameters
  • dt (float or array-like, optional) – The timestep or time series (from which the timestep is inferred).

  • a (array-like) – The autocorrelation spectra.

  • maxlag (float, optional) – The maximum time lag to include in the red noise fit.

  • imaxlag (int, optional) – As with maxlag but specifies the index instead of the physical time.

  • maxlag_fit (float, optional) – The maximum time lag to include in the output pure red noise spectrum.

  • imaxlag_fit (int, optional) – As with maxlag but specifies the index instead of the physical time.

  • axis (int, optional) – The “lag” dimension. Each slice along this axis should represent an autocorrelation spectrum generated with corr.

    • If axis is singleton, the data are assumed to be lag-1 autocorrelations and the timescale is computed from the lag-1 pure red noise formula.

    • If axis is non-singleton, the timescale is estimated from a least-squares curve fit to a pure red noise spectrum up to maxlag.

Returns

  • tau (array-like) – The autocorrelation timescales. The shape is the same as data but with axis reduced to length 1.

  • sigma (array-like) – The standard errors. If the timescale was inferred using the lag-1 equation, this is an array of zeros. The shape is the same as tau.

  • fit (array-like) – The best fit autocorrelation spectrum. The shape is the same as data but with axis of length nlag.

Examples

>>> import numpy as np
>>> import climopy as climo
>>> state = np.random.RandomState(51423)
>>> data = climo.rednoise(0.8, 500, 10, state=state)
>>> lag, auto = climo.autocorr(1, data, axis=0, maxlag=50)
>>> taus, sigmas, fit = climo.rednoisefit(lag, auto, axis=0)
>>> taus
array([[5.97691453, 4.29275329, 4.91997185, 4.87781027, 3.46404331,
        4.23444888, 4.91852921, 4.39283164, 4.79466674, 3.81250855]])

See also

corr, rednoise