Skip to content

Stream 6: Rejection numbers - #559

Merged
suraj-ranganath merged 11 commits into
developfrom
cursor/stream-6-rejection-numbers-a646
Nov 6, 2026
Merged

suraj-ranganath merged 11 commits into
developfrom
cursor/stream-6-rejection-numbers-a646

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Refs #551

Merged origin/develop cdbe303d, which includes #560 and #562. Head bcd6291d. This is a merge, not a rebase. Cancelling Reject extreme values, its channel-data variant, and the other ICA rejection dialogs leaves File, Edit, and Tools in place and writes no history. Cancelling Title in the scroll window leaves Figure, Display, and Settings in place.

pop_rejepoch keeps the scroll-window history EEG = pop_rejepoch( EEG, {matlab_array2str(indices)},0); and does not open its own dialog. confirm=-1 still keeps an empty dataset, and any other confirm value still names pop_rejepoch when every epoch is marked. The Reject marked epochs menu still records eeg_rejsuperpose only after pop_newset is accepted. Both changelog entries are kept. pop_eegthresh history records the reject flag that was applied. A scripted reject=1 call replays to the same dropped epochs. Continuous-array history uses one contarray helper and a number formatter. EEGPREP_SKIP_MATLAB=1 uv run pytest tests passed 2178 tests. The audit checkout check fails in this environment because git rewrites the GitHub remote, and it passes when that rewrite is absent.

Recheck against EEGLAB 8ac485f6: eeg_regepochs again inserts every regular event and lets pop_epoch drop a window past the data. Recurrence 0.25 with limits [0 0.5] keeps 952 trials, 2212 events, 1904 X events, and 1107 urevents. Recurrence 0.5 with limits [0 2] keeps 473 trials, 2506 events, 1892 X events, and 630 urevents. urevent stays an array. The MATLAB pop_autorej reference passes nogui,on and compares sorted [1 2 28 46 70] with EEGLAB's [1 46 70 2 28]. A dialog threshold -50 10 stays [min max] (27720 points, 8 regions); pop_rejcont.m:147 str2double would make that NaN. pop_rejcont history omits eegplot and records EEG = pop_select( EEG, 'nopoint',[3489 4128;4257 4608;...]); as its own entry. pop_eegthresh history is EEG = pop_eegthresh(EEG,1,[1:32] ,-75,75,-1,1.9922,0,0); and the dialog end time is 1.9922. Update Marks shows the noted-epochs warning. Two numbers in Add trails name pop_rejcont, the field, and an example such as 0.25. The natural-log multitaper scale and the linspace frequency axis were still held at that recheck.

Round 4: event type counts use the shared MATLAB struct-array records, so the overlapping-epoch reference compares EEGLAB's X-event totals. pop_rejcont with correct blank stores the zeroed samples again; on eeglab_data.set, 20-40 Hz at 10 dB with taper none zeroes 1312 float32 columns. pop_eegthresh times go through eeg_checkset._matlab_num2str (1.9922, 12.3457, 123.4568). Update Marks parents the warning to the main window and drops an unparented box when it closes.

Rejection counts follow the EEGLAB pop functions cited below. Local checks on this head: uv run pytest tests/test_stream6_rejection_numbers.py tests/test_misc_data_event_eeglab_tests.py --eeglab-backend python (the autorej MATLAB-only reference skips; the rest of stream 6 passes) and uv run pytest tests/test_rejection_workflows.py tests/test_pop_autorej.py tests/test_gui_rejection_dialogs.py. ruff check, ruff format --check, ty check, and ./pre-commit.py --changed-from origin/develop are clean on the touched files.

menu_actions.py is shared with Stream 11. This PR changes _run_rejsuperpose, the pop_rejepoch branch inside _run_pop_function, and adds pop_rejepoch to _NEWSET_COMMIT_ACTIONS so that branch uses the shared pop_newset commit path. qt.py gains the toggle_checked_text callback used by the channel-rejection normalization checkbox. eeg_regepochs.py stores event and urevent as object arrays and inserts every regular event. pop_eegplot.py shows the Update Marks warning from eeg_rejmacro.m:119-121.

console.py is Stream 11 and is not edited. History now uses MATLAB colon ranges ([1:32], [1:6 9]). The console translator does not expand those ranges, so replaying those lines in eegprep-console still needs Stream 11.

Automatic channel rejection (pop_rejchan, eeglab.m:650, e_hist) and automatic epoch rejection (pop_autorej, eeglab.m:651, e_hist) still overwrite the current dataset. Those two menu paths are left for Stream 2.

