You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
clean_asr: return the mask of samples it repaired #684
clean_asr / asr_process return the reconstructed data but not which samples were changed. Pipelines that report how much of a recording ASR reconstructed (NEMAR's nemar-ica records an asrBurstFraction quality metric, nemarOrg/nemar-process#81, epic nemarOrg/nemar-cli#2324) must recompute it by differencing input and output, mirroring the 1e-8 rule clean_artifacts uses for burst rejection. Request: have clean_asr (or asr_process) optionally return the boolean per-sample mask of samples whose reconstruction changed, with the same threshold clean_artifacts applies, so callers don't reimplement it.
Human decision on API shape (new public return value, so no PR opened yet)
Research
clean_asr already holds a float64 copy of the input (data) and the truncated output (outdata), but returns only the EEG (and optionally state). clean_artifacts snapshots the input a second time and recomputes the changed-sample mask with sum(|in - out|, axis=0) < 1e-8, so every external caller has to duplicate that rule. EEGLAB's clean_asr.m has no such output, so this is an EEGPrep-only API addition, not a parity fix.
Add a keyword-only return_mask: bool = False to clean_asr. Compute repaired = np.sum(np.abs(data - outdata), axis=0) >= 1e-8 (module constant shared with clean_artifacts) after the [:, :S] truncation, so the mask has length pnts and ignores the extrapolated tail. Return order: EEG, then state if requested, then mask if requested.
clean_artifacts then calls clean_asr(..., return_mask=BurstRejection), drops its own original_data copy, and starts from ~repaired. The <5-sample pruning stays in clean_artifacts (burst-rejection policy, not "what ASR changed"). On the ASRCalibrationError fallback the mask is all-False. True = repaired, so mask.mean() is directly the asrBurstFraction metric.
Estimate: ~40 lines + one test in tests/test_clean_asr.py asserting the mask equals the differenced output and that clean_artifacts' clean_sample_mask is unchanged. Docs: clean_asr docstring and the clean_rawdata Sphinx page.
Open questions
The overload set goes from 2 to 4 combinations (return_state x return_mask). Alternative with no signature change: always write EEG['etc']['clean_asr_mask'] (bool, 1 byte/sample), mirroring etc.clean_sample_mask. Downside: it gets saved into .set files and goes stale after later edits that change pnts. Which is preferred?
Polarity: True = repaired (proposed, matches the request) or True = kept (matches clean_sample_mask)?
Should asr_process also get it? Proposed: no. It works on streaming chunks with a lookahead delay, so the mask only lines up with input samples at the clean_asr level.
Activity
claude commentedon Nov 24, 2026
🤖 Plan:
Research
clean_asralready holds a float64 copy of the input (data) and the truncated output (outdata), but returns only the EEG (and optionallystate).clean_artifactssnapshots the input a second time and recomputes the changed-sample mask withsum(|in - out|, axis=0) < 1e-8, so every external caller has to duplicate that rule. EEGLAB'sclean_asr.mhas no such output, so this is an EEGPrep-only API addition, not a parity fix.Relevant code
clean_asr.py#L65-L80- signature;return_stateoverloads at L27-L62clean_asr.py#L250-L257- inputdataandoutdataboth available hereclean_artifacts.py#L271-L291- extra snapshot + 1e-8 maskclean_artifacts.py#L292-L309- short-run (<5 samples) pruning, stored asetc.clean_sample_maskProposed design
Add a keyword-only
return_mask: bool = Falsetoclean_asr. Computerepaired = np.sum(np.abs(data - outdata), axis=0) >= 1e-8(module constant shared withclean_artifacts) after the[:, :S]truncation, so the mask has lengthpntsand ignores the extrapolated tail. Return order:EEG, thenstateif requested, thenmaskif requested.clean_artifactsthen callsclean_asr(..., return_mask=BurstRejection), drops its ownoriginal_datacopy, and starts from~repaired. The <5-sample pruning stays inclean_artifacts(burst-rejection policy, not "what ASR changed"). On theASRCalibrationErrorfallback the mask is all-False.True= repaired, somask.mean()is directly the asrBurstFraction metric.Estimate: ~40 lines + one test in
tests/test_clean_asr.pyasserting the mask equals the differenced output and thatclean_artifacts'clean_sample_maskis unchanged. Docs:clean_asrdocstring and the clean_rawdata Sphinx page.Open questions
return_statexreturn_mask). Alternative with no signature change: always writeEEG['etc']['clean_asr_mask'](bool, 1 byte/sample), mirroringetc.clean_sample_mask. Downside: it gets saved into .set files and goes stale after later edits that changepnts. Which is preferred?True= repaired (proposed, matches the request) orTrue= kept (matchesclean_sample_mask)?asr_processalso get it? Proposed: no. It works on streaming chunks with a lookahead delay, so the mask only lines up with input samples at theclean_asrlevel.Align ADR 0137 with owner decisions for merge
ADR 0137: quality views drawn in the browser (#2342)
Cite sccn/eegprep#684 for the repaired mask
PZ: nemar-ica on the serving copy, with browser weights (#81)