running_moment

plasmapy.analysis.time_series.running_moments.running_moment(signal, radius: int, moment=1, time=None)[source]

Calculate either the running mean, standard deviation, skewness or excess kurtosis of a sequence.

Parameters:
  • signal (1D array_like) – Signal to be averaged.

  • radius (int) – The number of points on either side of each point for which the running moment is being calculated. The window size is 2 * radius + 1 for running mean and 4 * radius + 1 for higher moments.

  • moment (int) –

    Choose between:

    • 1: running mean

    • 2: running standard deviation

    • 3: running skewness

    • 4: running excess kurtosis

  • time (1D array_like, optional) – Time base of signal.

Returns:

Contains the following attributes:

  • run_moment: 1D array_like

    Running moment of signal. The length is (len(signal) - 2 * radius) for the running mean or (len(signal) - 4 * signal) for higher moments.

  • time: 1D array_like

    Time base corresponding to run_moment if time is not None.

Return type:

namedtuple

Raises:
  • ValueError – If moment is not in (1, 2, 3, 4).

  • ValueError – If signal and time don’t have same length.

  • ValueError – If len(signal) <= 4 * radius and moment > 1.

Notes

The running rms divides by window, not (window - 1).

Examples

>>> from plasmapy.analysis.time_series.running_moments import running_moment
>>> running_moment([1, 2, 3, 2, 1], 1, 4, [1, 2, 3, 4, 5])
Running_Moment(run_moment=array([3.]), time=[3])