Suraj decided both remaining quirks stay as deliberate EEGPrep behavior. Multitaper power is 10*log10, not 10*log at pop_rejspec.m:310. On eeglab_data_epochs_ica.set, ±35 dB marks no data epochs; EEGLAB marks epoch 37. ±30 dB marks no data epochs and no component epochs; EEGLAB marks data epoch 37 and components 13, 14, 15, 26, and 79. pop_rejcont uses the real FFT bin frequencies, not the linspace axis at pop_rejcont.m:211. On eeglab_data.set, 20–40 Hz at 10 dB keeps 27720 points in 8 regions; EEGLAB keeps 28008 points in 9. The MATLAB reference tests assert that difference when --eeglab-backend=matlab. No tolerance was added or changed.

Review follow-up on d7d5e5ff: each multitaper series stops on its own sum(abs(S-S1))/nfft > tol test and a non-finite change counts as stopped, so one NaN sample returns. Finite tutorial multitaper lists are still empty. contarray history uses num2str. eeg_rejsuperpose is recorded only after pop_newset accepts the new dataset.

The MATLAB reference workflow in AGENTS.md was not run here (no MATLAB). A hands-on GUI retest and Suraj's approval are still required before merge.

MATLAB checks still to run

Against EEGLAB 8ac485f654d6bbb1a6acb8dc9ef3f2eaf3d409ba (vendored submodule), on sample_data/eeglab_data.set and sample_data/eeglab_data_epochs_ica.set:

uv run pytest tests/test_stream6_rejection_numbers.py --eeglab-backend=matlab -k "test_reference_pop_rejcont_sample_regions or test_reference_pop_rejcont_two_sided_thresholds or test_reference_pop_rejchan_sample_channels or test_reference_pop_rejspec_multitaper_epochs or test_reference_threshold_75_marks_71_epochs or test_reference_pop_autorej_eeglab_omits_epoch_16 or test_reference_eeg_regepochs_keeps_events_inside_overlapping_epochs"

What those tests compare:

  • pop_rejcont elec 1:32, freqlimit [20 40], threshold 10, epochlength 0.5, contiguous 4, addlength 0.25, taper hamming, overlap 0.25. EEGPrep regions [[3489,4128],[4257,4608],[7713,7904],[13505,13664],[26561,26944],[27201,27360],[27553,27840],[28033,28640]] and 27720 points left. The same regions hold after pop_eegfiltnew(..., 1). EEGLAB's linspace axis keeps the previous 9 regions and 28008 points, starting [321 480; 3489 3936; ...; 28033 28544].
  • pop_rejcont with threshold [-50 10] keeps those same 8 regions and 27720 points. Threshold [-5 10] keeps 3432 points in 17 regions. EEGLAB still keeps 28008 points in 9 regions for [-50 10] and 3496 points in 16 regions for [-5 10].
  • pop_rejchan measure kurt and prob, elec 1:32, threshold 5, norm on, on eeglab_data.set. Expected kurtosis [1 2 6], probability [1 2].
  • pop_rejspec method multitaper and fft, freqlimits [15 30]. EEGPrep multitaper marks no data epochs at ±30 dB or ±35 dB and no ICA epochs at ±30 dB. EEGLAB's natural log marks data epoch 37 at both thresholds and ICA epochs [13 14 15 26 79] at ±30 dB. FFT lists stay at 44 data epochs and 46 ICA epochs.
  • pop_eegthresh on eeglab_data_epochs_ica.set, data mode, electrodes 1:32, thresholds -75 and 75, reject 0. Expected 71 marked epochs. Export marks to ICA reject then sets icarejmanual to those 71 epochs.
  • pop_autorej channel mode on eeglab_data_epochs_ica.set, with nogui,on. pop_autorej.m:224 reads icarejkurt, so MATLAB returns [1 46 70 2 28] (sorted [1 2 28 46 70]) and keeps 75 epochs. EEGPrep reads rejkurt and rejects [1 2 16 28 46 70] (74 epochs kept). The MATLAB assertion skips unless --eeglab-backend=matlab.
  • eeg_regepochs on eeglab_data.set. Recurrence 0.25, limits [0 0.5]: 952 trials, 2212 events, 1904 type X, 1107 urevents. Recurrence 0.5, limits [0 2]: 473 trials, 2506 events, 1892 type X, 630 urevents.

Per finding

