Skip to main content

Open-source Python library for AASM 2.6-compliant automated polysomnography scoring

Project description

psgscoring

PyPI License: BSD-3 Python Validated

Open-source Python library for AASM 2.6-compliant automated polysomnography scoring.

psgscoring extracts the core respiratory scoring algorithms from YASAFlaskified into a standalone, pip-installable library for the research community.

Validation (v0.2.95)

External validation on two public datasets:

PSG-IPA (PhysioNet, 5 recordings, 60 scorer sessions from 12 RPSGT/ESRS)

Metric Result Target
AHI bias +1.6/h <±5/h ✓
MAE 2.5/h
Pearson r 0.990 ≥0.85 ✓
Severity concordance 75% ≥70% ✓
Event-level F1 (SN3) 0.890

For 3/5 recordings, the algorithm's deviation from the scorer mean was smaller than the inter-scorer variability.

iSLEEPS (39 ischemic stroke patients, SOMNOmedics)

Severity Bias MAE
Normal/Mild (n=13) −0.1/h 3.3/h
Moderate/Severe (n=26) −16.6/h 16.6/h

Excellent for standard populations; systematic under-scoring in stroke patients (central apnea predominance).

Features

  • AASM 2.6 respiratory scoring: apnea/hypopnea detection with dual-sensor support
  • 12 systematic bias corrections: 6 over-counting + 6 under-counting
  • Breath-amplitude stability filter: rejects false-positive hypopneas during normal breathing
  • AHI confidence interval: strict/standard/sensitive profiles with robustness grade (A/B/C)
  • Hypoxic burden (v0.2.95): total SpO₂ desaturation area per event, normalised per hour (Azarbarzin et al., AJRCCM 2019)
  • Post-processing (v0.2.95): CSR-aware central reclassification, mixed apnea decomposition, central instability index
  • ECG-derived effort classification: spectral + TECG for central apnea detection
  • Configurable scoring profiles: strict (research), standard (AASM 2.6), sensitive (UARS)
  • PLM, SpO₂, RERA/RDI, signal quality assessment

Installation

pip install psgscoring

Quick start

from psgscoring import run_pneumo_analysis
import mne

raw = mne.io.read_raw_edf("recording.edf", preload=True)
hypno = ["W", "N1", "N2", "N3", "R", ...]  # 30-s epochs

results = run_pneumo_analysis(raw, hypno, scoring_profile="standard")

# AHI with confidence interval
iv = results["ahi_interval"]
print(f"AHI: {iv['standard']['ahi']} [{iv['strict']['ahi']}{iv['sensitive']['ahi']}]")
print(f"Grade: {iv['robustness_grade']}")

# Hypoxic burden (v0.2.95)
hb = results["hypoxic_burden"]
print(f"Hypoxic burden: {hb['hypoxic_burden']} {hb['unit']}")

# Post-processing results (v0.2.95)
pp = results["postprocess"]
print(f"CSR reclassified: {pp['n_csr_reclassified']}")
print(f"Mixed decomposed: {pp['n_mixed_decomposed']}")

What's new in v0.2.95

  • Ensemble-averaged hypoxic burden: baseline_method="ensemble" reproduces the original Azarbarzin et al. (2019) method with subject-specific search windows derived from ensemble-averaged SpO₂ curves. Default "percentile" is unchanged.
  • Hypoxic burden: per-event SpO₂ desaturation area, normalised %·min/h
    • Clinical thresholds: <20 low, 20–73 moderate, >73 high CV risk
  • CSR-aware reclassification: flagged obstructive/mixed events in CSR troughs → central
  • Mixed apnea decomposition: central portion ≥10s → reclassified as central
  • Central instability index: profile-dependent O/C uncertainty (0–1 scale)
  • iSLEEPS validation: 39 stroke patients, MAE 3.3/h at normal/mild
  • Event-level validation: F1=0.890, Δt=2.3s on severe-OSA recording

Documentation

📖 Online Supplement (Wiki) 📖 Technical Handbook

Live platform

slaapkliniek.be — upload EDF, receive complete PSG report.

Citation

Rombaut B, Rombaut B, Rombaut C. psgscoring: An Open-Source Python Library for AASM 2.6-Compliant Automated Polysomnography Scoring. 2026. https://github.com/bartromb/psgscoring

This library builds on YASA:

Vallat R, Walker MP. An open-source, high-performance tool for automated sleep staging. eLife. 2021;10:e70092.

License

BSD-3-Clause. See LICENSE.

Disclaimer: Research use only. Not CE-marked or FDA-cleared. See DISCLAIMER.md.

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

psgscoring-0.2.95.tar.gz (71.7 kB view details)

Uploaded Source

Built Distribution

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

psgscoring-0.2.95-py3-none-any.whl (76.7 kB view details)

Uploaded Python 3

File details

Details for the file psgscoring-0.2.95.tar.gz.

File metadata

  • Download URL: psgscoring-0.2.95.tar.gz
  • Upload date:
  • Size: 71.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for psgscoring-0.2.95.tar.gz
Algorithm Hash digest
SHA256 b59cd0246b78d033d629a3b8c5dccebb599dba80ad37b833bae90c067bf6230c
MD5 1f4202cd68d7819963455e19b72dd154
BLAKE2b-256 e279c8d75108339a60d3c7ccfd837b9715c4d5d6166229c694d70cd847f7355f

See more details on using hashes here.

File details

Details for the file psgscoring-0.2.95-py3-none-any.whl.

File metadata

  • Download URL: psgscoring-0.2.95-py3-none-any.whl
  • Upload date:
  • Size: 76.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for psgscoring-0.2.95-py3-none-any.whl
Algorithm Hash digest
SHA256 d09b279342aa66b30663d6dd52dff489b3e74d420e4988913649d2ebce6ab781
MD5 ca3cf501d4bee4e2ad312d3962f1f761
BLAKE2b-256 8ad5f803658e4bf4192bcbda635c09b7a57e11a7034b39aaadae4ee516539f8b

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