Skip to main content

PSG Power for Python

Project description

Sleep Spindle-Slow Oscillation Coupling Analysis

Overview

This package provides tools for analyzing sleep EEG data, focusing on Sleep Spindles (SPs) and Slow Oscillations (SOs) and their coupling interactions. The package includes functionalities for:

  • EEG Preprocessing
  • Slow Oscillation (SO) Detection
  • Sleep Spindle (SP) Detection
  • Phase-Amplitude Coupling (PAC) Analysis
  • Peri-Event Time Histogram (PETH) Analysis
  • Data Visualization for SOs and SPs

Features

  • Multi-method SO and SP Detection: Choose from various published detection methods.
  • Coupling Analysis: Computes phase-amplitude coupling between SOs and SPs.
  • Batch Processing: Analyze multiple EEG recordings efficiently.
  • Interactive and Static Plotting: Visualize SO and SP events using topomaps and time-series plots.

Installation

Ensure you have Python installed. Then, install dependencies using:

pip install -r requirements.txt

Usage

1️⃣ Load EEG & Hypnogram Data

from polysomnography import PolySomnoGraphy

psg = PolySomnoGraphy(
    eeg_path="subject1.edf",
    hypnogram_path="subject1.txt",
    hypnogram_type="RemLogic"
)

# Access raw EEG data
raw = psg.get_raw()
# Access hypnogram data
hypnogram = psg.get_hypnogram()

2️⃣ Detect Sleep Spindles & Slow Oscillations

so_results = psg.detect_slow_oscillations(method="Staresina")
spindle_results = psg.detect_spindles(method="Hahn2020")

3️⃣ Compute Phase-Amplitude Coupling (PAC)

pac_results = psg.pac()

4️⃣ Batch Processing for Multiple EEG Files

from somno import get_sosp_for_folder

event_summary, coupling_events, so_waveforms = get_sosp_for_folder(
    raw_folder="EEG_data",
    stage_folder="Hypnogram_data"
)

5️⃣ Visualizations

from metrics import plot_SO, plot_SP

# Plot Slow Oscillation Events
plot_SO(so_results, raw)

# Plot Spindle Events
plot_SP(spindle_results, raw)

Supported File Formats

  • EEG Files: .edf, .vhdr, .set, .fif, .bdf, .cnt
  • Hypnogram Files:
    • RemLogic (.txt)
    • Hume (.mat)

License

MIT License

Contributors

  • Roger Balcells Sanchez
  • Thea Ng
  • Atif Abedeen
  • Lindsey Mooney

Acknowledgments

This package integrates various methods from published research on sleep spindles and slow oscillations.

Issues & Support

For bug reports and feature requests, please open an issue on GitHub.


📌 Want to contribute? Feel free to submit a pull request! 🚀

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

somnopy-0.0.8.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

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

somnopy-0.0.8-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file somnopy-0.0.8.tar.gz.

File metadata

  • Download URL: somnopy-0.0.8.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.4

File hashes

Hashes for somnopy-0.0.8.tar.gz
Algorithm Hash digest
SHA256 10bc10af8b2e545ff425bdb7d178ffd69774164b88e0afc9498829a7133692e6
MD5 703a6fbce12306054e7779cdc44fcf51
BLAKE2b-256 04eb2baef81dbb94912dd8c6985e1b2442d96753643b09525f6389028acfc529

See more details on using hashes here.

File details

Details for the file somnopy-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: somnopy-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.4

File hashes

Hashes for somnopy-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 254066b5d47cd512d9b9756bfe79a93b5f0d5dd8d3d3c43fad6652227de1881a
MD5 bd9884f2af59a6afa1641a908af93aa8
BLAKE2b-256 efbb3cb55c8efa61d8b13ba123aa169351041ae06cb0fc0676e683f6318319ae

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