Repository navigation
biosig2eeglab: the last channel becomes events only when it holds triggers - #1005
Conversation
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Code reviewWho reviewed. Codex with the model GPT-6.1 Terra read the EEGLAB change (pull request 1005 of sccn/eeglab: #1005) and its Python port (pull request 868 of sccn/eegprep: sccn/eegprep#868), read only. Gemini 4 Carbon (Medium) was asked first through agy and gave no answer in 10 minutes. The code was written by Claude (Fable 5.2). Its verdict. One finding marked blocking and six smaller ones. It found the event loop faithful to MATLAB (first sample, last sample, negative and fractional values) and the channel removed consistently (data, labels, channel count, mixed sampling rates). Fixed.
Left, and why.
— orchestrator |
|
Arno answered on November 29, 2026: 1a, the label stays required, so a last channel with a plain label such as "Ch33" stays in the data even when it holds triggers. He asked to merge, and this pull request was merged together with the test of sccn/eeglab_tests#18. — orchestrator |
Fixes #1004 (biosig2eeglab turns a signal in the last channel of an EDF or BDF file into events and removes it: #1004). It follows issue 989 (biosig2eeglab takes the last EEG channel of an EDF file for an event channel: #989).
When an EDF or BDF file gives no event,
biosig2eeglabtook the last channel for a trigger channel on the number of its different values alone. With this change the last channel becomes events only when its label names a trigger channel (status,trig,event,marker, or a label that starts withsti, in upper or lower case) and it holds few different values, as before (20 at most in the first 100 samples, 1000 at most overall). Any other last channel stays a data channel. The rule is one local function,islasteventchan, and onlybiosig2eeglab.mchanges.Last channel of each file: EEGLAB before, EEGLAB after, EEGPrep, what is right
StatusStatusStatusDIG DTRIGSTATUSSTATUSStatusCQ_DRLsine 50 Hzsine 50 Hzsine 50 Hzsine 50 Hzsine 50 Hzsine 50 Hzsine 50 Hzsine 50 HzPOL $A2acc3sine 1 Hz0.2Hz Blk 1/0uVEEG O2EEG O2EEG F1-RefCzCz[F4 - M1]Right answers on these 26 files: 12 before, 25 after. Among the 17 files where the old rule fired, it was right 4 times and removed a signal 13 times. The file that stays wrong (ds002725) cannot be read by
pop_biosigbefore or after, for another reason. EEGPrep is the reader of pull request 868 of sccn/eegprep ([IO] Import EDF and BDF files with EEGPrep's own reader: BIDS import and File > Import data: sccn/eegprep#868), which holds the same function, ported line for line. Its two ds003343 files differ because of an open question there on where the data start, not because of this rule.What changes for users
Status,DIG DTRIG,Trigger,Event,Marker,STI 014). With another label (for exampleCh33) it stays in the data, and a message names the menu that extracts its events (File > Import event info > From data channel).'importevent', 'off'still turns the rule off.biosig2eeglab(GDF and others), as the old rule did. Only EDF and BDF files were tested here.Checks
tools/edf_bdf_reader_compare.mof sccn/eegprep on the files of the comparison of pull request 868, before (develop 579a27d) and after (this branch), MATLAB R2025b, BIOSIG 3.8.4. Data and events are the same in every file except 19: the 13 files of the table where the last channel now stays (flex2.edf,bdfPlusC.bdf,edfPlusC.edf,edfPlusD.edf,test_utf8_annotations.edf,test_generator.edf,test_legacy.edf,test_generator_2.edf,test_generator_2.bdf,chtypes_edf.edf,multiple_annotation_chans.bdf,test_stim_channel.edf,test_uneven_samp.edf) and 6 files that stopped with an error before and are read now (test_chan_types.bdf,test_dig_min_larger_max.bdf,test_invalid_dig_min_max.bdf,test_invalid_phys_min_max.bdf,test_phys_min_larger_max.bdf,SC4001EC-Hypnogram.edf). Three files of the pyedflib generator hangpop_biosigbefore and after and were left out.pop_biosig,pop_chaneventandbiosig2eeglabevent: 5 of 5 pass before and after. The new test of the tests pull request fails before and passes after.What the last channel holds in each file
StatusuVStatus, 99.6% of the samples at the resting value, whole numbers; EEGLAB's sample file with triggersStatusuVStatus, 99.5% of the samples at 0, 4 whole valuesStatusuVStatus, 99.5% of the samples at 0, 4 whole valuesDIG DTRIGuV?DIG DTRIG), values 0 and 100, 99% of the samples at 0STATUSBooleanTriggers and StatusSTATUS, dimensionBoolean, transducerTriggers and StatusSTATUSBooleanTriggers and StatusSTATUS, dimensionBoolean, transducerTriggers and StatusStatusuVStatus; theevents.tsvbeside the file lists the same codes (1, 47, 1283)CQ_DRLuVemotiv electrodeCQ_DRL), values 0 and 4sine 50 HzuVsine 50 Hz), 3 different valuessine 50 HzuVsine 50 Hz), 3 different valuessine 50 HzuVsine 50 Hz), 3 different valuessine 50 HzuVsine 50 Hz), 3 different valuessine 50 HzuVsine 50 Hz), 3 different valuessine 50 HzuVsine 50 Hz), 3 different valuessine 50 HzuVsine 50 Hz), 3 different valuessine 50 HzuVsine 50 Hz), 3 different valuesPOL $A2uVPOL $A2), a saturated channel with 2 changesacc3Gnoneacc3, physical dimensionG)sine 1 HzuVsine 1 Hz)0.2Hz Blk 1/0uVuVSoftware generated0.2Hz Blk 1/0uV), half of the samples at each valueEEG O2uVAgAgCl electrodeEEG O2(issue 989)EEG O2uVAgAgCl electrodeEEG O2(issue 989),channels.tsvlists it as EEGEEG F1-RefuVEEG F1-RefCzuVEMG sensorCzCzuVEMG sensorCz[F4 - M1]uV[F4 - M1]that starts flatWhy the values alone cannot decide
The contact quality channel of
flex2.edfholds the values 0 and 4, with 83% of its samples at 0. The saturated channel ofchtypes_edf.edfholds 2 values and changes twice. The block wave oftest_uneven_samp.edfholds 0 and 1. All three look like a trigger channel, and a real trigger channel can hold its codes for a long time. A threshold on the share of samples at rest separates these files by a few percent only (83% and 88% against 99%), so the label is asked first and the channel stays data when the label does not say "trigger".— orchestrator