2222import mne_bids
2323import numpy as np
2424import pandas as pd
25- from bids import BIDSLayout
2625from joblib import Parallel , delayed
2726from mne ._fiff .utils import _read_segments_file
2827from mne .io import BaseRaw
28+ from mne .utils .check import _soft_import
2929from mne_bids import BIDSPath
3030
3131from braindecode .datasets import BaseDataset
@@ -348,6 +348,14 @@ def __init__(
348348 data_dir = None , # location of bids dataset
349349 dataset = "" , # dataset name
350350 ):
351+ bids_lib = _soft_import ("bids" , purpose = "digestion of datasets" , strict = False )
352+
353+ if bids_lib is None :
354+ raise ImportError (
355+ "The 'pybids' package is required to use EEGBIDSDataset. "
356+ "Please install it via 'pip install eegdash[digestion]'."
357+ )
358+
351359 if data_dir is None or not os .path .exists (data_dir ):
352360 raise ValueError ("data_dir must be specified and must exist" )
353361 self .bidsdir = Path (data_dir )
@@ -359,7 +367,7 @@ def __init__(
359367 raise AssertionError (
360368 f"BIDS directory '{ dir_name } ' does not correspond to dataset '{ self .dataset } '"
361369 )
362- self .layout = BIDSLayout (data_dir )
370+ self .layout = bids_lib . BIDSLayout (data_dir )
363371
364372 # get all recording files in the bids directory
365373 self .files = self ._get_recordings (self .layout )
@@ -379,7 +387,7 @@ def check_eeg_dataset(self) -> bool:
379387 """
380388 return self .get_bids_file_attribute ("modality" , self .files [0 ]).lower () == "eeg"
381389
382- def _get_recordings (self , layout : BIDSLayout ) -> list [str ]:
390+ def _get_recordings (self , layout ) -> list [str ]:
383391 """Get a list of all EEG recording files in the BIDS layout."""
384392 files = []
385393 for ext , exts in self .RAW_EXTENSIONS .items ():
0 commit comments