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.10.tar.gz (33.0 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.10-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: somnopy-0.0.10.tar.gz
  • Upload date:
  • Size: 33.0 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.10.tar.gz
Algorithm Hash digest
SHA256 01f4b31e83c4370480166a701e916194b2fb2f191baf4c5b7f69bd350ff65f78
MD5 b1a6b8bd9251b43495511d2a884d6d0f
BLAKE2b-256 c182f5de20f62607db19fc3871669e0589fc5664206167c54124cbf08afd7b0d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: somnopy-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 34.8 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.10-py3-none-any.whl
Algorithm Hash digest
SHA256 c1c860ce9faf70ec581eff4f11af5d8dfc410f9ec310843a3d7cba275deae83f
MD5 fe55b3efac955eb46d929e786e23f17e
BLAKE2b-256 c9c623e0755585c3f461127ee4a1ef426e98d07b04484d0cfaf70882b8e52bd8

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