Skip to content

FIX MOABBDataset: add interval[0] once to trials that MOABB already shifted - #1849

Merged
bruAristimunha merged 3 commits into
braindecode:masterfrom
AxelNoun:fix/bd-t04-1-moabb-interval-once
Nov 30, 2026
Merged

bruAristimunha merged 3 commits into
braindecode:masterfrom
AxelNoun:fix/bd-t04-1-moabb-interval-once

Conversation

@AxelNoun

Copy link
Copy Markdown
Contributor

Summary

Since NeuroTechX/moabb#607, SetRawAnnotations in MOABB's default pipeline puts each trial at event + interval[0]. Without a stim channel, _annotations_from_moabb_stim_channel rebuilds the trials from these annotations and adds interval[0] again; raws from MOABB's raw cache have no stim channel. This fixes that shift, the first part of #1845, and leaves the BAD segments as they are.

Trial samples, synthetic datasets of #1845 (triggers at 1000 and 3000, 100 Hz, interval=(2, 6)):

case get_data() master this branch
stim channel 1200, 3200 1200, 3200 1200, 3200
no stim channel 1200, 3200 1400, 3400 1200, 3200
stim channel, raw cache 1200, 3200 1400, 3400 1200, 3200
no stim, pipeline with SetRawAnnotations 1400, 3400 1200, 3200
no stim, FixedPipeline([]) 1200, 3200 1200, 3200

Real BNCI2014_001, subject 4 (12 runs, 250 Hz): MOABBDataset minus get_data() onsets are 0 samples without the cache; with save_raw=True, 500 samples (2 s) on master and 0 on this branch.

Changes

  • _fetch_and_unpack_moabb_data: trials count as shifted when process_pipeline is MOABB's default or contains SetRawAnnotations, nested steps included.
  • _annotations_from_moabb_stim_channel: adds interval[0] to stim-channel trials, or to annotations MOABB did not shift.
  • Tests and whats_new.rst.

Testing

Windows, Python 3.12.10, moabb 1.7.2, MNE 1.13.2; master at 83f756a.

  • The 14 files of ci_plan.py, with BNCI2014_001 downloaded and zarr 3.4.2: 1040 passed, 73 skipped, 1 failed; master 1037 passed, same skips and failure (test_overwrite_keeps_one_cache_and_the_lazy_dataset_readable: Windows keeps a memory-mapped .npy). Skips: Windows-only, no CUDA or MPS, per-test reasons (-rfEs).

  • Mutations, each killed: onset always added, stim path not shifted, pipeline ignored, custom pipelines never shifted, nested steps not searched.

  • Unchanged on the scripts of MOABBDataset adds interval[0] twice without a stim channel and drops BAD annotations #1845: first_samp 500, an extra event code, BAD segments (still dropped), inferred targets (0, 1).

  • pre-commit: passed. Not run: other real datasets, moabb other than 1.7.2 (1.4.3, the floor, already shifts: read on its tag).

  • New or changed behavior is covered by relevant regression tests (or N/A with reason)

  • Style checks recorded, e.g. pre-commit run --files <changed files>

  • docs/whats_new.rst updated (at most 3 lines), or the no changelog label, which a maintainer adds, for changes to code that is not released yet (the changelog CI check requires one of the two)

Notes for reviewers

  • Datasets without a stim channel and with interval[0] != 0 move (from reading moabb 1.7.2: Huebner2017/2018, Kojima2024A, Nieto2022, ErpCore2021, BNCI2016_002, BNCI2019_001, BNCI2020_001), and any dataset read through the raw cache.

…hifted

Since NeuroTechX/moabb#607, SetRawAnnotations, a step of MOABB's default process
pipeline, puts each trial at event + interval[0]. Without a stim channel,
braindecode rebuilt the trials from these annotations and added interval[0]
again; raws read from MOABB's raw cache have no stim channel and took that path
too. Add the onset only when the trials come from the stim channel or from a
pipeline without SetRawAnnotations.
@AxelNoun

Copy link
Copy Markdown
Contributor Author

Also checked on a dataset without a stim channel: the real BNCI2020_001, subject 1 (moabb 1.7.2, 256 Hz, interval=[-2, 3], 161 trials, no stim channel). MOABBDataset trial onsets minus those of dataset.get_data(): -512 samples (-2 s, interval[0] added twice) on master, without and with the raw cache; 0 on this branch.

@bruAristimunha
bruAristimunha merged commit 258fc7f into braindecode:master Nov 30, 2026
@AxelNoun
AxelNoun deleted the fix/bd-t04-1-moabb-interval-once branch November 30, 2026 14:57
@bruAristimunha

Copy link
Copy Markdown
Collaborator

Maintainer note: checked the version suspicion before merging. braindecode declares moabb>=1.4.3, and moabb 1.4.3's SetRawAnnotations.transform already adds the interval[0] offset for no-stim annotations (events[:, 0] += offset on both branches), so the shifted-detection holds for every supported moabb. (Locally, moabb 1.4.2 predates that and fails the new test for that reason only.)

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.

2 participants