Finding Root cause Fix Test
F66 pop_rejcont thresholded each window on its own spectrum and then merged every run, so one hot window deleted the file. Port pop_rejcont.m:202-316: eeg_regepochs with overlap as the recurrence, trial-mean log spectrum, eegthresh frames, and the backwards merge. A length-2 threshold is [min max] (pop_rejcont.m:239); a cell of thresholds or frequency ranges is passed through (pop_rejcont.m:172-177). test_pop_rejcont_keeps_the_same_regions_after_1hz_highpass, test_pop_rejcont_two_sided_and_cell_thresholds; MATLAB test_reference_pop_rejcont_sample_regions, test_reference_pop_rejcont_two_sided_thresholds
F67 Kurtosis and probability used a one-sided cut and skipped the 10% trim on a 2-D channel sweep. Use the rejkurt / jointprob mask (rejkurt.m:131, jointprob.m:133) after the trim at rejkurt.m:109-114. Continuous file: kurtosis [1 2 6], probability [1 2]. test_pop_rejchan_normalized_channels_match_the_sample_sets; MATLAB test_reference_pop_rejchan_sample_channels
F68 rejspec Multitaper power was not pmtm, so ±35 dB marked nothing. See F110. True dB (10*log10) marks no data epochs at ±35 dB. EEGLAB's natural log marks epoch 37. test_pop_rejspec_multitaper_db_marks_no_tutorial_epochs
F68 autorej pop_autorej.m:224 reads icarejkurt even in channel mode, so EEGLAB never applies the kurtosis mark and keeps epoch 16 (75 epochs). EEGPrep's channel mode uses rejkurt and keeps 74. EEGPrep keeps reading rejkurt and still rejects epoch 16. The MATLAB list is locked beside the EEGPrep list. test_pop_autorej_channel_mode_keeps_the_kurtosis_epoch_eeglab_drops; MATLAB test_reference_pop_autorej_eeglab_omits_epoch_16 asserts [1 2 28 46 70]
F84 Same spectrum bug as F66. Spacing was left to eegplot (1.0 when no source EEG is attached). The dialog always showed Help. Same pop_rejcont port. Spacing is computed from eegplot.m:457-473 and passed in (80 on this file). Help is off, matching pop_rejcont.m:140. test_pop_rejcont_keeps_the_sample_recording_regions, test_pop_rejcont_scroll_spacing_and_dialog_have_no_help
F86 Same channel-score bug as F67, on eeglab_data_epochs_ica.set. Same trim and two-sided mask. Kurtosis rejects [1 2]. test_pop_rejchan_normalized_channels_match_the_sample_sets
F98 The measure popup included Standard deviation, the frequency range stayed enabled, and history was a Python repr. Unchecking normalization left the threshold labeled as a z-score. Popup is Probability, Kurtosis, Spectrum (pop_rejchan.m:96). Frequency controls enable only at index 3 (pop_rejchan.m:99-100). The norm checkbox relabels the threshold (pop_rejchan.m:86-89). History is the vararg2str line at pop_rejchan.m:246. measure='std' remains a scripted option. test_pop_rejchan_dialog_and_history_follow_vararg2str
F104 Export used the opposite typerej and never copied rejglobal onto icarejmanual. eeglab.m:661-662: superpose with typerej 1, then icarejmanual = rejglobal. On eeglab_data_epochs_ica.set, pop_eegthresh at ±75 marks 71 epochs and that export copies all 71 onto icarejmanual. test_threshold_75_marks_71_epochs_and_export_copies_them, test_export_marks_copies_rejglobal_onto_the_manual_field; MATLAB test_reference_threshold_75_marks_71_epochs
F107 The component dialog defaulted to 1:ncomponents. ICA elecrange default is the literal 1:5 from pop_eegthresh.m:120. test_component_threshold_dialog_defaults_to_the_first_five_components
F108 No code fix expected. ICA trend defaults already mark every epoch. Re-verified after the score-normalization change. No behavior change. test_ica_trend_and_kurtosis_defaults_mark_the_audited_epochs (80 marks)
F109 No code fix expected. ICA kurtosis defaults already match. Re-verified after the 2-D trim, which this call does not use. No behavior change. same test, epochs [9 10 16 53 69]
F110 Multitaper used the wrong taper count, a mean-removed spectrum, log10, a frequency mask, and a 20-iteration cap. pop_rejspec.m:307-326: seven adaptive Slepian tapers, 10*log10 dB, eegthresh bins, full-nfft convergence with no iteration cap. ±30 dB and ±35 dB mark no tutorial epochs. EEGLAB's 10*log marks data epoch 37 and ICA epochs [13 14 15 26 79] at ±30 dB. FFT lists are unchanged (44 data, 46 ICA). The dialog method popup defaults to FFT (pop_rejspec.m:149) and the threshold fields stay labeled dB. test_pop_rejspec_fft_epoch_lists_stay_unchanged, test_pop_rejspec_multitaper_db_marks_no_tutorial_epochs, test_pop_rejspec_dialog_defaults_to_fft; MATLAB test_reference_pop_rejspec_multitaper_epochs
F111 Export to data reject never copied rejglobal onto rejmanual. eeglab.m:674-675: superpose with typerej 0, then rejmanual = rejglobal. Kurtosis marks land on [9 10 16 53 69]. test_export_ica_marks_copies_the_audited_kurtosis_epochs
F112 The menu called pop_rejepoch with the stale rejglobal and did not superpose. Rejecting every epoch surfaced pop_select's empty-dataset error. The menu overwrote the current dataset. eeglab.m:663-677: confirm, superpose, pop_rejepoch, then e_newset via pop_newset. History is pop_rejepoch( EEG, [1:6 9] ,0). confirm=-1 follows pop_rejepoch.m:96-97 (erroronempty off). Any other confirm value names pop_rejepoch and says to clear a mark. test_reject_marked_epochs_superposes_before_removing_trials, test_pop_rejepoch_history_compresses_ranges_and_records_confirm_zero, test_pop_rejepoch_confirm_minus_one_keeps_an_empty_dataset, test_pop_rejepoch_names_the_empty_dataset_error

