Skip to content

Viewer: electrode position source in the topomap tooltip, BIDS ALS names (WV1) - #544

Merged
neuromechanist merged 6 commits into
stagingfrom
feature/pc-wv1-electrode-provenance
Nov 17, 2026
Merged

neuromechanist merged 6 commits into
stagingfrom
feature/pc-wv1-electrode-provenance

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Card WV1. The EEG viewer's topomap tooltip says where a store's electrode positions came from (subject or dataset, with the file named), never calls them measured, and BIDS's three ALS coordinate-system names are drawn the right way up. Base staging at afc2204. This PR deploys nothing by itself; a merge into staging deploys the test site.

Step 0: what the viewer read at the base

src/lib/eeg-viewer/store.ts: RecordingStore fields at lines 82 to 87, parse in openRecording at lines 390 to 432. It keeps electrode_positions entries of three finite numbers, reads electrode_coordinate_system and electrode_coordinate_units, and ignores every other root attribute.

src/lib/eeg-viewer/viewer.ts: the toggle's title is set once, in buildDom (lines 2260 to 2279): "Scalp topomap (split panel)", or the montage fallback sentence when estimated, or a disabled-reason sentence when nothing resolves. The group selector's handler (line 1776) only toggles disabled and never sets the title. resolveScalpPositions (lines 2655 to 2678) held a local named measured and a docblock saying the layout "is not measured"; the same wording sat in the comment above the toggle (line 2269). Its two callers (line 688 and buildDom) are both in viewer.ts.

src/lib/eeg-viewer/topo.ts line 25: ALS_SYSTEMS was EEGLAB, ALS, CTF, 4D, KIT, compared after toUpperCase(), so EEGLAB-HJ, 4DBti and KitYokogawa passed as RAS and were drawn rotated by 90 degrees. topo.test.ts had two alsToRas tests.

Tests: pure helpers under Vitest. store.test.ts opens a real zarrita store served from an in-memory fetch handler (fakeZarrV3Store); viewer.test.ts imports pure exports from viewer.ts. No existing test read the electrode attributes.

git grep -n electrodePositions finds only store.ts (the field and its parse) and viewer.ts (resolveScalpPositions). There is no other reader of the positions and no other place that shows store attributes, so the card's assumptions held and nothing stopped the work.

What changed

  • topo.ts: ALS_SYSTEMS gains EEGLAB-HJ, 4DBTI and KITYOKOGAWA (upper case, as the comparison reads them); the five existing entries stay, so no store drawn today moves.
  • store.ts: RecordingStore gains electrodePositionsSource (subject, dataset or null: any other value, any other case, or absent is null), electrodePositionsFile and electrodeCoordsystemFile (a non-empty string, else null), read by one exported pure function, parseElectrodeProvenance.
  • viewer.ts: one exported pure function, topoToggleTitle, chooses the toggle's tooltip. Positions from a store with subject give "Scalp topomap - electrode positions from this subject's electrodes file", with dataset "Scalp topomap - electrode positions from one electrodes file shared by every subject", each followed by the file in parentheses when the store names it. A store with no source word (converted before the converter wrote one) keeps the base title, and the montage fallback keeps its sentence. No tooltip uses the words measured, digitized or template.
  • viewer.ts: in resolveScalpPositions the local measured becomes declared, and the two comments saying "not measured" now say "not the dataset's own positions". Behavior unchanged.

Left alone, outside the card's Scope: two comments in standard-montage.ts (lines 13 and 420) still use the word "measured" about the standard montage tables.

