Note
Go to the end to download the full example code.
BIDS Dataset Example#
In this example, we show how to fetch and prepare a BIDS dataset for usage with Braindecode.
# Authors: Pierre Guetschel <pierre.guetschel@gmail.com>
#
# License: BSD (3-clause)
from pathlib import Path
import openneuro
from braindecode.datasets import BIDSDataset
First, we download a collection of (fake/empty) BIDS datasets.
# import tempfile
# data_dir = tempfile.mkdtemp()
data_dir = Path("~/mne_data/openneuro/").expanduser()
dataset_name = "ds004745" # 200Mb dataset
dataset_root = data_dir / dataset_name
if not dataset_root.exists():
openneuro.download(dataset=dataset_name, target_dir=dataset_root)
Now, loading the dataset is simply a one-line command:
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: Data will be preloaded. preload=False or a string preload is not supported when the data is stored in the .set file
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "1" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "2" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "3" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "4" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "5" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "6" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "7" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "8" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: Data will be preloaded. preload=False or a string preload is not supported when the data is stored in the .set file
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "1" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "2" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "3" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "4" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "5" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "6" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "7" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "8" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: Data will be preloaded. preload=False or a string preload is not supported when the data is stored in the .set file
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "1" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "2" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "3" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "4" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "5" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "6" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "7" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "8" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: Data will be preloaded. preload=False or a string preload is not supported when the data is stored in the .set file
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "1" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "2" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "3" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "4" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "5" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "6" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "7" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "8" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: Data will be preloaded. preload=False or a string preload is not supported when the data is stored in the .set file
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "1" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "2" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "3" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "4" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "5" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "6" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "7" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
/home/runner/work/braindecode/braindecode/braindecode/datasets/bids.py:190: RuntimeWarning: No BIDS -> MNE mapping found for channel type "n/a". Type of channel "8" will be set to "misc".
raw = mne_bids.read_raw_bids(bids_path, verbose=False)
And we can see that the events of this dataset are set in the .annotations
attribute of the raw data:
print(bids_ds.datasets[0].raw.annotations)
<Annotations | 58 segments: 1 (6), 10 (10), 2 (6), 3 (6), 4 (6), 5 (6), 6 ...>
Total running time of the script: (0 minutes 1.957 seconds)
Estimated memory usage: 899 MB