Skip to content

Use inverse-variance weights in the phase-slope regression - #346

Merged
benjaminpope merged 1 commit into
SAIL-Labs:mainfrom
benjaminpope:fix-phase-error-weights
Oct 8, 2026
Merged

benjaminpope merged 1 commit into
SAIL-Labs:mainfrom
benjaminpope:fix-phase-error-weights

Conversation

@benjaminpope

Copy link
Copy Markdown
Collaborator

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):

  • `niriss_fft`: 9.7e-5
  • `niriss_gauss`: 8.3e-5
  • `vampires_g18` (synthetic, large pistons so `phs_v2corr` ~0.04-0.6 and very sensitive): 10.4 (range of values 0.04-0.60 before, 0.13-0.70 after)

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

_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>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 01:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@benjaminpope
benjaminpope merged commit 6caa6d6 into SAIL-Labs:main Oct 8, 2026
11 checks passed
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.

2 participants