eegdash.dataset.bids_dataset module#
Local BIDS dataset interface for EEGDash.
This module provides the EEGBIDSDataset class for interfacing with local BIDS datasets on the filesystem, parsing metadata, and retrieving BIDS-related information.
- class eegdash.dataset.bids_dataset.EEGBIDSDataset(data_dir=None, dataset='', allow_symlinks=False, modalities=None)[source]
Bases:
objectAn interface to a local BIDS dataset containing electrophysiology recordings.
This class centralizes interactions with a BIDS dataset on the local filesystem, providing methods to parse metadata, find files, and retrieve BIDS-related information. Supports multiple modalities including EEG, MEG, iEEG, and NIRS.
The class uses MNE-BIDS constants to stay synchronized with the BIDS specification and automatically supports all file formats recognized by MNE.
- Parameters:
data_dir (str or Path) – The path to the local BIDS dataset directory.
dataset (str) – A name for the dataset (e.g., “ds002718”).
allow_symlinks (bool, default False) – If True, accept broken symlinks (e.g., git-annex) for metadata extraction. If False, require actual readable files for data loading. Set to True when doing metadata digestion without loading raw data.
modalities (list of str or None, default None) – List of modalities to search for (e.g., [“eeg”, “meg”]). If None, defaults to all electrophysiology modalities from MNE-BIDS: [‘meg’, ‘eeg’, ‘ieeg’, ‘nirs’].
- RAW_EXTENSIONS
Mapping of file extensions to their companion files, dynamically built from mne_bids.config.reader.
- Type:
- detected_modality
The modality of the first file found (e.g., ‘eeg’, ‘meg’).
- Type:
Examples
>>> # Load EEG-only dataset >>> dataset = EEGBIDSDataset( ... data_dir="/path/to/ds002718", ... dataset="ds002718", ... modalities=["eeg"] ... )
>>> # Load dataset with multiple modalities >>> dataset = EEGBIDSDataset( ... data_dir="/path/to/ds005810", ... dataset="ds005810", ... modalities=["meg", "eeg"] ... )
>>> # Metadata extraction from git-annex (symlinks) >>> dataset = EEGBIDSDataset( ... data_dir="/path/to/dataset", ... dataset="ds000001", ... allow_symlinks=True ... )
- RAW_EXTENSIONS = {'.CNT': ['.CNT'], '.EDF': ['.EDF'], '.EEG': ['.EEG'], '.bdf': ['.bdf'], '.bin': ['.bin'], '.cdt': ['.cdt'], '.cnt': ['.cnt'], '.con': ['.con'], '.ds': ['.ds'], '.edf': ['.edf'], '.fif': ['.fif'], '.lay': ['.lay'], '.mefd': ['.mefd'], '.pdf': ['.pdf'], '.set': ['.set', '.fdt'], '.snirf': ['.snirf'], '.sqd': ['.sqd'], '.vhdr': ['.vhdr', '.eeg', '.vmrk', '.dat']}
- channel_labels(data_filepath: str) list[str][source]
Get a list of channel labels from channels.tsv.
- check_eeg_dataset() bool[source]
Check if the BIDS dataset contains EEG data.
- Returns:
True if the dataset’s modality is EEG, False otherwise.
- Return type:
- eeg_json(data_filepath: str) dict[str, Any][source]
Get the merged eeg.json metadata for a data file.
- get_all_participants_tsv() dict[str, dict[str, Any]][source]
Get all rows from participants.tsv as a dictionary.
- Returns:
A dictionary mapping participant_id to a dict of column values. Returns
{}if no participants.tsv exists or it is empty.- Return type:
- get_bids_file_attribute(attribute: str, data_filepath: str) Any[source]
Retrieve a specific attribute from BIDS metadata.
- get_bids_metadata_files(filepath: str | Path, metadata_file_extension: str) list[Path][source]
Retrieve all metadata files that apply to a given data file.
Follows the BIDS inheritance principle to find all relevant metadata files (e.g.,
channels.tsv,eeg.json) for a specific recording.
- get_orphan_participants() dict[str, dict[str, Any]][source]
Get participant rows that have no matching file in the dataset.
Identifies subjects present in
participants.tsvbut with no corresponding recording file inself.files.- Returns:
A dictionary mapping orphan participant_id to their TSV data. Returns
{}if there are no orphans, no TSV, or no files.- Return type: