Repository navigation
Description
Split out of #454. #454 is closed because #471's ds003061 stage tests supersede it; this is the part they don't cover.
What was observed
On ds003061, tests/test_bids_preproc.py::TestBidsPreproc::test_end2end compares bids_preproc against scripts/bids_pipeline.m. It used to carry this note, which #459 (b4097276) removed:
testing up to here because pop_select occasionally retains events on py that are dropped by the MATLAB code, so things go out of sync at that point
Once the event lists differ, later stages drift; epoching runs on all events (EpochEvents=[]). That drift is one reason the test still compares data at abstol = 200 µV. This hasn't been reproduced yet, so it's a lead to confirm, not a confirmed bug.
Likely cause (code read on develop 796b970f)
- EEGLAB
pop_select.m:744ends withEEG = eeg_checkset(EEG, 'eventconsistency'). That does more than the latency bounds check. Among other things (eeg_checkset.m:424-450):- it removes a leading boundary event whose duration < 1 and clamps a first-event latency in (0, 1) to 0.5
- it removes events with invalid epoch numbers
- it merges duplicate boundary events
- it re-sorts events
- EEGPrep
src/eegprep/functions/popfunc/pop_select.py:542-555reimplements only the bounds check inline (0.5 <= latency <= pnts*trials+1), then calls plaineeg_checkset(EEG). - A full port already exists:
_eventconsistencyinsrc/eegprep/functions/adminfunc/eeg_checkset.py:49, reached througheeg_checkset(EEG, 'eventconsistency').pop_selectdoesn't use it. - Possible interaction with Event duration #328:
pop_load_frombids.py:441imports durations asmax(1, round(Fs*duration)). A zero-length leading boundary that EEGLAB would drop can therefore arrive in Python with duration 1 and survive.
How to reproduce
- Load ds003061 sub-001 (run 1 and run 2 from
eeglab_tests/ds003061) the waybids_preprocdoes (ApplyEvents=True,EventColumn='value'). Then runpop_select(EEG, channel=<EEG-type labels>), asbids_preproc.py:686does and asscripts/bids_pipeline.m:93does in MATLAB (pop_select(EEG, 'channel', keep)). - Feed the same input .set to MATLAB
pop_select(via the batch engine) and comparelen(event),type,latencyanddurationper event. Also cover a synthetic case: a leading boundary with duration 0, and duplicate boundaries. test_end2endwithSaveIntermediateStages=Truewritesstage02files from both sides, so the first stage where the event lists differ can also be read off directly.
Fix direction
Replace the inline check in pop_select with eeg_checkset(EEG, 'eventconsistency'), matching pop_select.m:744. Add a MATLAB comparison test on identical input, including the synthetic boundary cases. Then check whether the ds003061 chain summary (tests/parity_expected/ds003061_pipeline.json) changes. It shouldn't, but run it with --run-heavy-reference on MATLAB to confirm, and don't re-record it.
Other #454 points that #471 does not cover
#471 compares each stage function on identical inputs (run-1, AMARI ≤ 1e-5, Hungarian-matched rejection, chained summary JSON). That covers #454's ICA-weight and run-1 data concerns at the function level. These points are left:
bids_preprocitself has no tight MATLAB comparison.test_end2endis the only test of the wrapper, and it is host-gated (it skips on unknown hosts, so in CI). It also compares atabstol = 200µV; the removed note cited sub-001 ~10 µV and sub-002 ~160 µV.- The test compares different ICA algorithms: Python is called with
ICAAlgorithm='picard', whilescripts/bids_pipeline.m:121runspop_runica(EEG, 'icatype', 'runica', 'rndreset', 'no').icaweightstherefore can't match, and the weight assertion had been commented out. Either side should run the same algorithm (picard with identity init, as Match ds003061 MATLAB stages on identical inputs #471 does). - Run-1 cache shape mismatch: the test uses run 2 because "cached run 1 files hit an ICA shape mismatch" (removed note). That is in
bids_preproc'sSkipIfPresent/UseHashesintermediate-file reuse, which Match ds003061 MATLAB stages on identical inputs #471 doesn't use. Re-check whether it still happens.
Once the event fix lands, (1)–(3) can be handled together by replacing the 200 µV data check with per-stage, component-aligned comparisons, reusing #471's amari_distance / matched_mixing_correlation. Any new ceiling needs sign-off from me or Arno.
Activity