mpylab.tools.autocorrelation module

Specialized autocorrelation helpers for angular/non-uniform data.

Use mpylab.tools.stats.autocorrelation() for ordinary ordered sequences, including the MSC autocorrelation workflow. This module contains more specialized spline-based helpers for angular positions that may be non-uniformly spaced, plus noise-variance estimators for those data.

mpylab.tools.autocorrelation.calculate_autocorrelation_noisy(angles, values, lag_range=array([0., 0.06346652, 0.12693304, 0.19039955, 0.25386607, 0.31733259, 0.38079911, 0.44426563, 0.50773215, 0.57119866, 0.63466518, 0.6981317, 0.76159822, 0.82506474, 0.88853126, 0.95199777, 1.01546429, 1.07893081, 1.14239733, 1.20586385, 1.26933037, 1.33279688, 1.3962634, 1.45972992, 1.52319644, 1.58666296, 1.65012947, 1.71359599, 1.77706251, 1.84052903, 1.90399555, 1.96746207, 2.03092858, 2.0943951, 2.15786162, 2.22132814, 2.28479466, 2.34826118, 2.41172769, 2.47519421, 2.53866073, 2.60212725, 2.66559377, 2.72906028, 2.7925268, 2.85599332, 2.91945984, 2.98292636, 3.04639288, 3.10985939, 3.17332591, 3.23679243, 3.30025895, 3.36372547, 3.42719199, 3.4906585, 3.55412502, 3.61759154, 3.68105806, 3.74452458, 3.8079911, 3.87145761, 3.93492413, 3.99839065, 4.06185717, 4.12532369, 4.1887902, 4.25225672, 4.31572324, 4.37918976, 4.44265628, 4.5061228, 4.56958931, 4.63305583, 4.69652235, 4.75998887, 4.82345539, 4.88692191, 4.95038842, 5.01385494, 5.07732146, 5.14078798, 5.2042545, 5.26772102, 5.33118753, 5.39465405, 5.45812057, 5.52158709, 5.58505361, 5.64852012, 5.71198664, 5.77545316, 5.83891968, 5.9023862, 5.96585272, 6.02931923, 6.09278575, 6.15625227, 6.21971879, 6.28318531]), smoothing_factor=None)

Calculate normalized autocorrelation for noisy data.

A smoothing spline is fitted before calculating the autocorrelation.

Parameters:
  • angles – Angular positions in radians.

  • values – Noisy measured values.

  • lag_range – Angular lags.

  • smoothing_factors parameter for scipy.interpolate.UnivariateSpline. If None, scipy uses its default estimate. If a float is given, it is passed directly; larger values produce a smoother curve.

Returns:

(lags, autocorr).

mpylab.tools.autocorrelation.calculate_autocorrelation_nonuniform(angles, values, lag_range=array([0., 0.06346652, 0.12693304, 0.19039955, 0.25386607, 0.31733259, 0.38079911, 0.44426563, 0.50773215, 0.57119866, 0.63466518, 0.6981317, 0.76159822, 0.82506474, 0.88853126, 0.95199777, 1.01546429, 1.07893081, 1.14239733, 1.20586385, 1.26933037, 1.33279688, 1.3962634, 1.45972992, 1.52319644, 1.58666296, 1.65012947, 1.71359599, 1.77706251, 1.84052903, 1.90399555, 1.96746207, 2.03092858, 2.0943951, 2.15786162, 2.22132814, 2.28479466, 2.34826118, 2.41172769, 2.47519421, 2.53866073, 2.60212725, 2.66559377, 2.72906028, 2.7925268, 2.85599332, 2.91945984, 2.98292636, 3.04639288, 3.10985939, 3.17332591, 3.23679243, 3.30025895, 3.36372547, 3.42719199, 3.4906585, 3.55412502, 3.61759154, 3.68105806, 3.74452458, 3.8079911, 3.87145761, 3.93492413, 3.99839065, 4.06185717, 4.12532369, 4.1887902, 4.25225672, 4.31572324, 4.37918976, 4.44265628, 4.5061228, 4.56958931, 4.63305583, 4.69652235, 4.75998887, 4.82345539, 4.88692191, 4.95038842, 5.01385494, 5.07732146, 5.14078798, 5.2042545, 5.26772102, 5.33118753, 5.39465405, 5.45812057, 5.52158709, 5.58505361, 5.64852012, 5.71198664, 5.77545316, 5.83891968, 5.9023862, 5.96585272, 6.02931923, 6.09278575, 6.15625227, 6.21971879, 6.28318531]), method='discrete')

Calculate normalized autocorrelation for non-uniform angular positions.

Parameters:
  • angles – Angular positions in radians, in the range [0, 2*pi).

  • values – Associated values.

  • lag_range – Angular shifts for which the correlation is calculated.

  • method"discrete" for spline-based discrete integration or "quad" for adaptive integration.

Returns:

(lags, autocorr) with normalized autocorrelation values where R(0) = 1.

mpylab.tools.autocorrelation.estimate_noise_variance(angles, values, initial_smoothing_factor=1.0)

Estimates the noise variance sigma^2 by fitting a highly smoothed spline and calculating the variance of the residuals.

Parameters: angles: Sorted angular positions. values: Measured values. initial_smoothing_factor: Starting guess for ‘s’. Higher means smoother fit.

Returns: sigma_sq: Estimated noise variance.

mpylab.tools.autocorrelation.estimate_noise_variance_robust(angles, values)

Estimates noise variance using local differences (robust against signal fitting bias). Assumes the signal is smooth compared to the noise.