Skip to main content

Activity detection algorithm compatible with the UK Biobank Accelerometer Dataset

Project description

actinet

A tool to extract meaningful health information from large accelerometer datasets. The software generates time-series and summary metrics useful for answering key questions such as how much time is spent in sleep, sedentary behaviour, or doing physical activity. The backbone of this repository is the self-supervised learning of Hang et al.: https://www.nature.com/articles/s41746-024-01062-3

Install

Minimum requirements: Python>=3.9, Java 8 (1.8)

The following instructions make use of Anaconda to meet the minimum requirements:

  1. Download & install Miniconda (light-weight version of Anaconda).

  2. (Windows) Once installed, launch the Anaconda Prompt.

  3. Create a virtual environment:

    conda create -n actinet python=3.9 openjdk pip
    

    This creates a virtual environment called actinet with Python version 3.9, OpenJDK, and Pip.

  4. Activate the environment:

    conda activate actinet
    

    You should now see (actinet) written in front of your prompt.

  5. Install actinet:

    pip install actinet
    

You are all set! The next time that you want to use actinet, open the Anaconda Prompt and activate the environment (step 4). If you see (actinet) in front of your prompt, you are ready to go!

Usage

# Process an AX3 file
$ actinet sample.cwa

# Or an ActiGraph file
$ actinet sample.gt3x

# Or a GENEActiv file
$ actinet sample.bin

# Or a CSV file (see data format below)
$ actinet sample.csv

Troubleshooting

Some systems may face issues with Java when running the script. If this is your case, try fixing OpenJDK to version 8:

conda create -n actinet openjdk=8

Offline usage

To use this package offline, one must first download and install the relevant classifier file and model modules. This repository offers two ways of doing this.

Run the following code when you have internet access:

actinet --cache-classifier

Following this, the actinet classifier can be used as standard without internet access, without needing to specify the flags relating to the model repository.

Alternatively, you can download or git clone the ssl modules from the ssl-wearables repository.

In addition, you can donwload/prepare a custom classifier file.

Once this is downloaded to an appopriate location, you can run the actinet model using:

actinet sample.cwa -c /path/to/classifier.joblib.lzma -m /path/to/ssl-wearables

Output files

By default, output files will be stored in a folder named after the input file, outputs/{filename}/, created in the current working directory. You can change the output path with the -o flag:

$ actinet sample.cwa -o /path/to/some/folder/

<Output summary written to: /path/to/some/folder/sample-outputSummary.json>
<Time series output written to: /path/to/some/folder/sample-timeSeries.csv.gz>

The following output files are created:

  • Info.json Summary info, as shown above.
  • timeSeries.csv Raw time-series of activity levels

See Data Dictionary for the list of output variables.

Plotting activity profiles

To plot the activity profiles, you can use the -p flag:

$ actinet sample.cwa -p
<Output plot written to: data/sample-timeSeries-plot.png>

Crude vs. Adjusted Estimates

Adjusted estimates are provided that account for missing data. Missing values in the time-series are imputed with the mean of the same timepoint of other available days. For adjusted totals and daily statistics, 24h multiples are needed and will be imputed if necessary. Estimates will be NaN where data is still missing after imputation.

Processing CSV files

If a CSV file is provided, it must have the following header: time, x, y, z.

Example:

time,x,y,z
2013-10-21 10:00:08.000,-0.078923,0.396706,0.917759
2013-10-21 10:00:08.010,-0.094370,0.381479,0.933580
2013-10-21 10:00:08.020,-0.094370,0.366252,0.901938
2013-10-21 10:00:08.030,-0.078923,0.411933,0.901938
...

Processing multiple files

Windows

To process multiple files you can create a text file in Notepad which includes one line for each file you wish to process, as shown below for file1.cwa, file2.cwa, and file2.cwa.

Example text file commands.txt:

actinet file1.cwa &
actinet file2.cwa &
actinet file3.cwa 
:END

Once this file is created, run cmd < commands.txt from the terminal.

Linux

Create a file command.sh with:

actinet file1.cwa
actinet file2.cwa
actinet file3.cwa

Then, run bash command.sh from the terminal.

Collating outputs

A utility script is provided to collate outputs from multiple runs:

actinet-collate-outputs outputs/

This will collate all *-Info.json files found in outputs/ and generate a CSV file.

Citing our work

When using this tool, please consider citing the works listed in CITATION.md.

Licence

See LICENSE.md.

Acknowledgements

We would like to thank all our code contributors, manuscript co-authors, and research participants for their help in making this work possible.

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

actinet-0.2.2.tar.gz (61.4 kB view details)

Uploaded Source

Built Distribution

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

actinet-0.2.2-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

Details for the file actinet-0.2.2.tar.gz.

File metadata

  • Download URL: actinet-0.2.2.tar.gz
  • Upload date:
  • Size: 61.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for actinet-0.2.2.tar.gz
Algorithm Hash digest
SHA256 c1b69fb388e0f584e03f81b8eb24e9766201e8afb13763279173c1d2a1b8991c
MD5 0a11f16d54a136d53112a2882449032f
BLAKE2b-256 7a57cf4c69a51fbf30fdd9b9f9da1e4b2622647a91b00cb49cf962758e5ffa48

See more details on using hashes here.

File details

Details for the file actinet-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: actinet-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 43.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for actinet-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 82f7a49e75a6b65af4c5a6b9b957f13a26cfd032a6ceb628c8be767f50f75cc8
MD5 b28990bed8a177f2cb6c45ae79579183
BLAKE2b-256 eaa4a5c1dcc29e13f124bc673ee880e3fe2bdbf62f9a538d0a3ece5250b6b032

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