Spectroscopy physics review: qPlus setpoint gate, time-axis sanitisation, derivative units#27
Merged
Merged
Conversation
…ative units
Physics review of the spectroscopy package (probeflow/spectroscopy +
io/spectroscopy.py), pinned by tests/test_spectroscopy_physics.py:
- _createc_setpoint_a read Current[A]/SetPoint unconditionally as amps: for
a constant-delta-f qPlus .VERT (PLL on / FBChannel != 0) SetPoint is a
frequency shift in hertz, so metadata carried e.g. setpoint_a = 3.2 "A"
and setpoint normalization silently divided spectra by a frequency
pretending to be a current (~10 orders of magnitude off, no error). The
same bug was fixed for scan metadata earlier; the spectroscopy path now
shares that gate (_createc_feedback_is_current), so a qPlus file reports
no current setpoint and setpoint normalization blocks honestly.
- SpecFreq=0/negative/non-finite turned the whole time-trace x axis into
inf or negative seconds (x = idx / spec_freq). Sanitised to the
documented 1000 Hz missing-value default, with a log warning.
- Derivative unit propagation now mirrors SpectrumDeltaMeasurement.slope_unit:
A/V for the usual case, 1/V when y is unitless ("A/" .rstrip slicing
previously collapsed mixed cases), bare y unit when x is unitless.
Verified clean: pipeline order (smoothing -> derivative -> normalization ->
outliers -> offset, now pinned numerically), monotonicity-guarded
np.gradient(y, x), all four normalization modes raise on bad denominators,
channel-normalization-with-derivative rejected, forward+backward sweeps
refused. Noted unchanged: per-trace span normalization in
nearest_point_across_traces mildly biases cross-trace snapping; jump-mode
outlier masking excludes finite neighbours of NaN samples (defensible).
Co-Authored-By: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Physics/maths correctness review of
probeflow/spectroscopy+io/spectroscopy.py(first dedicated pass over this package).Findings (physics-check format)
[CRITICAL]
io/spectroscopy.py:341— fixedWhat:
_createc_setpoint_areadSetPointunconditionally as amps.Why: on constant-Δf qPlus VERT files
SetPointis a frequency shift in Hz; the value feeds setpoint normalization, silently dividing displayed spectra by a frequency pretending to be a current (~10 orders of magnitude wrong, no error). Same bug class fixed for scan metadata in an earlier round — the spec path never got the gate.Fix: share
_createc_feedback_is_currentwith the scan path; qPlus files report no current setpoint and setpoint normalization now blocks with a clear error.[WARN]
io/spectroscopy.pytime axis — fixedWhat:
x = idx / spec_freqwithSpecFreq=0/negative/non-finite → inf or negative seconds.Fix: sanitise to the documented 1000 Hz missing-value default with a log warning.
[INFO]
spectroscopy/transforms.py:67— fixedWhat: derivative unit built via
f"{y}/{x}".rstrip("/")collapsed empty-unit cases.Fix: mirror
SpectrumDeltaMeasurement.slope_unit(A/V,1/V, or bare y-unit).Verified clean: pipeline order (smoothing→derivative→normalization→outliers→offset, now pinned numerically), monotonicity-guarded
np.gradient(y, x), forward+backward sweep refusal, all normalization denominator guards, channel-norm-with-derivative rejection, unit propagation to "relative", export round-trips.Noted, unchanged: per-trace span normalization in
nearest_point_across_tracesmildly biases cross-trace click snapping; jump-mode outlier masking drops finite neighbours of NaN samples (defensible — their derivative is unknown).Test plan
tests/test_spectroscopy_physics.py(22 tests) covering the header→setpoint seam end-to-end, time-axis sanitisation, unit propagation, and pipeline-order invariants.🤖 Generated with Claude Code