Review follow-ups

  • pop_rejcont history is the commented vararg2str line, without eegplot, plus a separate EEG = pop_select( EEG, 'nopoint',[...]); entry. test_pop_rejcont_two_sided_and_cell_thresholds.
  • pop_autorej names the dialog field and a valid example when the entry is not numeric. test_pop_autorej_names_a_non_numeric_dialog_field. The MATLAB reference passes nogui,on and sorts the returned epochs.
  • eeg_regepochs stores urevent as an array and inserts every regular event. pop_epoch warns event N out of data boundary and drops that epoch. test_reference_eeg_regepochs_keeps_events_inside_overlapping_epochs. The type count reads dicts and MATLAB structured arrays (test_type_count_reads_matlab_struct_event_arrays).
  • Dialog text -50 10 is kept as a two-sided threshold. test_pop_rejcont_two_sided_and_cell_thresholds.
  • pop_eegthresh history and the 1.9922 end time: test_pop_eegthresh_history_and_dialog_follow_num2str. Larger values use num2str (12.3457, 123.4568). A reject=1 call records that flag, and test_pop_eegthresh_reject_one_history_replays_dropped_epochs replays it to the same dropped epochs. The reject=0 history string is unchanged.
  • Update Marks notice: test_update_marks_shows_the_eeglab_notice. The box is parented to the main window, or removed from the session list when it closes.
  • Add trails must be one number of seconds: test_pop_rejcont_names_a_two_number_add_trails_value.
  • correct blank on float32 data zeroes 1312 columns for 20-40 Hz, 10 dB, taper none. test_pop_rejcont_blank_zeroes_float32_sample_columns.
Open in Web Open in Cursor 

cursoragent and others added 2 commits November 6, 2026 01:29
…arks.

Port pop_rejcont's overlapping-window spectrum, pop_rejchan's trimmed two-sided scores, and pop_rejspec's adaptive multitaper, and copy superposed marks onto the manual reject fields.

Co-authored-by: Suraj Ranganath <[email protected]>
Pass [min max] and cell thresholds through pop_rejcont, record MATLAB history, and route marked-epoch rejection through pop_newset.

Co-authored-by: Suraj Ranganath <[email protected]>
@cursor
cursor Bot force-pushed the cursor/stream-6-rejection-numbers-a646 branch from 093b8bf to 49203d2 Compare November 6, 2026 01:42
cursoragent and others added 2 commits November 6, 2026 03:33
Insert every regular event before pop_epoch drops a window past the data, and record pop_rejcont and pop_eegthresh history in EEGLAB's form.

Co-authored-by: Suraj Ranganath <[email protected]>
Write blanked samples back onto the dataset, count structured event arrays, and format threshold times with the shared num2str rule.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 04:41

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 1m 59s —— View job


Code review

  • Overall assessment: Needs changes. I found one bug: a hang that MATLAB does not have. The rest of the ported logic I checked matches the cited EEGLAB lines: the pop_rejcont window merge, the eegthresh frame limits, the trimmed rejkurt/jointprob normalization, the export-marks typerej swap, and the superpose step before pop_rejepoch.
  • Highest-risk area: the new adaptive multitaper loop in _rejection._multitaper_power.
  • Merge recommendation: Needs changes.

