Skip to main content

sleep-utils

A python toolbox for sleep researchers. Plot hypnograms, spectrograms, confusion matrices, PSG summaries

sample_hypnogram.png spectrogram_multitaper.png
Hypnogram summary
{'TRT': 460.5,
 'TST': 444.5,
 'WASO': 16.0,
 'lat_REM': 65.0,
 'lat_N1': 0.0,
 'lat_N2': 2.0,
 'lat_SWS': 9.0,
 'min_REM': 109.5,
 'min_N1': 13.5,
 'min_N2': 214.0,
 'min_SWS': 107.5,
 'perc_REM': 0.24634420697412823,
 'perc_N1': 0.030371203599550055,
 'perc_N2': 0.4814398200224972,
 'perc_SWS': 0.24184476940382452,
 'perc_W': 0.03474484256243214,
 'recording_length': 547.0,
 'sleep_offset_after_rec_start': 534.0,
 'sleep_onset_after_rec_start': 73.5}

Install

pip install sleep-utils

or

pip install git+https://github.com/skjerns/sleep-utils

Modules

The sleep-utils package is organized into several modules, each providing specific functionalities for sleep data analysis.

sleep_utils.gui

This module provides graphical user interface (GUI) components built with tkinter. It simplifies tasks like selecting files and folders, and getting user input, making your scripts more interactive.

sleep_utils.plotting

A comprehensive module for creating various plots related to sleep analysis. You can use it to:

  • Plot hypnograms
  • Generate spectrograms of EEG data
  • Visualize confusion matrices for inter-rater reliability
  • Plot noise characteristics of your signals

sleep_utils.sigproc

This module contains a collection of functions for signal processing of physiological data. Key features include:

  • Filtering and resampling signals
  • Detecting artifacts in your data
  • Heuristics for spindle detection and other sleep-related events.

sleep_utils.tools

A set of utility functions that make working with sleep data easier. This module provides tools for:

  • Reading and writing hypnograms in various formats
  • Calculating and summarizing sleep statistics (e.g., TST, WASO, sleep efficiency) based on AASM guidelines.
  • Inferring relationships between PSG and hypnogram files.

sleep_utils.usleep_utils

This module provides a convenient wrapper around the U-Sleep API for automatic sleep staging. You can use it to:

  • Predict sleep stages from EEG/EOG data using the U-Sleep model
  • Manage prediction sessions with the API
  • It supports both mne.io.Raw objects and EDF files as input.

By default requests go to the public service at https://sleep.ai.ku.dk. If you run your own U-Sleep server, point the functions at it with url=:

hypno = predict_usleep(edf_file, api_token, eeg_chs=..., eog_chs=...,
                       url="http://my-usleep-server:8887")

Alternatively set the USLEEP_API_URL environment variable to redirect every call without touching any code. predict_usleep, predict_usleep_raw and delete_all_sessions all accept url=; omitting it keeps the previous behaviour.

Download files

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

Source Distribution

sleep_utils-1.27.tar.gz (41.0 kB view details)

Uploaded Source

Built Distribution

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

sleep_utils-1.27-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

Details for the file sleep_utils-1.27.tar.gz.

File metadata

  • Download URL: sleep_utils-1.27.tar.gz
  • Upload date:
  • Size: 41.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for sleep_utils-1.27.tar.gz
Algorithm Hash digest
SHA256 4354c9095e97a286052906a22004abaad3e0eb853d0e57d0d6368ff99dd455c7
MD5 287488f5945ae1e3029474fbed4e6cd3
BLAKE2b-256 11b15ab732bf211ba0b5786db60889c5324719ca25d3c5ab41177e2e4a51df0a

See more details on using hashes here.

File details

Details for the file sleep_utils-1.27-py3-none-any.whl.

File metadata

  • Download URL: sleep_utils-1.27-py3-none-any.whl
  • Upload date:
  • Size: 41.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for sleep_utils-1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 92ae767937f4b1604987b715a6488a0302f99c57ae565ef5cdaa65d39bee0ebd
MD5 abca353568358b0f0daaa40689a170dd
BLAKE2b-256 b5746d191b43e1af395da75b2ce67b8daa01619c74f09e12194117ad916adacf

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.27 This release

2 files

1.26

2 files

1.25

2 files

1.24

2 files

1.23

2 files

1.22

2 files

1.21

2 files

1.20

2 files

1.19

2 files

1.17

2 files

1.16

2 files

1.15

2 files

1.13

2 files

1.12

2 files

1.11

2 files

1.1

2 files

1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page