Skip to content

feat: Delaunay source plots — add the likelihood's interpolated view #700

Closed

Description

@Jammy2211

Overview

Delaunay/KNN source reconstructions are plotted as flat-shaded triangles (tripcolor, one colour per triangle). That shows where the mesh spends resolution, but it is not the piecewise-linear (barycentric) interpolant the likelihood evaluates between vertices — reported on PyAutoLabs/.github#46 with a minimal example (true Sersic at the vertices of a Hilbert-Delaunay mesh). This task keeps the triangles as the default, adds an interpolated view built from the mapper's own interpolator, always shows it in inversion_#.png, and adds an off-by-default config switch to show it in the lens fit.png.

Plan

  • Keep flat-shaded triangles as the default source plot; reword the _plot_delaunay docstring to say plainly they show mesh resolution, not the between-vertex interpolant.
  • Add an interpolated view: a fresh interpolator of the mapper's own type (same mesh, mesh_grid), data_grid = a uniform plot grid over the panel extent (~400x400 default, configurable), evaluated and drawn with imshow — exactly the interpolant the likelihood uses. KNN and DelaunayNN mappers use their own interpolants; log colour scales supported; rectangular meshes skip cleanly.
  • inversion_#.png: panel 11 "Source Reconstruction (Interpolated)" always appears for Delaunay/KNN/NN meshes.
  • fit.png (PyAutoLens only — autogalaxy's fit.png has no source panel): new fit: subplot_fit_source_interpolated: false switch; when on, imaging panel 7 (mid zoom) and interferometer panel 7 (zoomed) are drawn as "Source Plane (Interpolated)". Layout unchanged.
  • Config pattern as in the Oct 2026 point-figure work: key + # ...? comment in library plots.yaml (PyAutoLens, PyAutoArray fit: section), read via should_plot(name) in the imaging and interferometer fit plotters, then mirrored into autolens_workspace, autolens_workspace_test, HowToLens, autolens_assistant, autolens_visualization (libraries first).
  • Tier: judge — effective level: supervised; merge mode: human /prm.
Detailed implementation plan

Affected Repositories

  • PyAutoArray (primary)
  • PyAutoLens
  • Workspace mirrors (config only, after library PRs): autolens_workspace, autolens_workspace_test, HowToLens, autolens_assistant, autolens_visualization

Branch Survey

Repository Current Branch Dirty?
PyAutoArray main clean (fresh cloud clone)
PyAutoLens main clean (fresh cloud clone)

Shared claims (human-approved, no file overlap): PyAutoArray with galaxy-duplicate-pytree-registration (autoarray/abstract_ndarray.py only); autolens_workspace with cluster-regime-narrative (scripts/cluster/ only).

Suggested branch: feature/delaunay-interpolated-plot

Implementation Steps

  1. autoarray/plot/inversion.py
    • interpolated_values_from(mapper, pixel_values, extent, shape_native): build type(mapper.interpolator)(mesh=..., mesh_grid=..., data_grid=Grid2D.from_extent(extent, shape_native), adapt_data=...) with numpy; evaluate sum(weights * recon[mappings]) from the sparse mappings/weights in chunks (no dense mapping matrix, so large meshes and grids stay cheap); pixels outside the mesh convex hull → NaN (transparent) so nearest-vertex extrapolation is not drawn as source.
    • plot_inversion_interpolated(...): imshow with the same extent / norm (norm_from, log10) / colorbar conventions as the triangle panel; returns without drawing for rectangular interpolators.
    • Reword the _plot_delaunay docstring.
  2. autoarray/inversion/plot/inversion_plots.py subplot_of_mapper: panel 11 = interpolated reconstruction, titled "Source Reconstruction (Interpolated)"; grid size from visualize config (default 400).
  3. autoarray/inversion/plot/mapper_plots.py: plot_mapper(..., interpolated=False) passthrough so downstream callers can request it.
  4. autoarray/config/visualize/plots.yaml: fit: subplot_fit_source_interpolated: false # In fit.png, draw the mid-zoom source panel as the interpolated reconstruction the likelihood uses (Delaunay/KNN meshes), instead of flat triangles?
  5. PyAutoLens autolens/imaging/plot/fit_imaging_plots.py and autolens/interferometer/plot/fit_interferometer_plots.py: _plot_source_plane(..., interpolated=False); subplot_fit(..., source_interpolated=False) redraws panel 7.
  6. PyAutoLens autolens/imaging/model/plotter.py, autolens/interferometer/model/plotter.py: pass should_plot("subplot_fit_source_interpolated"); add the key to autolens/config/visualize/plots.yaml.
  7. Workspace mirrors of the key/comment/default (after library PRs merge).

Witness / testing

  • Unit tests: interpolated values equal the fresh interpolator's mapping_matrix @ reconstruction on a small plot grid (Delaunay, KNN, NN); log-scale case; rectangular skip; panel 11 title present; lens subplot_fit switch changes panel 7.
  • Reporter's minimal example (true Sersic at Hilbert-Delaunay vertices): interpolated panel matches the analytic interpolant.
  • Laptop follow-ups (cannot run in the cloud session that opened this — no LFS datasets / gallery harness / worktrees): workspace smoke for the affected workspaces; re-render the Delaunay figures in autolens_visualization / autogalaxy_visualization.

Key Files

  • autoarray/plot/inversion.py — interpolated view + docstring
  • autoarray/inversion/plot/inversion_plots.py — inversion_#.png panel 11
  • autolens/imaging/plot/fit_imaging_plots.py, autolens/interferometer/plot/fit_interferometer_plots.py — fit.png panel 7
  • autolens/imaging/model/plotter.py, autolens/interferometer/model/plotter.py — config read
  • config/visualize/plots.yaml (libraries + workspaces)

Original Prompt

Click to expand starting prompt

Delaunay source plots: show the piecewise-linear interpolant the likelihood uses

Type: feature
Target: autoarray
Repos:

From @Lasloruhberg on hub #46 (Bugs & Errors, 2026-11-13, with a minimal script and figure).

What

autoarray/plot/inversion.py _plot_delaunay draws Delaunay/KNN reconstructions with
ax.tripcolor default flat shading: one colour per triangle (mean of its vertices). Its
docstring now justifies this (the area integral per triangle equals the linear interpolant's),
but the figure is blocky and is not the reconstruction the likelihood uses between vertices.
The reporter's example: a perfect source (true Sersic at the mesh vertices) is visibly
misrepresented by the plot.

Design decided by the human on 2026-11-17 (and promised to the reporter on #46,
PyAutoLabs/.github#46 (comment)):

  • Keep flat-shaded triangles as the default source plot. They show how much resolution the
    mesh spends where: small triangles mean fine structure is being resolved, which an
    interpolated image hides. Fix the docstring/tutorial wording so it says this plainly.
  • Add the interpolated view (reporter's method: evaluate the mapper's own interpolator on a
    uniform plotting grid over the source extent, via a fresh interpolator of the same type,
    mesh and mesh_grid, with data_grid = the plot grid, then imshow), so the figure is
    exactly the barycentric interpolant the likelihood uses.
  • inversion_#.png: the interpolated reconstruction always appears as an extra panel.
  • fit.png: a visualization-config switch, off by default, to show the interpolated
    panel as well.
  • Mind cost for big meshes (default grid ~400x400, configurable), KNN mappers (their own
    interpolant) and log colour scales.

Witness

The reporter's minimal example (true Sersic on a Hilbert-Delaunay mesh) shows the plot matching
the interpolant, and the autolens_visualization / autogalaxy_visualization Delaunay figures are
re-rendered and look right.

Activity

  1. Jammy2211 commented on Nov 17, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PRs created

    API changes: added only (new kwargs, helpers and config keys). Nothing is removed or renamed.

    Evidence (cloud session):

    • autoarray: 2399 passed. autolens: 1008 passed.
    • The reporter's Sersic / Hilbert-Delaunay example: the interpolated panel equals the likelihood's mapping_matrix @ recon to 1.8e-15.
    • Published Heart board GREEN.

    Next: /start_workspace, to mirror subplot_fit_source_interpolated into autolens_workspace, autolens_workspace_test, HowToLens, autolens_assistant and autolens_visualization. These are config-only changes and merge after the library PRs.

    Laptop follow-ups, not yet run (the cloud session has no LFS datasets or gallery harness):

    1. Workspace smoke runs for the affected workspaces.
    2. Re-render the Delaunay figures in autolens_visualization and autogalaxy_visualization, and check them.

    Merge mode: human /prm (judge tier).


    Generated by Claude Code

  2. Jammy2211 commented on Nov 17, 2026

    @Jammy2211
    CollaboratorAuthor

    Workspace PRs open (merge after the library PRs)

    Each one mirrors fit: subplot_fit_source_interpolated: false (same comment and default) into config/visualize/plots.yaml:

    The autogalaxy workspaces were not mirrored: the switch is lens-only, because autogalaxy's fit.png has no source panel.

    Merge order (human /prm): PyAutoArray#701, then PyAutoLens#864, then the five workspace PRs.

    Laptop follow-ups before close-out:

    1. Workspace smoke runs for autolens_workspace, autolens_workspace_test and HowToLens.
    2. Re-render the Delaunay figures in autolens_visualization and autogalaxy_visualization (the new inversion_#.png panel 11), and check them.

    Generated by Claude Code

  3. Jammy2211 commented on Nov 17, 2026

    @Jammy2211
    CollaboratorAuthor

    Design change (human, 2026-11-17): interpolated panel is on by default

    fit: subplot_fit_source_interpolated now defaults to true.

    Imaging fit.png with a Delaunay/kNN source. The right-hand column, top to bottom, is:

    1. Max Zoom (flat triangles);
    2. No Zoom (flat triangles);
    3. Interpolated (bottom right), drawn over the max-zoom extent.

    The mid-zoom panel is gone in this layout. Setting the key to false, or using a rectangular or parametric source, restores max / mid / no zoom.

    Interferometer fit.png has only two source panels:

    • default: Zoomed (triangles) and Interpolated (bottom right);
    • false: zoomed and no zoom;
    • array-free 2×3 layout: the interpolated view goes in its empty last panel.

    Changes and tests:


    Generated by Claude Code

  4. Jammy2211 commented on Nov 18, 2026

    @Jammy2211
    CollaboratorAuthor

    Laptop follow-ups: smoke tests, re-renders and the agreed layout changes

    The cloud session couldn't run the smoke tests or the figure re-renders. I ran both on the laptop. Reviewing the figures led to some layout changes, which are now pushed to the same branches.

    Decision (human, 2026-11-18): fit: subplot_fit_source_interpolated defaults to true (interpolated view on). The human has also approved the re-rendered figures (2026-11-18).

    Changes pushed after review

    Repo Commit Change
    PyAutoArray#701 e8a174a6 Delaunay/KNN inversion_#.png: right column is Source Plane (Max Zoom) / Source Plane (Interpolated) / Source Plane (No Zoom), matching fit.png. The interpolated panel is now square with a full-height colorbar; imshow(aspect="auto") had been resetting the box aspect. Title changed from "Source Reconstruction (Interpolated)" to "Source Plane (Interpolated)". Rectangular inversions are unchanged.
    PyAutoLens#864 1e212b43b Source column in every fit.png: No Zoom is always bottom right, and the middle-right panel is Interpolated (Delaunay/KNN with the key on, max-zoom extent) or Mid Zoom otherwise. fit_log10.png gets the same column. The interferometer fit.png drops Dirty Signal-To-Noise Map; Dirty Model Image moves to panel 2, giving the interferometer the same source column as imaging (Max / Interpolated or Mid / No). Its source panels now share one colour scale: the Interpolated panel had autoscaled to 4.18 against 4.06.
    5 workspace PRs 627a35cb, bee5f24, 9b3cbab, 787cc0a, e99de4c plots.yaml comment for the key updated to the new placement.

    This resolves the known gap filed as draft/feature/autolens/interferometer_fit_png_show_zoomed_no_zoom.md: the interferometer fit.png now shows Max Zoom, Interpolated and No Zoom.

    Library tests after the changes: PyAutoArray test_autoarray 2470 passed, PyAutoLens test_autolens 1032 passed, 1 xfailed.

    Smoke tests (branch libraries, final pushed heads)

    Run with pyauto-heart smoke autolens autolens_test howtolens (isolated cached environments, live branch source) at PyAutoArray e8a174a6, PyAutoLens 1e212b43b, autolens_workspace 627a35cb, autolens_workspace_test bee5f24, HowToLens 9b3cbab.

    Workspace Passed Failed Total
    autolens_workspace (scripts) 42 0 42
    autolens_workspace (notebooks) 2 0 2
    autolens_workspace_test 39 0 39
    HowToLens 41 0 41
    Total 124 0 124

    Two earlier runs, on the original cloud-session heads and on the first round of edits, also gave 124/124. No skips, timeouts or failures.

    Caveat: the laptop's canonical PyAutoNerves, PyAutoFit and PyAutoGalaxy checkouts, which the task bundle links to, were 1, 3 and 6 commits behind origin/main (docs and session commits, plus the PyAutoGalaxy convert helper rename #717). No script failed.

    Figures checked

    Rendered through each gallery's harness (gallery/gallery_run.sh imaging interferometer), both of which passed --check. Each figure was compared pixel for pixel with the same producer run against main PyAutoArray/PyAutoLens and identical sibling libraries.

    • autolens_visualization, imaging Delaunay: fit.png, fit_log10.png and inversion_0_0.png have Max Zoom / Interpolated / No Zoom on a shared scale (0 to 3.21). The interpolated panel covers the max-zoom extent, lines up with the triangle panels and is blank outside the mesh hull.
    • autolens_visualization, interferometer Delaunay: fit.png has Max Zoom / Interpolated / No Zoom, all on 0 to 4.06, with the S/N panel gone. inversion_0_0.png has the new right column. Parametric fit.png has Max / Mid / No Zoom.
    • autogalaxy_visualization, imaging and interferometer Delaunay: inversion_0_0.png has the new right column. These are the only galaxy figures that changed.
    • Controls (scratch copies of the lens imaging producer): a rectangular mesh (all 10 figures pixel-identical to main: old inversion layout, Max/Mid/No fit.png), a KNN mesh (new layouts), and Delaunay with the key false (fit.png back to Max/Mid/No).
    • Across all lens imaging and interferometer figures, exactly 6 changed and 44 are pixel-identical to main.

    Noted, not changed, and all pre-existing on main:

    • the interferometer Max Zoom barely zooms on this reconstruction (zoom_to_brightest), so its three source panels look alike;
    • rectangular panels are not square (_plot_rectangular has the same imshow(aspect="auto") pattern);
    • the rectangular Max Zoom is off-centre, and the rectangular inversion panels 10 and 12 are empty.

    Re-rendered gallery PNGs were not committed.

    Rendered images (laptop)

    • Side-by-side review page (branch vs main): C:\Users\Jammy\Workspace\Science\scratch\delaunay_interpolated_plot_2026-11-18\index.html, images in ...\img\
    • Lens gallery renders: ~/Code/PyAutoLabs-wt/delaunay-interpolated-plot/autolens_visualization/scripts/{imaging,interferometer}/images/visualization/{delaunay,parametric}/

    Next: human /prm, library first (PyAutoArray#701, then PyAutoLens#864, then the 5 workspace PRs).

    🤖 Generated with Claude Code

  5. Jammy2211 commented on Nov 18, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    All seven PRs were merged on 2026-11-18 by human-typed /prm, library first. CI was GREEN on every head.

    PR Merged head
    #701 e8a174a6
    PyAutoLabs/PyAutoLens#864 1e212b43b
    PyAutoLabs/autolens_workspace#678 627a35cb
    PyAutoLabs/autolens_workspace_test#367 bee5f24
    PyAutoLabs/HowToLens#137 9b3cbab
    PyAutoLabs/autolens_assistant#187 787cc0a
    PyAutoLabs/autolens_visualization#19 e99de4c

    What users get:

    • plot_mapper(..., interpolated=True) draws a Delaunay/kNN source reconstruction as the interpolant the likelihood uses.
    • fit.png and fit_log10.png show it in the middle of the right-hand column, between Max Zoom and No Zoom. It is on by default (fit: subplot_fit_source_interpolated: true); false shows Mid Zoom instead.
    • inversion_#.png for Delaunay/kNN meshes has the same Max Zoom / Interpolated / No Zoom column.
    • The interferometer fit.png drops the Dirty S/N panel so it has the same source column.

    Laptop verification is in the comment above: smoke 124/124, and figures pixel-diffed against main and approved by the human.

    PyAutoArray and PyAutoLens are merged but not yet released: they are pending release.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions