Repository navigation
Use inverse-variance weights in the phase-slope regression - #346
Merged
Merged
Conversation
_compute_phs_error passed phs["err"] (sigma-like, 1/|dummy|) to regress_noc, which multiplies by its weights, so the noisiest slopes got the most weight. IDL's REGRESS uses 1/sigma^2; do the same. Zero, infinite or non-finite errors get zero weight. Only phs_v2corr changes. Regenerated only the phs_v2corr entries of tests/data/reference_outputs.npz (niriss_fft, niriss_gauss, vampires_g18; the multitri cases do not store it); all other entries are untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 8, 2026
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.
Bug
`_compute_phs_error` passed `phs["err"]` to `regress_noc` as `weights`. `phs["err"]` is sigma-like (`1/|dummy|`), but `regress_noc` uses weights multiplicatively (in `xwx` and `MSE = sum(w*resid^2)/(n-p)`), so the noisiest slopes got the most weight. IDL's `REGRESS` uses `1/sigma^2`.
Fix
Pass `1/err^2` (new helper `_phase_slope_weights`); zero, infinite or non-finite errors get zero weight. New test checks the weights are inverse variances and that a very noisy point barely moves the fit (while it dominates with the old sigma-like weights).
Effect
Only `phs_v2corr` changes; `vis2`, `e_vis2`, `cp`, `e_cp` and every other stored entry are unchanged (to ~1e-14, platform noise). `phs_v2corr` is applied multiplicatively to V^2 in `calibration.py`, so calibrated V^2 changes by the same relative amount.
Max relative change in `phs_v2corr` (and so in calibrated V^2):
Reference data
Regenerated only the `phs_v2corr` entries of `tests/data/reference_outputs.npz` for those three cases (from the old code plus exactly this change); all other entries are unchanged.
🤖 Generated with Claude Code