Blocking

None.

Important

  1. The multitaper loop hangs on NaN data (src/eegprep/functions/popfunc/_rejection.py:298-305).
    • Cause: this PR removed the iteration cap, and the exit test is np.max(...) - tolerance <= 0. One NaN sample in any channel or epoch makes that test NaN <= 0, which is always False.
    • Effect: pop_rejspec(..., 'method','multitaper') never returns, and the GUI freezes.
    • MATLAB: pmtm's while sum(abs(S-S1))/nfft > tol exits on NaN. It also tests convergence per series, while this version pools every series.
    • Fix: a suggestion is posted inline. Compute the per-row change and stop when no row has change > tolerance. Add one regression test with a NaN sample.

Nits

  • Shared history helpers live inside pop_rejchan.py. pop_eegthresh, pop_rejepoch and pop_rejcont now import the private _matlab_contarray, _matlab_number and _matlab_history_value from pop_rejchan.py.
    • The repo already has functions/adminfunc/vararg2str.py, and AGENTS.md lists "Parallel implementations of existing helpers" as a failure pattern.
    • There are now also two different number formatters: _matlab_number uses :g, while pop_eegthresh uses eeg_checkset._matlab_num2str.
    • Fix: move the contarray port (vararg2str.m:196-242) into adminfunc/vararg2str.py, use one number formatter, and import from there.
  • History can mention a superpose that never happened. In menu_actions.py, the pop_rejepoch branch records the eeg_rejsuperpose history line before the shared pop_newset commit. If the user cancels the new-dataset dialog, that line stays in ALLCOM even though no dataset changed. Fix: record it only after the commit succeeds.

Test gaps

EEGLAB parity notes

  • The vendored EEGLAB submodule is not checked out in this runner. I did not re-verify the eeglab.m line references (661-677) or the MATLAB-only reference tests. The MATLAB reference run listed in the PR description is still required before merge.

Checked: correctness of the changed pop and menu code, EEG dict handling (event and urevent as object arrays, 0-based urevent pointers), the history strings, the dialog defaults, and AGENTS.md compliance.

updated = np.sum(weighted * eigenspectra, axis=1) / np.maximum(
np.sum(weighted, axis=1), np.finfo(float).tiny
)
converged = bool(np.max(np.mean(np.abs(updated - spectrum), axis=1) - tolerance) <= 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: this loop never ends if any channel or epoch contains a NaN.

If one sample in any series is NaN, that row of spectrum/updated becomes NaN. np.max(...) then returns NaN, and NaN <= 0 is False. converged stays False, and with the 20-iteration cap removed, pop_rejspec(..., 'method','multitaper') hangs and freezes the GUI.

MATLAB stops in this case. pmtm's while sum(abs(S-S1))/nfft > tol evaluates NaN > tol as false, so the loop exits. MATLAB also tests convergence per series. This line pools all series, so rows that have already converged keep iterating until the slowest row converges.

Suggested fix: compare per row and treat non-finite differences as converged, to match MATLAB's exit:

Suggested change
converged = bool(np.max(np.mean(np.abs(updated - spectrum), axis=1) - tolerance) <= 0)
change = np.mean(np.abs(updated - spectrum), axis=1)
converged = bool(np.all(~(change > tolerance)))

Test to add: run multitaper pop_rejspec on _epochs() with one NaN sample in one epoch, and assert it returns.

cursoragent and others added 2 commits November 6, 2026 04:46
Multitaper power is 10*log10, and pop_rejcont thresholds the real bin frequencies. Both are deliberate differences from EEGLAB on the tutorial file.

Co-authored-by: Suraj Ranganath <[email protected]>
Each series freezes on its own pmtm test, including a non-finite change. History arrays use num2str, and eeg_rejsuperpose is stored only after pop_newset succeeds.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 05:59
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 05:59
Keep Stream 3's pop_rejepoch history and Stream 6's superpose history that is recorded only after pop_newset is accepted.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 07:49
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 07:49
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 1m 54s —— View job


Code review

  • Overall assessment: Needs changes. I found one history regression. The NaN multitaper hang and the superpose-history nit from the last review are fixed. _multitaper_power now stops each series on its own, treats a non-finite change as stopped, and records leading_command only after pop_newset accepts the new dataset.
  • Highest-risk area: pop_eegthresh history replay.
  • Merge recommendation: Needs changes. One small fix.

Blocking

None.

Important

  1. pop_eegthresh history always records reject=0 (src/eegprep/functions/popfunc/pop_eegthresh.py:228).
    • Cause: the last history argument is now the literal "0", and the reject parameter goes unused. Before this PR it recorded int(bool(reject)).
    • Effect: a scripted call with reject=1 removes the marked trials through pop_rejepoch (_eegplot_rejection.py:159-160), but the history line ends in ,0,0);. Replaying ALLCOM would only mark those epochs, so the replayed dataset keeps more trials than the original.
    • Fix: use str(int(bool(reject))) (inline suggestion posted) and add one reject=1 history assertion. Fix this →%3B&repo=sccn/eegprep)

