Skip to content

Read renamed iEEG channels as their electrode contacts - #574

Merged
neuromechanist merged 5 commits into
stagingfrom
fix/ieeg-channel-electrode-name-map
Nov 20, 2026
Merged

neuromechanist merged 5 commits into
stagingfrom
fix/ieeg-channel-electrode-name-map

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What

Collaborator pull requests on iEEG mirror datasets now write channels.tsv names as the recording headers do (POL A1-AV, EEG G_03-REF, EEGGA_01REF, A1-A2, EEG M2-Ref) while electrodes.tsv keeps the contact names (A1, G03, GA01).
The Brain panel and the live Activity view join channels to contacts in one place, joinChannels (src/lib/ieeg-spatial/geometry.ts) over channel-match.ts; this PR extends that one rule, no data changes.

The rule (channel-match.ts)

Exact name first, then an exact bipolar pair, then, tier by tier, the first tier with one reading decides and two readings refuse:

  1. normalized: whitespace off; a leading EEG or POL in upper-case only with spaces, or EEG run into a shaft letter (EEGGA_01REF), off; compare with the contact name except for leading zeros in the index and an underscore between a shaft letter and the index (not after a digit: G1_2 is not G12), on both sides (G_03, G03, G3 are one name); a bipolar pair X-Y whose halves read that way maps to both contacts (midpoint for display), so POL B1-B2 reaches B01 and B02.
  2. suffix: one trailing reference token off any of those forms: -REF/-Ref (any case, optional number), REF right after the index with no hyphen, -AV, or four-plus digits after a hyphen; then the same comparison.
  3. Claims: an exact name keeps its contact; two differently written channels reaching one contact or pair both lose it (duplicate_contact).

New in this PR: the underscore, REF without a hyphen, EEG with no space, and zero-tolerant bipolar halves.
Deliberately not read: POL $A11 (no stated meaning), case-folded contact names (on004624 counts from 0 against a file from 1), POLAR1-style names (POL needs a space), and X-A1/X-A2 as ear references (new pending pattern ear_reference; where both ends are contacts the name is a bipolar pair).

Match table

Electrodes reached by at least one channel, summed over every channels file of the dataset that has an electrodes file beside it (sourcedata/ and derivatives/ skipped), measured on main and on the fix-20261018 pull request of each nemarDatasets repository.

Dataset Electrode rows main, exact name branch, exact name branch, rule before branch, rule now Unreached on the branch
on004194 33306 33306 13277 28274 33306 none
on004551 13788 13788 1 13739 13739 POL $A11, POL $A12 (polarity marker, still refused)
on005007 3388 3388 0 3337 3337 POL $A11, POL $A12, POL $B.. (same)
on005545 38596 38596 0 16944 17154 contacts no bipolar channel names
on005931 1724 1724 0 862 862 contacts no channel names (the branch drops half the channels)
on006107 17812 17812 0 17795 17795 contacts of A..-AV channels the file lacks
on006233 39567 39567 0 17264 17306 contacts no bipolar channel names
on006914 39936 39936 0 17376 17418 contacts no bipolar channel names

Where the branch reaches fewer electrodes than main, it has fewer channels: on005545, on006233 and on006914 are bipolar derivations (POL A1-A2, 66 channels for 128 contacts, the monopolar rows moved to sourcedata/channels-removed-2026-10-18), and on005931 keeps half its channels.
An independent reading of every unlocated channel (lower case, type word and reference token off, underscore and zeros off, written apart from the module) finds no further contact for any of them, so the counts above are what the names allow.

False-match checks over all eight datasets: no channel reaches a contact of another shaft; no two differently written channels hold one contact or one bipolar pair (adjacent bipolar channels share a contact, as they must).
Residual unlocated channels, by kind: auxiliary (DC01, SG1, TRIG, OSAT, EKG1), scalp references (EEG C3-Ref), contacts the electrodes file lacks (POL A10, POL A9-A10 where there is no A10), and the $ marker.
POL A1-Ref beside EEG A1-Ref in one recording (on004551 sub-051) is refused as a duplicate claim on A1, as designed.

Tests

  • channel-rename.test.ts: real name columns of eleven recordings from the eight datasets (test/fixtures/ieeg-channel-renames/, commit and SHA-256 of each whole file inside), counts per recording, a shaft and unique-claim check, an independent reading that must agree with the module on every channel, and one row per form. No mocks.
  • Existing channel-match and provenance tests updated where the sentence or the case rule changed.
  • vitest run: 5675 passed; biome check: clean; astro check: 0 errors.

The same rule is in nemarOrg/nemar-cli (scripts/ieeg_geometry/ieeg_geometry/names.py) for the geometry pipeline, held to the same counts on the same files.

Review round: the type word is upper case only (owner, 2026-11-20); _expected-joins.json (digest pinned) holds the per-channel join of every fixture recording and is byte-identical in nemar-cli; the shaft check is strict (letters equal, per half).

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit 239a2cf into staging Nov 20, 2026
4 checks passed
@neuromechanist
neuromechanist deleted the fix/ieeg-channel-electrode-name-map branch November 20, 2026 22:50
neuromechanist added a commit that referenced this pull request Nov 20, 2026
neuromechanist added a commit that referenced this pull request Nov 20, 2026
neuromechanist added a commit that referenced this pull request Nov 20, 2026
* Changelog: renamed iEEG channel pairing (#574)

* Changelog: #574 prepares for renamed channels

* Survey pattern text: type word is upper case

* Changelog: exact wording of the #574 forms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant