Repository navigation
Stream 6: Rejection numbers - #559
Conversation
…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]>
093b8bf to
49203d2
Compare
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]>
There was a problem hiding this comment.
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 finished @suraj-ranganath's task in 1m 59s —— View job Code review
BlockingNone. Important
Nits
Test gaps
EEGLAB parity notes
Checked: correctness of the changed pop and menu code, EEG dict handling ( |
| 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) |
There was a problem hiding this comment.
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:
| 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.
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]>
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]>
|
Claude finished @suraj-ranganath's task in 1m 54s —— View job Code review
BlockingNone. Important
Nits
Test gaps
EEGLAB parity notes
I checked the multitaper convergence loop (per series, NaN-safe), the |
| _history_vector(starttime), | ||
| _history_vector(endtime), | ||
| str(int(bool(superpose))), | ||
| "0", |
There was a problem hiding this comment.
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.
| "0", | |
| str(int(bool(reject))), |
| return all(character.isdigit() or character in ".:-+eE,; " for character in token) | ||
|
|
||
|
|
||
| def _num2str_contarray(values: list[float]) -> str: |
There was a problem hiding this comment.
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]>
|
Responses to the Claude review of 9719afb. All fixed in 3b5685c:
The GUI recheck side by side with EEGLAB (reject confirm and cancel, reject-all error, Cancel at |
… Tools. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 44s —— View job Code review
BlockingNone. ImportantNone. NitsNone. Test gapsNone. The new EEGLAB parity notes
What I checked (diff
|
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]>
|
Claude finished @suraj-ranganath's task in 29s —— View job Code review
BlockingNone. ImportantNone. NitsNone.
Test gapsNone. EEGLAB parity notes
What I checked (diff
|
|
Follow-up at 7405279. Cancel menu loss (fe32039 + 7405279): PySide/shiboken collected Claude r4 nit (duplicate keep/retain helpers): agreed it isn't worth extracting for two windows. We'll move it into 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
|
Claude finished @suraj-ranganath's task in 1m 0s —— View job Code review
BlockingNone. ImportantNone. NitsNone. Test gapsNone. EEGLAB parity notesNone. Nothing in the merge changes parity.
What I checked (merge
|
Refs #551
Merged origin/develop
cdbe303d, which includes #560 and #562. Headbcd6291d. 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_rejepochkeeps the scroll-window historyEEG = pop_rejepoch( EEG, {matlab_array2str(indices)},0);and does not open its own dialog.confirm=-1still keeps an empty dataset, and any other confirm value still namespop_rejepochwhen every epoch is marked. The Reject marked epochs menu still recordseeg_rejsuperposeonly afterpop_newsetis accepted. Both changelog entries are kept.pop_eegthreshhistory records the reject flag that was applied. A scriptedreject=1call replays to the same dropped epochs. Continuous-array history uses one contarray helper and a number formatter.EEGPREP_SKIP_MATLAB=1 uv run pytest testspassed 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_regepochsagain inserts every regular event and letspop_epochdrop 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.ureventstays an array. The MATLABpop_autorejreference passesnogui,onand compares sorted[1 2 28 46 70]with EEGLAB's[1 46 70 2 28]. A dialog threshold-50 10stays[min max](27720 points, 8 regions);pop_rejcont.m:147str2doublewould make that NaN.pop_rejconthistory omitseegplotand recordsEEG = pop_select( EEG, 'nopoint',[3489 4128;4257 4608;...]);as its own entry.pop_eegthreshhistory isEEG = 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 namepop_rejcont, the field, and an example such as 0.25. The natural-log multitaper scale and thelinspacefrequency 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_rejcontwithcorrectblankstores the zeroed samples again; oneeglab_data.set, 20-40 Hz at 10 dB with tapernonezeroes 1312 float32 columns.pop_eegthreshtimes go througheeg_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) anduv 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/developare clean on the touched files.menu_actions.pyis shared with Stream 11. This PR changes_run_rejsuperpose, thepop_rejepochbranch inside_run_pop_function, and addspop_rejepochto_NEWSET_COMMIT_ACTIONSso that branch uses the sharedpop_newsetcommit path.qt.pygains thetoggle_checked_textcallback used by the channel-rejection normalization checkbox.eeg_regepochs.pystoreseventandureventas object arrays and inserts every regular event.pop_eegplot.pyshows the Update Marks warning fromeeg_rejmacro.m:119-121.console.pyis 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 ineegprep-consolestill 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, not10*logatpop_rejspec.m:310. Oneeglab_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_rejcontuses the real FFT bin frequencies, not thelinspaceaxis atpop_rejcont.m:211. Oneeglab_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 ownsum(abs(S-S1))/nfft > toltest and a non-finite change counts as stopped, so one NaN sample returns. Finite tutorial multitaper lists are still empty.contarrayhistory usesnum2str.eeg_rejsuperposeis recorded only afterpop_newsetaccepts 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), onsample_data/eeglab_data.setandsample_data/eeglab_data_epochs_ica.set:What those tests compare:
pop_rejcontelec 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 afterpop_eegfiltnew(..., 1). EEGLAB's linspace axis keeps the previous 9 regions and 28008 points, starting[321 480; 3489 3936; ...; 28033 28544].pop_rejcontwith 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_rejchanmeasure kurt and prob, elec 1:32, threshold 5, norm on, oneeglab_data.set. Expected kurtosis[1 2 6], probability[1 2].pop_rejspecmethod 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_eegthreshoneeglab_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 setsicarejmanualto those 71 epochs.pop_autorejchannel mode oneeglab_data_epochs_ica.set, withnogui,on.pop_autorej.m:224readsicarejkurt, so MATLAB returns[1 46 70 2 28](sorted[1 2 28 46 70]) and keeps 75 epochs. EEGPrep readsrejkurtand rejects[1 2 16 28 46 70](74 epochs kept). The MATLAB assertion skips unless--eeglab-backend=matlab.eeg_regepochsoneeglab_data.set. Recurrence 0.25, limits[0 0.5]: 952 trials, 2212 events, 1904 typeX, 1107 urevents. Recurrence 0.5, limits[0 2]: 473 trials, 2506 events, 1892 typeX, 630 urevents.Per finding
pop_rejcontthresholded each window on its own spectrum and then merged every run, so one hot window deleted the file.pop_rejcont.m:202-316:eeg_regepochswith overlap as the recurrence, trial-mean log spectrum,eegthreshframes, 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; MATLABtest_reference_pop_rejcont_sample_regions,test_reference_pop_rejcont_two_sided_thresholdsrejkurt/jointprobmask (rejkurt.m:131,jointprob.m:133) after the trim atrejkurt.m:109-114. Continuous file: kurtosis[1 2 6], probability[1 2].test_pop_rejchan_normalized_channels_match_the_sample_sets; MATLABtest_reference_pop_rejchan_sample_channelspmtm, so ±35 dB marked nothing.10*log10) marks no data epochs at ±35 dB. EEGLAB's natural log marks epoch 37.test_pop_rejspec_multitaper_db_marks_no_tutorial_epochspop_autorej.m:224readsicarejkurteven in channel mode, so EEGLAB never applies the kurtosis mark and keeps epoch 16 (75 epochs). EEGPrep's channel mode usesrejkurtand keeps 74.rejkurtand still rejects epoch 16. The MATLAB list is locked beside the EEGPrep list.test_pop_autorej_channel_mode_keeps_the_kurtosis_epoch_eeglab_drops; MATLABtest_reference_pop_autorej_eeglab_omits_epoch_16asserts[1 2 28 46 70]eegplot(1.0 when no source EEG is attached). The dialog always showed Help.pop_rejcontport. Spacing is computed fromeegplot.m:457-473and passed in (80 on this file). Help is off, matchingpop_rejcont.m:140.test_pop_rejcont_keeps_the_sample_recording_regions,test_pop_rejcont_scroll_spacing_and_dialog_have_no_helpeeglab_data_epochs_ica.set.[1 2].test_pop_rejchan_normalized_channels_match_the_sample_setspop_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 thevararg2strline atpop_rejchan.m:246.measure='std'remains a scripted option.test_pop_rejchan_dialog_and_history_follow_vararg2strtyperejand never copiedrejglobalontoicarejmanual.eeglab.m:661-662: superpose with typerej 1, thenicarejmanual = rejglobal. Oneeglab_data_epochs_ica.set,pop_eegthreshat ±75 marks 71 epochs and that export copies all 71 ontoicarejmanual.test_threshold_75_marks_71_epochs_and_export_copies_them,test_export_marks_copies_rejglobal_onto_the_manual_field; MATLABtest_reference_threshold_75_marks_71_epochs1:ncomponents.1:5frompop_eegthresh.m:120.test_component_threshold_dialog_defaults_to_the_first_five_componentstest_ica_trend_and_kurtosis_defaults_mark_the_audited_epochs(80 marks)[9 10 16 53 69]pop_rejspec.m:307-326: seven adaptive Slepian tapers,10*log10dB,eegthreshbins, full-nfftconvergence with no iteration cap. ±30 dB and ±35 dB mark no tutorial epochs. EEGLAB's10*logmarks 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; MATLABtest_reference_pop_rejspec_multitaper_epochsrejglobalontorejmanual.eeglab.m:674-675: superpose with typerej 0, thenrejmanual = rejglobal. Kurtosis marks land on[9 10 16 53 69].test_export_ica_marks_copies_the_audited_kurtosis_epochspop_rejepochwith the stalerejglobaland did not superpose. Rejecting every epoch surfacedpop_select's empty-dataset error. The menu overwrote the current dataset.eeglab.m:663-677: confirm, superpose,pop_rejepoch, thene_newsetviapop_newset. History ispop_rejepoch( EEG, [1:6 9] ,0).confirm=-1followspop_rejepoch.m:96-97(erroronemptyoff). Any other confirm value namespop_rejepochand 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_errorReview follow-ups
pop_rejconthistory is the commentedvararg2strline, withouteegplot, plus a separateEEG = pop_select( EEG, 'nopoint',[...]);entry.test_pop_rejcont_two_sided_and_cell_thresholds.pop_autorejnames 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 passesnogui,onand sorts the returned epochs.eeg_regepochsstoresureventas an array and inserts every regular event.pop_epochwarnsevent N out of data boundaryand 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).-50 10is kept as a two-sided threshold.test_pop_rejcont_two_sided_and_cell_thresholds.pop_eegthreshhistory and the 1.9922 end time:test_pop_eegthresh_history_and_dialog_follow_num2str. Larger values usenum2str(12.3457,123.4568). Areject=1call records that flag, andtest_pop_eegthresh_reject_one_history_replays_dropped_epochsreplays it to the same dropped epochs. Thereject=0history string is unchanged.test_update_marks_shows_the_eeglab_notice. The box is parented to the main window, or removed from the session list when it closes.test_pop_rejcont_names_a_two_number_add_trails_value.correctblankon float32 data zeroes 1312 columns for 20-40 Hz, 10 dB, tapernone.test_pop_rejcont_blank_zeroes_float32_sample_columns.