Repository navigation
Description
Overview
Phase 1 of making the adapt-mesh-weighting result (PyAutoArray#714) the library default. A new image mesh, image_mesh.HilbertSNR, places Hilbert mesh points by absolute source S/N with a fixed point budget, instead of (adapt / max) ** weight_power, so adaptation no longer depends on how bright the brightest pixel is. A shared soft S/N transform gives AdaptSplit the same signal. Approved by the human at gate 2 (2026-11-26) after fits on 10 HST + 10 COWLS datasets and an offline check from peak S/N 5 to 1000. Hilbert and AdaptSplit keep their behaviour (backward compatibility); workspaces switch to the new default in later phases.
Plan
- Add
image_mesh.HilbertSNR, aHilbertsubclass whose weighting is the approved one;HilbertSNR(pixels=...)with no other arguments gives it. - Add one shared soft S/N transform, used by the mesh and (as the adapt image) by AdaptSplit.
- Document the weighting, why it uses absolute S/N, and its two known limits.
- Unit tests against the science project's reference implementation, a bright compact-source case, and unchanged
Hilbertoutput. - Later phases (own issues): PyAutoGalaxy one-call adapt images (S/N map before the 1% floor + soft AdaptSplit image); every workspace switches to the new default and drops
weight_power=3.5, weight_floor=0.01and the S/N 3 cap. - Tier: effective level: supervised; merge mode: human /prm
Detailed implementation plan
Affected Repositories
- PyAutoArray (primary, this phase)
- PyAutoGalaxy (phase 2, separate issue; currently claimed by likelihood-lifecycle-r6d-prerelease-fixes)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./array/PyAutoArray | main | clean |
| ./galaxy/PyAutoGalaxy | main | clean (claimed by another task) |
Suggested branch: feature/adapt-mesh-weighting
Implementation Steps
autoarray/inversion/mesh/image_mesh/hilbert_snr.py:class HilbertSNR(Hilbert)overriding onlyweight_map_from(called byHilbert.image_plane_mesh_grid_fromon the adapt values along the Hilbert curve,hilbert.py:284). Per cell with S/Ns,x = max(s - snr_noise, 0):p = background_share / n + peak_share * (s / max s) ** peak_power / sum + (1 - background_share - peak_share) * soft / sum(soft),soft = (x / (x + snr_soft)) ** soft_power. Defaultsbackground_share=0.25, peak_share=0.05, peak_power=8.0, snr_noise=2.0, snr_soft=3.0, soft_power=2.0. A blank adapt image (no positive signal) gives an even mesh. Negative adapt values are treated as 0. The deterministic draw, edge points and guards are inherited.autoarray/inversion/mesh/image_mesh/snr_transform.py:soft_snr_from(snr, snr_noise=2.0, snr_soft=3.0, soft_power=2.0)andadapt_image_soft_from(snr, minimum_percent=0.01, ...)(negatives to 0, soft transform, floored at 1% of its maximum: the AdaptSplit input).HilbertSNRusessoft_snr_from.- Export
HilbertSNRfromimage_mesh/__init__.py(reachesag.image_mesh/al.image_mesh), and the transforms from a sensible public place. - Docstrings: formula and knobs; why absolute S/N (peak normalisation put everything below S/N ~67 on the floor at peak 250); the input should be the S/N map before
adapt_minimum_percentflooring (sky reads 2.5 at peak 250 otherwise); known limits (peak ~5: points cluster on the few pixels above S/N 2; very bright sources: points spread evenly over all detected emission). - Tests
test_autoarray/inversion/mesh/image_mesh/test_hilbert_snr.py: probabilities and mesh equal the referencepeak_share(Science/development/adapt_snr_cap/scripts/mesh_weighting.py) on a fixed adapt image;adapt_image_soft_fromequalsregularization_image_from; a compact peak-250 component keeps the sky share near 0.25; blank input;Hilbertmeshes unchanged.
Key Files
autoarray/inversion/mesh/image_mesh/hilbert.py—Hilbert,image_plane_mesh_grid_from, drawautoarray/inversion/mesh/image_mesh/abstract_weighted.py— currentweight_map_fromautoarray/inversion/regularization/adapt_split.py,adapt.py— unchanged (BC)- Evidence:
Science/development/adapt_snr_cap/(scripts/mesh_weighting.py,scripts/slam.py,scripts/snr_range.py,results/snr_range/,wiki/project/state.md)
Original Prompt
Click to expand starting prompt
Adapt mesh weighting: S/N-budget Hilbert mesh and soft adapt image in the library
Type: feature
Target: PyAutoArray
Repos:
- PyAutoArray
- PyAutoGalaxy
Difficulty: large
Autonomy: supervised
Priority: high
Consequence: judge
Parent: active/make_the_source_adapt_image_hilbert_image.md (PyAutoArray#714, task adapt-mesh-weighting)
Filed: 2026-11-26
Library phase of PyAutoArray#714. Research phases 1-2 ran in the science project
~/Science/Science/development/adapt_snr_cap/ (read its AGENTS.md and
wiki/project/state.md). The human approved the result at gate 2 on 2026-11-26 ("looks good, I
approve proceed", on results/snr_range/index.html), after the unified arm was fitted on the
10 HST and 10 COWLS datasets (RAL 416941, 416981) and checked offline from peak S/N 5 to 1000.
The workspace phase (autolens_workspace scripts drop the S/N 3 cap of autolens_workspace #522
and use this default) and the docs are separate prompts, after this one ships.
Scope, as the human set it (2026-11-26)
I approve, can you make this the default everywhere (but keep BC via
Hilbertgreat idea,
ensureAdaptSplitretians BC too), so all workspaces use the new one and a user doesnt need
to supply weight_power=3.5 and weight_floor=0.01 the default always gives this great adaption
image_mesh.HilbertSNR(pixels=...)with no other arguments gives the approved weighting.image_mesh.Hilbertandreg.AdaptSplitkeep their current behaviour and signatures (backward
compatibility); the new behaviour reaches AdaptSplit only through the adapt image it is given.- Every workspace (autolens_workspace, autogalaxy_workspace, HowToLens / HowToGalaxy, the
_testworkspaces where they model with Hilbert) switches to the new default and stops
passingweight_power/weight_floorand the S/N 3 cap.
Phases: (1) PyAutoArray: HilbertSNR + the soft S/N transform; (2) PyAutoGalaxy: one call
giving the unfloored S/N map and the soft AdaptSplit image; (3) workspaces switch (own
prompts); then the science project's slam.py uses the library calls.
What the human approved (the peak_share_unified arm)
Reference implementation: the project's scripts/mesh_weighting.py (peak_share,
soft_term, above_noise, regularization_image_from, image_plane_mesh_grid_from) and
scripts/slam.py (unfloored_source_snr_from, galaxy_name_image_dict_from, source_pix_2).
- Hilbert image-mesh weighting (in place of
w = (|a| / max a) ** 3.5, floored at 0.01),
per Hilbert cell with S/Nsandx = max(s - 2, 0):
p = 0.25 / n + 0.05 * (s / max s) ** 8 / sum(...) + 0.70 * (x / (x + 3)) ** 2 / sum(...):
25% of the points spread evenly over the mask, 5% on cells within about 25% of the peak
S/N, 70% by a soft S/N saturation in absolute S/N (not normalised by the peak). Points are
then drawn by the existing deterministic Hilbert inverse-transform sampling. - AdaptSplit adapt image: the same soft transform pixel by pixel,
(x / (x + 3)) ** 2,
floored at 1% of its maximum, in place of the S/N map (or the S/N map capped at 3).
AdaptSplit itself is unchanged (it still divides by the maximum and raises to its free
signal_scale). - Both from the S/N map before the adapt floor:
galaxy_name_image_dict_via_result_from
floors every adapt image atadapt_minimum_percent(1%) of its maximum; above a peak S/N of
200 that lifts empty sky over the S/N 2 threshold (sky reads 2.5 at peak 250, 10 at 1000) and
breaks both. The S/N map before the floor (it is already cached raw, as
files/galaxy_images_snr.fits), negatives set to 0, is the input. Evidence:
scripts/snr_range.py,results/snr_range/summary.txt.
Open design questions for the plan
- New image-mesh class (e.g.
image_mesh.HilbertSNR, with the six numbers as keyword
arguments) or a new weighting mode onHilbert? A new class keeps every existing pinned
workspace_test value unchanged and old fits reproducible. - Where the soft transform and the unfloored map live in PyAutoGalaxy so a workspace script
needs one call to get both the mesh input and the AdaptSplit image (an option on
galaxy_name_image_dict_via_result_from, or a small helper next to it). Other users of the
floored adapt image (other regularizations, model-image adapt images) keep the floor. - Order against
draft/bug/autoarray/hilbert_image_mesh_frame_independent.md, which changes
the same Hilbert interpolation and re-pins workspace_test values.
Known limits (measured, accepted by the human)
- At peak S/N ~5 most points sit on the few pixels above S/N 2 (median 36 per image pixel over
19 lenses) and the AdaptSplit image has no source/sky contrast. - When the whole source is very bright (peak 250-1000) the mesh spreads evenly over all
detected emission, arcs and faint wings alike (the saturation at S/N ~3).
Done when
- Unit tests: the weighting reproduces the project's
peak_shareprobabilities and meshes on a
test adapt image (to rounding); the soft transform matchesregularization_image_from; the
unfloored input is used; a peak-250 compact-source test keeps the sky share near 0.25. - Existing Hilbert behaviour and pinned values unchanged.
- The project's
slam.pyunified arm can be rewritten to the library calls and gives the same
mesh (0.0 arcsec) on a test-mode lens.
Activity
Jammy2211 commentedon Nov 26, 2026
Library PR Created
pending-release; tier judge, merge by human/prm)API: adds
image_mesh.HilbertSNR(point budget in absolute S/N;HilbertSNR(pixels=...)gives the approved default),image_mesh.soft_snr_fromandimage_mesh.adapt_image_soft_from(the AdaptSplit adapt image).Hilbertand all regularizations unchanged.Evidence: 8 new tests, full
test_autoarray2622 passed; library mesh and adapt image equal the science project's unified arm exactly (test-mode fit, and 15 real lenses).Next: phase 2 PyAutoGalaxy (one call for the unfloored S/N map + soft AdaptSplit image; PyAutoGalaxy currently claimed by likelihood-lifecycle-r6d-prerelease-fixes), then phase 3 workspaces switch to the new default (
/start_workspace).Jammy2211 commentedon Nov 26, 2026
Shipped
cda647d391), awaiting the next release (pending-release).Adds
image_mesh.HilbertSNR(point budget in absolute S/N;HilbertSNR(pixels=...)is the approved default),image_mesh.soft_snr_fromandimage_mesh.adapt_image_soft_from(the AdaptSplit adapt image).Hilbertand all regularizations are unchanged.Remaining phases are filed in Mind as their own prompts: phase 2 PyAutoGalaxy (
draft/feature/autogalaxy/adapt_mesh_weighting_galaxy_adapt_images.md), phase 3 workspaces default toHilbertSNR(draft/feature/autolens_workspace/adapt_mesh_weighting_workspace_default.md).