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.9.tar.gz (32.4 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.9-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for somnopy-0.0.9.tar.gz
Algorithm Hash digest
SHA256 398ffe24e5a3c3541f6a1d364c61f4d5b691c070b6744d024588777a6158c132
MD5 82ac04295007fcc23bdf071d9f414ff2
BLAKE2b-256 e95bb47735ae7181029e7222e891108a8165e33d1b16cfb08070f1bedcf9959f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for somnopy-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 d16c31cc0421d30b068ba0c0762bbdbcfb6dd834c3dbf23be4adc717f1bdce60
MD5 c5adc0fa500ba90acb98270d0203b23f
BLAKE2b-256 fcb1f283fddb178c1782868e115c868cc09838393947b4baaeb2bd5e20dc2fbc

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