Skip to content

Window the spectrum and the trace independently; fix post_filter for SHG - #29

Open
chrisbrahms wants to merge 9 commits into
LupoLab:mainfrom
chrisbrahms:fix/independent-spectral-windows
Open

chrisbrahms wants to merge 9 commits into
LupoLab:mainfrom
chrisbrahms:fix/independent-spectral-windows

Conversation

@chrisbrahms

@chrisbrahms chrisbrahms commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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 as TraceData.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. None means the spectrum's full extent. Sessions gain lams_min_nm and lams_max_nm (default unset), and the Prepare stage gains a λs range control, seeded from the loaded spectrum.

post_filter no longer removes an SHG result (#22). The session pipeline and the retrieve stage now window the retrieved field with TraceData.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_exponent takes trace_window and spectrum_window in place of window, 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=...) becomes trace_window= and spectrum_window=. To reproduce the old behaviour, pass the same window to both.

Verification

  • uv run poe check on 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 docs builds without warnings. Updated pages: howto/preprocessing, howto/gui, howto/grids_and_filtering, explanation/marginals, howto/marginal_checks.
  • Tests cover:
    • SHG load_and_clean with independent windows in both directions, and a PG case;
    • an old session file without the new keys;
    • the trust-window functions and their error paths;
    • the new GUI controls, driven through qtbot.
  • Two rounds of independent review, with the findings fixed.

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

chrisbrahms and others added 9 commits November 12, 2026 14:52
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
- 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
@chrisbrahms chrisbrahms added bug Something isn't working enhancement New feature or request area: preprocessing Loading, preprocessing, delay origin and marginal checks labels Nov 13, 2026
@read-the-docs-community

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

area: preprocessing Loading, preprocessing, delay origin and marginal checks bug Something isn't working enhancement New feature or request

Projects

None yet

1 participant