Skip to main content

DETACH (Device Temperature and Acceleration Change) algorithm for detecting non-wear from raw accelerometer data.

Project description

nimbaldetach

DOI

DETACH (Device Temperature and Acceleration Change) algorithm detects non-wear periods for body-worn accelerometers by integrating a ‘rate-of-change’ criterion for temperature into a combined temperature-acceleration algorithm.

Publication

Vert, A., Weber, K. S., Thai, V., Turner, E., Beyer, K. B., Cornish, B. F., Godkin, F. E., Wong, C., McIlroy, W. E., & Van Ooteghem, K. (2022). Detecting accelerometer non-wear periods using change in acceleration combined with rate-of-change in temperature. BMC Medical Research Methodology, 22. https://doi.org/10.1186/s12874-022-01633-6

Using the DETACH Algorithm

The DETACH algorithm is stored as a function called nimbaldetach within the /src/nimbaldetach/nimbaldetach.py Python file.

The function itself is defined as follows

nimbaldetach(x_values, y_values, z_values, temperature_values, accel_freq=75,
             temperature_freq=0.25, std_thresh_mg=8.0, low_temperature_cutoff=26, high_temperature_cutoff=30,
             temp_dec_roc=-0.2, temp_inc_roc=0.1, num_axes=2, quiet=False)

Input Arguments

The input arguments and their definitions are listed in the table below:

Argument Data Type Optional (default value) or Required Description
x_values NumPy Array Required x-axis accelerometer values
y_values NumPy Array Required y-axis accelerometer values
z_values NumPy Array Required x-axis accelerometer values
temperature_values NumPy Array Required Temperature values
accel_freq float Optional (75) Frequency of the accelerometer in Hz
temperature_freq float Optional (0.25) Frequency of the temperature in Hz
std_thresh_mg float Optional (8.0) The value which the standard deviation (STD) of an axis in the window must be below to trigger non-wear
low_temperature_cutoff float Optional (26.0) Low temperature threshold for non-wear classification (see paper for more details)
high_temperature_cutoff float Optional (30.0) High temperature threshold for non-wear classification (see paper for more details)
temp_dec_roc float Optional (-0.2) Temperature decrease rate-of-change threshold for non-wear classification (see paper for more details)
temp_inc_roc float Optional (0.1) Temperature increase rate-of-change threshold for non-wear classification (see paper for more details)
num_axes int Optional (2) Number of axes that must be below the STD threshold to be considered non-wear
quiet bool Optional (False) Whether or not to quiet print statements.

Returns

The algorithm returns a tuple with two objects:

  1. start_stop_df: A pandas DataFrame with the start and end datapoints of the non-wear bouts.
  2. vert_nonwear_array: A numpy array with the same length of the accelerometer data marked as either wear (0) or non-wear (1)

Example

Example python code to determine the percentage of non-wear time from

from src.nimbaldetach.nimbaldetach import nimbaldetach
import numpy as np

# Load Data
accelerometer_vals = np.load("path\to\raw\accelerometer.npy")
temperature_values = np.load("path\to\raw\temperature.npy")
x_values = accelerometer_vals[0]
y_values = accelerometer_vals[1]
z_values = accelerometer_vals[2]

# Define Frequencies
accel_freq = 75
temperature_freq = 0.25

# Calculate Non-wear
start_stop_df, nonwear_array = nimbaldetach(x_values=x_values, y_values=y_values, z_values=z_values,
                                            temperature_values=temperature_values, accel_freq=accel_freq,
                                            temperature_freq=temperature_freq)

# Analysis
total_wear_time = np.sum(nonwear_array)
pct_worn = total_wear_time / len(nonwear_array) * 100

print("The device was not worn %s percent of the time" % pct_worn)

Version/Changelog

v1.0.3

  • loosen dependency requirements to minimum version instead of minor version

v1.0.2

Installation

To install the latest release of nimbaldetach directly from GitHub using pip, run the following line in terminal or console:

pip install git+https://github.com/nimbal/nimbaldetach

To install a specific release, insert @v#.#.# after the repository name replacing with the tag associated with that release. For example:

pip install git+https://github.com/nimbal/nimbaldetach@v1.0

Include nimbaldetach as Package Dependency

To include the latest release of nimbaldetach as a dependency in your Python package, include the following string within the list alongside your other dependencies:

install_requires=['nimbaldetach@git+https://github.com/nimbal/nimbaldetach@[version]']

To include a specific release, replace [version] with the tag associated with that release.

nimbaldetach Package Dependencies

  • numpy
  • pandas
  • scipy

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

nimbaldetach-1.0.3.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

nimbaldetach-1.0.3-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file nimbaldetach-1.0.3.tar.gz.

File metadata

  • Download URL: nimbaldetach-1.0.3.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for nimbaldetach-1.0.3.tar.gz
Algorithm Hash digest
SHA256 584e59d02cbdde9e94d61fbb29d3baad896358b86c67f30dcd260d2431b61df5
MD5 64002fdc9705146644d9eb83b2aa87aa
BLAKE2b-256 259486211af410f21b498c9e5e3bf435b485ebce273360154c6ed745bf337f8c

See more details on using hashes here.

File details

Details for the file nimbaldetach-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for nimbaldetach-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f90e09c2ee6f34cec5dd3c5b9e57012e238ce4bfb6d65d4af1947695e8417dd2
MD5 8671f2b9ee0b83cd8c856f995db3c722
BLAKE2b-256 55c605f8269e30b4293c727567b441f55fb30b6211773fb9fbf393545055f76e

See more details on using hashes here.

Supported by

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