Repository navigation
[spectra] Add detrend argument to compute_spectra - #690
Conversation
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.
compute_spectra forwards detrend to scipy.signal.welch. The default False keeps EEGLAB spectopo parity. Fixes #689
9e22654 to
2d72ca5
Compare
arnodelorme
left a comment
There was a problem hiding this comment.
This review was written by an AI assistant during a nightly check, not by Arno.
Code review
- Overall assessment: needs changes. The code change is correct and the default path is unchanged, but the branch conflicts with
developand the merge evidence that AGENTS.md asks for is missing. - Highest-risk area: none in the numerics.
detrend=Falsereacheswelchexactly as before, so default spectra are the same as ondevelop. - Merge recommendation: needs changes (rebase, then one EEGLAB reference run).
Blocking
None.
Important
-
Merge conflict with
developindocs/source/changelog.rst. GitHub reports the pull request as conflicting. A trial merge of 2d72ca5 withdevelopat 046117e conflicts only in the "Unreleased" list.spectra.pyandtests/test_spectra_summaries.pymerge cleanly. Fix: rebase ondevelopand keep the new entry. -
No EEGLAB reference run in the description.
src/eegprep/functions/sigprocfunc/spectra.pyholdscompute_spectra, the estimator behindspectopo, so this pull request changes a core function implementation. AGENTS.md says: "Before merging a PR that changes core function implementations (EEGLAB-ported processing code), trigger.github/workflows/eeglab-reference.yml(EEGLAB reference,workflow_dispatch) on the PR branch, or run the suite locally once on the final branch" and "Put that run in the PR description". No run of that workflow exists foragent/20261125-fix-689, and by the same section the green "EEGLAB Python backend" check does not count. Fix: after the rebase, trigger the workflow once and add to the description the run, the EEGLAB and eeglab_tests commits, the pass, fail and skip counts, and the runtime. The same section also asks for human approval before the merge.
Nits
-
compute_spectradoes not checkdetrend(spectra.pyline 34, forwarded at line 118). A wrong value reaches SciPy, which answersValueError: Trend type must be 'linear' or 'constant'.That message does not namecompute_spectraand does not say thatFalseturns detrending off. Wrong values are likely here becausenewtimefandtimefreqin this package takedetrend="on"anddetrend="off". Checked on the pull request code with SciPy 1.15.3:"off","on","mean"andTrueraise that SciPy error, while""andNonerun with no detrending and no message. Suggested fix, next to thewintypecheck at line 93:if detrend not in (False, "constant", "linear"): raise ValueError("compute_spectra: detrend must be False, 'constant' or 'linear'")
Test gaps
None.
EEGLAB parity notes
-
Default parity holds.
spectopo.mcallspwelch(..., winlength, g.overlap, fftlength, srate)at lines 941 to 942, andpwelchdoes not detrend.'rmdc'defaults to'off'at line 207. The defaultFalsekeeps both. -
detrend="constant"is not EEGLAB's'rmdc', 'on'.spectopo.mlines 270 to 271 subtract each channel's mean over the whole record (over each epoch for 3-D data) beforepwelch. The new option subtracts the mean of each Welch window. The two differ at low frequencies when the record drifts slowly. The docstring says the default "matches EEGLAB, which does not detrend", which is true, but a reader may take"constant"forrmdc. One clause would settle it, for example: "This is not EEGLAB'srmdc, which removes the mean of the whole record." EEGPrep'sspectopodoes not havermdc. That is outside this pull request.
Tests run
tests/test_spectra_summaries.py on the code of 2d72ca5, in a separate worktree, with Python 3.11 and SciPy 1.15.3: 11 passed in 5 s.
Three more checks by hand on the same code, with random data plus a constant offset per channel. detrend="constant" gives the same dB values (largest difference 0) as cutting 128-sample windows by hand, removing each window's mean and passing them as epochs, which is the workaround that issue 689 wants to drop. Adding a constant offset changes the detrend="constant" result by at most 7e-15 dB. A 3-D array and the same epochs concatenated in 2-D give equal results with detrend="constant" for the Hamming window, the Blackman-Harris window, a 50 % overlap, and with detrend="linear".
Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Follow-up to the review. The branch is up to date with develop, merged twice with no force push. The second merge conflicted in The EEGLAB reference run on this branch (46183713516) is in the description: 4,484 passed, 5 failed and 58 skipped. The 5 failures are the suite's current baseline, also seen on the November 27 run of another branch, and none involves The review is now clean and every other check passes, so I merged it with a squash, as Arno asked. After #804 was merged its changelog entry conflicted with this one, so develop was merged in once more (changelog only); the spectra tests, lint and docs build passed again before the merge. — orchestrator |
compute_spectra accepts detrend ("constant" or "linear") and forwards it to scipy's welch for each window, so callers can get a per-window mean detrend without cutting windows themselves. The default False keeps EEGLAB spectopo parity. The Matplotlib-free home requested in the issue already exists in sigprocfunc/spectra.py.
Fixes #689
EEGLAB reference run
EEGLAB reference run 46183713516 on 4576a64 (develop merged in), EEGLAB
d0963be9, eeglab_testsfec88f9f: 4,484 passed, 5 failed, 58 skipped, about 36 minutes (19:56 to 20:32 UTC). The 5 failures are the suite's current baseline and do not involvecompute_spectra:test_coregister_traditional_warp_matches_eeglab,test_synthetic_traditional_warp_matches_fieldtrip,test_bem_leadfield_and_multifit_match_fieldtrip,test_matlab_kmeans_numbering_matches_fixed_initial_centroidsandtest_struct_near_assertion_matches_source. The same five failed on the November 27 reference run ofagent/20261127-fix-746(45951378985).