Skip to content

eeg_lat2point: the fixed tolerance of 1e-12 point is too small above 8,192 samples (last sample kept at 250, 500 and 1000 Hz) #867

Done

Description

@arnodelorme

The tolerance of eeg_lat2point.py on develop was a fixed 1e-12 point, which is smaller than one eps once a recording has more than 8,192 samples. On longer recordings at 250, 500, and 1000 Hz, EEGPrep therefore kept the last sample when a point range ended one sample before the end, just as EEGLAB did before sccn/eeglab pull request 1002.

  • Where it stands: Closed. Arno answered "Yes, put the same tolerance in EEGPrep 1a" and then asked to merge by email on November 29, 2026, after merging sccn/eeglab pull request 1002 (579a27d0d). Pull request 879, [eeg_lat2point] Scale the out-of-range tolerance as EEGLAB does ([eeg_lat2point] Scale the out-of-range tolerance as EEGLAB does #879), is merged into develop (487ce5dda).
  • Example: on 100,000 samples at 250 Hz, pop_select(EEG, point=[2, 99999]) returned 99,999 samples on develop (e435f436) and now returns 99,998 samples, matching EEGLAB develop (579a27d0d).
  • Numbers: compared with EEGLAB develop (579a27d0d) in MATLAB R2025b, pull request 879 differs in 0 of 9,243 short ranges (0 before), 0 of 280 long calls (9 before), 0 of 75 extra-long and offset calls up to 10,000,000 samples (21 before), and 0 of 6,740 direct eeg_lat2point calls (max_ulp_diff = 0).
  • Related: #879, #856, #853, #864.
Details

The question Arno answered with "1a" on November 29, 2026: (a) put the same tolerance in EEGPrep in one small pull request after merging EEGLAB pull request 1002, or (b) leave EEGPrep as it is.

eeg_lat2point.py line 71 flagged a point as out of range when it exceeded max_valid by more than 1e-12 point. At 250, 500, and 1000 Hz the last sample evaluates one eps above max_valid, and one eps of 8,192 is 1.8e-12, larger than 1e-12. pop_select.py then dropped the last rejection region and kept the last sample. Pull request 879 ports the merged EEGLAB eeg_lat2point.m test (min(16 * eps(max(max_valid, max(abs(timewin_sec)) * srate)), 0.5)), clamps points within the tolerance to max_valid without setting flag, and matches MATLAB max/min NaN behavior.

Another 156 of the 9,243 short ranges keep the last sample in both EEGLAB 579a27d0d and EEGPrep, at 300, 1024, 2048, and 30000 Hz, because eeg_point2lat rounds times to 1e-9 s. That separate pop_select cause is tracked on its own issue and pull requests.

— orchestrator

Activity

  1. added
    needs-arno
    on Nov 29, 2026
  2. claude commented on Nov 29, 2026

    @claude
    Contributor

    🤖 Plan:

    • Read issue and check prerequisites
    • Implement option 1a (blocked, see below)

    Status: blocked, no PR opened. This changes numerical output relative to EEGLAB, which AGENTS.md requires Arno's explicit approval for, and the issue records his current decision as "keep EEGPrep like this". Option 1a is also conditioned on sccn/eeglab#1002 being merged; it is still open (checked 2026-11-29).

    Needed to proceed: (1) Arno's answer "1a", and (2) sccn/eeglab#1002 merged.

    Proposed fix once unblocked (one line): src/eegprep/functions/popfunc/eeg_lat2point.py#L71 replace max_valid + 1e-12 with max_valid + 16 * np.spacing(max(max_valid, np.max(np.abs(timewin_sec)) * srate)), plus a regression test in tests/test_pop_select.py for point=[2, 99999] on 100,000 samples at 250 Hz expecting 99,998 samples, and a MATLAB reference run against an EEGLAB checkout containing #1002.

  3. removed
    needs-arno
    on Nov 29, 2026
  4. arnodelorme commented on Nov 29, 2026

    @arnodelorme
    CollaboratorAuthor
    • Arno's answer (email, November 29, 2026 at 08:58): "Yes, put the same tolerance in EEGPrep 1a". This is his approval of the numerical change that AGENTS.md asks for.
    • The condition is met: he merged sccn/eeglab pull request 1002 the same morning (develop 579a27d0d).
    • Next step: one small pull request on the branch agent/issue-867 puts the tolerance of the merged EEGLAB fix in eeg_lat2point.py, with the comparison against EEGLAB develop on the 9,243 short ranges and the 280 long calls. It will wait for his merge.
    • The other question of the same email: he also chose to fix now the 156 ranges that keep the last sample at 300, 1024, 2048 and 30000 Hz ("Yes, fix it now in two pull requests. 2b"). That is a change of pop_select in EEGLAB and in EEGPrep, on its own issues and pull requests, not here.

    — orchestrator

  5. arnodelorme commented on Nov 29, 2026

    @arnodelorme
    CollaboratorAuthor

    Done: Opened pull request 879 scaling the eeg_lat2point round-off tolerance to match EEGLAB develop 579a27d0d; it waits for Arno's merge

    Pull request: #879

    — orchestrator, reported with orch done

  6. arnodelorme commented on Nov 29, 2026

    @arnodelorme
    CollaboratorAuthor

    Done: Merged pull request 879 ([eeg_lat2point] Scale the out-of-range tolerance as EEGLAB does) into develop at commit 487ce5d after resolving the changelog conflict with pull request 797.

    Pull request: #879

    — orchestrator, reported with orch done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions