https://badge.fury.io/py/yasa.svg https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8%20%7C%203.9-blue https://img.shields.io/github/license/raphaelvallat/yasa.svg https://travis-ci.org/raphaelvallat/yasa.svg?branch=master https://codecov.io/gh/raphaelvallat/yasa/branch/master/graph/badge.svg https://pepy.tech/badge/yasa
_images/yasa_logo.png

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 preprint 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 and stage tranisitions.

For more details, check out the API documentation, try the tutorial (Jupyter notebooks) or read the FAQ.


Installation

To install YASA, simply open a terminal or Anaconda command prompt and enter:

pip install --upgrade yasa

What are the prerequisites for using YASA?

To use YASA, all you need is:

  • Some basic knowledge of Python, especially the NumPy, Pandas and MNE packages.

  • A Python editor: YASA works best with Jupyter Lab, a web-based interactive user interface.

  • Some sleep EEG data and optionally a sleep staging file (hypnogram).

I have sleep EEG data in European Data Format (.edf), how do I load the data in Python?

If you have sleep EEG data in standard formats (e.g. EDF or BrainVision), you can use the MNE package to load and preprocess your data in Python. A simple preprocessing pipeline using MNE is shown below:

import mne
# Load the EDF file
raw = mne.io.read_raw_edf('MYEDFFILE.edf', preload=True)
# Downsample the data to 100 Hz
raw.resample(100)
# Apply a bandpass filter from 0.1 to 40 Hz
raw.filter(0.1, 40)
# Select a subset of EEG channels
raw.pick_channels(['C4-A1', 'C3-A2'])

How do I get started with YASA?

If you want to dive right in, you can simply go to the main documentation (API reference) and try to apply YASA’s functions on your own EEG data. However, for most users, we strongly recommend that you first try running the examples Jupyter notebooks to get a sense of how YASA works and what it can do! The notebooks also come with example datasets so they should work right out of the box as long as you’ve installed YASA first. The notebooks and datasets can be found on GitHub (make sure that you download the whole notebooks/ folder). A short description of all notebooks is provided below:

Automatic sleep staging

Event detection

Spectral analysis

  • bandpower: calculate spectral band power, optionally averaged across channels and sleep stages.

  • IRASA: separate the aperiodic (= fractal = 1/f) components of the EEG power spectrum using the IRASA method.

  • spectrogram: plot a multi-taper full-night spectrogram on single-channel EEG data with the hypnogram on top.

  • nonlinear_features: calculate non-linear EEG features on 30-seconds epochs and perform a naive sleep stage classification.

  • SO-sigma_coupling: slow-oscillations/spindles phase-amplitude coupling and data-driven comodulogram.

  • topoplot: topoplot.



Development

YASA was created and is maintained by Raphael Vallat, a postdoctoral researcher in Matthew Walker’s lab at UC Berkeley. Contributions are more than welcome so feel free to contact me, open an issue or submit a pull request!

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.


Citation

To cite YASA, please use the preprint publication: