Getting Started¶
Installation¶
Install the wristpy package from PyPI via:
pip install wristpy
Introduction¶
The main processing pipeline of the wristpy module can be described as follows:
Data loading: sensor data is loaded using
actfast, and aWatchDataobject is created to store all sensor data.Data calibration: A post-manufacturer calibration step can be applied, to ensure that the acceleration sensor is measuring 1g force during periods of no motion. There are three possible options:
None,gradient,ggir.Data imputation In the special case when dealing with the Actigraph
idle_sleep_mode == enabled, the gaps in acceleration are filled in after calibration, to avoid biasing the calibration phase.Metrics Calculation: Calculates various activity metrics on the calibrated data, namely ENMO (Euclidean norm, minus one), MAD (mean amplitude deviation)1, Actigraph activity counts2, MIMS (monitor-independent movement summary) unit3, and angle-Z (angle of acceleration relative to the x-y axis).
Non-wear detection: We find periods of non-wear based on the acceleration data. Specifically, the standard deviation of the acceleration values in a given time window, along each axis, is used as a threshold to decide
wearornot wear. Additionally, we can use the temperature sensor, when available, to augment the acceleration data. This is used in the CTA (combined temperature and acceleration) algorithm4, and in theskdhDETACH algorithm5. Furthermore, ensemble classification of non-wear periods is possible by providing a list (of any length) of non-wear algorithm options.Sleep Detection: Using the HDCZ6 and HSPT7 algorithms to analyze changes in arm angle we are able to find periods of sleep. We find the sleep onset–wakeup times for all sleep windows detected. Any sleep periods that overlap with detected non-wear times are removed, and any remaining sleep periods shorter than 15 minutes (default value) are removed. Additionally, the SIB (sustained inactivity bouts) and the SPT (sleep period time) windows are provided as part of the output to aid in sleep metric post-processing.
Physical activity levels: Using the chosen physical activity metric (aggregated into time bins, 5-second default) we compute activity levels into the following categories: [
inactive,light,moderate,vigorous]. The threshold values can be defined by the user, while the default values are chosen based on the specific activity metric and the values found in the literature 8910.Data output: The output results can be saved in
.csvor.parquetdata formats, with the run-time configuration parameters saved in a.jsondictionary.
Supported formats & devices¶
The package currently supports the following formats:
Format |
Manufacturer |
Device |
Implementation status |
|---|---|---|---|
GT3X |
Actigraph |
wGT3X-BT |
✅ |
BIN |
GENEActiv |
GENEActiv |
✅ |
Physical Activity Metrics Explained¶
ENMO— Euclidean Norm Minus One¶
ENMO quantifies movement intensity from calibrated 3-axis acceleration by taking the vector magnitude and subtracting 1 g (gravity). Values below zero are set to 0 (they mostly reflect noise or tiny calibration errors).
References:
van Hees, V. T., Gorzelniak, L., Dean León, E. C., Eder, M., Pias, M., Taherian, S., Ekelund, U., Renström, F., Franks, P. W., Horsch, A., & Brage, S. (2013). Separating movement and gravity components in an acceleration signal and implications for the assessment of human daily physical activity. PLoS ONE, 8(4), e61691. https://doi.org/10.1371/journal.pone.0061691
Hildebrand, M., van Hees, V. T., Hansen, B. H., & Ekelund, U. (2014). Age group comparability of raw accelerometer output from wrist- and hip-worn monitors. Medicine & Science in Sports & Exercise, 46(9), 1816–1824. https://doi.org/10.1249/MSS.0000000000000289
MAD — Mean Amplitude Deviation¶
MAD summarizes how much the acceleration magnitude fluctuates within an epoch. Specifically it’s the mean of the absolute deviations from the epoch’s mean acceleration magnitude. It correlates well with energy expenditure and is orientation-independent.
Reference:
Vähä-Ypyä, H., Vasankari, T., Husu, P., Suni, J., & Sievänen, H. (2015). A universal, accurate intensity-based classification of different physical activities using raw data of accelerometer. Clinical Physiology and Functional Imaging, 35(1), 64–70. https://doi.org/10.1111/cpf.12127
MIMS — Monitor-Independent Summary Units¶
MIMS is a standardized, device-agnostic summary unit. The pipeline interpolates to a fixed frequency (100 Hz), extrapolates values outside device range, band-pass filters, integrates area-under-the-curve per axis over each epoch, then combines axes (sum or vector magnitude) with small-value truncation. It’s designed to be comparable across devices and studies. This metric is computationally intensive and will run significantly slower than the other algorithms.
Reference:
John, D., Tang, Q., Albinali, F., & Intille, S. (2019). An open-source monitor-independent movement summary for accelerometer data processing. Journal for the Measurement of Physical Behaviour, 2(4), 268–281. https://doi.org/10.1123/jmpb.2019-0011
ActiGraph Activity Counts (ag_counts)¶
This reproduces the open ActiGraph counts method: resample to 30 Hz, apply the published IIR band-pass filter, scale to device units, threshold, downsample to 10 Hz, and sum within each epoch. The three axes are finally combined to yield epoch-level “counts.”
Reference:
Neishabouri, A., Wilson, K. E., Williams, D. K., Keadle, S. K., Sampson, J., John, D., & Staudenmayer, J. (2022). Quantification of acceleration as activity counts in ActiGraph wearable. Scientific Reports, 12(1), 11169. https://doi.org/10.1038/s41598-022-16003-x
A Special Note on Idle Sleep Mode.¶
The idle_sleep_mode for Actigraph watches will lead to uneven sampling rates during periods of no motion (read about this here). Consequently, this causes issues when implementing wristpy’s non-wear and sleep detection. As of this moment, we fill in the missing acceleration data with the assumption that the watch is perfectly idle in the face-up position (Acceleration vector = [0, 0, -1]). The data is filled in at the same sampling rate as the raw acceleration data. In the special circumstance when acceleration samples are not evenly spaced, the data is resampled to the highest effective sampling rate to ensure linearly sampled data.
References¶
[1] Vähä-Ypyä H, Vasankari T, Husu P, Suni J, Sievänen H. A universal, accurate intensity-based classification of different physical activities using raw data of accelerometer. Clin Physiol Funct Imaging. 2015;35(1):64-70. doi: https://doi.org/10.1111/cpf.12127. PMID: 24393233.
[2] Neishabouri A, Wilson KE, Williams DK, et al. Quantification of acceleration as activity counts in ActiGraph wearable. Sci Rep. 2022;12(1). doi: https://doi.org/10.1038/s41598-022-16003-x.
[3] John D, Tang Q, Albinali F, Intille S. An Open-Source Monitor-Independent Movement Summary for Accelerometer Data Processing. Journal for the Measurement of Physical Behaviour. 2019;2(4):268–281.
[4] Zhou S, Hill RA, Morgan K, et al. Classification of accelerometer wear and non-wear events in seconds for monitoring free-living physical activity. BMJ Open. 2015;5:e007447. doi: https://doi.org/10.1136/bmjopen-2014-007447.
[5] Vert A, et al. Detecting accelerometer non-wear periods using change in acceleration combined with rate-of-change in temperature. BMC Med Res Methodol. 2022;22(1):147. doi: https://doi.org/10.1186/s12874-022-01633-6.
[6] van Hees VT, Sabia S, Jones SE, et al. Estimating sleep parameters using an accelerometer without sleep diary. Sci Rep. 2018;8:12975. doi: https://doi.org/10.1038/s41598-018-31266-z.
[7] van Hees VT, et al. A Novel, Open Access Method to Assess Sleep Duration Using a Wrist-Worn Accelerometer. PLoS One. 2015;10:e0142533. doi: https://doi.org/10.1371/journal.pone.0142533.
[8] Hildebrand M, et al. Age group comparability of raw accelerometer output from wrist- and hip-worn monitors. Med Sci Sports Exerc. 2014;46(9):1816–1824. doi: https://doi.org/10.1249/mss.0000000000000289.
[9] Treuth MS, Schmitz K, Catellier DJ, et al. Defining accelerometer thresholds for activity intensities in adolescent girls. Med Sci Sports Exerc. 2004;36(7):1259–1266. PMID: 15235335; PMCID: PMC2423321.
[10] Aittasalo M, Vähä-Ypyä H, Vasankari T, et al. Mean amplitude deviation calculated from raw acceleration data: a novel method for classifying the intensity of adolescents’ physical activity irrespective of accelerometer brand. BMC Sports Sci Med Rehabil. 2015;7:18. doi: https://doi.org/10.1186/s13102-015-0010-0.