Repository navigation
Reject identical and collinear electrode positions - #609
Conversation
Raise when centered coordinates have no second principal axis, and warn when a layout is only planar, so channel cleaning and spherical interpolation no longer treat a collapsed montage as a normal cap. 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 24s —— View job Code review
Blocking
Important
Nits
Test gapsNone. The tests cover identical, collinear, nearly collinear, ring, jittered-planar, invdist and headplot cases, plus standard montages with channels removed. I could not run them in this job because pytest needs approval in this sandbox. EEGLAB parity notes
|
|
|
||
|
|
||
| def spheric_spline(xelec, yelec, zelec, xbad, ybad, zbad, values, params, dtype='float32'): | ||
| def spheric_spline(xelec, yelec, zelec, xbad, ybad, zbad, values, params, dtype='float32', *, _check_positions=True): |
There was a problem hiding this comment.
Important (maintainability): _check_positions is a private flag on a public signature, and the only in-tree caller passes False (
eegprep/src/eegprep/functions/popfunc/eeg_interp.py
Lines 168 to 180 in 436a80f
sphericalSplineInterpolate has the same pattern: its only caller, RANSAC, also passes False (eegprep/src/eegprep/plugins/clean_rawdata/private/ransac.py
Lines 144 to 146 in 436a80f
True branch only runs from tests. The MATLAB ports also differ from spheric_spline.m / sphericalSplineInterpolate.m only to support that flag. AGENTS.md calls out "Boolean dispatch where separate clear functions would be simpler."
Suggested fix: Keep validation at the public entry points (clean_channels, eeg_interp, headplot_setup). Remove the flag and the validation from both spline helpers, and drop the matching assertions in test_spline_helpers_reject_a_line_and_warn_on_a_ring.
| def test_degenerate_threshold_is_one_quarter_of_a_hemisphere(): | ||
| """A hemispherical shell has thickness 1/2; the cutoff is a quarter of that.""" | ||
| from eegprep.functions.sigprocfunc.electrode_geometry import ( | ||
| DEGENERATE_THICKNESS_RATIO, | ||
| HEMISPHERE_THICKNESS_RATIO, | ||
| ) | ||
|
|
||
| assert _hemisphere_thickness_ratio() == pytest.approx(0.5, abs=1e-12) | ||
| assert HEMISPHERE_THICKNESS_RATIO == pytest.approx(_hemisphere_thickness_ratio()) | ||
| assert DEGENERATE_THICKNESS_RATIO == HEMISPHERE_THICKNESS_RATIO / 4.0 |
There was a problem hiding this comment.
Nit (AGENTS.md §Testing / §Code Style): This test only checks module constants against each other (DEGENERATE_THICKNESS_RATIO == HEMISPHERE_THICKNESS_RATIO / 4.0). AGENTS.md says: "Do not write tautological tests that only assert types, constants, or implementation details." The behavior tests below already lock in the threshold. The function-level imports here and at L346 also go against "All imports go at the top."
Suggested fix: Delete this test, or keep only the _hemisphere_thickness_ratio() ≈ 0.5 derivation if you want the math documented. Move the electrode_geometry import to the top of the module.
Public spheric_spline and sphericalSplineInterpolate still reject identical or collinear electrodes. eeg_interp and RANSAC call the unchecked kernels after the full montage has already been checked. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 1m 30s —— View job Code review
Blocking
ImportantNone. Nits
Test gapsNone. The new tests cover:
I could not run pytest in this job because the sandbox requires approval for it. EEGLAB parity notes
|
| located = good_idx + bad_idx | ||
| if located and method in ('spherical', 'sphericalKang', 'sphericalCRD', 'sphericalfast'): | ||
| raw = np.vstack([[locs[i][c] for i in located] for c in ('X', 'Y', 'Z')]).astype(float).T | ||
| validate_electrode_positions(raw, operation='eeg_interp') | ||
| elif located and method in ('invdist', 'v4', 'spacetime'): | ||
| validate_electrode_positions(_planar_points(locs, located), operation='eeg_interp') |
There was a problem hiding this comment.
Nit (correctness of the guard): The check runs on good_idx + bad_idx, but the spline fit (Gelec in _spheric_spline, and _planar_v4_interpolate / _spacetime_interpolate) depends only on the good channels. If the remaining good channels are collinear or identical, the bad channels can still add enough spread to pass the check, and the degenerate fit runs anyway. For example, interpolating several channels off a sparse strip, or interpolating channels added through _handle_chanloc_interpolation, which have real positions.
eegprep/src/eegprep/functions/popfunc/eeg_interp.py
Lines 152 to 159 in afa35dd
Suggested fix: Validate good_idx only, since the fit's well-posedness depends on those positions. The if located guard becomes if good_idx.
eeg_interp classifies the channels it fits when three or more remain, so filled-in channels off a line no longer hide a degenerate fit. Two source channels stay legal, because any two positions are collinear and EEGLAB still interpolates from them. 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 49s —— View job Code review
Blocking
ImportantNone. Nits
Test gapsNone. The new tests cover:
I could not run pytest in this job because the sandbox needs approval for it. EEGLAB parity notes
|
Two distinct source channels are not rejected for collinearity alone. The whole located montage is still classified and can raise or warn. Co-authored-by: Suraj Ranganath <[email protected]>
Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 49s —— View job Code review
BlockingNone. ImportantNone. NitsNone. Test gapsNone. I did not run pytest in this job. The tests cover:
EEGLAB parity notesNone blocking. This is an intentional deviation: EEGLAB's What I checked:
|
…electrode-positions-3446 Co-authored-by: Suraj Ranganath <[email protected]> # Conflicts: # docs/source/user_guide/eeglab_migration.rst
|
Claude finished @suraj-ranganath's task in 41s —— View job Code review
BlockingNone. ImportantNone. NitsNone. Test gapsNone. EEGLAB parity notesNone blocking. The checks are an intentional, documented and tested deviation. EEGLAB's What I checked:
I could not run pytest in this job because the sandbox needs approval for Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance. |
Reject identical or collinear electrode positions in clean_channels, spherical interpolation, and headplot. Planar layouts, including a ring, warn and still run, matching what EEGLAB accepts. The cutoff is one quarter of the centered singular-value thickness of a hemispherical shell.
MATLAB verification: checked on jamming with MATLAB R2025b, EEGLAB d0963be9, and eeglab_tests fec88f9f, compared against develop 2736f99, on 2026-11-17 between about 13:16 and 17:50 PT. The full suite, run with --run-heavy-reference, had 3745 outcomes: 3709 passed, 22 skipped, and 14 failed or timed out. 13 of those 14 fail the same way on develop, so they are pre-existing: the limo reference tests, riemannian ASR, float32 avg-ref, BIDS e2e/import, pop_studydesign history, the tutorial movie/event study, the replay_20261015 fuzz test and limo hybrid. The 14th, test_pop_load_frombids_reads_bom_json_sidecars, failed only inside the full suite; it passes on its own on both this branch and develop.
Fixes #539