Skip to content

Add public convert_to_bids method to BaseDataset for clean BIDS export#988

Merged
bruAristimunha merged 17 commits intodevelopfrom
copilot/add-public-bids-conversion-function
Feb 26, 2026
Merged

Add public convert_to_bids method to BaseDataset for clean BIDS export#988
bruAristimunha merged 17 commits intodevelopfrom
copilot/add-public-bids-conversion-function

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

BIDS conversion was only accessible via get_data(cache_config=...), coupling it to the caching system and embedding a processing-pipeline hash (desc-<hash>) in all filenames — unsuitable for producing shareable BIDS datasets.

Changes

  • New BaseDataset.convert_to_bids(path=None, subjects=None, overwrite=False, verbose=None) method — the canonical public API for BIDS conversion
    • Saves raw EEG as BIDS-compliant EDF without desc-<hash> entities in filenames
    • Skips already-converted subjects when overwrite=False (checks for existing EDF files); erases and re-saves on overwrite=True
    • Does not write lock files (lock files are an internal detail of the caching mechanism only)
    • Returns the BIDS root Path
  • Internal _BIDSInterfaceRawEDFNoDesc subclass — overrides desc → None, overrides _write_lock_file() as a no-op, and replaces erase() with shutil.rmtree on the subject directory
  • BIDSInterfaceBase.save() refactored to extract lock file writing into a _write_lock_file() method, allowing subclasses to opt out
  • BIDSInterfaceBase.__repr__ fixed to handle desc=None without a TypeError

Usage

from moabb.datasets import AlexMI

dataset = AlexMI()
bids_root = dataset.convert_to_bids(path="/data/bids", subjects=[1, 2])
# → /data/bids/MNE-BIDS-alexandre-motor-imagery/
# Files: sub-1_ses-0_task-imagery_run-0_eeg.edf  (no desc-hash, no lock files)

For pseudo-BIDS caching of epochs/arrays, get_data(cache_config=...) remains the appropriate path.

Original prompt

This section details on the original issue you should resolve

<issue_title>BIDS conversion should be more public</issue_title>
<issue_description>At the moment, all the datasets can be easy convert to bids with the cache.

The main problem is the interface of the cache, the cache is design to be invisible, so the interface is not clear.

We need to one public function that convert the dataset to bids that don't write the description hash that it is linked with the cache logic.

Needs to be minimum interface.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ut cache hash

Co-authored-by: bruAristimunha <42702466+bruAristimunha@users.noreply.github.com>
Copilot AI changed the title [WIP] Add public function for BIDS conversion Add public convert_dataset_to_bids function for clean BIDS export Feb 20, 2026
Copilot AI requested a review from bruAristimunha February 20, 2026 10:03
@PierreGtch
Copy link
Collaborator

@bruAristimunha could we make convert_dataset_to_bids a method of BaseDataset?

@bruAristimunha
Copy link
Collaborator

@copilot, work on the last suggestion

Co-authored-by: bruAristimunha <42702466+bruAristimunha@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 24, 2026

@copilot, work on the last suggestion

Done in a0ae65d. The BIDS conversion logic is now a convert_to_bids method on BaseDataset:

dataset = AlexMI()
bids_root = dataset.convert_to_bids(path='/data/bids', subjects=[1, 2])

The standalone convert_dataset_to_bids function in bids_interface.py now just delegates to this method.

Copilot AI changed the title Add public convert_dataset_to_bids function for clean BIDS export Add public convert_to_bids method to BaseDataset for clean BIDS export Feb 24, 2026
bruAristimunha and others added 6 commits February 26, 2026 06:57
Co-authored-by: Pierre Guetschel <25532709+PierreGtch@users.noreply.github.com>
Signed-off-by: Bru <b.aristimunha@gmail.com>
Co-authored-by: Pierre Guetschel <25532709+PierreGtch@users.noreply.github.com>
Signed-off-by: Bru <b.aristimunha@gmail.com>
Co-authored-by: Pierre Guetschel <25532709+PierreGtch@users.noreply.github.com>
Signed-off-by: Bru <b.aristimunha@gmail.com>
Add enhancement entry in whats_new.rst for the new convert_to_bids
method. Fix versionadded from 1.1.0 to 1.5 in the docstring.
@bruAristimunha bruAristimunha marked this pull request as ready for review February 26, 2026 06:02
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a0df1c352

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Update _BIDSInterfaceRawEDFNoDesc docstring to reference
BaseDataset.convert_to_bids instead of the removed
convert_dataset_to_bids function.
- Validate subjects against subject_list before the loop so invalid
  subjects are caught before any data is erased.
- When overwrite=False, check for preexisting subject directories
  (e.g. from cache_config) to avoid writing duplicate BIDS files.
@bruAristimunha
Copy link
Collaborator

And the lock file @copilot? Should not exist within this function

Co-authored-by: bruAristimunha <42702466+bruAristimunha@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 26, 2026

And the lock file @copilot? Should not exist within this function

Fixed in 9c58f2d. convert_to_bids no longer uses lock files:

  • _BIDSInterfaceRawEDFNoDesc overrides _write_lock_file() to do nothing (so save() never writes one)
  • The skip check now looks for existing EDF files (subject_dir.rglob("*.edf")) instead of checking for a lock file

- Set DatasetType to "raw" for public BIDS export (was "derivative")
- Skip SourceDatasets DOI when None to avoid JSON schema violation
- Write *_electrodes.json sidecar with SpatialReference (required by BIDS)
- Move make_dataset_description after write loop with overwrite=True so
  it is not clobbered by mne_bids.write_raw_bids internal calls
The SpatialReference error was only triggered because DatasetType was
"derivative". With DatasetType correctly set to "raw", the BIDS
validator does not require SpatialReference in electrodes sidecars for
raw EEG data. mne-bids handles everything needed.
Allow users to choose the output file format (EDF, BrainVision, BDF,
EEGLAB) instead of always writing EDF. The format is propagated through
BIDSInterfaceRawEDF to mne_bids.write_raw_bids, and the file-existence
skip check uses the correct extension for the chosen format.
pybv >= 0.7.3 is required by mne-bids for converting files to
BrainVision format, fixing CI ImportError in test_convert_to_bids_format.
@bruAristimunha bruAristimunha merged commit 200a91b into develop Feb 26, 2026
13 of 14 checks passed
@bruAristimunha bruAristimunha deleted the copilot/add-public-bids-conversion-function branch February 26, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BIDS conversion should be more public

3 participants