Gates

  • bun install --frozen-lockfile: no changes.
  • bun run typecheck: 0 errors, 0 warnings, 19 hints (the same 19 hints on the base).
  • bun run lint: Checked 419 files in 215ms. No fixes applied.
  • bun run test: Test Files 175 passed | 3 skipped (178), Tests 4955 passed | 14 skipped (4969).
  • bun run test src/lib/eeg-viewer: Test Files 16 passed (16), Tests 525 passed (525); every test that existed on the base passes unchanged (the only edit to an existing test file's helper is one optional rootAttrs option on fakeZarrV3Store).
  • Leak check on this body: nothing printed. On the changed files it prints only one data-plane host name that is already on the base in viewer.ts and viewer.test.ts (the check's allowlist lacks it) and that no line of this PR adds.

Mutations (each reverted, git status --porcelain clean after each)

  1. Remove 4DBTI from ALS_SYSTEMS: alsToRas > turns BIDS's three ALS names like EEGLAB, in any letter case fails with expected [ 1, 2, 3 ] to deeply equal [ -2, 1, 3 ], and the 4DBti projection test fails too.
  2. Accept any string as the source: parseElectrodeProvenance > gives null for any other word, any other case, any other type, and absence fails with expected 'Subject' to be null.
  3. Drop the null check in topoToggleTitle: keeps the base title for a store converted before the attributes existed fails with expected 'Scalp topomap - electrode positions f…' to be 'Scalp topomap (split panel)'.
  4. Drop the parseElectrodeProvenance spread in openRecording (the wiring): both openRecording carries the provenance... tests fail with expected undefined to be 'dataset' and expected undefined to be null.

Not run

  • Not run, would check: the viewer in a browser. After the manager merges into staging, a store with a dataset source on test.nemar.org should show the clause with the file, and a store converted before the converter wrote the attributes should show the base title, because this card makes no deploy and runs no browser.
  • Not run, would check: the call site topoBtn.title = topoToggleTitle(scalp, store) in buildDom, because buildDom needs a DOM and the suite is pure-helper tests; typecheck pins the argument shape.
  • Not run: Prepare release, any deploy, any merge, any version change.

Review round 1 (head 2b26c94)

The review of 8ac618a found no critical or important issue. Changes after it:

  • Deliberate hardening from review, stricter than the card's "a non-empty string": a store is outside data and its file paths reach a tooltip. parseElectrodeProvenance now accepts a path (electrode_positions_file, electrode_coordsystem_file) only when it is a trimmed, single-line string of at most 200 characters with no control, invisible or direction-changing character (Unicode categories Cc, Cf, Zl and Zp), and repository-relative: no leading /, no backslash anywhere, no scheme: prefix such as http:, file: or a drive letter. Any other path makes the file unknown (null) and leaves a valid source word alone, so the tooltip then shows the sentence without a file.
  • New tests, one per rejected shape (line feed, carriage return, tab and other control characters, invisible characters, 201 characters against exactly 200, empty, whitespace only and padded, leading slash or backslash, backslash anywhere, file: and https: prefixes, a colon after a folder name kept). Each fails under one mutation, reverted after each: drop Cc from the class (control test), drop Cf (invisible test), drop the length cap, drop the trim check, drop the leading-slash check, drop the backslash check, drop the scheme check, treat any colon as a scheme, read the wrong attribute for the coordsystem file, reject any slash (normal-path test).
  • The resolveScalpPositions docblock now says "The coordinates the store carries from its electrodes file".
  • Gate numbers corrected: the full bun run test on 2b26c94 reads Test Files 175 passed | 3 skipped (178) and Tests 4965 passed | 14 skipped (4979) (the earlier "4955 passed" figure was from before this round's ten new tests; a reviewer run that measured 4952 passed | 17 skipped on 8ac618a had three more skips in its environment, the same 4969 total). bun run test src/lib/eeg-viewer reads Tests 535 passed (535), bun run typecheck 0 errors, 0 warnings, 19 hints, bun run lint Checked 419 files in 291ms. No fixes applied.

Known wording limit, left as the card decided and pinned by tests: a store with a source word and a named file but fewer than three valid position rows falls back to the standard montage, and the tooltip then keeps the montage sentence ("dataset ships no electrodes.tsv").

@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit 0fa8cc3 into staging Nov 17, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/pc-wv1-electrode-provenance branch November 17, 2026 11:38
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