Skip to main content

A sleep classification tool for wearables

Project description

asleep: a sleep classifier for wearable sensor data using machine learning

This is a Python package for classifying sleep stages from wearable sensor data / wrist - worn accelerometer. The underlying model was trained and tested in 1000 + nights of multi - centre polysomnography with tri - axial accelerometer data.

The key features of this package are as follows:

  • A simple and easy - to - use API for sleep stage classification.
  • Sleep / wake metric estimation including total sleep duration and sleep efficiency.
  • Sleep architecture metric estimation including rapid - eye - movement(REM) / NREM sleep duration.

Dependencies

  • Python 3.8
  • Java 8 (1.8.0) or greater

Check with:

$ python --version
$ java -version

Installation

$ pip install asleep

Usage

All the processing will be much faster after the first time because the model weights will to have to be downloaded the first time that the package is used.

# Process an AX3 file
$ get_sleep sample.cwa

# Or an ActiGraph file
$ get_sleep sample.gt3x

# Or a GENEActiv file
$ get_sleep sample.bin

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

Output

Summary
-------
{
    "Filename": "sample.cwa",
    "Filesize(MB)": 65.1,
    "Device": "Axivity",
    "DeviceID": 2278,
    "ReadErrors": 0,
    "SampleRate": 100.0,
    "ReadOK": 1,
    "StartTime": "2013-10-21 10:00:07",
    "EndTime": "2013-10-28 10:00:01",
    "Total sleep duration(min)": 655.7,
    "Total overnight sleep(min)": 43132,
    ...
}

Estimated total sleep duration
---------------------
              total sleep duration(min)
time
2013 - 10 - 21     435.2
2013 - 10 - 22     436.2
2013 - 10 - 23    432.2
...

Output: outputs / sample/

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

Citation

If you want to use our package for your project, please cite our paper below:

@article {Yuan2023.07.07.23292251,
	author = {Hang Yuan and Tatiana Plekhanova and Rosemary Walmsley and Amy C. Reynolds and Kathleen J. Maddison and Maja Bucan and Philip Gehrman and Alex Rowlands and David W. Ray and Derrick Bennett and Joanne McVeigh and Leon Straker and Peter Eastwood and Simon D. Kyle and Aiden Doherty},
	title = {Self-supervised learning of accelerometer data provides new insights for sleep and its association with mortality},
	elocation-id = {2023.07.07.23292251},
	year = {2023},
	doi = {10.1101/2023.07.07.23292251},
	publisher = {Cold Spring Harbor Laboratory Press},
	URL = {https://www.medrxiv.org/content/early/2023/07/08/2023.07.07.23292251},
	eprint = {https://www.medrxiv.org/content/early/2023/07/08/2023.07.07.23292251.full.pdf},
	journal = {medRxiv}
}

Acknowledgements

We would like to thank all our code contributors, manuscript co - authors, and research participants for their help in making this work possible. The data processing pipeline of this repository is based on the step_count package from our group. Special thanks to @chanshing for his help in developing the package.

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

asleep-0.4.10.tar.gz (41.2 MB view details)

Uploaded Source

Built Distribution

asleep-0.4.10-py3-none-any.whl (43.7 kB view details)

Uploaded Python 3

File details

Details for the file asleep-0.4.10.tar.gz.

File metadata

  • Download URL: asleep-0.4.10.tar.gz
  • Upload date:
  • Size: 41.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for asleep-0.4.10.tar.gz
Algorithm Hash digest
SHA256 335f3cbaf90d94ddec05e35f5b6b59d845c0d8af2222439710469c9100ac2db2
MD5 3650dc737f5cdd12f713d1e73e041728
BLAKE2b-256 ece14b50a1e025101103796a40590223da9d42629b4a3d4aa870ece81db83ccd

See more details on using hashes here.

File details

Details for the file asleep-0.4.10-py3-none-any.whl.

File metadata

  • Download URL: asleep-0.4.10-py3-none-any.whl
  • Upload date:
  • Size: 43.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for asleep-0.4.10-py3-none-any.whl
Algorithm Hash digest
SHA256 777c85cf8203a07dbda92e7ae5fc9fe95ef7dee8417be5ee0963b567e43ea802
MD5 abb295828fe8597a8e36b97ae3a1bb0b
BLAKE2b-256 c0ec0783ba84f8bdd8ebfb29468481ad07488815e283ff9773d8c7f89c2413e4

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