Skip to content

pop_select: keep continuous point ranges in points so the last sample is not kept - #1008

Open
arnodelorme wants to merge 2 commits into
developfrom
agent/issue-1007
Open

arnodelorme wants to merge 2 commits into
developfrom
agent/issue-1007

Conversation

@arnodelorme

@arnodelorme arnodelorme commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1007. pop_select kept the last sample of a continuous recording when a point range ended one sample before it at 300, 1024, 2048 and 30000 Hz. The cause is the trip of the point range through seconds: eeg_point2lat rounds times to 1e-9 s, and the limit converted back with eeg_lat2point fell 1e-7 sample after the end of the data. This pull request adds one branch to pop_select.m (43 added lines, no line removed or changed): when the range was given in points ('point', 'nopoint', 'rmpoint') on continuous data, the regions to reject are built in points. The same change is in sccn/eegprep pull request 881, and the test is in sccn/eeglab_tests pull request 20.

Example (10 samples holding 0 to 9, MATLAB R2025b)

Call develop (579a27d0d) this pull request (b887b4c35)
pop_select(EEG, 'point', [3 9]) at 300 Hz samples 3 to 10 (2..9), one too many. The last region starts at point 10.000000100000001, eeg_lat2point flags it and the region [10 10] is dropped samples 3 to 9 (2..8), as requested
pop_select(EEG, 'nopoint', [10 10]) at 1024 Hz samples 1 to 10, sample 10 is not removed samples 1 to 9, sample 10 removed
pop_select(EEG, 'nopoint', [2 4]) at 1024 Hz with an event on sample 2 samples 2 to 4 removed, but the event stays at latency 2 samples 2 to 4 removed and the event with them, as at 100 and 300 Hz
pop_select(EEG, 'point', [3 10]) at 300 Hz samples 3 to 10 samples 3 to 10

Comparison with EEGPrep (MATLAB R2025b against Python 3.11, every point range [a b] with a < b on 10 and on 37 samples at 100, 128, 250, 256, 300, 500, 512, 600, 1000, 1024, 2048, 4900 and 30000 Hz)

9,243 short point ranges EEGLAB develop and EEGPrep develop this pull request and EEGPrep pull request 881
Ranges where EEGLAB does not return the requested samples 156 (43 at 300 Hz, 35 at 1024 Hz, 35 at 2048 Hz, 43 at 30000 Hz) 0
Ranges where EEGLAB and EEGPrep differ 0 0
Ranges changed by this pull request 156, all ending one sample before the end, none at the start of the data
Samples kept minus samples requested, EEGLAB develop this pull request
0 9,087 9,243
+1 156 0
Samples kept by EEGLAB minus samples kept by EEGPrep develop and develop this pull request and EEGPrep pull request 881
0 9,243 9,243
Other sets Changed by this pull request EEGLAB wrong before, after EEGLAB differs from EEGPrep before, after
280 point ranges on 30,504 to 122,882 samples 21 (300, 2048 and 4096 Hz, all ending one sample before the end) 21, 0 9, 0
182 ranges in seconds ('time', 'notime', 'rmtime', on a sample and between samples) 0 0, 0 0, 0
224 'nopoint' and 'rmpoint' regions that touch the start or the end 6 (sample 10 of 10 at 1024 Hz, now removed) 6, 0 6, 0
135 calls with two keep ranges or one sample regions 0 see the note on issue 864 below 15, 15
25 calls on epoched data 0 not judged 12, 12
140 calls compared in depth (values, EEG.xmax, boundary events, latencies, com) 19 1, 0

The 15 and the 12 calls that differ between the two programs are old differences that this pull request does not touch: keep ranges that overlap or are not in increasing order (EEGPrep sorts and merges them, EEGLAB does not), and point ranges on epoched data (EEGPrep keeps one more sample). They are listed in the EEGPrep pull request.

Why the change is in pop_select.m, and why it is one added branch

A range given in points is already in the unit that eeg_eegrej takes. The trip through seconds added an error of up to 0.5e-9 * srate sample, which is not floating point round-off: 10.0000001 is really after the end of the data, so eeg_lat2point is right to flag it, and eeg_point2lat.m cannot stop rounding without changing its other callers. The other two candidates (deciding "this limit is the end of the data" with a tolerance, or snapping a time close to EEG.xmax) keep the trip through seconds and need a threshold that depends on the sampling rate. Keeping points in points needs no threshold and is exact at every sampling rate.

The checks above the new branch (g.time and g.notime computed with eeg_point2lat, clipped, with their messages and errors) are not touched, so that a call refused today is refused the same way and a message printed today is printed the same way. The new branch only replaces what was passed to eeg_eegrej. It repeats the lines of the time code below it with sample 1, sample EEG.pnts and a step of one sample, then clips points after the end and drops a last region clipped to zero length, as eeg_lat2point and lines 591 to 594 did. Epoched data (EEG.trials > 1) takes the first branch of the same if and never reaches it.

