Fix pop_select nopoint removing two samples too few - #317
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.
🤖 Fix
pop_selectso user-supplied removal ranges (nopoint,notime,rmpoint,rmtime) remove exactly the requested samples, matching EEGLAB.Problem
On
sample_data/eeglab_data.set(30504 samples, 128 Hz), compared against EEGLAB R2025b:nopoint=[276, 525]nopoint=[1, 10]point=[276, 525]The keep path (
point/time) was already correct; only the removal path was off by one sample at every interior edge.Cause
EEGLAB
pop_select.m(lines 564-584) shifts interior edges by +/-1/srate only insideif isempty(g.notime), i.e. whennotimeis derived as the complement of a user-suppliedtimekeep range (so the kept samples are exactly[t0, t1]). User-suppliednotime/nopoint(and theirrmtime/rmpointaliases, which are plain reassignments at lines 261-266) go straight toeeg_lat2pointandeeg_eegrej.Python
pop_select.py(previously lines 96-97 and 408-420) applied that shift to every notime matrix except one that came fromrmtime, sonopoint,notime, andrmpointeach removed two samples too few (one at each edge, or one at a dataset edge).Fix
Move the +/-1-sample interior-edge adjustment into the branch that builds the complement from
time_mat, and drop thenotime_from_rmtimespecial case. All four user-supplied removal keywords now pass through unchanged, and the derived-complement case fortime/pointis unchanged.Verification
MATLAB (R2025b, EEGLAB) vs Python after the fix, on
sample_data/eeglab_data.setwith the branch onPYTHONPATH. Boundaries are(latency, duration);maxabsis the max absolute data difference.nopoint=[276, 525]nopoint=[1, 10]nopoint=[30495, 30504]rmpoint=[276, 525]notime=[2.15, 4.1]rmtime=[2.15, 4.1]point=[276, 525]time=[2.15, 4.1]nopoint=[[100, 200], [300, 400]]point=[[100, 200], [300, 400]]Tests added in
tests/test_pop_select.py:TestPopSelectContinuousRemoval(6 tests): exactpntsand boundary(latency, duration)for the cases above, plus a complement test thatpoint=[a, b]keeps exactly the samplesnopoint=[a, b]removes and that concatenating the two reconstructs the original data.TestPopSelectParity.test_parity_nopoint_continuous: MATLAB parity fornopoint(skips without MATLAB).No
pop_rejconttest encoded the old off-by-one values, so none needed updating.ruff checkandruff format --checkpass on the changed files.