Repository navigation
Stream 5: Channel locations and re-reference (F36, F45, F46, F43, F62, F70, F12, F61) - #573
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.
|
Claude finished @suraj-ranganath's task in 3m 15s —— View job Code review
Blocking
Important
NitsNone. Test gaps
EEGLAB parity notes
Also checked: every in-repo caller of |
| urchans = chanlocs_as_list(eeg.get("urchanlocs")) if eeg is not None else [] | ||
|
|
||
| for key, value in options.items(): | ||
| chanlocs.extend(chanlocs_as_list(chaninfo.pop("nodatchans", []))) |
There was a problem hiding this comment.
Blocking: nodatchans entries without a datachan key are counted as data channels, so pop_chanedit stops working on a dataset after a common reref.
Line 557 adds every chaninfo["nodatchans"] entry to chanlocs. Lines 559-560 then sort them with loc.get("datachan", True). Entries that EEGPrep creates itself usually have no datachan key:
pop_reref(EEG, 'Cz')withkeepref='off':reref()returnscopy.deepcopy(locs[idx])(sigprocfunc/reref.py:108)._store_removed_ref_channelsappends that copy tonodatchans. Data chanlocs have nodatachanbecauseeeg_checkchanlocsremoves it (eeg_checkchanlocs.py:96), andeeg_checksetnever runseeg_checkchanlocsagain.readegilocsputs rawreadlocsfiducial rows intonodatchans.
On such a dataset, len(data_locs) == nbchan + n_nodat, so line 698 raises "location count does not match data channels". That happens for any later pop_chanedit(EEG, 'changefield', ...) and for Ok in the channel editor, even when the user changed nothing. The editor's datachan checkbox also shows these reference locations as data channels (line 77 has the same problem).
Suggested fix: mark the entries as non-data when they are merged, here and at line 77:
nodat = chanlocs_as_list(chaninfo.pop("nodatchans", []))
chanlocs.extend({**loc, "datachan": 0} for loc in nodat)Please also add a regression test that runs pop_reref(EEG, 5) and then pop_chanedit(EEG, 'changefield', [1, 'labels', 'X']).
|
Addressed Claude's review on head Blocking — Important — dead MATLAB / GUI evidence (also for the parity note):
Retriggering Claude after this push. |
|
Claude finished @suraj-ranganath's task in 2m 29s —— View job Code review (re-review of
|
| data_locs = [loc for loc in chanlocs if loc.get("datachan", True)] | ||
| chaninfo["nodatchans"] = [loc for loc in chanlocs if not loc.get("datachan", True)] |
There was a problem hiding this comment.
Important: Read locations fails on files that contain fiducials.
This split only checks datachan. Locations returned by readlocs never have that key. readlocs does tag fiducials (Nz, LPA, RPA, FidNz, FidT9, FidT10, …) with type="FID" (readlocs.py#L256-L258), but that tag is ignored here. Because load replaces the whole list (L594-L595), the fiducials are counted as data channels.
Example: a 128-channel EGI dataset plus a GSN .sfp file with 3 fiducials gives 131 "data" locations. Line 563 then raises "location count does not match data channels". This happens for pop_chanedit(EEG, 'load', 'GSN.sfp') and for Read locations → Ok in the editor.
EEGLAB handles this case: pop_chanedit.m runs eeg_checkchanlocs after readlocs, which moves FID/ignore types into chaninfo.nodatchans. EEGPrep's eeg_checkchanlocs applies the same _NO_DATA_TYPES rule.
Suggested fix: when datachan is absent, decide data vs. non-data from the type. One way is a small helper used by both lines:
def _is_data_location(loc):
if "datachan" in loc:
return bool(loc["datachan"])
return str(loc.get("type", "")).strip().lower() not in {"fid", "ignore"}Alternatively, run the loaded locations through eeg_checkchanlocs in the load branch.
Test: load an .sfp file with FidNz/FidT9/FidT10 plus N data rows onto an N-channel EEG. Check that nbchan == N and that the 3 fiducials end up in chaninfo["nodatchans"].
|
Addressed Claude's Important finding from the
Retriggering Claude after this push. |
|
Claude finished @suraj-ranganath's task in 45s —— View job Code review (re-review of
|
| def _is_data_location(loc: dict[str, Any]) -> bool: | ||
| if "datachan" in loc: | ||
| return bool(loc["datachan"]) | ||
| return str(loc.get("type", "")).strip().lower() not in {"fid", "ignore"} |
There was a problem hiding this comment.
Nit: this repeats eeg_checkchanlocs._NO_DATA_TYPES as a second literal.
The same {"fid", "ignore"} set already lives in eeg_checkchanlocs.py, and this module already imports from it (line 18). If someone adds a no-data type there later, pop_chanedit and eeg_checkchanlocs will sort the same location differently.
AGENTS.md says: "Put magic strings and magic numbers in top-level constants when they are reused or semantically important", and lists "Parallel implementations of existing helpers" as a pattern to avoid. Fix: import the constant. Either make it public (NO_DATA_TYPES) or import the private name, whichever this repo usually does:
| return str(loc.get("type", "")).strip().lower() not in {"fid", "ignore"} | |
| return str(loc.get("type", "")).strip().lower() not in NO_DATA_TYPES |
(and add NO_DATA_TYPES to the eeg_checkchanlocs import on line 18).
|
Addressed the remaining Claude nit and the CI failures on head Nit — CI (macos/windows): Two tests asserted pre-parity behavior. Updated expectations only:
Retriggering Claude after this push. Still not merging without Suraj's explicit approval. |
|
Claude finished @suraj-ranganath's task in 30s —— View job Code review (re-review of
|
|
claude review this Please re-review head |
|
@claude review claude review this Re-review PR head |
|
Claude finished @suraj-ranganath's task in 1m 1s —— View job Code review (re-review of
|
|
@claude review Please re-review head
Focus on whether those two nits are resolved and whether anything new is Blocking/Important. |
|
Claude finished @suraj-ranganath's task in 48s —— View job Code review (re-review of
|
| Input | Result |
|---|---|
X=Y**12**12 |
rejected (exponent is not a literal) |
X=Y**(1+1) |
rejected (exponent is not a literal) |
X=2**53*2**53 |
rejected (exponent 53 > 12) |
X, Y = Y, X |
rejected (Tuple node not allowed) |
X=1e300*1e300 |
evaluates to inf, then _validated_field_value rejects it |
X=(-Y)**0.5 |
evaluates to nan, then _validated_field_value rejects it |
Nit 2: EEGLAB pin citations — resolved
All three Known Differences rows (eeglab_migration.rst:189-213) now name both 8ac485f6 and d0963be9 and say the logic and line ranges are the same at both. I could not check the line ranges myself because there is no EEGLAB checkout on this runner, so this relies on your statement. The new text about constants and powers (finite numbers, ±2**53 integers, literal exponents from -12 to 12) matches the code.
Blocking
None.
Important
None.
Nits (optional)
- NumPy warning:
X=(-Y)**0.5prints NumPy'sRuntimeWarning: invalid value encountered in sqrtbefore theValueError. It is harmless and does not need a change. - Exponent ±13 vs ±12: the
large-exponentandnegative-large-exponenttest cases use ±13, andtest_chanedit_transform_accepts_bounded_numeric_powerscovers ±12 being accepted. Together they pin both sides of the limit. No change needed.
Tests run
uv run pytest tests/test_phase1b_file_edit_pop_functions.py -k transform: 26 passed, 1 failed.
- All 14
test_chanedit_transform_rejects_expensive_expressionscases passed, each well under 1 s, and so did all 6accepts_bounded_numeric_powerscases. - The one failure is
test_chanedit_action_dialog_applies_to_the_current_montage[button_transform_axes…]. It raisedRuntimeError: PySide6 is requiredbecause PySide6 is not installed on this runner. This push did not change that test, and it passes in CI, where the GUI extra is installed.
Co-authored-by: Suraj Ranganath <[email protected]> # Conflicts: # docs/source/changelog.rst
Keep both Stream 11 and Stream 5 changelog entries. Co-authored-by: Suraj Ranganath <[email protected]>
pop_reref now treats numeric channels as 1-based and subtracts one itself. pop_biosig still subtracted one before that call, so ref=[2] removed channel 1 instead of channel 2. The Stream 9 reader expectation matches the documented 1-based reference. 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 52s —— View job Code review (re-review of
|
Channel-location lookup now uses the expected standard-montage orientation, recognizes BESA ELP files, and preserves polar-file units and labels. The channel editor supports its action buttons, ordered edits, and replayable history. Rereferencing and interpolation consistently accept one-based public channel numbers, including GUI fields, console replay, CLI, and internal callers.
Findings
run_dialog_action; automatic lookup when labels exist without coordinates; channel index navigation preserved after insert/delete..elclookup orientation fixed (no more X/Y swap);.elpmatching fixed; zero matches no longer wipe coordinates..locsCartesian defaults to 85 mm head radius; EOG labels preserved.pop_rerefexclude/ref indices are 1-based in the GUI and API; history records 1-based indices.eeg_interptakes 1-based indices likeeeg_interp.m/pop_interp; out-of-range errors name1..nbchan.unknown.pop_chanedithistory emits MATLAB cell-array form.Validation
Unit / CI
0d9a2909green (ubuntu/macOS/Windows, Python 3.12/3.13, EEGLAB Python backend, docs, Claude review check).F62 live GUI e2e (Tools → Re-reference, exclude
2 6, accept new-dataset)#2: reref_excl_26,ref=average,CURRENTSET=2.max_abs=0.0); other channels changed as expected for average reference with those excludes.EEG = pop_reref( EEG, [], 'exclude', [2 6]);thenpop_newset(..., 'setname', 'reref_excl_26', 'overwrite', 'off', 'savenew', 'on').pop_rerefwith exclude2 6(earlier blank EEGLAB shot retaken).EEGLAB reference suite (jamming, flock; mirrors
eeglab-reference.yml)workflow_dispatchis 403 for this token, so the suite was run on jamming underflock ~/eegprep-bench/matlab.lockwith the same shard matrix and pins as the workflow.stream5-chanlocs)585a4463d7afa45e4d6434336d2f714a33024a04EEGLAB_TESTS_EEGLAB_COMMIT)d0963be9d81acc5b66e84f8d3d7c89e3ce127cc4EEGLAB_TESTS_COMMIT)fec88f9ffe7c225eb1de8924db8b6a3e0d53a4d9-k)-k)Failure analysis (no tolerances loosened):
tests/test_bids_preproc.py::test_crashability_slow/test_end2end(core, 2): On hostnamejammingthe suite expects a localdata/directory. That path was missing in the Stream 5 worktree, soos.listdirraised instead of skipping. Same host mapping exists on develop; GHA runners are notjammingand setroot_path=Noneso these skip there. Not a Stream 5 code regression.test_average_reference_matches_matlab_on_64_channel_float32(parity, 1):max_abs=0.109375µV vs1e-5. Reproduced onorigin/developwith the same pins and the samemax_abs.reref.pyis unchanged in this PR; empty-ref average reference does not go through the new 1-based index conversion. Pre-existing float32 BLAS vs MATLAB accumulation difference on this host (scipy-openblas), not introduced by Stream 5. Downstream parity stages that share a Python reref input (clean / interp / etc.) still passed.Intentional EEGLAB departures (documented)
Listed under Known Differences in
docs/source/user_guide/eeglab_migration.rst(pinned EEGLABpop_chanedit.m/8ac485f6):str2num+evalaccepts non-numeric text; EEGPrep rejects with a field-specific error (F43). Test:test_chanedit_rejects_nonnumeric_coordinates.eval; EEGPrep AST-limited numeric assignments only. Tests:test_chanedit_transform_rejects_arbitrary_code(new), happy-pathtest_chanedit_transform_and_repeated_fields_replay_in_order.test_chanedit_insert_data_channel_count_mismatch_raises(new),test_chanedit_cannot_delete_a_data_channel_or_overwrite_data.Gap-close on
22cfc64b22cfc64bwere green; superseded by nit-fix head below.Claude review
Initial review requested changes (
nodatchans/datachan, dead_validate_channel_text, fiducial/_is_data_locationnit). All addressed on585a4463; Claude then said Looks good / Safe to merge on code review.Gap-close re-review of
22cfc64b(run 42406786128): Looks good with two nits (Pow/Constant hang; pin citation).Nit-fix re-review of
0d9a2909(Claude Code run 42407932423): Looks good. Both prior nits resolved. Blocking/Important: none. Merge recommendation: Safe to merge on code review (still needs human approval per AGENTS.md). Optional leftover: NumPyRuntimeWarningon(-Y)**0.5before the ValueError — harmless, no change.Nit fix on
0d9a2909exec; regression tests (test_chanedit_transform_rejects_expensive_expressions) finish in <1s.8ac485f6andd0963be9(sharedpop_chanedit.mlogic/line ranges; verified identical at those ranges).QMessageBoxand keeps the app alive (screenshotpr573_count_mismatch_dialog.png).Notes
eeg_interp1-based change landed here); [Interp] Make eeg_interp channel indices 1-based #572 closed.Fixes #550
Fixes #569