RollingStatistic

class gpype.backend.transform.rolling_statistic.RollingStatistic[source]

Bases: IONode

One statistic per channel over a sliding window.

Amplitude features and amplitude-based quality judgements both need this, and most of these are reachable by no combination of the other nodes: a moving average is the mean and only the mean. Peak-to-peak over a window, in particular, is the textbook way to spot a channel that has come loose.

The window is a real window: every emitted value describes the last window_size samples, and the first values are computed against a history primed with the first sample rather than against silence, so there is no start-up ramp to mistake for signal.

One row per input frame, so a frame longer than one sample lowers the rate. A row is timed at the last sample of its frame, and start_time is moved to the first frame’s. A marker in the input context then moves to the first row at or after it. A gap covers every row whose window holds a missing sample, at any frame size.

Every statistic but "var" is in its input’s unit. A variance is in that unit squared, so its channels record no unit.

ONE_OF = (('window_size', 'window_seconds'),)

Exactly one of these must be given; the window is either a sample count or a duration.

STATISTICS = ('rms', 'mean', 'var', 'std', 'min', 'max', 'peak_to_peak', 'median')

Statistics this node can compute.

class Configuration[source]

Bases: Configuration

Configuration class for RollingStatistic parameters.

class Keys[source]

Bases: Keys

Configuration keys for RollingStatistic settings.

STATISTIC = 'statistic'

Which statistic to compute

class OptionalKeys[source]

Bases: OptionalKeys

Optional configuration keys.

WINDOW_SIZE = 'window_size'

Window length in samples

WINDOW_SECONDS = 'window_seconds'

Window length in seconds, resolved against the rate

__init__(statistic='rms', window_size=None, window_seconds=None, **kwargs)[source]

Initialize the rolling statistic.

Parameters:
  • statistic (str) – One of STATISTICS.

  • window_size (Optional[int]) – Window length in samples.

  • window_seconds (Optional[float]) – Window length in seconds, as an alternative to window_size; resolved once the sampling rate is known.

  • **kwargs – Additional arguments for the parent IONode.

Raises:

ValueError – If the statistic is unknown, if both or neither window form is given, or if a window is not positive.

setup(data, port_context_in)[source]

Resolve the window and allocate the history.

Parameters:
Return type:

dict[str, dict]

Returns:

Output port contexts.

Raises:

ValueError – If a window in seconds was requested and the input declares no sampling rate.

step(data)[source]

Update the window and emit the statistic.

Parameters:

data (dict[str, ndarray]) – Input frame.

Return type:

dict[str, ndarray]

Returns:

One row holding the statistic per channel.