Skip to content

Add wavelength calibration with lamps of known lines - #5

Open
berameric wants to merge 2 commits into
mainfrom
feat/wavelength-calibration
Open

berameric wants to merge 2 commits into
mainfrom
feat/wavelength-calibration

Conversation

@berameric

Copy link
Copy Markdown
Owner

What and why

Corrects the instrument's factory wavelength calibration with a lamp of known lines, in two clicks: choose the source, check the matched lines, Apply.

  • Where: a new Wavelength stage in the processing bar (factory / ±10 pm); its popover shows the calibration in use, Calibrate… and Use factory. On phones the tile shows λ.
  • Sources: fluorescent room light (Hg lines), mercury-argon lamp, neon lamp, lasers (He-Ne, Ar⁺, Kr⁺), or own lines typed in. Air wavelengths from NIST ASD.
  • Matching (src/analysis/calibration.js, pure): every peak–line pair proposes a shift (±5 nm, ±10 nm for one line); the shift pairing the most lines wins, then the pairing is refined with the fitted correction; lines far off the fit are rejected.
  • Model: Δλ polynomial added to the factory axis: offset (1 line), linear (2–3), quadratic (≥4). Per-line error in pm, RMS, shift at 400/550/700 nm. Saturated, weak and off-the-fit lines are marked; any line can be unticked or its value edited.
  • Kept per instrument (model + serial) in the browser, applied on connect; recorded in the CSV header (with coefficients) and the PNG footer. Nothing is written to the instrument.
  • Mock: the simulated HDX now reports wavelengths off by 0.35–0.65 nm and has argon lines.

How it was tested

  • npm test passes; new tests/test_web_calibration.mjs (Hg-Ar and fluorescent spectra through a drifted axis, outlier rejection, edge cases)
  • Simulated HDX in headless Chrome, desktop and phone layout: Hg-Ar → 13 lines, quadratic, RMS 10–15 pm, recovered shift +346/+444/+615 pm against the simulated +349/+450/+619 pm; 546.074 nm line reads 546.078 after Apply; no console errors
  • On a real instrument: not yet. To be tested on the HDX with the fluorescent room light before merging.

Checklist

  • Independent of other open pull requests
  • No build step or dependencies; analysis code free of DOM access
  • Colours from the CSS tokens
  • Driver unchanged

🤖 Generated with Claude Code

A Wavelength stage in the processing bar opens a calibration dialog. Spektra
detects the peaks of the spectrum on screen, matches them to the lines of the
chosen source (fluorescent light, mercury-argon, neon, a laser line or the
user's own lines) and fits a correction on top of the factory calibration:
offset for one line, linear for two or three, quadratic from four. Each line
shows its error and can be unticked or edited; lines far off the fit,
saturated or weak are marked.

The correction is kept per instrument in the browser, applied on connect and
written to the CSV header and the PNG footer. Nothing is written to the
instrument. The simulated HDX reports slightly drifted wavelengths and has
argon lines, so the feature can be tried without hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Broad bands, such as the phosphor of a white LED, and noise ripples on top of
them could be detected as peaks and paired with a reference line by chance.
Peaks wider than 5 nm FWHM are no longer considered, and the message for no
match mentions that a white LED has no narrow lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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