Skip to main content

OpenSpindleNet

An open-source tool for sleep spindle detection using neural networks.

Installation

Basic installation (core detection only):

pip install .

Full installation with CLI capabilities:

pip install .[cli]

Usage

Python API

import numpy as np
from openspindlenet import detect

# From a file
results = detect("path/to/eeg.txt", model_type="eeg")

# From a numpy array
eeg_data = np.random.randn(7500)
results = detect(eeg_data, model_type="eeg")

# Optional: evaluate against segmentation labels (same length as signal)
labels = np.zeros(7500, dtype=np.float32)
scored = detect(eeg_data, model_type="eeg", labels=labels)
print(scored["metrics"]["detection"])  # precision/recall/f1 + TP/FP/FN
print(scored["metrics"]["segmentation"])  # precision/recall/f1 + TP/FP/FN

# Access results
print(f"Number of spindles detected: {len(results['detection_intervals'])}")
for i, (start, end, confidence) in enumerate(results['detection_intervals']):
  print(f"Spindle {i+1}: start={start:.1f}, end={end:.1f}, conf={confidence:.2f}")

Command Line Interface

The CLI requires additional dependencies. Install with pip install openspindlenet[cli].

# Detect spindles in an EEG file
openspindlenet detect path/to/eeg.txt --model-type eeg --visualize

# Detect spindles in an iEEG file
openspindlenet detect path/to/ieeg.txt --model-type ieeg --visualize

# Evaluate one signal against labels and write JSON/CSV outputs
openspindlenet eval path/to/eeg.txt path/to/labels.txt --visualize

# Show information about available models
openspindlenet info

# Run detection on included example data
openspindlenet example --data-type eeg

eval writes timestamped JSON and CSV metric outputs by default and, with --visualize, generates a PDF that includes predictions, labels, and metric summary.

Development

Testing

Run the test suite:

# Install dev dependencies
pip install -e .[dev]

# Run tests
pytest tests/

Cite

If you find our work useful, please cite our publication

@article{sejak2025openspindlenet,
  title={OpenSpindleNet: An open-source deep learning network for reliable sleep spindle detection in scalp and intracranial EEG},
  author={Sejak, Michal and Mivalt, Filip and Sladky, Vladimir and Vsiansky, Vit and Carvalho, Diego Z and Louis, Erik K St and Worrell, Gregory A and Kremen, Vaclav},
  journal={Computers in Biology and Medicine},
  volume={197},
  pages={110854},
  year={2025},
  publisher={Elsevier}
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for openspindlenet 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openspindlenet 0.1.1
File Size Uploaded
openspindlenet-0.1.1.tar.gz 6.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for openspindlenet 0.1.1
File Interpreter ABI Platform
openspindlenet-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 MB

Release files / openspindlenet-0.1.1.tar.gz

Download URL openspindlenet-0.1.1.tar.gz
Size 6.2 MB
Tags Source
SHA-256 checksum
How to use checksums
8a918b76bdf75b6eed9de84203ed89460bee8293a9ea190d2735de05c4732767
BLAKE2b-256 checksum
How to use checksums
b71dbff4a08b8169ac1d9b7275c8ace642805db08c0a90f02ac6b831788772b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / openspindlenet-0.1.1-py3-none-any.whl

Download URL openspindlenet-0.1.1-py3-none-any.whl
Size 6.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
d513095db4c21ba73712d7ffd0694d29910b1a7c62970ebe79873ba7a631a8ff
BLAKE2b-256 checksum
How to use checksums
d9c4cfd33fce4b1c338d11a2d0bccfee99781408ee0fa40cdbca3dc163a90992
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

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