PixelRefine: checkpoint before cleanup (factored model + all diagnostic levers)

Snapshot of the messy state: factored likelihood Terms 1+2+3 behind PR_*
env flags (PR_INTENSITY/PR_SHAPE/PR_RECENTER) alongside the old per-pixel
ShoeboxResidual, plus diagnostic scaffolding (PR_R0/R1/COV/FIX_R0/FIX_R/
ADAPT_R1/CENTROID/RECENTER) and the FACTORED_MODEL.md spec. Next commit
makes Terms 1+2 the model and strips all of this.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-13 21:34:33 +02:00
co-authored by Claude Opus 4.8
parent c93d381dc8
commit 6f2033db00
4 changed files with 601 additions and 8 deletions
+34
View File
@@ -446,6 +446,28 @@ bool IndexAndRefine::PixelRefineIntegrate(DataMessage &msg,
if (const auto bw = experiment.GetBandwidthFWHM())
prd.bandwidth = bw.value() / 2.3548; // FWHM -> sigma
// TEMPORARY diagnostic knobs to probe the effect of the (currently fixed) spot
// widths R[0] (radial/partiality) and R[1] (tangential/profile). Remove after.
if (const char *r0 = std::getenv("PR_R0")) prd.R[0] = std::stod(r0);
if (const char *r1 = std::getenv("PR_R1")) prd.R[1] = std::stod(r1);
// TEMPORARY: PR_COV refines G,B,R and dumps their per-image correlation matrix.
if (std::getenv("PR_COV")) {
prd.refine_scale = true; prd.refine_B = true; prd.refine_R = true;
prd.compute_covariance = true;
}
if (std::getenv("PR_FIX_R0")) prd.fix_R0 = true; // hold R0, refine R1 only
if (std::getenv("PR_FIX_R")) prd.refine_R = false; // hold R0 and R1: G-B correlation only
if (std::getenv("PR_ADAPT_R1")) prd.adaptive_R1 = true; // measure R1 from spot moments
if (std::getenv("PR_CENTROID")) prd.measure_centroid = true; // observed-vs-predicted offset
if (std::getenv("PR_RECENTER")) prd.recenter_profile = true; // recentre profile on centroid
if (const char *s = std::getenv("PR_RECENTER_SIGNIF")) prd.recenter_min_signif = std::stod(s);
if (std::getenv("PR_INTENSITY")) { // factored-likelihood Term 1: per-reflection intensity residual
prd.intensity_residual = true;
prd.refine_orientation = false; prd.refine_R = false;
prd.refine_scale = true; prd.refine_B = true;
}
if (std::getenv("PR_SHAPE")) prd.shape_R1 = true; // Term 2: per-resolution R1 from spot moments
std::vector<uint8_t> buffer;
const uint8_t *ptr = image.GetUncompressedPtr(buffer);
switch (image.GetMode()) {
@@ -465,6 +487,18 @@ bool IndexAndRefine::PixelRefineIntegrate(DataMessage &msg,
return false;
}
if (prd.covariance_valid)
fprintf(stderr, "[cov] GB=%.3f GR0=%.3f GR1=%.3f BR0=%.3f BR1=%.3f R0R1=%.3f\n",
prd.corr_GB, prd.corr_GR0, prd.corr_GR1, prd.corr_BR0, prd.corr_BR1, prd.corr_R0R1);
if (prd.adaptive_R1)
fprintf(stderr, "[R1] %.5f\n", prd.R[1]);
if (prd.shape_R1 && std::isfinite(prd.shape_R1_lores))
fprintf(stderr, "[shapeR1] lores=%.5f hires=%.5f\n", prd.shape_R1_lores, prd.shape_R1_hires);
if (prd.measure_centroid && std::isfinite(prd.centroid_lo_tang_c))
fprintf(stderr, "[res] lo_s=%.1f lo_tc=%.3f lo_tp=%.3f lo_rc=%.3f hi_s=%.1f hi_tc=%.3f hi_tp=%.3f hi_rc=%.3f\n",
prd.centroid_lo_signif, prd.centroid_lo_tang_c, prd.centroid_lo_tang_p, prd.centroid_lo_rad_c,
prd.centroid_hi_signif, prd.centroid_hi_tang_c, prd.centroid_hi_tang_p, prd.centroid_hi_rad_c);
// PixelRefine output flows into the normal save/merge path: the refined
// geometry/lattice and the already-scaled reflections become the outcome.
i_outcome.reflections = std::move(prd.reflections);