Nits

  • Two contarray ports in adminfunc/vararg2str.py. The new _num2str_contarray (line 58) repeats the existing _matlab_contarray/_matlab_integer_row (lines 134-177). Only the number formatter differs.
    • Callers are now split. pop_eegthresh._history_vector uses _matlab_contarray plus its own num2str branch. pop_rejchan and pop_rejcont use _num2str_contarray.
    • AGENTS.md lists "Parallel implementations of existing helpers" as a failure pattern.
    • Fix: keep one contarray with a formatter choice, and route pop_eegthresh._history_vector through _matlab_history_value.

Test gaps

EEGLAB parity notes

  • The vendored EEGLAB checkout (src/eegprep/eeglab/) is not present in this runner. I could not re-check the cited .m line numbers: the pop_rejcont.m:293-316 merge, rejkurt.m:109-114 trim, pop_eegthresh.m:251-252 history, and eeglab.m:661-677. I compared the ports with the descriptions and line references in the PR body.
  • The 10*log10 multitaper scale and the real FFT bin frequencies in pop_rejcont are deliberate differences from EEGLAB. Both are documented in resources/help/pop_rejspec.md and pop_rejcont.md and locked by tests, so I did not count them as parity bugs.
  • Before merge, the PR still needs the MATLAB reference run listed in its description and in AGENTS.md (core-function PR).

I checked the multitaper convergence loop (per series, NaN-safe), the pop_rejcont port (bands, eeg_regepochs windows, the backwards merge, history split into a comment line and a pop_select line), the 2-D trim in rejkurt/jointprob, the typerej swap and copy onto the manual field in export marks, the superpose and confirm steps in Reject marked epochs, empty-dataset handling in pop_rejepoch, the dialog defaults, and AGENTS.md compliance.

_history_vector(starttime),
_history_vector(endtime),
str(int(bool(superpose))),
"0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: the history always records reject=0, even when epochs were removed.

Before this PR, history recorded int(bool(reject)). Now the last argument is hard-coded to "0", and the reject parameter goes unused. A scripted pop_eegthresh(EEG, 1, [1:32], -75, 75, -1, 1.99, 0, 1) runs pop_rejepoch in run_epoched_mark_rejection (_eegplot_rejection.py:159-160) and drops the marked trials. Its history line ends in ,0,0);, though. Replaying ALLCOM would mark those epochs without removing them, so the replayed dataset keeps more trials than the original session.

The tests only cover reject=0 (test_rejection_workflows.py:372, test_stream6_rejection_numbers.py:368), so they don't catch this.

Fix: record the value that was applied, then add one reject=1 history assertion.

Suggested change
"0",
str(int(bool(reject))),

return all(character.isdigit() or character in ".:-+eE,; " for character in token)


def _num2str_contarray(values: list[float]) -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: a second port of vararg2str.m contarray in the same file.

_matlab_contarray / _matlab_integer_row at lines 134-177 already port vararg2str.m:196-242, using the same colon-range algorithm. _num2str_contarray differs only in its number formatter: _matlab_num2str versus _matlab_num (.16g). Callers are now split. pop_eegthresh._history_vector uses _matlab_contarray and adds its own num2str branch for non-integer values. pop_rejchan and pop_rejcont use _num2str_contarray through _matlab_history_value. AGENTS.md lists "Parallel implementations of existing helpers" as a failure pattern.

Fix: keep one contarray. Give _matlab_contarray or _matlab_integer_row a formatter argument, or have _matlab_history_value call _matlab_contarray and use num2str only in the non-integer branch. Then make pop_eegthresh._history_vector call _matlab_history_value.

A scripted reject=1 call now replays to the same dropped epochs. Continuous-array history uses one contarray helper and a number formatter.

Co-authored-by: Suraj Ranganath <[email protected]>

