Repository navigation
fix: express pixelized source flux per data pixel in the latents - #728
Merged
Merged
Conversation
`_pixelized_source_flux` (PR #727) returned the plain surface integral `sum_i s_i A_i` over the source mesh, but every other flux latent in the module is a sum over data pixels (`integral / A_pix`), and the reconstruction `s_i` is in those per-data-pixel units. The pixelized `magnification` therefore scaled with the data's pixel scale: on the Euclid pipeline's 0.1"/pixel simulated dataset it came out 1095, exactly 100x the plausible 10.95. The 1" fixtures have `A_pix = 1`, which hid it. Divide by the data pixel area read from `fit.dataset.grids.lp` (the grid the light-profile term is evaluated on), a Python float so the jit path is unaffected; NaN plus one warning if no pixel area resolves. Docstrings state the convention. Tests: the existing pixelized tests state `sum(s A) / A_pix`; a fit at 0.5"/pixel pins the division (4.561 -> 1.140, exactly the pixel-area factor); an unresolvable pixel area gives NaN and one warning; a fixed-field-of-view scene observed at 0.4" and 0.2" gives magnifications within a factor 2 of each other, which the undivided value violated by 4x. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011kyfKgDB1rMkcQsn19ow4T
This was referenced Sep 5, 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.
Summary
Correction to #727 (part of #726).
_pixelized_source_fluxreturned the plain surface integralΣᵢ sᵢ Aᵢover the source mesh, but every other flux latent inautolens/analysis/latent.pyis a sum over data pixels (∫ I d²θ / A_pix), and the reconstructionsᵢis in those per-data-pixel units (the mapping matrix mapssonto image-pixel values). The pixelizedmagnificationtherefore scaled with the data's pixel scale: on the Euclid pipeline's 0.1"/pixel simulated dataset it came out 1095, exactly 100× the plausible 10.95 (the Sersic control on the same scene is 15.15). PyAutoLens' fixtures use 1" pixels (A_pix = 1), which is why #727's tests could not see it.The helper now divides by the data pixel area read from
fit.dataset.grids.lp— the same grid the light-profile flux term is evaluated on, so both terms oftotal_source_fluxshare one convention.Grid2D.pixel_areais a Python float, so the per-samplejax.jitlatent path is unaffected. If no pixel area resolves (nopixel_area, nopixel_scaleson the grid or dataset) the helper returns NaN with a once-per-process warning rather than a silently unscaled number. Docstrings on_pixelized_source_flux,total_source_flux,total_source_flux_mujyandmagnificationstate the convention and why the ratio is then the physical∫ I d²θ / ∫ S d²β.Measured after the fix on the Euclid
euclid_dr1_likescene (Delaunay, 150 Hilbert + 30 edge points, PyPI autoarray's Voronoi areas):magnification10.95,total_source_flux1.257 (Sersic control 15.15 / 0.868). The accuracy check against truth stays the human acceptance step on #726.API Changes
Changed behaviour, no signature changes:
total_source_flux,total_source_flux_mujyandmagnificationfor a pixelized source are nowΣ sᵢAᵢ / A_pixbased rather thanΣ sᵢAᵢ— a factor1/A_pix(100× at 0.1"/pixel) relative to fix: magnification latent finite for pixelized sources #727, which was never released. Light-profile-only fits and 1"/pixel data are numerically unchanged.See full details below.
Test Plan
test_autolens/analysis/test_latent.py: 34 passed (3 new — a rectangular pixelized fit at 0.5"/pixel pinsΣ sA / 0.25(4.561 → 1.140, exactly the pixel-area factor); an unresolvable pixel area gives NaN and exactly one warning; a fixed-field-of-view Sersic-behind-isothermal scene observed at 0.4" and 0.2" gives pixelized magnifications within a factor 2 of each other (48.97 / 61.22), which the undivided value violated by 4×). With the division reverted exactly the two value-bearing tests fail.python -m pytest test_autolens/ -n auto: 620 passed, 1 xfailedFull API Changes (for automation & release notes)
Added
autolens.analysis.latent._data_pixel_area(fit) -> Optional[float]— private helper;fit.dataset.grids.lp.pixel_area, falling back to the product ofpixel_scaleson the grid then the dataset;Noneif none resolves.Changed
autolens.analysis.latent._pixelized_source_flux(fit, xp=np)— returnsΣ sᵢAᵢ / A_pix(wasΣ sᵢAᵢin fix: magnification latent finite for pixelized sources #727); NaN + one warning whenA_pixcannot be resolved.total_source_flux,total_source_flux_mujy,magnification— pixelized-source values rescaled by1/A_pixaccordingly; unchanged for light-profile-only sources.Removed
Migration
Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code
https://claude.ai/code/session_011kyfKgDB1rMkcQsn19ow4T
Generated by Claude Code