Skip to content

fix(chirp): background baseline mean skips NaNs (chirp-edge rows wiped whole columns) - #62

Merged
garrekstemo merged 1 commit into
mainfrom
fix-background-nan-mean
Jul 27, 2026
Merged

fix(chirp): background baseline mean skips NaNs (chirp-edge rows wiped whole columns)#62
garrekstemo merged 1 commit into
mainfrom
fix-background-nan-mean

Conversation

@garrekstemo

Copy link
Copy Markdown
Owner

Bug

With a background correction downstream of correct_chirp (QPSLab orders chirp first), every wavelength column with a negative chirp shift came back fully NaN — 409/512 display columns null on a real S1.5 dataset.

correct_chirp NaN-fills samples shifted past the time-axis edges. For negative shifts that NaN region is at the start of the axis — exactly inside typical pre-pump baseline windows (e.g. −20…0 ps). subtract_background computed the per-column baseline with a plain mean, so a single NaN row poisoned the entire column via data .- baseline'. Positive-shift columns survived only because their NaN row is at the end of the axis, outside the window.

Fix

  • subtract_background(::TimeResolvedMatrix): baseline is now the per-column mean over finite values only. A window with no finite values yields a NaN baseline (the column stays NaN — no background is determinable) and emits a warning.
  • _auto_baseline_range: row means skip NaNs, and NaN gradients are scored -Inf so they cannot win the onset argmax (previously a NaN would, since isless sorts NaN last).
  • Version 0.1.2 → 0.1.3.

Tests

  • Chirp (+1/−1 ps shifts, sign flip mid-axis) + explicit-window background: no fully-NaN columns, finite samples subtract exactly, chirp NaNs pass through untouched.
  • All-NaN window: warning emitted, affected column NaN, other columns exact.
  • Auto-range path on a chirped step-onset matrix: finite range, no fully-NaN columns, pre-pump rows ≈ 0.

Full suite: 1899/1899 pass locally.

QPSLab will pin [compat] OpticalSpectroscopy = "0.1.3" and add an end-to-end regression test on its side.

🤖 Generated with Claude Code

correct_chirp NaN-fills samples shifted past the time-axis edges — for
columns with a negative polynomial shift that lands at the START of the
axis, inside typical pre-pump baseline windows. subtract_background's
plain per-column mean then turned one NaN row into an all-NaN column,
wiping every negative-shift wavelength from the corrected matrix
(observed in QPSLab: 409/512 display columns fully null with a
background + chirp pipeline).

- subtract_background: per-column mean over finite values only; a window
  with no finite values gets a NaN baseline plus a warning.
- _auto_baseline_range: NaN-skipping row means and a NaN-proof argmax so
  chirp-edge rows cannot blank the onset search.
- Tests: chirp+background combo leaves no fully-NaN columns (explicit
  and auto t_range) and the all-NaN-window warning path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@garrekstemo
garrekstemo merged commit 8c30ed7 into main Jul 27, 2026
3 checks passed
@garrekstemo
garrekstemo deleted the fix-background-nan-mean branch July 27, 2026 09:29
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