Repository navigation
pop_biosig: boundary event at each gap of EDF+D and BDF+D files - #1006
Conversation
pop_biosig joins the data records of a discontinuous EDF+D or BDF+D file. biosig2eeglab now places a boundary event at each gap: half a sample before the first sample after the gap, with the missing time in samples as duration (NaN where two records overlap). The record start times are the time-keeping annotations BIOSIG returns in HDR.EDFplus.ANNONS. The data and files without gaps do not change. Fixes #1003. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
After the review by Codex GPT-6.1 Terra. BIOSIG's HDR.EDFplus.ANNONS is read from a wrong offset in BDF+ files and is empty when the annotation channels are not next to each other, so the time-keeping annotations are now read from the first annotation channel of the file. A gap counts from one sample on, since eeg_checkset removes a first boundary shorter than one sample. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Code reviewThe boundary events at the gaps of EDF+D and BDF+D files were reviewed by another AI, read-only: Codex, model GPT-6.1 Terra. It read the three changes together (commit 84d34982 of sccn/eegprep#868, the first commit of #1006 and the test of sccn/eeglab_tests#19) and asked for changes, with four findings it rated blocking and four rated "should fix". Gemini 4 Carbon at medium effort (through agy) was asked first with the same text and had returned nothing after 20 minutes. Three of the blocking findings and one other are fixed, in commits 9d979439 (sccn/eegprep), 49a92d0 (sccn/eeglab) and 5b8a3e7 (sccn/eeglab_tests). Four are left, with the reason for each. Fixed
Left, and why
After the fixes: the 59 tests of the two EEGPrep test files pass, the 9 EEGLAB tests pass in MATLAB R2025b, the 55 files of the EEGPrep comparison are identical before and after the fix commit, and on 54 files EEGLAB develop and EEGLAB with the change differ only by the boundaries of the two files with gaps, which are the same as EEGPrep's. — orchestrator |
After the review by Gemini 4 Carbon: with a data range that holds no gap, nothing is printed and the events are left as they are. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Code review, second reviewerThe review by Gemini 4 Carbon at medium effort (through agy) arrived after the comment above, 22 minutes after it was asked. It read the first commits, before the fixes made for Codex, and also asked for changes, with 5 findings it rated blocking, 3 "should fix" and one nit. Four repeat findings of Codex that were already fixed or answered. Two are new and fixed, in commits 169f1a31 (sccn/eegprep) and the third commit of #1006. New and fixed
Already fixed for Codex: the wrong offset of BIOSIG in BDF+ files, annotation channels that are not next to each other, a first boundary shorter than one sample (Gemini adds that Left, and why
After these fixes the 60 tests of the two EEGPrep test files pass, the 9 EEGLAB tests pass in MATLAB R2025b, and the 55 files of the EEGPrep comparison are unchanged. — orchestrator |
# Conflicts: # functions/sigprocfunc/biosig2eeglab.m
|
Pull request #1005 was merged, so develop is now merged into this branch (commit bbaf064), as Arno asked on November 29, 2026. The only conflict was in — orchestrator |
pop_biosignow places a boundary event at each gap of a discontinuous EDF+D or BDF+D file. The data do not change. Fixes #1003.Example file
edf_plus_d_gaps.edf(8 records of 1 second at 50 Hz that start at 0, 1, 3, 4, 5.25, 6.25, 7.25 and 10.25 seconds, https://raw.githubusercontent.com/sccn/eegprep/84d349821b7158427bf55f8fc8e97816b07e5df1/tests/data/edf_plus_d_gaps.edf), read withEEG = pop_biosig('edf_plus_d_gaps.edf'):resp287.5, 10boundary100.5, 50 ·boundary200.5, 12.5 ·resp287.5, 10 ·boundary350.5, 100EEGLAB with this change against EEGPrep (Python), on the example file (EEGPrep's reader at commit 84d34982 of pull request sccn/eegprep#868, sccn/eegprep#868):
bdf_plus_d_gaps.bdf, 24-bit samples) gives the same three boundaries in EEGLAB with this change and in EEGPrep.edfPlusD.edfof the R package edfReader (5 gaps, 2200 samples), EEGLAB with this change and EEGPrep give the same 5 boundaries (latencies 200.5, 400.5, 1600.5, 1800.5, 2000.5, durations 200, 200, 400, 400, 600) and the same data (0 µV on the 10 channels EEGLAB keeps).pop_biosigwas run on 54 files before and after. The 44 files without gaps that EEGLAB reads are identical (data and events), 8 files give the same error before and after, and the 2 files with gaps gain only their boundaries.respat 287.5 (EEGPrep: 226, its place in the joined data) and does not importstim, which has no duration (EEGPrep: 126). Both are described in issue pop_biosig joins the records of an EDF+D file without a boundary event #1003 under "Seen on the way".Where the gaps were lost, and where the record start times come from
sreadreturns the data records one after the other, andsopencreates no event for a gap. BIOSIG is third party code and is not changed.HDR.HeadLenandHDR.AS). BIOSIG also returns these bytes inHDR.EDFplus.ANNONS, and the first commit used them, but the review showed two defects there: in BDF+ files BIOSIG reads them from a wrong offset (sopen.mmultiplies an offset in bytes by 3 again), and it leaves the field empty when the annotation channels are not next to each other. Onbdf_plus_d_gaps.bdfthe field holds signal bytes.EDF+DorBDF+Dcomes fromHDR.reserved1.functions/sigprocfunc/biosig2eeglab.m, in a new subfunctiongapboundaries, because this file is where EEGLAB turns what BIOSIG returns into events and where it has the data range (interval) of theblockrangeoption.pop_biosig.mis not changed.The rules, the same as in EEGPrep
eeg_eegrejwrites a boundary.eeg_eegrejon samples 195 to 205 of the example then gives one boundary of 23.5 samples (11 removed plus the 12.5 of the gap).pop_mergesetwrites a break of unknown length. Never a negative duration.eeg_checksetremoves a first boundary shorter than one sample, which would make EEGLAB and EEGPrep differ.HDR.SPRsamples per record).eeg_checksetsorts the events, so it comes last among events at the same latency. Its type is the oneeeg_boundarytypegives.EEG.trialsof 1), and only files whose header saysEDF+DorBDF+D.'importevent', 'off'): a boundary describes the data. EEGPrep does the same.What was checked not to change
'blockrange':pop_biosig(file, 'blockrange', [1 6])returns samples 51 to 300 as before, with the two boundaries inside the range at 50.5 and 150.5, counted from the first sample read.EEG = pop_biosig('edf_plus_d_gaps.edf');andEEG = pop_biosig('edf_plus_d_gaps.edf', 'blockrange',[1 6] );).S001R01.edfof eeglab_tests (8000 samples, 1 event, no boundary). On the example file it stops before and after with the same error, "Output argument DAT not assigned" inpop_biosig>readfile, because the file is shorter than one memory block.'blockepoch', 'on': on the example file this call does not return on develop, without this change (stopped after 100 seconds). The new code does not run for epoched data. This is reported in issue pop_biosig joins the records of an EDF+D file without a boundary event #1003 and not fixed here.eeg_eegrej. It iseeg_checksetthat fills the field. Types and latencies of the other events are unchanged (checked on the 2199 events ofedfPlusD.edf).eeg_checksetleaves the events as they are,pop_epochkeeps an epoch with no boundary inside and removes one that crosses a boundary,eeg_eegrejandpop_selectkeep the boundaries and add theirs.pop_biosig,biosig2eeglabevent,pop_epochandeeg_eegrej(foldersunittesting_binary/pop_biosig,unittesting_sigprocfunc/biosig2eeglabevent,unittesting_popfunc/pop_epoch,unittesting_popfunc/eeg_eegrej), MATLAB R2025b: the 8 existing tests pass before and after. The new testpass_edfplusd_boundaries(EDF+D file, BDF+D twin, data range, gaps of 0.75 and 1 sample, a continuous file) fails before and passes after. No test folder of eeglab_tests is named afterbiosig2eeglaboreeg_checkset.tools/edf_bdf_reader_compare.mof sccn/eegprep) plus the example file, less two files on whichpop_biosigdoes not finish on develop (test_generator.bdfand one more file of pyedflib, whose channels have a common rate of millions of samples per record).Refs sccn/eegprep#868, sccn/eegprep#865.
Three commits: the change, the fixes after the review by Codex GPT-6.1 Terra, and one after the review by Gemini 4 Carbon (the two review comments below list them).
🤖 Generated with Claude Code