Repository navigation
[Phase 3] Implement rejection and component workflows - #76
suraj-ranganath merged 3 commits into
Conversation
|
Claude finished @suraj-ranganath's task in 6m 41s —— View job Claude Code PR Review
SummaryBig, well-organized PR — pulls 12 rejection workflows + The findings below are about behavioral parity gaps, not structure. Issues found (high → low)1. 2. 3. 4. 5. 6. Smaller notes (not posted inline)
Positive notes
What I did not verify
|
|
🤖 Phase 3 implementation/spec and GUI evidence Problem: Phase 3 issue #63 still had component-selection and non-browser rejection menu placeholders after the ICLabel PR. EEGLAB exposes these through Approach: Added shared rejection helpers plus Key code: The shared helper layer in Tests: Verification run locally: Non-slow pytest result: Visual parity side-by-side images are attached below; these are upload artifacts, not committed repo files. Phase 3 visual parity
|
| out, _command = pop_eegthresh( | ||
| EEG, 1, electrodes, -threshold, threshold, EEG.get("xmin", 0), EEG.get("xmax", 0), 0, 0, return_com=True | ||
| ) | ||
| marks = np.asarray((out.get("reject") or {}).get("rejthresh", []), dtype=bool) | ||
| rejected = set((np.flatnonzero(marks) + 1).tolist()) |
There was a problem hiding this comment.
pop_autorej accumulates threshold-rejected epochs into rejected but never removes them from out.
EEGLAB's pop_autorej.m calls pop_eegthresh(EEG, 1, ..., 0, 1) — the trailing 1 is the reject flag, so the high-amplitude epochs are dropped before the joint-probability loop runs. Here the call passes 0 for reject, so:
out["trials"]is unchanged after the threshold step.remaining = list(range(1, work["trials"] + 1))then starts from the full set, so when the jointprob loop reportscurrent = [k]it maps to the k-th surviving epoch including the high-amplitude ones. Indices accumulated intorejectedfrom later iterations therefore can collide with already-counted threshold indices.- The returned dataset still contains the worst-amplitude trials, defeating the whole purpose of the function.
Suggested fix: pass reject=1 to pop_eegthresh (and rebuild remaining/rejected from the post-rejection trial count), matching EEGLAB.
| out, _command = pop_eegthresh( | |
| EEG, 1, electrodes, -threshold, threshold, EEG.get("xmin", 0), EEG.get("xmax", 0), 0, 0, return_com=True | |
| ) | |
| marks = np.asarray((out.get("reject") or {}).get("rejthresh", []), dtype=bool) | |
| rejected = set((np.flatnonzero(marks) + 1).tolist()) | |
| out, _command = pop_eegthresh( | |
| EEG, 1, electrodes, -threshold, threshold, EEG.get("xmin", 0), EEG.get("xmax", 0), 0, 1, return_com=True | |
| ) | |
| marks = np.asarray((EEG.get("reject") or {}).get("rejthresh", np.zeros(int(EEG.get("trials", 1) or 1)))).astype(bool) | |
| # pop_eegthresh stores marks on the pre-rejection dataset before dropping; recover the original 1-based indices. | |
| rejected = set((np.flatnonzero(_pre_marks_from(EEG, electrodes, threshold)) + 1).tolist()) |
(or simpler: capture the indices returned by pop_eegthresh directly before dropping, then translate current against a remaining list rebuilt after the drop). Fix this →
| ControlSpec("text", "Spectrum computation method"), | ||
| ControlSpec("spacer"), | ||
| ControlSpec("popupmenu", "FFT|Multitaper", tag="method", value=2), |
There was a problem hiding this comment.
The dialog offers FFT|Multitaper (with Multitaper as the default value=2) but the implementation only ever computes an FFT.
spectrum_marks in _rejection.py uses np.fft.fft regardless of options["method"]. The chosen method is just written into the history command (_history_command's default is even "multitaper"), so:
- Recorded history can read
'method', 'multitaper'while the actual marks come from an FFT — replay produces a different result than the live computation says it did. - A user picking "Multitaper" gets silent FFT-based marks.
Either implement the multitaper branch (e.g. via scipy.signal.windows.dpss with averaged tapers) or, if multitaper is out of scope, remove the popup option and default to FFT in _history_command. The dialog should not offer a control that has no effect. Fix this →
| raise ValueError("EEG data must be 2-D or 3-D") | ||
| elec = one_based_indices(options.get("elec"), limit=int(out.get("nbchan", flat.shape[0])), default_all=True) | ||
| selected = [item - 1 for item in elec] | ||
| threshold = parse_numeric_sequence(options.get("threshold", 400), dtype=float) |
There was a problem hiding this comment.
Programmatic threshold default of 400 doesn't match the GUI default (5) or EEGLAB's z-score default.
The dialog spec sets threshold to "5" and the docstring promises a z-score interpretation; EEGLAB's pop_rejchan.m also defaults to a small z-score threshold (5 for normalized kurtosis). When a caller invokes pop_rejchan(EEG, "measure", "kurt") without a threshold key, this falls back to 400 — which is essentially an unreachable threshold for normalized scores and almost certainly never returns any flagged channels.
Either drop the default and require an explicit threshold (raise on missing) or align it with the GUI default of 5. Fix this →
| fig_obj, axes = plt.subplots(1, min(len(indices), PLOTS_PER_FIGURE), squeeze=False) | ||
| labels = _channel_labels(EEG) | ||
| for axis, index in zip(axes.ravel(), indices[:PLOTS_PER_FIGURE]): | ||
| axis.axis("off") | ||
| label = labels[index - 1] if index - 1 < len(labels) else str(index) | ||
| axis.text(0.5, 0.5, label, ha="center", va="center", fontsize=10) | ||
| axis.set_title(str(index)) | ||
| fig_obj.suptitle("View channels properties - pop_viewprops()") | ||
| fig_obj.tight_layout() | ||
| return [fig_obj] |
There was a problem hiding this comment.
Channel mode of pop_viewprops shows only channel labels — no actual properties.
When typecomp=1 (channel mode), _plot_props draws a row of axes whose only content is axis.text(0.5, 0.5, label, ...) and a numeric title. EEGLAB's pop_viewprops for channels produces a property panel with topography, spectrum, and ERP-image thumbnails per channel. The known_differences note only mentions that scrolling activity is omitted; it doesn't acknowledge that the entire per-channel property visualization is missing.
If the channel property rendering is intentionally out of scope for this phase, the known_differences text should call that out (so the visual parity reviewer doesn't expect parity), and the dialog spec should probably disable the channel mode entry-point (or the menu wiring should route Plot > Channel properties to a coming-soon stub) until it lands. Fix this →
| row_count = int(out.get("nbchan", 0) or 0) if int(bool(typerej)) else _component_count(out) | ||
| rejglobal = np.zeros(trials, dtype=bool) | ||
| rejglobal_e = np.zeros((row_count, trials), dtype=bool) |
There was a problem hiding this comment.
rejglobalE is sized by nbchan for typerej=1, but the function may then OR in icarejXxxxE matrices that have ncomp rows.
When typerej=1 and Rothertype=1, the second _add_family("ica", ...) call ORs icarejmanualE/icarejjpE/etc. into a buffer sized (nbchan, trials). If ncomp != nbchan (very common — e.g. ICA on a subset of channels), _or_matrix silently truncates rows:
rows = min(out.shape[0], values.shape[0])
out[:rows, :cols] |= values[:rows, :cols]
So component-level marks past row nbchan are dropped without warning, and the row indices of the surviving ones no longer correspond to channels OR components — they get mixed.
Symmetrically, typerej=0 allocates by _component_count and would lose channel rows. EEGLAB's eeg_rejsuperpose keeps the data and ICA per-row matrices distinct and only ORs along the trial vector when crossing families. Recommend either: (a) skip OR-ing the per-row matrix from the other family entirely (only superpose the per-trial vector when Rothertype=1), or (b) raise/warn when nbchan != ncomp and Rothertype=1. Fix this →
| QPushButton#butfreq { background: #cc99ff; max-width: 30px; padding: 0; } | ||
| QPushButton#butspec { background: #cc99ff; max-width: 30px; padding: 0; } |
There was a problem hiding this comment.
Nit: QPushButton#butspec rule is dead. No control in the spec ever sets tag="butspec" — the spectra section uses tag="butfreq" via threshold_rows("Find abnormal spectra (slow)", "freq", ...). Either drop the unused rule or rename to match the active tag.
604d690 to
423fd5f
Compare
|
@claude review this |
Claude Code PR Review
View job run · Branch: |












Implement non-browser Phase 3 rejection and component workflows, including rejection mark superposition, automated/statistical rejection wrappers, channel/continuous rejection, component selection, and viewprops. Adds GUI/menu/console wiring, help resources, visual parity cases, sample-data tests, and deterministic EEG_REJSUPERPOSE MATLAB parity coverage.
Part of #63