Copy link
Copy Markdown
Member Author

Responses to the Claude review of 9719afb. All fixed in 3b5685c:

  • pop_eegthresh history hard-codes reject=0: agreed and fixed. History now records the reject flag that was applied, and a reject=1 call replayed from the console drops the same epochs. The reject=0 string is unchanged. This differs on purpose from EEGLAB, which always writes 0 there, so a replayed EEGLAB history only marks the epochs.
  • Duplicate helpers in vararg2str.py: agreed and fixed. _num2str_contarray and _matlab_integer_row are gone. _matlab_contarray takes the formatter, and every existing history string is unchanged.
  • Test gap for reject=1 history: covered by the new replay test.
  • MATLAB reference run: done on 3b5685c against EEGLAB d0963be9 and eeglab_tests fec88f9f. 32 MATLAB reference tests passed. The patched-EEGLAB parity checks match: multitaper marks [], rejcont 27720/8 and 3432/17, 1312 blank columns, and the pmtm dB correlation is 0.9995. The deliberate 10*log10 and FFT-bin differences are documented and tested.

The GUI recheck side by side with EEGLAB (reject confirm and cancel, reject-all error, Cancel at pop_newset, rejcont) found no regressions.

@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 10:04
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 10:04
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 44s —— View job


Code review

  • Overall assessment: Looks good. Both items from the last review are fixed in 3b5685c, and I found nothing new in fe32039.
  • Highest-risk area: _matlab_contarray in adminfunc/vararg2str.py. matlab_array2str and every pop_* history string now share it.
  • Merge recommendation: Safe to merge once the human approval described in AGENTS.md is in place. The MATLAB reference run is reported in the author's reply (EEGLAB d0963be9, eeglab_tests fec88f9f, 32 passed).

Blocking

None.

Important

None.

Nits

None.

Test gaps

None. The new reject=1 replay test covers the history fix. tests/test_gui_main_window.py adds a test for the menu bar surviving a cancelled dialog.

EEGLAB parity notes

  • The pop_eegthresh history now records the applied reject flag, while pop_eegthresh.m:252 always writes 0. This is a deliberate difference that keeps replay correct. It is documented in changelog.rst and covered by the replay test, so it is not a parity bug.
  • The vendored src/eegprep/eeglab/ checkout is missing in this runner, so I could not reopen vararg2str.m:196-242 here. I compared the merged _matlab_contarray with the removed _num2str_contarray and the old _matlab_integer_row. The range-collapse branches match line for line.
  • One behavior change: the integer test is now exact (round(x) == x, as in MATLAB) instead of np.isclose. It only affects whether near-integer floats get collapsed into colon ranges. Each value still prints the same, so replay is unaffected.

What I checked (diff 9719afb..fe32039)

  • vararg2str.py: there is now one contarray with a formatter argument. NaN rows still take the integer path, and the 1-value and 2-value cases are unchanged. _matlab_integer_row, _num2str_contarray and _history_vector are all gone, with no leftover callers.
  • pop_eegthresh._history_command: it calls _matlab_history_value, the reject flag is restored, and the _matlab_num2str and Any imports are still used.
  • main_window.py: _menu_refs holds the Python wrappers for every top-level menu and submenu, and each _build_menus replaces the list so it does not grow. The comment explains a non-obvious Qt/shiboken lifetime issue. It is not a workaround justification.
  • I could not run the tests: the runner's tool permissions blocked uv run pytest.

addMenu's QMenu and menu action are owned by Python. Collecting those wrappers while Display is popped up deletes the menu's actions, so Title never opens. Keep every browser menu wrapper for the window lifetime.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 10:45
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 10:45
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 29s —— View job


Code review

  • Overall assessment: Looks good. The only commit since the last review is 7405279. It keeps Python references to the eegbrowser menus, the same fix fe32039 made in main_window.py. I found no problems in it.
  • Highest-risk area: the Qt/shiboken object lifetime in EEGBrowserWindow._build_menus (src/eegprep/functions/guifunc/eegbrowser.py:221-307).
  • Merge recommendation: Safe to merge once a human approves, as AGENTS.md requires. The author reported the MATLAB reference run in an earlier reply: EEGLAB d0963be9, eeglab_tests fec88f9f, 32 passed.

Blocking

None.

Important

None.

Nits

None.

  • main_window.py and eegbrowser.py each now have their own version of the kept list plus retain helper. They are short, sit in different classes and don't share a builder, so I wouldn't merge them now. If a third Qt window needs the same fix, move it into one helper in guifunc/qt.py.

Test gaps

