Skip to content

Exclude unpopulated lag bins from plateau and half-power lag - #40

Merged
richteague merged 2 commits into
masterfrom
fix-plateau-empty-lag-bins
Aug 18, 2026
Merged

Exclude unpopulated lag bins from plateau and half-power lag#40
richteague merged 2 commits into
masterfrom
fix-plateau-empty-lag-bins

Conversation

@richteague

Copy link
Copy Markdown
Collaborator

Unpopulated lag bins were being treated as real measurements when locating the
structure-function plateau and the half-power lag, biasing both heuristics.
This excludes empty bins from those calculations.

Also includes the fix from #37 (ValueError in
StructureFunction2DStack.calculate_modal_power, which this branch builds on
— merging this supersedes that PR.

🤖 Generated with Claude Code
EOF
)

richteague and others added 2 commits August 6, 2026 11:17
calculate_modal_power unpacked two values from the stack's fit_spiral,
which returns three (popts, perrs, model_fns), so every call raised
"too many values to unpack (expected 2)". The method had no test
coverage and no in-repo caller, so the breakage went unnoticed when
fit_spiral gained its per-ring model_fns return.

Discard the third element; behaviour is otherwise unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`_s2_kernel` leaves a lag bin with no finite pairs at its initialized
0.0, which is indistinguishable from a genuine S2 = 0. `plateau()`
pooled those bins into its outer-lag median, so any annulus whose lag
range runs off the grid -- or into a deprojection mask -- reported a
plateau pulled towards zero, and with it a correspondingly short
half-power lag.

Adds `counts_x`/`counts_y` and a `_populated_slice(axis)` helper that
masks zero-count bins to NaN, routed through `plateau()` and
`half_power_lag()` so `plateaus`, `half_power_lags`,
`reliability_weight('neff')` and `measure_heuristics` all inherit it.
`half_power_lag` also guards the interpolation when the bin below the
crossing is itself empty.

`fit_GRF` has always masked the same bins (`counts > 0`), so this only
brings the model-free path into line with the fitted one; GRF fits are
unchanged.

Measured on a 60-annulus polar grid where 30 annuli carry empty radial
bins, the noise-free heuristic bias against truth goes

  ell_r      -0.022 -> +0.016
  ell_s      -0.024 -> +0.015
  alpha_r    -0.465 -> +0.007
  alpha_phi  -0.499 -> +0.014

The residual on ell_r is the sqrt(2 ln 2) = 1.177 half-power factor.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@richteague
richteague merged commit 6d6026b into master Aug 18, 2026
3 checks passed
@richteague
richteague deleted the fix-plateau-empty-lag-bins branch August 18, 2026 15:27
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