Skip to main content

A Device-Agnostic, Open-Source Python Software for Wearable Circadian Rhythm and Sleep Analysis and Visualization

Project description

made-with-python PyPI download month PyPI version shields.io Maintenance GitHub watchers GitHub stars

HypnosPy :sleeping_bed:

A Device-Agnostic, Open-Source Python Software for Wearable Circadian Rhythm and Sleep Analysis and Visualization

Installation :computer:

You can install HypnosPy with pip in a (bash) shell environment, type:

pip install hypnospy

To update HypnosPy type:

pip install -U hypnospy

Dependencies include python 3.7 and the following packages:

Usage :bulb:

Here is a simple example of how you can use HypnosPy in your research:

from hypnospy import Wearable
from hypnospy.data import MESAPreProcessing
from hypnospy.analysis import SleepWakeAnalysis, Viewer, NonWearingDetector

# MESAPreProcessing is a specialized class to preprocess csv files from Philips Actiwatch Spectrum devices used in the MESA Sleep experiment
# MESA Sleep dataset can be found here: https://sleepdata.org/datasets/mesa/
preprocessed = MESAPreProcessing("../data/examples_mesa/mesa-sample.csv")

# Wearable is the main object in HypnosPy.
w = Wearable(preprocessed)

# In HypnosPy, we have the concept of ``experiment day'' which by default starts at midnight (00 hours).
# We can easily change it to any other time we wish. For example, lets run this script with experiment days
# that start at 3pm (15h)
w.change_start_hour_for_experiment_day(15)

# Sleep Wake Analysis module
sw = SleepWakeAnalysis(w)
sw.run_sleep_algorithm("ScrippsClinic", inplace=True) # runs alg and creates new col named 'ScrippsClinic'
sw.run_sleep_algorithm("Cole-Kripke", inplace=True)   # runs alg and creates new col named 'Cole-Kripke'

# View results
v = Viewer(w)
v.view_signals(signal_categories=["activity"], signal_as_area=["ScrippsClinic", "Cole-Kripke", "Oakley"],
               colors={"area": ["green", "red", "blue"]}, alphas={"area": 0.6})

# Easily remove non-wearing epochs/days.
nwd = NonWearingDetector(w)
nwd.detect_non_wear(strategy="choi")
nwd.check_valid_days(max_non_wear_minutes_per_day=180)
nwd.drop_invalid_days()

Some of the amazing features of HypnosPy are shown in the here. Try it out! :test_tube:

Under the hood :mag_right:

Here we'll iput a breakdown of the software architecture

centered image

Ignacio to provide a breakdown of the main software functionalities here

Circadian

centered image

HR algorithm (update)

centered image

We found that HR quantiles offered a personalized method to direct our sleeping window search as observed in the figure bellow:

centered image

Example

centered image

Cite our work! :memo::pencil:

Contributing :handshake:

We are very keen on having other colleagues contribute to our work and to make this as generalizable as possible of a package. This project came about due to the frustration of not having a centralized analysis tool that worked across devices, so if you find our project interesting or think you can improve it, please contribute by:

  • reporting bugs (how you got it and if possible, how to solve it)
  • adding new tools- if you are interested on this please email one of the main developers, we'd love to hear from you
  • adding pre-processing pipelines for new devices. The more, the merrier.
  • sharing our work with your colleagues, this will allow the project to improve and not die in this corner of the interweb.
  • reaching out!- we are always keen on learning more of how you are using/want to use hypnospy

License :clipboard:

This project is released under a BSD 2-Clause Licence (see LICENCE file)

Contributions :man_technologist: :woman_technologist:

  • João Palotti (MIT) @joaopalotti main developer
  • Marius Posa (Cambridge) @marius-posa main developer
  • Ignacio Perez-Pozuelo (Cambridge) @ippozuelo main developer

Research that uses HypnosPy :rocket:

  • Perez-Pozuelo, I., Posa, M., Spathis, D., Westgate, K., Wareham, N., Mascolo, C., ... & Palotti, J. (2020). Detecting sleep in free-living conditions without sleep-diaries: a device-agnostic, wearable heart rate sensing approach. medRxiv.

Acknowledgements :pray:

  • We thank the MRC Epidemiology Unit at Cambridge for supporting some of the research associated to this work as well as QCRI and MIT.

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

hypnospy-0.0.2.tar.gz (45.0 kB view details)

Uploaded Source

Built Distributions

hypnospy-0.0.2-py3.8.egg (106.6 kB view details)

Uploaded Source

hypnospy-0.0.2-py3-none-any.whl (50.4 kB view details)

Uploaded Python 3

File details

Details for the file hypnospy-0.0.2.tar.gz.

File metadata

  • Download URL: hypnospy-0.0.2.tar.gz
  • Upload date:
  • Size: 45.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for hypnospy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ac74f9e73e2603bcf176dd6c577c38f4009aa51a58fad3784385cc3af4f76eab
MD5 8929823ca2182c4b464842096626ea07
BLAKE2b-256 4194a6a0b56c6ba935d3adace67e7e98ec5f6c5c98bd7c2615424b8248682434

See more details on using hashes here.

File details

Details for the file hypnospy-0.0.2-py3.8.egg.

File metadata

  • Download URL: hypnospy-0.0.2-py3.8.egg
  • Upload date:
  • Size: 106.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for hypnospy-0.0.2-py3.8.egg
Algorithm Hash digest
SHA256 c693e0c3cda3c58895d6ff5564748aba72c861d211b180f16ccd9e2a672c441e
MD5 65487caa4535955efa611ed418103230
BLAKE2b-256 876c9306705feaeba1556ec88238e728f72f26c1e93b19c7cf59a4c7cc8cb392

See more details on using hashes here.

File details

Details for the file hypnospy-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: hypnospy-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 50.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for hypnospy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 75fb0e7a7a02fd9a8b73543943bb0a2a2b760f92af8040b340ba6881402e0f6e
MD5 6f9dd4dded49798f908d0b630fa9e129
BLAKE2b-256 4411022087fcf25a2c91a443882b37aa0be3fedf23da6d7071a3be2c8f5e6d34

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