None. test_gui_cancel_browser_menu_dialog_keeps_menu_bar opens Display, runs gc.collect(), cancels the Title dialog, and then checks that the actions are still valid and that the menu bar and menu tree are unchanged. That reproduces the reported bug. It uses the existing modal_dialogs marker that tests/conftest.py:230 handles.

EEGLAB parity notes

  • This commit doesn't change any EEGLAB parity behavior. The browser menu labels and their order (Figure, Display, Settings, Help) are unchanged, and the test checks them.

What I checked (diff fe32039..7405279)

  • Menus kept: all 10 menus created with addMenu in _build_menus are kept along with their menuAction(). No addMenu call is missed.
  • References: _menu_refs is replaced on each build, not appended to, so it can't grow.
  • Comment: the comment at eegbrowser.py:150-152 explains a non-obvious lifetime rule. It doesn't justify a workaround, so AGENTS.md allows it.
  • Not run: this runner's tool permissions blocked uv run pytest tests/test_eegplot_gui.py, so I could not run the new test.

Copy link
Copy Markdown
Member Author

Follow-up at 7405279.

Cancel menu loss (fe32039 + 7405279): PySide/shiboken collected QMenu wrappers while a menu was still popped up, which removed File/Edit/Tools from the main window and could do the same to the scroll window's Figure/Display/Settings menus. Both _build_menus now hold every menu wrapper. GUI tests cancel all 7 rejection dialogs, plus dialogs opened from the browser menus, and they failed before the fix. A hands-on recheck found the menus, history and dataset intact after repeated cancels, and the earlier flows still work: cancel at pop_newset keeps 80 trials, confirming reject leaves 9, and rejcont gives 27720 points. No numeric code changed since the 3b5685c parity run.

Claude r4 nit (duplicate keep/retain helpers): agreed it isn't worth extracting for two windows. We'll move it into guifunc/qt.py if a third window needs it.

CI is green on Ubuntu 3.12/3.13, macOS and Windows.

…jection-numbers-a646

Co-authored-by: Suraj Ranganath <[email protected]>

# Conflicts:
#	docs/source/changelog.rst
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 15:22
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 15:22
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 1m 0s —— View job


Code review

  • Overall assessment: Looks good. The only new commit since my last review (7405279) is the merge of origin/develop at cdbe303 (Stream 4: Signal processing #560). The merge did not change any of this PR's own behavior, and it did not drop or revert anything from develop.
  • Highest-risk area: the merge resolution in _rejection.py. Develop and this branch both edited spectrum_marks and _multitaper_power.
  • Merge recommendation: Safe to merge once a human approves, as AGENTS.md requires. Wait until the in-progress Tests run on bcd6291 is green.

Blocking

None.

Important

None.

Nits

None.

Test gaps

None.

EEGLAB parity notes

None. Nothing in the merge changes parity.

  • The two deliberate differences from EEGLAB are unchanged: 10*log10 multitaper power, and real FFT bin frequencies in pop_rejcont. So is the pop_eegthresh history recording the reject flag that was applied.
  • The MATLAB reference run in the author's reply (EEGLAB d0963be9, eeglab_tests fec88f9f, 32 passed) was made on 3b5685c. The author says no numeric code has changed since then, and the merge adds none to the PR's files.

What I checked (merge bcd6291, parents 7405279 and cdbe303)

  • Nothing from develop was dropped. git diff cdbe303 bcd6291 touches exactly the 23 files listed for this PR (+2137/−219). No other develop file was changed by the merge.
  • _rejection.py: the round_mat import from develop is kept, and _trimmed_channel_scores uses it. Develop's FFT frequency-mask path in spectrum_marks still runs for method='fft', and the multitaper branch uses _time_window. The NaN-safe, per-series convergence loop is intact.
  • changelog.rst: the one real conflict. It was resolved as a pure insertion under Unreleased (+92/−0), so no develop entry was lost or duplicated.
  • Other files: the diffs against develop for eegbrowser.py, main_window.py, pop_eegthresh.py, pop_rejepoch.py and eeg_regepochs.py match what I reviewed before. pop_select still accepts the erroronempty keyword that pop_rejepoch passes.
  • Not done: this runner's tool permissions blocked uv run pytest, so I could not run the tests. I relied on CI: Documentation passed and Tests was still running when I posted. The vendored EEGLAB checkout is not present here, so I did not reopen the cited .m lines.

@suraj-ranganath
suraj-ranganath merged commit c724723 into develop Nov 6, 2026
11 checks passed
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.

2 participants