Skip to content

viewer: auto-scale initial gain to each recording's amplitude #109

Closed

Description

@neuromechanist

Problem

The viewer opens with a fixed vertical scale per modality (DEFAULT_SCALINGS.EEG = 75 µV/div in src/lib/eeg-viewer/dsp.ts) and gain = 1 (viewer.ts:97). Recordings whose real amplitude differs a lot from that default don't display well until the user manually presses Scale +/−:

  • Low-amplitude recordings open nearly flat. e.g. on003800 (average-referenced auditory-gamma .set) is genuinely ~1.6 µV std / ~20 µV p2p, so at 75 µV/div the traces are ~invisible and the topo readout shows nV; the user must Scale-up ~26× (scale bar drops to ~2.9 µV) to see anything.
  • High-amplitude / noisy recordings (e.g. on003810 at ±45 µV) fit at the default but can clip against the per-channel slot when many channels share the fixed-height scope.

Data is intact (verified)

This came up while chasing a suspected conversion bug. Both stores were checked against the reference reader (MNE) on the source files: correlation 1.0, exact std match, correct channel order — on003800 store unit is uV and equals MNE; on003810 (EDF, n/a unit) equals MNE up to the unit factor. So nothing is corrupted or mis-scaled in the Zarr conversion. The only gap is the viewer's fixed initial scale.

Proposed

Auto-scale the initial gain to the recording on load:

  • Compute a robust amplitude estimate per recording — e.g. the median across channels of a high percentile (~95th) of |signal| (or a robust std) from the already-loaded overview / first window — and set the initial gain so a typical trace fills ~60–80% of its channel slot.
  • Keep manual Scale +/− as an override; keep the per-modality DEFAULT_SCALINGS as the no-data fallback.
  • Optional: a "fit" hotkey/button to re-autoscale to the current view, and re-autoscale on group switch.

Pointers

  • physPerDiv = defaultScaling(modality) (viewer.ts); scale bar = physPerDiv / gain; gain init viewer.ts:97; Scale buttons viewer.ts:560.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions