wristpy.core.computations

This module will contain functions to compute statistics on the sensor data.

Functions

moving_mean(array[, epoch_length, name])

Calculate the moving mean of the sensor data in array.

moving_median(array, epoch_length)

Applies moving median to acceleration data.

moving_std(array[, epoch_length])

Calculate the moving standard deviation (std) of the sensor data in array.

resample(measurement, delta_t)

Resamples a measurement to a different timescale.

wristpy.core.computations._moving(measurement: Measurement, epoch_length: float, aggregation: Literal['mean', 'std', 'median'], *, centered: bool = False, continuous: bool = False, name: str | None = None) Measurement[source]

Internal handler of rolling window functions.

Parameters:
  • measurement – The measurement to apply a rolling function to.

  • epoch_length – Length of the window in seconds.

  • aggregation – Name of the function to apply, either ‘mean’, ‘std’, or ‘median’.

  • centered – If true, centers the window. Defaults to False.

  • continuous – If true, applies the window to every measurement. If false, groups measurements into chunks of epoch_length. Defaults to False.

  • name – The name of the Measurement object.

Returns:

The measurement with the rolling function applied to it.

wristpy.core.computations.moving_mean(array: Measurement, epoch_length: float = 5, name: str | None = None) Measurement[source]

Calculate the moving mean of the sensor data in array.

Parameters:
  • array – The Measurement object with the sensor data we want to take the mean of

  • epoch_length – The length, in seconds, of the window.

  • name – The name of the Measurement object.

Returns:

The moving mean of the array in a new Measurement instance.

Raises:

ValueError – If the epoch length is not an integer or is less than 1.

wristpy.core.computations.moving_median(array: Measurement, epoch_length: float) Measurement[source]

Applies moving median to acceleration data.

Step size for the window is hard-coded to 1 sample.

Parameters:
  • array – The Measurement object with the sensor data we want to take the median of.

  • epoch_length – Size of the moving median window. Window is centered. Measured in seconds.

Returns:

Measurement object with rolling median applied to the measurement data. The measurements data will retain its shape, and the time data will be returned unaltered.

wristpy.core.computations.moving_std(array: Measurement, epoch_length: float = 5) Measurement[source]

Calculate the moving standard deviation (std) of the sensor data in array.

Parameters:
  • array – The Measurement object with the sensor data we want to take the std of

  • epoch_length – The length, in seconds, of the window.

Returns:

The moving std of the array in a new Measurement instance.

Raises:

ValueError – If the epoch length is less than 1.

wristpy.core.computations.resample(measurement: Measurement, delta_t: float) Measurement[source]

Resamples a measurement to a different timescale.

Parameters:
  • measurement – The measurement to resample.

  • delta_t – The new time step, in seconds. This will be rounded to the nearest nanosecond.

Returns:

The resampled measurement.

Raises:

ValueError – Raised for zero or negative delta_t.