yasa.bandpower

yasa.bandpower(data, sf=None, ch_names=None, hypno=None, include=(2, 3), win_sec=4, relative=True, bands=[(0.5, 4, 'Delta'), (4, 8, 'Theta'), (8, 12, 'Alpha'), (12, 30, 'Beta'), (30, 40, 'Gamma')], kwargs_welch={'average': 'median', 'window': 'hamming'})[source]

Calculate the Welch bandpower for each channel and, if specified, for each sleep stage.

New in version 0.1.6.

Parameters
datanp.array_like or mne.io.BaseRaw

1D or 2D EEG data. Can also be a mne.io.BaseRaw, in which case data, sf, and ch_names will be automatically extracted, and data will also be converted from Volts (MNE default) to micro-Volts (YASA).

sffloat

The sampling frequency of data AND the hypnogram. Can be omitted if data is a mne.io.BaseRaw.

ch_nameslist

List of channel names, e.g. [‘Cz’, ‘F3’, ‘F4’, …]. If None, channels will be labelled [‘CHAN001’, ‘CHAN002’, …]. Can be omitted if data is a mne.io.BaseRaw.

hypnoarray_like

Sleep stage vector (hypnogram). If the hypnogram is loaded, the bandpower will be extracted for each sleep stage defined in include.

The hypnogram must have the exact same number of samples as data. To upsample your hypnogram, please refer to yasa.hypno_upsample_to_data().

Note

The default hypnogram format in YASA is a 1D integer vector where:

  • -1 = Artefact / Movement

  • 0 = Wake

  • 1 = N1 sleep

  • 2 = N2 sleep

  • 3 = N3 sleep

  • 4 = REM

includetuple, list or int

Values in hypno that will be included in the mask. The default is (2, 3), meaning that the bandpower are sequentially calculated for N2 and N3 sleep. This has no effect when hypno is None.

win_secint or float

The length of the sliding window, in seconds, used for the Welch PSD calculation. Ideally, this should be at least two times the inverse of the lower frequency of interest (e.g. for a lower frequency of interest of 0.5 Hz, the window length should be at least 2 * 1 / 0.5 = 4 seconds).

relativeboolean

If True, bandpower is divided by the total power between the min and max frequencies defined in band.

bandslist of tuples

List of frequency bands of interests. Each tuple must contain the lower and upper frequencies, as well as the band name (e.g. (0.5, 4, ‘Delta’)).

kwargs_welchdict

Optional keywords arguments that are passed to the scipy.signal.welch() function.

Returns
bandpowerspandas.DataFrame

Bandpower dataframe, in which each row is a channel and each column a spectral band.

Notes

For an example of how to use this function, please refer to https://github.com/raphaelvallat/yasa/blob/master/notebooks/10_bandpower.ipynb