What else changes, and what does not (300 edge calls, 25 changed)

300 calls with odd or wrong input on 10 and 37 samples at 100, 300 and 1024 Hz, with three events, compared on values, EEG.xmax, events, messages, errors and com between develop and this pull request (edge.m):

Kind of call Calls changed Before After
Range ending one sample before the end at 300 Hz (single, single class, two ranges) and 'nopoint', [10 11] at 1024 Hz 7 last sample kept last sample removed
Event on the first sample of a removed region at 300 and 1024 Hz 4 event kept at the latency of a removed sample event removed, as at 100 Hz
Half sample limits 'point', [2.5 7.5] at 1024 Hz 2 5 samples 6 samples, as at 100 and 300 Hz
Points of class int32 12 wrong result ('point', int32([3 9]) returned an empty dataset, integer arithmetic in eeg_point2lat) the requested samples (the branch converts to double)
Everything else: ranges out of the data, reversed ranges, vector format, column vectors 0 of 275 the same values, the same 32 errors on the same calls, the same messages

com is the same in all 300 calls. A region completely after the end of the data ('nopoint', [11 11] on 10 samples) still removes nothing, and a range that passes the end ('point', [3 50]) is still clipped.

Adjacent keep ranges (sccn/eegprep issue 864, 'point', [1 3; 4 8]) are not part of this pull request: the call still returns 0, 1, 4, 5, 6, 7 on 0:9, and none of the 135 multi range calls changes.

Tests

Tests of sccn/eeglab_tests in the folders of pop_select, eeg_lat2point, eeg_point2lat, pop_epoch, eeg_eegrej, eegrej, pop_selectevent, pop_comperp, pop_autorej, eeg_interp, eeg_insertbound, eeg_checkchanlocs and mmo (sccn/eeglab_tests has no folder for pop_rejcont or eeg_checkset): 46 pass before and after. test_check_eeglab_mmo fails before and after because pop_firws is not installed in the worktree. The new test pass_point2lat fails on develop and passes here.

The branch has two commits because the first version of the fix (2ca1ff72d) moved the checks into points as well, which changed 3 kinds of out of range 'nopoint' calls into errors. The second commit (b887b4c35) restores the checks of develop and keeps only the added branch. The difference with develop is the 43 added lines.

— orchestrator

@claude

claude Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@arnodelorme

Copy link
Copy Markdown
Collaborator Author

Code review

Independent review by Codex (OpenAI GPT-6.1 Terra), asked by the orchestrator. The first version of this change was written by Gemini 4 Carbon and the present version (commit b887b4c, one added branch) by Claude Fable 5.2, so the reviewer is from a third vendor. Codex read the diff against develop in a read-only sandbox and found nothing blocking. It could not run MATLAB, so its review is a reading of the code. The runs are in the description of the pull request.

Finding 1, a nit, left as it is. Codex notes that the comment says the regions are built as in the time code, although that code tests for time 0 and not for EEG.xmin, so the two would differ on continuous data whose xmin is not 0 (the new branch would then be the one that returns the requested samples). I left the comment because eeg_checkset sets xmin to 0 on continuous data (lines 850 to 856 of eeg_checkset.m), and my test with xmin = -0.01 confirms that the dataset reaches pop_select with xmin = 0.

Finding 2, a remark, nothing to fix. A range far after the end of the data is still refused by the checks that this pull request does not touch, as on develop. Measured on 300 odd calls: the same 32 errors on the same calls before and after.

What I fixed before this review. My own check of the first version found that it changed three kinds of out of range 'nopoint' calls into errors ([11 11], [20 30] and [3 50; 7 9] on 10 samples) and re-indented 50 lines. The second commit restores the checks of develop and keeps only the added branch.

The text of Codex, unchanged

No blocking findings. The new branch preserves the intended point selection for the cases reviewed, including multirow and reversed ranges, subject to the existing validation checks. Epoched data with EEG.trials > 1 take the preceding branch. The seconds based removal path is unchanged.

Nit, pop_select.m:568: The comment says the regions are built as in the time path, but that path tests for time zero rather than EEG.xmin. For continuous data with xmin = -1, srate = 10, pnts = 21, and point = [11 15], the new path keeps samples 11 through 15. In exact arithmetic, the old path also keeps samples 1 through 10. The new result matches the requested range, but the comment should acknowledge that the paths can differ when xmin is nonzero.

Out of range caveat: The three examples have the requested results if they pass the unchanged checks. For example, with xmin = 0, srate = 10, and pnts = 100, nopoint = [101 101] still errors at the existing upper limit check. That is preexisting behavior.

Column vectors and other inputs without two columns are rejected before the new branch. I found no new indexing error for empty rejection regions. This is a source review only. MATLAB and Octave were unavailable for execution.

— orchestrator

This branch has not been deployed

No deployments
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.

pop_select keeps the last sample at 300, 1024, 2048 and 30000 Hz from eeg_point2lat rounding

1 participant