Skip to content

W3: montages by digest, viewer topomap on sensor-field - #593

Merged
neuromechanist merged 15 commits into
feature/issue-586-epic-pipeline-progressfrom
feature/issue-588-w3-montages
Nov 26, 2026
Merged

neuromechanist merged 15 commits into
feature/issue-586-epic-pipeline-progressfrom
feature/issue-588-w3-montages

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Phase W3 of the quality-views epic (#586), tracked in #588, part of nemarOrg/nemar-cli#2324 (nemar-cli ADR 0137 as amended; website ADR 0035).

What changed

  1. The montages are copied by digest.
    scripts/copy-quality-views-vocabulary.mjs and test/quality-views-vocabulary-drift.test.ts now copy views/montages/*.json, PROVENANCE.json included, into src/lib/quality-views/vocabulary/montages/, pinned in pin.json like the registry and the vectors.
    A montages/ entry the rule cannot place is refused, never skipped.
    The drift test also checks that every montage PROVENANCE.json lists is shipped at the digest it records.
    CI's sparse checkout adds the montages folder, so the "hash what nemar-cli has beside its list" check covers them.
    MNE-Python's BSD-3-Clause text and EEGLAB's BSD 2-Clause text ship in public/licenses/quality-views/NOTICE.txt, item 3, beside the color maps' notices.
    They are also listed under Required in THIRD_PARTY_NOTICES.md, with the upstreams PROVENANCE.json records (FieldTrip, EGI, BioSemi; none states a license).
    test/quality-views-montages.test.ts holds both license texts to the ones PROVENANCE.json carries.
  2. The six template-center checks are independent.
    montages.ts reads one nemar.montage.v1 file strictly.
    montage-loader.ts fetches one montage per lazy chunk, and PROVENANCE.json is never fetched.
    montageCentersFrom (which read the center from the vector itself) is replaced by montageCentersFromFiles, which reads each center from the copied files.
    The six template cases (positions_template, positions_template_midline, template_montage, template_full_1005, template_midline_9, template_coronal_9) now check their centers against data the vectors do not supply.
  3. The viewer's topomap is on the W2 core.
    • The new eeg-viewer/scalp-map.ts places the sensors once per recording:
      • The recording's own positions go through sensorLayout.
      • Pixels, ACPC and ScanRAS are refused with frame_not_scalp, with no fallback to names.
      • Positions with no row typed EEG are refused with no_eeg_sensors.
      • An electrodes file that names none of the recording's channels is refused with positions_unmatched (a viewer word).
      • When the layout refuses with frame_unknown, positions_flat or positions_partial, the drawn rows (the positioned rows typed EEG, as neuroschema's drawn_rows and named_eeg) are placed by name instead. Positioned EOG, ECG and MISC rows, and rows naming no channel (GND, REF), neither block the fallback nor are placed. The reason is kept (unused_positions) and shown.
      • When no positioned row is typed EEG but some channel is, the sentence says "none of the channels the electrodes file positions is typed EEG"; with no channel typed EEG at all it says none of the recording's channels is.
      • On the names path, no candidate channel is too_few_channels, and scalp channels all typed and none EEG are no_eeg_sensors. A recognized net that matches one or two names, with the 10-05 montage matching none, is too_few_matched; no match anywhere stays labels_unrecognized. The store's OTHER (a channels.tsv type of n/a) reads as untyped, pinned by a test.
      • Template positions by name use name-placement.ts on neuroschema's montage files, centered on the file's own center (see "Accepted deviations from ADR 0137", item 1).
    • The map is drawn by nemar.sensor-field.v1 in the quality views' worker. The viewer imports worker-client.ts lazily, so the client is a chunk of its own. One draw is in flight at a time, and the newest request replaces any queued one.
    • It is painted with SEQUENTIAL_STOPS on the minmax color axis, with EEGLAB's head, nose and ears, and a marker per plotted row.
    • Every refusal word leaves the map undrawn with its sentence (SCALP_MAP_SENTENCES): the canvas and legend are hidden, and the sentence stands in their place.
      • This covers the five placement words, labels_unrecognized, montage_unavailable and the three sensor-field words.
      • It also covers a worker that cannot draw, and a MontageCenterUnavailable, which is caught by type.
      • Nothing throws past the module. The decisions are pure functions (viewOfPlacement, viewOfDraw) under test.
    • The toggle keeps its markup, aria-pressed and title. The title now also says "template positions from " or gives the refusal sentence.
    • Deleted: topo.ts (the thin-plate spline, projectPositions, renderTopomap, viridisColor, VIRIDIS_CSS) and its test, plus the hand-copied standard-montage.ts and net-montages.ts.
    • ieeg-spatial/activity.ts and live-activity.ts take their colors from colorAt(SEQUENTIAL_STOPS, ...). Digests taken from the former code pin the overlay's 256-entry table and colorFor at 102,001 values, rounding ties included: the colors are unchanged.
  4. The worker's production build is confirmed, and the size check measures from each lazy importer.
    The measuring half moved to scripts/quality-views-size-lib.mjs.
    Its roots are now every chunk that something other than the client imports dynamically and whose static imports reach the client.
    So two lazy panels that share a split-out client are each measured with their own code.
    The client's own in-thread fallback is never a root.
    test/quality-views-size.test.ts runs it on made-to-order chunk layouts, including the Quality views: W2 follow-ups (cold first view, size gate, guard tests) #592 layout, where one panel is over budget and the earlier rule did not see it.
    Static imports include the re-exports export {..} from and export * from, so a facade that re-exports the client is followed.
    It also measures every chunk that imports the client statically but sits in no lazy root's set (a page that statically imports a panel that imports the client), against the same budget, and names the chunks above it (the page) in a note. The review's page.js -> dataset-panel.js -> worker-client.js layout is a test case.
    • website#592: measure from each dynamically imported chunk that reaches the client.
  5. Screenshots are below. An e2e spec, e2e/viewer-scalp-map.spec.ts, covers a drawn map through the worker, template positions with their note, and a refusal. It runs locally only, like every e2e spec here.

The visible change

Before is on the left and after on the right. All four were taken from the local dev server on public recordings, at the window's center (5.00 s).

Recording Before / after
on002718: the subject's electrodes file, channels typed EEG on002718
on004504: no electrodes file, 10-20 names on standard_1005 on004504
nm000103: EGI 129-channel net, its own electrodes file nm000103
on004584: electrodes file, but channels.tsv types every channel n/a on004584
nm000254: electrodes file in frame Other, positioned ECG and EOG rows; its 61 EEG rows placed by name nm000254

What differs, and why:

  • The color axis is minmax with a 5% margin, not symmetric ±max.
    The legend reads, for example, −85 µV to 32 µV where it read ±61 µV, and the full color range is used.
    This is the amendment's minmax rule, with the sequential map.
  • Mean removal.
    The field interpolates each value's deviation from the mean and adds the mean back, so a shared offset no longer ripples across the map.
    The old thin-plate spline had an affine term and a ridge, so the maps differ in shape and not only in color: on002718's frontal low and parietal high stand out more.
  • EEGLAB's head.
    The nose and ears are EEGLAB's polylines, and the head circle is drawn at 0.5 * squeezefac, while the field fills the 0.5 circle.
    When sensors sit below the equator, as on EGI nets (nm000103) or with T7/T8 at the rim (on004504), the head is drawn smaller inside the field, as EEGLAB's topoplot does.
    The old view squeezed every sensor inside the rim.
  • The 8-sensor minimum.
    A map needs 8 interpolated sensors (too_few_sensors), where the old one drew with 3.
    None of these four is affected; a recording with 3 to 7 placed channels now shows the sentence.
  • An unknown frame no longer bends the map.
    nm000254's positions are in Other; the old view projected them in an assumed frame. The new one does not use them, says why, and places the 61 EEG rows by name on standard_1005.
  • Refusals.
    on004584 and on003478 drew maps before.
    Their channels.tsv types every channel n/a, which the converter stores as OTHER, so no positioned row is typed EEG and the map is refused with no_eeg_sensors, as the amendment defines it ("untyped, or ..."). See "Accepted deviations from ADR 0137", item 2.

Chunk sizes (production astro build, gzip level 9)

Chunk Before (base 3689f2f) After
viewer 166.8 KB, 58.6 KB gz 153.8 KB, 53.5 KB gz
worker-client (lazy, first imported by the viewer) not emitted 7.9 KB, 3.2 KB gz
module worker worker-*.js not emitted 12.5 KB, 5.2 KB gz (budget 12 KB)
in-thread fallback worker.*.js (only without Worker) not emitted 10.2 KB, 4.3 KB gz, not counted
standard_1005 montage (lazy, on demand) in the viewer chunk 13.8 KB, 5.2 KB gz
GSN-HydroCel-129 / -257, biosemi128 / 256 montages in the viewer chunk 2.0 / 3.4 / 1.4 / 2.6 KB gz

bun scripts/check-quality-views-size.mjs --require-build reports two site-build lines.
The main thread is measured from worker-client: 11.7 KB gz with its static imports, against a 30 KB budget. Those imports include the embed page's own chunk, which holds Vite's preload helper.
The worker is 5.2 KB gz against a 12 KB budget.
The entry build gives 5.2 KB and 5.2 KB.

Mutation testing

The script lives outside the repository. Each mutation edits one file, runs the named Vitest files, and restores the file.

Area Mutation Result
montage pin one byte of a copied montage changed killed (1 failed)
montage pin PROVENANCE.json dropped from the pin killed (2)
montage pin the drift test's copy rule ignores montages/ killed (3)
montage pin the montage reader accepts any orientation killed (1)
center check montage center read with x and y swapped killed (6)
center check montage center not rotated into ALS killed (4)
center check montage center off by 1 mm in z killed (4)
center check template layout centered on a sphere fit, ignoring the montage killed (5)
undrawn on refusal a refused placement asks for a map killed (2)
undrawn on refusal a refused map is shown as a map killed (2)
undrawn on refusal MontageCenterUnavailable not caught by the placement killed (1)
undrawn on refusal a montage that fails to load is skipped past killed (1)
undrawn on refusal intracranial frames drawn killed (3)
undrawn on refusal names replace positions when some row is not EEG killed (1)
undrawn on refusal positions with no EEG row drawn killed (1)
undrawn on refusal a worker failure shown as unchanged killed (1)
undrawn on refusal a dimmed channel keeps its value killed (1)
size walk roots are the client chunks only (the #592 gap) killed (2)
size walk the client's own fallback counted as a root killed (1)
size walk static imports not followed killed (3)
size walk dynamic imports not seen killed (3)
iEEG colors overlay colors one 8-bit step off at the top killed (3)
iEEG colors overlay position computed as plain u (a rounding tie differs) killed (1)
review: fallback fallback blocked by a positioned non-EEG row (the first revision's rule) killed (4)
review: fallback fallback places every candidate channel, not the drawn rows killed (1)
review: fallback drawn rows include untyped, unmatched rows killed (2)
review: words positions naming no channel not told apart from no_eeg_sensors killed (1)
review: words zero candidates reported as labels_unrecognized killed (2)
review: words all-non-EEG channels reported as too_few_channels killed (1)
review: OTHER the store's OTHER read as a type killed (1)
review: size walk a panel importing the client eagerly not measured killed (1)
review: size walk the eager walk ignores the lazy roots' sets (a panel measured twice) killed (1)
review: size walk the client's own fallback counted as an eager importer killed (1)
review: size walk the page above the panel not named killed (1)
round 2 drawn rows include untyped rows (round 1's surviving N3) killed (4)
round 2 the positioned no_eeg_sensors sentence never chosen killed (1)
round 2 the positioned sentence always chosen killed (1)
round 2 the sentence override ignored killed (1)
round 2 some matches reported as labels_unrecognized killed (1)
round 2 re-exports not followed by the size walk killed (3)

Testing

  • bun run typecheck: 0 errors, 0 warnings.
  • bun run lint: clean.
  • Targeted Vitest (the quality-views files, src/lib/eeg-viewer, src/lib/ieeg-spatial): 1,494 passed, 4 skipped (after the review fixes). The skips are the perf gate outside its step, and the vocabulary drift's nemar-cli checks with no sibling checkout.
  • The vocabulary drift test, strict (NEMAR_CLI_QUALITY_VIEWS) against a checkout of nemar-cli's epic branch: 15/15.
  • bunx astro build, then bun scripts/check-quality-views-size.mjs --require-build: passes (sizes above).
  • bun run test:quality-views-perf: 128 sensors, median view 23.6 ms (first maps 8.1 ms); 256 sensors, 76.3 ms (14.4 ms). Cold first run: 60.7 ms and 86.2 ms.
  • Full bun run test: 7,033 passed, 52 skipped (after the review fixes).
  • e2e/viewer-scalp-map.spec.ts against the local dev server: 3/3.
  • Mutation table above.

Expected red in CI, as in W1 and W2: the 6 vocabulary and pipeline drift tests compare with nemar-cli dev, which does not carry neuroschema 0.6.0 until epic nemarOrg/nemar-cli#2324 merges there.
The budget steps run regardless.

Accepted deviations from ADR 0137

  1. EGI nets are chosen by names alone, until W2b (owner's ruling).
    name-placement.ts keeps the #855 rule: numbered E labels give a HydroCel 129 or 257 net by the highest number, BioSemi bank labels a BioSemi cap, otherwise the 10-05 montage, case-insensitive, with T3/T4/T5/T6. The coordinates and centers are neuroschema's files.
    ADR 0137's amendment forbids the first part: a recording is placed on a HydroCel net only when its CapManufacturersModelName names that net, because older EGI nets number their electrodes alike on other positions, so names alone never decide an EGI net.
    The #855 rule also has no 0.8 share rule (only 3 matched names and BioSemi's 60% bank dominance), and checks none of montage_ambiguous, duplicate_label, net_coverage_low or the hyphen split; that is part of this deviation.
    W2b replaces the file with nemar.sensor-labels.v1 and removes all of it; a comment in name-placement.ts says so.
  2. Untyped rows refuse, until neuroschema 0.6.1 (owner's ruling).
    W3 ships the strict rule: the store's OTHER (a channels.tsv type of n/a) is untyped, and measured positions with no row typed EEG are refused with no_eeg_sensors (on004584, on003478 and 27 more of the surveyed recordings).
    The owner is taking a narrow rule to ADR 0137 and neuroschema 0.6.1: in an _eeg recording, a positioned row typed n/a or OTHER counts as EEG unless its name carries a non-EEG prefix, and explicit non-EEG types stay out.
    The viewer follows once neuroschema 0.6.1 lands; it is not implemented here.

Other deviations

  1. Three of the viewer's own words (too_few_matched is sensor-labels.v1's word, used here for the interim rule's partial matches), each with its sentence: positions_unmatched (an electrodes file naming none of the recording's channels), montage_unavailable (a montage that cannot be loaded, MontageCenterUnavailable included) and worker (a worker that cannot draw). No specification word covers them.
  2. The viewer draws no contour lines (contours: "none"), as before. The worker's contours stay available for W4's views.
  3. The legend shows the minmax axis's two ends with their signs, where it showed ±max.
  4. The plan's W3 also listed "an undeclared frame follows open question 3"; the amendment's precedence covers it (frame_unknown falls back to names, never to an assumed frame).

Upstream converter note

on004022's channel labels carry trailing spaces in the store ("C3 "), while its electrodes file says C3, so no exact name matches and the viewer says positions_unmatched.
That is a converter matter, not a viewer one: the viewer compares names exactly, as the specification does. No code change here.

Effect on the surveyed recordings

Of 622 surveyed recordings, 269 carry positions. The 54 whose positions have a non-EEG or unmatched row were run through the first revision and through this one, on their real store attributes:

  • The 40 with no positioned EEG row: all refused with no_eeg_sensors before; now 29 no_eeg_sensors and 11 positions_unmatched (electrodes files labeled 1, 2, ... or Fp1 against channels E1 or Channel1; on004022's channel labels carry trailing spaces, so no exact name matches).
  • The 14 with mixed rows: the 6 in a known frame are unchanged (their own positions); the 8 in Other or an undeclared frame, all frame_unknown before, now place by name: nm000254, on003690, on003039, on005473 and on005280 on standard_1005 (59 to 64 channels), on004000 on biosemi128 (100), and on007987 and on006171 on standard_1005 with 6 channels each, which the map then refuses with too_few_sensors.

What W4 needs

  • Cold first view (Quality views: W2 follow-ups (cold first view, size gate, guard tests) #592).
    The viewer now creates the worker on the first draw after the panel opens.
    The cold numbers above (60.7 ms at 128 sensors against a median of 23.6 ms) are the same cold JIT that Quality views: W2 follow-ups (cold first view, size gate, guard tests) #592 measured.
    The viewer's layout is known as soon as the store opens, so building the geometry early would warm the worker, but only for views that send their layout first.
    Two things to know for the fix:
    • The worker caches geometry by layoutKey and checks the numbers, so any stable key works.
    • Each SensorFieldClient starts its own worker. A page that shows a quality panel beside the viewer would hold two unless they share one client.
  • The size check: W6's panel and W9's drill-down are each a root when they import the client lazily, measured with their static imports. A panel imported statically by a page is measured on its own (the panel and its imports) against the same budget, and the page above it is named in a note, not measured. The client's own in-thread fallback is never counted.
  • montage-loader.ts and centersOf give W4's sensor-field views without a layout role the montageCenter they need for template positions; sensorLayout still throws MontageCenterUnavailable without it.
  • W2b replaces name-placement.ts with nemar.sensor-labels.v1 on the same montage files, and adds the nine label refusal words to SCALP_MAP_SENTENCES.

Refs #588, #592, nemarOrg/nemar-cli#2324

Agentic AI tools were used.

Widen the vocabulary copy rule and its drift test to views/montages/*.json, PROVENANCE.json included, pinned by SHA-256 like the registry and vectors. Ship MNE-Python's and EEGLAB's license texts in the quality views' notice and list them under Required. Tested: drift test strict against the nemar-cli epic checkout.
Add montages.ts (strict nemar.montage.v1 reader) and a lazy per-file loader. The parity tests now read each montage center from the copied files, so the six template cases' center checks are independent of the vectors. Tested: montages, layout, field and worker tests.
The activity overlay takes its sequential colors from the quality views' SEQUENTIAL_STOPS and colorAt instead of the viewer's viridisColor. Digests taken from the former code pin the overlay's table and colorFor, ties included, as unchanged. Tested: iEEG spatial and colormap tests.
The live topomap is placed by nemar.sensor-layout.v1 (own positions; intracranial frames and non-EEG rows refused; unknown, flat or partial positions fall back to names and say why) or by name on neuroschema's montage files centered on each file's center, and drawn by nemar.sensor-field.v1 in the quality views' worker with the sequential map on the minmax axis. Every refusal, a montage that cannot load (MontageCenterUnavailable included) and a worker failure leave the map undrawn with a sentence. Removes the thin-plate spline, projectPositions, renderTopomap and the hand-copied montages. Tested: viewer, scalp-map and name-placement tests.
The size check now measures from every dynamically imported chunk whose static imports reach the client, so two lazy panels sharing a split-out client are each counted with their own code (website#592); the client's own in-thread fallback is never a root. The measuring half moves to quality-views-size-lib.mjs and is tested on made-to-order chunk layouts. Tested: astro build and the size check (client chunk 11.6 KB gz with its imports, worker 5.2 KB gz).
Name scalp-map.ts, name-placement.ts, the montages and the size library in the architecture map, and update the CI comment on the size step. Docs only.
Hide the empty canvas and the legend while a refusal stands in for the map, and show them again when a map is drawn. Checked in the dev server on a refused and a drawn recording.
Before and after the move onto nemar.sensor-field.v1, from the dev server on public recordings: own positions (on002718, nm000103), names on standard_1005 (on004504), and a refusal for untyped channels (on004584). Docs only.
On the embed route with public recordings: a map through the module worker, template positions by name with their note, and a refusal that hides the canvas and legend. Tested: 3/3 locally against the dev server.
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

After a refused projection, place by name only the positioned rows typed EEG, as neuroschema's drawn_rows and named_eeg do; positioned EOG, ECG and MISC rows and rows naming no channel no longer block it. Add positions_unmatched (a viewer word), too_few_channels and no_eeg_sensors on the names path, and pin the store's OTHER as untyped. Regression fixtures from nm000254, on003690 and on003039 now place on standard_1005. Tested: eeg-viewer tests, mutations killed.
Comment in name-placement.ts that choosing an EGI net by names alone, the missing 0.8 share rule and the other sensor-labels checks are an accepted deviation from ADR 0137 that W2b removes. Comment only.
The size walk also measures every chunk that statically imports the client but sits in no lazy root's set, and names the chunks above it in a note; the client's own lazy fallback is excluded. Reproduces the review's page -> dataset-panel -> worker-client layout. Tested: size tests, astro build and the size check.
on004584 shows the reworded no_eeg_sensors sentence; nm000254 (frame Other, positioned ECG and EOG rows) now places its EEG rows by name on standard_1005. Docs only.
no_eeg_sensors on the positions path says the positioned channels are not EEG when some channel is; a recognized net matching one or two names and the 10-05 montage none says too_few_matched. Tests for both, and for placing only the drawn rows (no unpositioned EEG channel, no OTHER channel with an electrode name). Tested: eeg-viewer tests, mutations killed.
staticImports also follows export {..} from and export * from, so a facade re-exporting the client is measured; each docblock now sits above its own function. Tested: size tests, astro build and the size check.
@neuromechanist
neuromechanist merged commit a1e4fc8 into feature/issue-586-epic-pipeline-progress Nov 26, 2026
3 of 4 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-588-w3-montages branch November 26, 2026 00:35
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