Repository navigation
[Phase 3] Implement ICLabel component workflows - #69
Conversation
|
Claude finished @suraj-ranganath's task in 5m 21s —— View job Claude PR Review for #69Reviewed the Phase 3 ICLabel/component-removal workflows against the diff vs Concrete findings posted inline; summary below.
FindingsParity (EEGLAB) — please address before merge
Behavior
Minor / nits
What looked good
RecommendationApprove once the two parity issues (#1 and #2) are addressed (or explicitly deferred with a follow-up tracking issue) and the list-mode dialog UX (#3) is loosened. #4 and the nits can land in the same change or a quick follow-up. |
|
🤖 Phase 3 PR 1 specification Problem: Issue #63 needs ICA-adjacent data workflows to stop being placeholders before later component views, rejection, and DIPFIT work can build on them. The missing PR1 surface was pop_icflag and GUI/API/console-ready pop_subcomp, including menu dispatch, history replay, help resources, and visual parity coverage. Approach: Added eegprep.plugins.ICLabel.pop_icflag over eeg_icflag, preserved EEGLAB's open-interval threshold semantics and reject-field behavior, and removed pop_icflag from placeholder metadata. Reworked pop_subcomp to support return_com, GUI input, flagged-component defaults, keepcomp, 1-based component arguments, ICLabel/DIPFIT trimming, menu dispatch, and console-valid history. Browser/plot confirmation remains explicitly out of scope for later Phase 3/4 work. Key code: pop_icflag normalizes a 7x2 threshold matrix, writes only EEG.reject.gcompreject, and emits a pasteable command with keyword thresholds. pop_subcomp computes activations from icaweights*icasphere over icachansind, projects remaining components through icawinv, clears ICA activations/rejection state like EEGLAB, and keeps component indices user-facing and 1-based. Tests: Added GUI/unit coverage for pop_icflag and pop_subcomp, sample_data integration tests, console command-order routing coverage, package export coverage, menu placeholder inventory updates, and visual parity cases for both dialogs. Verified with focused GUI/console/sample tests, ruff check, ruff format --check, ty check, visual parity capture/compare against /Users/suraj/Desktop/eeglab, and EEGPREP_SKIP_MATLAB=1 uv run --no-sync pytest -m "not slow". |
| if isinstance(EEG, list) and not any(_flagged_components(item) for item in EEG): | ||
| raise ValueError("No components are flagged for rejection. Flag components first or pass components.") |
There was a problem hiding this comment.
🤖 The list path raises before the dialog can open. If a user selects several datasets and none have flagged components yet, they cannot even open pop_subcomp to type a component list manually — but the dialog itself accepts a manually typed remove/retain list and is supposed to handle that case (see the help text at pop_subcomp_dialog_spec which says "Leave blank to remove flagged components in each selected dataset"). The error message ("Flag components first or pass components") references options the user can't reach from here.
Consider letting the dialog open, then deferring the "no components specified" feedback to _remove_components (which already logs a warning and skips), or only raising when the user submits a blank dialog and no datasets are flagged.
| output["setname"] = f"{output.get('setname', '')} pruned with ICA".strip() | ||
| output["icaact"] = np.array([]) | ||
| output["icaweights"] = weights[keep_mask, :] | ||
| output["icawinv"] = mixing[:, keep_mask] |
There was a problem hiding this comment.
🤖 Parity divergence from EEGLAB. pop_subcomp.m recomputes the unmixing inverse from the trimmed weights:
EEG.icaweights = EEG.icaweights(compkeep, :);
EEG.icawinv = pinv(EEG.icaweights * EEG.icasphere);EEGPrep instead preserves the corresponding columns of the original mixing matrix (mixing[:, keep_mask]). For square invertible ICA these are numerically close, but for rank-reduced decompositions (e.g. PCA-pre-whitened runica, where weights is k × N with k < N) pinv(W_keep @ S) and original_mixing[:, keep] are different matrices. Downstream callers that re-derive activations from icawinv (notably plotting and back-projection) would see different scales than they would in EEGLAB.
Suggest replacing the line with something like output["icawinv"] = finite_pinv(finite_matmul(weights[keep_mask, :], sphere)) to match EEGLAB exactly.
| output["icawinv"] = mixing[:, keep_mask] | ||
| output["specicaact"] = np.array([]) | ||
| output["specdata"] = np.array([]) | ||
| output["reject"] = {} |
There was a problem hiding this comment.
🤖 Parity divergence from EEGLAB. pop_subcomp.m only resets gcompreject and leaves the rest of the rejection struct alone:
EEG.reject.gcompreject = zeros(size(EEG.icaweights,1), 1);Clearing the whole reject dict drops sibling fields like rejmanual, rejglobal, channel/trial rejection flags, etc. The unit test at tests/test_gui_pop_subcomp.py:61 is asserting the current behavior (out["reject"] == {}), so that assertion also needs to change.
Suggested replacement:
existing_reject = dict(output.get("reject") or {})
existing_reject["gcompreject"] = np.zeros(int(keep_mask.sum()), dtype=int)
output["reject"] = existing_reject| if isinstance(EEG, list): | ||
| outputs = [pop_subcomp(item, components, plotag, keepcomp, gui=False, return_com=False) for item in EEG] | ||
| command = _history_command(components, plotag, keepcomp) | ||
| return (outputs, command) if return_com else outputs |
There was a problem hiding this comment.
🤖 Inconsistent with the single-dataset branch (line 59), which only emits a history command when something was actually removed. The list branch always emits a command, even when every dataset bailed out via logger.warning("No components specified, no rejection performed"). Replaying the resulting history would then re-do nothing-but-still-noisy pop_subcomp calls.
Consider filtering by whether any dataset returned a non-empty command, e.g. only set command = _history_command(...) when any(...) removal succeeded, or capture per-item history strings and skip blanks.
| if thresholds is None: | ||
| thresholds = DEFAULT_ICFLAG_THRESHOLDS | ||
| thresholds = _normalize_thresholds(thresholds) | ||
|
|
||
| if isinstance(EEG, list): | ||
| output = [pop_icflag(item, thresholds, gui=False, return_com=False) for item in EEG] | ||
| command = _history_command(thresholds) | ||
| return (output, command) if return_com else output | ||
|
|
||
| _require_iclabel(EEG) | ||
| output = eeg_icflag(copy.deepcopy(EEG), thresholds) | ||
| command = _history_command(thresholds) | ||
| return (output, command) if return_com else output |
There was a problem hiding this comment.
🤖 Minor: when EEG is a list (line 64), _require_iclabel is never called on the individual datasets in this top-level branch — the validation only runs in the singleton path (line 69), which is reached through each recursive call at line 65. That recursion happens inside pop_icflag(item, ...), so the singleton call site does see the check. This is fine, but if anyone refactors the dispatch later it would be easy to lose the per-item validation. Worth a one-line comment, or moving the recursive list handling above the singleton path so the structure makes the per-item validation explicit.
Also: the recursive call on line 65 deep-copies inside eeg_icflag/pop_icflag (line 70 makes a deepcopy). Good — the input list is not mutated.
|
@claude review this |
|
Claude encountered an error after 5m 13s —— View job Claude PR Review for #69 (re-review)Re-reviewing the latest state of the PR per @suraj-ranganath's request.
· branch [`phase/3-ica-iclabel-workflows`](https://github.com/sccn/eegprep/tree/phase/3-ica-iclabel-workflows)
|
b725419 to
3f085f8
Compare
|
@claude review this |
|
Claude finished @suraj-ranganath's task in 4m 1s —— View job Claude PR Review for #69 (re-review)
TL;DRThe follow-up commit cleanly resolves the actionable items from my first pass and adds two nice bonus improvements (MATLAB-style Corrections to my previous reviewI fetched EEG.data(EEG.icachansind,:,:) = compproj;
EEG.setname = [ EEG.setname ' pruned with ICA'];
EEG.icaact = [];
goodinds = setdiff_bc(1:size(EEG.icaweights,1), components);
EEG.icawinv = EEG.icawinv(:,goodinds);
EEG.icaweights = EEG.icaweights(goodinds,:);
EEG.specicaact = [];
EEG.specdata = [];
EEG.reject = [];
New observation introduced by the follow-up commit
output["reject"] = dict(output.get("reject") or {})
output["reject"]["gcompreject"] = np.zeros(int(keep_mask.sum()), dtype=int)EEGLAB's behavior ( Two clean options:
I do not have a strong preference — both are reasonable — but as written there is no signal in the code that this is intentional, which will trip up the next parity pass. Fix this → Items from previous review — status
Additional improvements in the follow-up commit
What still looks good (unchanged from first pass)
RecommendationApprove once the new |



Add GUI, API, console, help, and menu support for pop_icflag and pop_subcomp. This removes the matching Phase 3 placeholders while preserving EEGLAB indexing, ICLabel flag semantics, and component-removal history replay.\n\nPart of #63