Skip to content

Commit

Permalink
BIDS path: specify run index in run and run description in task
Browse files Browse the repository at this point in the history
This required to remove the paradigm that was specified via task
  • Loading branch information
PierreGtch committed Nov 16, 2023
1 parent 301390c commit 1702b97
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions moabb/datasets/bids_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ def subject_bids_to_moabb(subject: str):
return int(subject)


def run_moabb_to_bids(run: str):
"""Convert the run to run index plus eventually description."""
p = r"([0-9]+)(|[a-zA-Z]+[a-zA-Z0-9]*)"
idx, desc = re.fullmatch(p, run).groups()
out = {"run": idx}
if desc:
out["task"] = desc
return out


def run_bids_to_moabb(path: mne_bids.BIDSPath):
"""Extracts the run index plus eventually description from a path."""
if path.task is None:
return path.run
return f"{path.run}{path.task}"


@dataclass
class BIDSInterfaceBase(abc.ABC):
"""Base class for BIDSInterface.
Expand Down Expand Up @@ -173,7 +190,7 @@ def load(self, preload=False):
session_moabb = path.session
session = sessions_data.setdefault(session_moabb, {})
run = self._load_file(path, preload=preload)
session[path.run] = run
session[run_bids_to_moabb(path)] = run
log.info("Finished reading cache of %s", repr(self))
return sessions_data

Expand Down Expand Up @@ -223,12 +240,12 @@ def save(self, sessions_data):
)
continue

run_kwargs = run_moabb_to_bids(run)
bids_path = mne_bids.BIDSPath(
root=self.root,
subject=subject_moabb_to_bids(self.subject),
session=session,
task=self.dataset.paradigm,
run=run,
**run_kwargs,
description=self.desc,
extension=self._extension,
datatype=self._datatype,
Expand Down

0 comments on commit 1702b97

Please sign in to comment.