Skip to content

feat: interactive Zarr signal viewer (website#99) - #101

Merged
neuromechanist merged 19 commits into
mainfrom
feat/issue-99-zarr-viewer
Jun 3, 2026
Merged

neuromechanist merged 19 commits into
mainfrom
feat/issue-99-zarr-viewer

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Implements the in-browser EEG/MEG/iEEG/EMG signal viewer (Stream D of the NEMAR Zarr serving-copy epic, nemar-cli#684). Clicking a .set/.edf/.bdf/.vhdr/.fif file in the BIDS tree opens an inline viewer that streams the recording's per-recording Zarr v3 store from zarr.nemar.org with zarrita (ranged GETs, no decode backend), exactly like the existing TSV/JSON inline previews.

What it does

  • Reads the non-sharded view pyramid for the visible window (bounded transfer, ~130 KB for a 10 s view regardless of recording length); renders a min/max decimation waveform that preserves EEG texture.
  • Clinical "scope" UI: fixed-height plot that fits the embed (no growth with channel count), grouped toolbar (Time / Scale / Channels / Display), horizontal time scrubber, magnifier channel zoom with a vertical scrollbar that only appears once you zoom into a portion of a large montage.
  • First-class events layer (one events group per recording): vertical lines + labels via label_map, a type legend.
  • DC removal (default on), 75 uV default scale with gain controls, MNE-style nav keys, channel-type colors, "Signal loading..." state, resilient retries, light/dark via design tokens.

Architecture

  • src/lib/zarr-base.ts - base URL (PUBLIC_ZARR_BASE_URL) + BIDS-path -> store-URL mapping.
  • src/lib/eeg-viewer/ - store.ts (zarrita reader: view pyramid + events, parallel open, retry), dsp.ts, render.ts (Canvas 2D), events.ts, viewer.ts (orchestration). Pure helpers unit-tested (no mocks).
  • Hook: the eeg branch of src/pages/dataset/[id].astro dynamic-imports the viewer (code-split; zarrita only loads when a signal file is opened).
  • Signal files now show a format badge (SET/EDF/...) like TSV/JSON instead of the old "Vis - soon" stub.

Why the view pyramid (not level-0)

Level-0 is a single whole-array shard; zarrita reads the entire shard (multi-MB) for any access, which is far too heavy and tripped the gateway. The view pyramid is the interactive hot path (134 KB vs 9 MB, ~0.9 s vs ~13 s, zero 502s). Sample-level zoom from level-0 needs per-segment sharding in the producer; deferred.

Validated

  • zarrita reads the live nm000132 store (sharding + view pyramid + events) end-to-end; rendered against real recordings.
  • zarr.nemar.org CORS verified (allows ww2/localhost origins, denies third-party, Range + expose-headers work).
  • typecheck (0 errors), 510 unit tests pass, lint clean, production build succeeds.

Closes #99 (P0). Follow-ups: per-segment level-0 sharding for sample-level zoom; P1 client HP/LP/notch filters, butterfly, bad-channel marking, overview minimap.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6df2abb
Status: ✅  Deploy successful!
Preview URL: https://c00e41c3.nemar-website.pages.dev
Branch Preview URL: https://feat-issue-99-zarr-viewer.nemar-website.pages.dev

View logs

- readEvents: empty catch -> warn log
- discoverViewLevels: log non-404 probe failures; dtype guard before cast
- retryingFetch: throw on transient exhausted instead of returning bad response
- openGroup: warn on n_channels mismatch; annotate errors with group name; dtype guard on level0
- parseChannels: export for unit testing
- ChannelWindow: { kind: "line"; line } | { kind: "band"; min; max } (remove isBand from WindowData)
- FrameChannel: same discriminated shape with label + color
- readLevel0/readViewLevel: return kind-tagged objects
- render.ts: dispatch on ch.kind === "band"
- viewer.ts: dispatch on cw.kind, return kind-tagged FrameChannel
- dsp.ts: add exported removeBandDc (midpoint-mean DC removal for band channels)
- viewer.ts: import from dsp, remove local duplicate
- mountEegViewer: call prior _eegvCleanup before rebuild; collect RO/MO into cleanups[]; set _eegvCleanup on slot
- render() catch: set firstPaint=false, paint error message on canvas, update status text
- channel cap: min(visible, win.channels) to prevent out-of-bounds indexing
- render.ts: guard gain > 0 (use 1 on bad input); move clipPx inside per-channel loop (per slot)
- escapeAttr: also escape ' -> ' and > -> >
- [id].astro: bind + log err in EEG mount catch
- render-dir-listing: add tree__tag--signal modifier class to EEG file badges (SET/EDF/BDF/VHDR/FIF)
- BidsTree.astro: .tree__tag--signal style uses --color-link tint so signal files stand out from muted JSON/TSV badges
…lebar position, formatSi/pickViewLevel/zarr-base/label_map)
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.

Zarr signal viewer: zarrita browser reading Zarr from cached S3

1 participant