A Python-native EDF and XML annotation viewer for sleep science
Project description
Sleep Science Viewer
A Python-native EDF file and XML annotation viewer.
Description
SleepScienceViewer is a Python-native application for visualizing and analyzing sleep data stored in EDF (European Data Format) and corresponding annotation files (XML). Designed with sleep science workflows in mind, the tool enables efficient review of signals and sleep stages through a responsive and customizable GUI.
SleepScienceViewer uses a class-based architecture to represent EDF and annotation files. These classes can also be used independently to access specific information from the files, supporting flexible review and analysis within notebooks or other Python programs.
Figure 1. Sleep Science Viewer interface with signals, hypnogram, spectrogram, and annotations.
Key Features
-
EDF & Annotation Support
- Load EDF files with associated XML annotation files
- Visualize up to 10 simultaneous signals
- View and interact with a full hypnogram display (see Figure 1)
-
Annotation Interaction
- Filter listed annotations by type
- Hypnogram-aligned annotation plot with automatically assigned colors
- Annotation combo box directly linked to annotation plot and list for synchronized selection (see Figure 1)
-
Custom Display Options
- Change epoch duration for signal navigation
- Toggle visibility of hypnogram, spectrogram, and annotation plots (see Figure 3 for signal-only mode)
- Switch hypnogram rendering between line trace and background-colored stage rectangles
- Generate multi-taper spectrograms for selected signals; if not feasible (e.g., low sampling frequency), display a compact heatmap instead
- Customize signal colors via color picker; choices persist across pan/zoom events
- Legends automatically update with user-defined signal colors
-
Report Generation & Export Tools
-
Generate EDF summary reports
-
Export individual signals to folder(s) for downstream use
-
Export annotation data including:
- A full annotation listing
- Sleep stage timeline
- Summary reports for review and documentation
-
-
Interface
- Show/hide hypnogram, spectrogram, and annotation panels from the main menu (see Figures 1 and 3)
-
Navigation
- Double-click on hypnogram, spectrogram, or annotation plots to move to the selected epoch
- Double-click on annotation list entries to jump to annotation start times
Figure 2. Signal Viewer interface displaying a single channel with epochs and overlays.
-
Signal Viewer
-
Signals
- View a single signal as a raster plot with 15 epochs displayed vertically (see Figure 2)
- Sleep stages shown as background rectangles behind the signal trace
- X-axis moved to the bottom of the plot for improved readability
-
Interface/Plotting
- Toggle hypnogram, spectrogram, and annotation overlays similar to the main viewer
- Signal-only mode available (see Figure 4)
-
Processing & Analysis
- Compute spectrograms (or default to heatmap if sampling frequency is insufficient)
- Apply common Band Pass and Notch filters on demand
-
Considering (future work)
- Displaying annotations directly on signal plots
- Support for marking epochs in-progress
-
*Figure 3. Sleep Science Viewer with hypnogram, spectrogram, and annotations hidden (signal-only mode).*
*Figure 4. Signal Viewer in signal-only mode with hypnogram, spectrogram, and annotations hidden.*
Workarounds
Double-click navigation is implemented but may be unstable due to limitations in how matplotlib interacts with PySide6. Framework code is in place, but full functionality is not guaranteed. Known workarounds:
- Avoid frequent switching between the Sleep Science Viewer and Signal Viewer windows.
- Redrawing figures within a window or reloading data often restores expected behavior.
Getting Started
The Sleep Science Viewer requires an EDF and Annotation file. We used files downloaded from the National Sleep Research Resource tutorial to develop the interface.
We recommend using a virtual environment when running the Sleep Science Viewer.
Intended Use
Ideal for researchers, clinicians, and developers working in sleep research, human performance, or bio-signal analysis. The interface and tools are designed to streamline review and reporting workflows for sleep study data.
Dependencies
This application was developed in Python 3.12, with the GUI built using PySide6. Please refer to requirements.txt for a complete list of required dependencies.
Download Test Data
We tested the SleepScienceViewer with data from here.
Installing
1. Install pipx
python -m pip install --user pipx
python -m pipx ensurepath
2. Download install package
git clone https://github.com/DennisDean/SleepScienceViewer4.git
cd SleepScienceViewer4/dist
3. Install SleepScience Viewer
pipx install sleepscienceviewer-0.1.0-py3-none-any.whl
Running the Application
To launch the application:
SleepScienceViewer
Help
Help documentation will be added as questions are received and common usage scenarios emerge. For questions or feedback, feel free to reach out to the author listed below.
Authors
Dennis A. Dean, II, PhD dennis.a.dean@gmail.com
Version History
-
v0.1.1
- Added display toggles for hypnogram, spectrogram, and annotation panels
- Hypnogram background color rendering for sleep stages
- Annotation synchronization between combo box, plot, and list
- Spectrogram-to-heatmap fallback for low sampling rates
- Signal color customization with legends
- Added Signal Viewer with raster view of single-channel data
-
v0.1
- First functioning release
License
This project is licensed under the GNU Affero General Public License v3.0 License. See the LICENSE.md file for details.
Acknowledgments
This project builds on work originally developed during my time at Brigham and Women's Hospital, where a similar class structure was used in earlier internal tools.
The original MATLAB version of this tool was shaped by valuable community feedback received following its public release on MATLAB Central.
It also benefited from code developed at Case Western Reserve University.
Special thanks to the authors of the multitaper_spectrogram_python.py module, which was refactored for this application to support multi-taper spectrogram visualization. More information on the multi-taper method can be found on the Prerau Lab website.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sleepscienceviewer-0.3.0.tar.gz.
File metadata
- Download URL: sleepscienceviewer-0.3.0.tar.gz
- Upload date:
- Size: 117.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e319e8b6deacaec2fe25bef83217bd06d8e7d36c0c55c5cdbdb5f590e23ecd8e
|
|
| MD5 |
5c51c8c89461bb4525500508e9ba7f6c
|
|
| BLAKE2b-256 |
64ae503969e2f1bdc4f1cb76ee3453fbb9a744102059b8c436ff0a549c3e5508
|
File details
Details for the file sleepscienceviewer-0.3.0-py3-none-any.whl.
File metadata
- Download URL: sleepscienceviewer-0.3.0-py3-none-any.whl
- Upload date:
- Size: 117.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fab1fe74650f073fb391c7b36a714cfb3772e5411190140c1210ba6f9d026e24
|
|
| MD5 |
89927a94515f85cef2a0d502051bb6fe
|
|
| BLAKE2b-256 |
5d0de30ea157d54c98f4b26dcf97c4ee870320429956f45117029a3f1f982938
|