Repository navigation
Window the spectrum and the trace independently; fix post_filter for SHG - #29
chrisbrahms wants to merge 14 commits into
Conversation
The fundamental spectrum was windowed by the trace's λm mapped through omega0_scale, so for SHG a trace window cut the spectrum at twice its wavelength and vice versa. load_and_clean now takes lams_lims for the spectrum (default: its full extent) and TraceData offers fundamental_window for windowing the retrieved field. Refs LupoLab#23 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL
apply_post_filter and the retrieve stage passed the trace window lamm_lims to post_filter, which measures it from the fundamental carrier. For SHG the window then lay above the grid and removed the whole spectrum. Both now use TraceData.fundamental_window. Refs LupoLab#22 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL
PreprocParams gains lams_min_nm/lams_max_nm (None: the spectrum's full extent, which is also how older options files read back), seeded from the loaded spectrum and dropped with it. The Prepare stage gets a λs control next to λm. Refs LupoLab#23 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL
auto_third_order_exponent takes trace_window and spectrum_window in place of the shared window, and the marginal-check stage has one control for each. For SHG the spectrum lies an octave below the marginal, so a shared region could not hold both. Refs LupoLab#23 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL
- Reject a spectrum window that is reversed, empty or misses the spectrum, and fall back to the full extent when a replaced spectrum would clamp the kept window to zero width. - Raise on a half-set window in a session; take the PG/SD fallback from the interaction rather than comparing carriers. - Native-grid simulated loads window the field to the signal band. - The retrieve stage's spectral post-filter is off, and says why, when there is no window at the fundamental (SHG without a spectrum). - Regression tests through the session pipeline and the retrieve stage that fail if the trace window is passed again; drop a test that could not fail. - Name which trust window an error refers to; say that PG/SD sessions that narrowed λm lose their spectrum taper on reload. Refs LupoLab#22, LupoLab#23 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL
…0-1000 nm For PG and SD the trace window is the signal's measured support at the fundamental, so the post-filter keeps using it; the spectrum window serves SHG only. A measured spectrum's trust region defaults to its range within 190-1000 nm, as the shared region did, or its full range outside that band. Refs LupoLab#22, LupoLab#23 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL
- The spectrum window check uses filter_spectrum's open band and rejects a window without positive intensity. - The retrieve stage refreshes the spectral post-filter's availability on re-entry, so a re-prepared trace cannot leave it stale. - Text that called λs the post-filter window now says so for SHG only. - A native-grid simulated spectrum's window is its full extent. - Tests for the spectrum trust-window message and the simulated entry. Refs LupoLab#22, LupoLab#23 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
jtravs
left a comment
There was a problem hiding this comment.
Looks good overall. The physics is right, the post-filter fix for #22 is correct, and the regression tests would genuinely fail if the trace window were passed again. A few points, mostly about default windows, before merging.
What's right
fundamental_window. λm for PG/SD (the trace sits at the fundamental and its support bounds the field's) and λs for SHG; the 650 + 1000 nm → 394 nm example is exactly why a doubled λm is not a bound. ReturningNonefor SHG without a spectrum, and disabling the retrieve stage's spectral post-filter with a tooltip, is the honest choice.- The split. The
omega0_scalemapping is gone, the trace taper is unchanged, and_check_spectrum_windowfails loudly on a reversed, empty or dark window. With λs at the spectrum's full extent,filter_spectrum's taper lies outside the data, so "unset" really means "no window". - Tests. Both directions for SHG, an old options file, a half-set window, and regressions through
apply_post_filterand the retrieve stage.
Points to address
-
The marginal check's default spectrum trust region clips spectra that cross 1 µm. A measured spectrum's region is clipped to 190–1000 nm, falling back to the full range only when the spectrum lies wholly outside that band. A 1030 nm Yb spectrum measured on a 900–1100 nm spectrometer gets 900–1000 nm, which cuts off the peak; the predicted marginal and the Auto exponent's target then come from a sliver of one wing. The shared region did the same before, so this is not new, but 190–1000 nm was a heuristic for the trace detector, and the split is the natural moment to drop it for the spectrum. Suggest defaulting the spectrum region to its full range, like Prepare's λs.
-
The two spectrum windows default differently, and one item of #23 is not done. Prepare's λs defaults to the full extent while the marginal check's spectrum region defaults to the clipped band, so noisy wings excluded from the check still reach the spectral regularisation target. #23's to-do says "seed the Prepare windows from them" (from the trust regions); that isn't done and the PR doesn't mention it. Either do it here (after fixing point 1) or say so in the description and open a follow-up issue.
-
PG/SD behaviour changes, which #23 lists under "Must not change".
- With default windows the PG/SD spectrum used to be tapered at the trace's extent; now it is not windowed at all. Usually harmless, since the retrieval grid bounds it.
- A saved session that narrowed λm silently reloads with a different spectrum taper, and sessions carry no version to detect this. It is documented in the changelog and docs, but nothing warns at load time. A cheap alternative: when a file has no
lams_*keys, set λs from λm ×omega0_scaleon read, which reproduces old sessions exactly (SHG included). Maintainer's call whether to migrate or accept the documented change.
-
Small things.
- When the spectrum trust region misses the spectrum, the status reads "No independent spectrum: showing the trace marginal only." There is a spectrum, so the message is misleading (a test asserts that text).
- Some edited paragraphs in
docs/explanation/marginals.md,docs/howto/gui.mdanddocs/howto/marginal_checks.mdwere not re-wrapped and have very long lines. - With the default λs (the spectrometer's full range) the SHG spectral post-filter does essentially nothing. Correct, but the help text could say so.
The auto_third_order_exponent rename and its new spectrum_window default (whole spectrum rather than 210–1000 nm) are correctly described in the breaking fragment.
Drafted with Claude Code.
A measured spectrum's trust region was clipped to the trace detector's 190-1000 nm band, which cut a spectrum crossing 1 um down to one wing. It now defaults to the spectrum's full range, as Prepare's lams does. The status also says which input is missing when there is no summary: no spectrum, no usable spectrum in its trust region, or too little trace marginal in the trace's trust region. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
…graphs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
Bump options_version to 3. A file older than that, with lamm but no lams keys, reads back with lams = lamm x omega0_scale of its loader's interaction, which reproduces the old spectrum taper. A current file omits an unset lams too, so the version tells the two apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
A migrated session has a spectrum window but no bounds, so Prepare showed lams disabled while the window still applied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
|
Thanks for the review. Drafted by Claude (AI) on behalf of the author; the changes are in 70c21b6..c242656.
|
What changed
The spectrum gets its own window (#23).
load_and_clean(..., lams_lims=None)windows the independent fundamental spectrum by its own wavelength range, stored asTraceData.lams_lims. Before, the spectrum was cut by the trace window λm mapped through the interaction's carrier scaling, so an SHG spectrum was cut at twice the trace window.Nonemeans the spectrum's full extent. Sessions gainlams_min_nmandlams_max_nm(default unset), and the Prepare stage gains a λs range control, seeded from the loaded spectrum.post_filterno longer removes an SHG result (#22). The session pipeline and the retrieve stage now window the retrieved field withTraceData.fundamental_window: for SHG, λs (or the full grid when it is unset); for PG and SD, λm as before. Before, SHG was given the trace-domain window, which lies at the second harmonic. A regression test covers SHG; PG and SD keep their behaviour.The marginal check has a trust region for each marginal (#23).
auto_third_order_exponenttakestrace_windowandspectrum_windowin place ofwindow, and the marginal-check stage has two range controls. A measured spectrum's region in the GUI still defaults to 190–1000 nm, or to its full range if it lies wholly outside that band.Behaviour changes users will notice
changed: an SHG spectrum is no longer windowed by 2λm, so its outer wings now reach the spectral regularisation target and the initial guess unless λs is narrowed. This applies to PG and SD too: a saved session that narrowed λm reads back with λs unset (the full spectrum).breaking:auto_third_order_exponent(window=...)becomestrace_window=andspectrum_window=. To reproduce the old behaviour, pass the same window to both.Verification
uv run poe checkon the final commit: ruff, pyright (0 errors), codespell, changelog check, and 1931 tests passed (2 skipped) with 100 % statement and branch coverage.uv run poe docsbuilds without warnings. Updated pages:howto/preprocessing,howto/gui,howto/grids_and_filtering,explanation/marginals,howto/marginal_checks.load_and_cleanwith independent windows in both directions, and a PG case;qtbot.Related
Closes #22. Closes #23. Touches #17 (the marginal-check numerics this changes still live partly in the GUI stage). Dispersive SHG (#24) builds on the λs window.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WM2AxMiUXc12ViRwSf2cyL