YASA (Yet Another Spindle Algorithm) is a command-line sleep analysis toolbox in Python. The main functions of YASA are:
- Automatic sleep staging of polysomnography data (see eLife article).
- Event detection: sleep spindles, slow-waves and rapid eye movements, on single or multi-channel EEG data.
- Artefact rejection, on single or multi-channel EEG data.
- Spectral analyses: bandpower, phase-amplitude coupling, 1/f slope, and more!
- Hypnogram analysis: sleep statistics, stage transitions, visualization, and manipulation.
For more details, try the tutorials or read the FAQ.
YASA can be easily installed using pip, conda, or uv:
uv pip install yasa
pip install --upgrade yasa
conda install -c conda-forge yasaSome features require optional dependencies. Install them with extras:
pip install "yasa[full]" # all optional dependenciesTo build and install from source, clone this repository and install in editable mode with uv
git clone https://github.com/raphaelvallat/yasa.git
cd yasa
uv pip install --group=test --editable .
# test the package
pytest --verboseFor common questions about prerequisites, data formats, and how to load EEG data, see the FAQ.
The best starting point is the tutorials section of the documentation, which includes a quickstart guide and step-by-step walkthroughs of the most common workflows.
Additional worked examples are available as Jupyter notebooks on GitHub. Note that some notebooks may not reflect the latest API.
Below some plots demonstrating the functionalities of YASA. For step-by-step examples, see the tutorials or the Jupyter notebooks.
The top plot show an overlay of the detected spindles on real EEG data. The middle left panel shows a time-frequency representation of the whole-night recording (spectrogram), plotted with the hypnogram (sleep stages) on top. The middle right panel shows the sleep stage probability transition matrix, calculated across the entire night. The bottom row shows, from left to right: a topographic plot, the average template of all detected slow-waves across the entire night stratified by channels, and a phase-amplitude coupling comodulogram.
YASA was created and is maintained by Raphael Vallat. Contributions are more than welcome! See the contributing guide for guidelines.
To see the code or report a bug, please visit the GitHub repository.
Note that this program is provided with NO WARRANTY OF ANY KIND.
To cite YASA, please use the eLife publication:
- Vallat, Raphael, and Matthew P. Walker. "An open-source, high-performance tool for automated sleep staging." Elife 10 (2021). doi: https://doi.org/10.7554/eLife.70092
