Skip to main content

Wear-time detection algorithms for IMU wearable sensors

Project description

IMU Wear-Time Detection

License PyPI version DOI

A Python library providing validated wear-time detection algorithms for lower-back worn IMU sensors. Includes both established methods from the literature and novel signal processing, machine learning, and deep learning approaches.

This library was developed as part of the SUSTAIN Mobilise-D project and implements algorithms designed to work within the MobGap ecosystem for mobility analysis.

Novel algorithms outperform all literature methods by 8- to 131-fold in wear-time quantification accuracy.

Software developed by Dr Dimitrios Megaritis. Scientific authorship is listed in CITATION.cff.


Installation

From PyPI (recommended)

pip install imu-weartime

From source

git clone https://github.com/[username]/imu-weartime.git
cd imu-weartime
pip install .

Quick Start

from mobgap.data import LabExampleDataset
from mobgap.utils.conversions import to_body_frame
from imu_weartime.weartime import WtdMegaritis_CNN

# Load example data
data = LabExampleDataset().get_subset(
    cohort="HA", participant_id="001", test="Test11", trial="Trial1"
)

# Apply wear-time detection
wtd = WtdMegaritis_CNN(version="cnn_lstm").detect(
    to_body_frame(data.data_ss), 
    sampling_rate_hz=data.sampling_rate_hz
)

print(f"Total wear-time: {wtd.total_weartime_hours_:.2f} hours")
print(wtd.weartime_list_)

Available Algorithms

Novel Algorithms (Megaritis et al.)

Developed and validated specifically for this library (ranked by performance):

  1. WtdMegaritis_CNN - Deep learning with 1D CNN and CNN-LSTM variants (best-performing)

    • Versions: "cnn" (baseline) or "cnn_lstm" (with LSTM, default)
    • Operates on raw windowed IMU data (no feature engineering)
  2. WtdMegaritisXGBoost - Gradient boosting classifier

    • Versions: "full" (230 features) or "lightweight" (79 features, default)
    • SHAP-based feature selection for lightweight variant
  3. WtdMegaritis_LogReg - Logistic regression with feature scaling

    • Versions: "full" (230 features) or "lightweight" (99 features, default)
    • StandardScaler normalization included
  4. Wtd_Megaritis_signal - Signal processing using gyroscope spectral patterns

    • Gyroscope spectral centroids (ML and IS axes) with accelerometer variability (PA axis)
    • Multi-level voting with biomechanical post-processing
    • No machine learning required

Literature Algorithms

Implementations of published methods (adapted for compatibility):

  • WtdTroiano, WtdChoi, WtdVanHees, WtdAhmadi, WtdKing, WtdDuncan, WtdRasmussen, WtdZhou, WtdVert, WtdPagnamenta, WtdNishiyama, WtdHecht

See individual algorithm documentation for references and parameter details.


Usage Examples

Deep Learning (Recommended)

from imu_weartime.weartime import WtdMegaritis_CNN

# CNN-LSTM (best performing)
wtd = WtdMegaritis_CNN(version="cnn_lstm").detect(
    imu_data, sampling_rate_hz=100.0
)

# CNN baseline
wtd = WtdMegaritis_CNN(version="cnn").detect(
    imu_data, sampling_rate_hz=100.0
)

Machine Learning

from imu_weartime.weartime import WtdMegaritisXGBoost, WtdMegaritis_LogReg

# XGBoost (lightweight by default)
wtd_xgb = WtdMegaritisXGBoost(version="lightweight").detect(
    imu_data, sampling_rate_hz=100.0
)

# Logistic Regression
wtd_lr = WtdMegaritis_LogReg(version="lightweight").detect(
    imu_data, sampling_rate_hz=100.0
)

Signal Processing

from imu_weartime.weartime import Wtd_Megaritis_signal

wtd = Wtd_Megaritis_signal().detect(imu_data, sampling_rate_hz=100.0)

Literature Methods

from imu_weartime.weartime import WtdTroiano, WtdVanHees, WtdAhmadi

wtd_troiano = WtdTroiano(nci=False).detect(imu_data, sampling_rate_hz=100.0)
wtd_vanhees = WtdVanHees().detect(imu_data, sampling_rate_hz=100.0)
wtd_ahmadi = WtdAhmadi(version="sd_xyz").detect(imu_data, sampling_rate_hz=100.0)

Algorithm Performance

Novel algorithms ranked by validation performance:

  1. CNN-LSTM (best overall)
  2. CNN
  3. XGBoost (lightweight)
  4. Signal Processing = Logistic Regression

Novel methods outperform all literature algorithms by 8- to 131-fold in wear-time quantification accuracy.

Detailed performance metrics and validation results will be published in the accompanying manuscript.


Citation

If you use this library in your research, please cite:

@software{megaritis2026imu_weartime,
  author    = {Megaritis, Dimitrios},
  title     = {IMU Wear-Time Detection: Validated Algorithms for Wearable Sensors},
  year      = {2026},
  publisher = {GitHub},
  url       = {https://github.com/[username]/imu-weartime},
  license   = {Apache-2.0}
}

Compatibility

  • Python: 3.9 to 3.13
  • Dependencies: mobgap==1.1.0, pandas, numpy, scikit-learn, xgboost, tensorflow
  • Sensor: Lower-back worn IMU (100 Hz sampling recommended)
  • Data format: MobGap body-frame coordinates

Funding and Support

This work was supported by the SUSTAIN Mobilise-D Consortium. Content in this publication reflects the authors' view and neither EFPIA, or any Associated Partners are responsible for any use that may be made of the information contained herein.


License

Licensed under the Apache License 2.0. Free to use for any purpose, including commercial use. See LICENSE for full terms.

Disclaimer: This software is provided "as is" without warranty. It is not a medical product nor licensed for medical use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imu_weartime-1.0.0.tar.gz (8.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imu_weartime-1.0.0-py3-none-any.whl (8.7 MB view details)

Uploaded Python 3

File details

Details for the file imu_weartime-1.0.0.tar.gz.

File metadata

  • Download URL: imu_weartime-1.0.0.tar.gz
  • Upload date:
  • Size: 8.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.10 Darwin/24.6.0

File hashes

Hashes for imu_weartime-1.0.0.tar.gz
Algorithm Hash digest
SHA256 24e53fe1af68eeb6135e93c3e5c303dbac3d3904c35716079a43eaa0afb94e95
MD5 f3c4a7568d2da3a2eccdf7ffe813f552
BLAKE2b-256 4f3c53b769134ca09869f99041f567dc38f6d0f1ee90658c494360dff6df94fb

See more details on using hashes here.

File details

Details for the file imu_weartime-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: imu_weartime-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.10 Darwin/24.6.0

File hashes

Hashes for imu_weartime-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28b8c10ec0e6b3a806480e1b6cf7bca411d19e10d23481cd855294e967823787
MD5 85288d6910fad4f0b61e6bd72cf16c78
BLAKE2b-256 23ea4c791ce887aff907561a0cfc06b71eef2d1579306cfce47529d70ab9a935

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page