Skip to content

Commit

Permalink
Fix saving to BIDS runs with descriptions in their name (#530)
Browse files Browse the repository at this point in the history
* BIDS path: specify run index in run and run description in task
This required to remove the paradigm that was specified via task

* Update whats_new.rst

* Use recording instead of task and reintroduce paradigm as task
  • Loading branch information
PierreGtch authored Nov 17, 2023
1 parent 301390c commit 4b297b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/source/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Bugs
~~~~

- Fix TRCA implementation for different stimulation freqs and for signal filtering (:gh:522 by `Sylvain Chevallier`_)
- Fix saving to BIDS runs with a description string in their name (:gh:`530` by `Pierre Guetschel`_)

API changes
~~~~~~~~~~~
Expand Down
22 changes: 20 additions & 2 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["recording"] = desc
return out


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


@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,13 @@ 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 4b297b9

Please sign in to comment.