yasa.bandpower¶
- yasa.bandpower(data, sf=None, ch_names=None, hypno=None, include=(2, 3), win_sec=4, relative=True, bandpass=False, bands=[(0.5, 4, 'Delta'), (4, 8, 'Theta'), (8, 12, 'Alpha'), (12, 16, 'Sigma'), (16, 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 casedata
,sf
, andch_names
will be automatically extracted, anddata
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 amne.io.BaseRaw
.- ch_nameslist
List of channel names, e.g. [‘Cz’, ‘F3’, ‘F4’, …]. If None, channels will be labelled [‘CHAN000’, ‘CHAN001’, …]. Can be omitted if
data
is amne.io.BaseRaw
.- hypnoarray_like
Sleep stage (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 toyasa.hypno_upsample_to_data()
.Note
The default hypnogram format in YASA is a 1D integer vector where:
-2 = Unscored
-1 = Artefact / Movement
0 = Wake
1 = N1 sleep
2 = N2 sleep
3 = N3 sleep
4 = REM sleep
- 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 whenhypno
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
.- bandpassboolean
If True, apply a standard FIR bandpass filter using the minimum and maximum frequencies in
bands
. Fore more details, refer tomne.filter.filter_data()
.- 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.
- datanp.array_like or
- Returns
- bandpowers
pandas.DataFrame
Bandpower dataframe, in which each row is a channel and each column a spectral band.
- bandpowers
Notes
For an example of how to use this function, please refer to https://github.com/raphaelvallat/yasa/blob/master/notebooks/08_bandpower.ipynb