Make raw-file BIDS event latencies 1-based - #316
Open
arnodelorme wants to merge 1 commit into
Open
Conversation
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖
Problem
EEG event latencies are 1-based (latency 1.0 = first sample, EEGLAB convention). The neo-based event reader in
src/eegprep/plugins/EEG_BIDS/raw.py(_read_neo_events, used for.edf/.bdf/.vhdr) computednp.searchsorted(times_sec, all_times)without the+1, so annotations stored in the raw file came out 0-based: an event on the first sample had latency 0.The
events.tsvpath inpop_load_frombidsalready adds 1 (ev_lats = ev_lats + 1). Consequences:events.tsvevents (and relative to.setfiles andmne_raw_to_eeg, which are 1-based).bidsevent='merge'compared 0-based raw latencies against 1-based tsv latencies, so its de-duplication missed every match: an event present in both sources was kept twice.bidsevent=False/'append'returned off-by-one raw latencies.Fix
raw.py:event_latencies = np.searchsorted(times_sec, all_times) + 1— same rounding policy as the tsv path, now 1-based. One-line change; all consumers inpop_load_frombids(replace,merge,append,False) are unchanged.Verification
New tests in
tests/test_bids_load_frombids_helpers.pywrite a real EDF+ file withpyedflib(100 Hz, 10 s, 2 channels) into a minimal BIDS tree (dataset_description.json,*_eeg.json,*_channels.tsv,*_events.tsv) with annotations at 0.0 s, 1.0 s, 9.99 s, and anevents.tsvcontaining two of those plus one extra event at 5.0 s.Latencies from
load_raw_eeg_fileon that EDF:[0, 100, 999][1, 101, 1000]bidsevent='merge'event countbidsevent='append'bidsevent='replace'bidsevent=False[0, 100, 999][1, 101, 1000]Both new tests fail on
origin/developand pass with the fix.No docs change:
docs/source/user_guide/does not describe raw-file BIDS event latency behaviour.Related, not changed here
raw.pyleaves neo annotation durations as returned by neo (seconds for EDF/BDF;0.5in the test), whereas theevents.tsvpath converts to samples (round(max(1, Fs*duration))). Separate inconsistency, left out of this PR.bids_preproc.py(events.tsv export) indexestimes[e['latency']]with a 1-based latency, i.e. one sample late; pre-existing for tsv-derived events and unrelated to this change.