Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions eegdash/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import mne_bids
import numpy as np
import pandas as pd
from bids import BIDSLayout
from joblib import Parallel, delayed
from mne._fiff.utils import _read_segments_file
from mne.io import BaseRaw
from mne.utils.check import _soft_import
from mne_bids import BIDSPath

from braindecode.datasets import BaseDataset
Expand Down Expand Up @@ -348,6 +348,14 @@ def __init__(
data_dir=None, # location of bids dataset
dataset="", # dataset name
):
bids_lib = _soft_import("bids", purpose="digestion of datasets", strict=False)

if bids_lib is None:
raise ImportError(
"The 'pybids' package is required to use EEGBIDSDataset. "
"Please install it via 'pip install eegdash[digestion]'."
)

if data_dir is None or not os.path.exists(data_dir):
raise ValueError("data_dir must be specified and must exist")
self.bidsdir = Path(data_dir)
Expand All @@ -359,7 +367,7 @@ def __init__(
raise AssertionError(
f"BIDS directory '{dir_name}' does not correspond to dataset '{self.dataset}'"
)
self.layout = BIDSLayout(data_dir)
self.layout = bids_lib.BIDSLayout(data_dir)

# get all recording files in the bids directory
self.files = self._get_recordings(self.layout)
Expand All @@ -379,7 +387,7 @@ def check_eeg_dataset(self) -> bool:
"""
return self.get_bids_file_attribute("modality", self.files[0]).lower() == "eeg"

def _get_recordings(self, layout: BIDSLayout) -> list[str]:
def _get_recordings(self, layout) -> list[str]:
"""Get a list of all EEG recording files in the BIDS layout."""
files = []
for ext, exts in self.RAW_EXTENSIONS.items():
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ dependencies = [
"numba",
"numpy",
"pandas",
"pybids",
"pymongo",
"python-dotenv",
"s3fs",
"scipy",
"tqdm",
"h5io >= 0.2.4",
"pymatreader",
Expand All @@ -63,6 +61,7 @@ Issues = "https://github.com/sccn/EEG-Dash-Data/issues"
tests = [
'pytest',
'pytest-cov',
'pytest-sugar',
'codecov',
'pytest_cases',
'pytest-benchmark',
Expand Down Expand Up @@ -90,10 +89,15 @@ docs = [
"graphviz",
]

digestion = [
"pybids",
]

all = [
"eegdash[docs]",
"eegdash[dev]",
"eegdash[tests]",
"eegdash[digestion]",
]

[tool.setuptools]
Expand Down