Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autolens/config/visualize/plots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ positions: # Settings for plots with resampling
fit: # Settings for plots of all fits (e.g. FitImaging, FitInterferometer).
subplot_fit: true # Plot subplot of all fit quantities for any dataset (e.g. the model data, residual-map, etc.)?
subplot_fit_log10: false # Plot subplot of all fit quantities for any dataset using log10 color maps (e.g. the model data, residual-map, etc.)?
subplot_fit_source_interpolated: true # In fit.png, show the interpolated reconstruction the likelihood uses (Delaunay/KNN meshes) in the middle source panel, between max zoom and no zoom? If false, show max, mid and no zoom flat-triangle panels instead.
subplot_of_planes: false # Plot subplot of the model-image, subtracted image and other quantities of each plane?
subplot_galaxies_images: false # Plot subplot of the image of each plane in the model?
fits_fit: true # Output a .fits file containing the fit model data, residual map, normalized residual map and chi-squared?
Expand Down
10 changes: 10 additions & 0 deletions autolens/imaging/model/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def should_plot(name):
source_plane_lines, source_plane_line_colors,
)

# `fit.png` and `fit_log10.png` show the likelihood's interpolant in the
# middle source panel (Delaunay / kNN sources) when this is on (default);
# off restores the mid-zoom panel.
source_interpolated = should_plot("subplot_fit_source_interpolated")

# Quick updates write the normal fit subplot (plain `fit.png`, final
# plane as source) regardless of plane count, so the live display
# always has one canonical filename to refresh.
Expand All @@ -85,6 +90,7 @@ def should_plot(name):
image_plane_lines=ip_lines, image_plane_line_colors=ip_colors,
source_plane_lines=sp_lines, source_plane_line_colors=sp_colors,
title_prefix=self.title_prefix,
source_interpolated=source_interpolated,
)
return

Expand All @@ -98,13 +104,15 @@ def should_plot(name):
image_plane_lines=ip_lines, image_plane_line_colors=ip_colors,
source_plane_lines=sp_lines, source_plane_line_colors=sp_colors,
title_prefix=self.title_prefix,
source_interpolated=source_interpolated,
)
else:
subplot_fit(
fit, output_path=output_path, output_format=fmt,
image_plane_lines=ip_lines, image_plane_line_colors=ip_colors,
source_plane_lines=sp_lines, source_plane_line_colors=sp_colors,
title_prefix=self.title_prefix,
source_interpolated=source_interpolated,
)

if plot_setting(section="tracer", name="subplot_tracer"):
Expand All @@ -125,13 +133,15 @@ def should_plot(name):
image_plane_lines=ip_lines, image_plane_line_colors=ip_colors,
source_plane_lines=sp_lines, source_plane_line_colors=sp_colors,
title_prefix=self.title_prefix,
source_interpolated=source_interpolated,
)
else:
subplot_fit_log10(
fit, output_path=output_path, output_format=fmt,
image_plane_lines=ip_lines, image_plane_line_colors=ip_colors,
source_plane_lines=sp_lines, source_plane_line_colors=sp_colors,
title_prefix=self.title_prefix,
source_interpolated=source_interpolated,
)
except ValueError:
pass
Expand Down
109 changes: 97 additions & 12 deletions autolens/imaging/plot/fit_imaging_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _plot_source_plane(fit, ax, plane_index, zoom_to_brightest=True,
lines=None, line_colors=None, vmax=None,
zoom_extent_scale: float = 1.0,
regions=None, region_alpha: float = 0.25,
region_labels=None):
region_labels=None, interpolated: bool = False):
"""
Plot the source-plane image (or a blank inversion placeholder) into an axes.

Expand Down Expand Up @@ -112,6 +112,11 @@ def _plot_source_plane(fit, ax, plane_index, zoom_to_brightest=True,
The alpha of each region's fill.
region_labels : list of str, optional
A label drawn at the centre of each region, matching its image-plane counterpart.
interpolated : bool, optional
For an inversion source on a Delaunay / kNN mesh, draw the reconstruction the
likelihood uses between mesh vertices (the mapper's own interpolant on a uniform
grid) instead of flat-shaded triangles. Ignored for parametric sources and
rectangular meshes.
"""
tracer = fit.tracer_linear_light_profiles_to_light_profiles
if not tracer.planes[plane_index].has(cls=aa.Pixelization):
Expand Down Expand Up @@ -168,6 +173,7 @@ def _plot_source_plane(fit, ax, plane_index, zoom_to_brightest=True,
vmax=vmax,
zoom_to_brightest=zoom_to_brightest,
zoom_extent_scale=zoom_extent_scale,
interpolated=interpolated,
lines=lines,
line_colors=line_colors,
regions=regions,
Expand All @@ -181,6 +187,25 @@ def _plot_source_plane(fit, ax, plane_index, zoom_to_brightest=True,
ax.set_title(f"Source Reconstruction (plane {plane_index})")


def _source_has_interpolated_view(fit, plane_index) -> bool:
"""
Whether the source at ``plane_index`` is a pixelization whose mesh has an
interpolated view (Delaunay / kNN / natural-neighbour), so a
``source_interpolated`` panel differs from the flat-triangle one.
"""
from autoarray.plot.inversion import mapper_has_interpolated_view

try:
tracer = fit.tracer_linear_light_profiles_to_light_profiles
if not tracer.planes[plane_index].has(cls=aa.Pixelization):
return False
mapper_list = fit.inversion.cls_list_from(cls=Mapper)
mapper = mapper_list[plane_index - 1] if plane_index > 0 else mapper_list[0]
return mapper_has_interpolated_view(mapper)
except Exception:
return False


def subplot_fit(
fit,
output_path: Optional[str] = None,
Expand All @@ -192,6 +217,7 @@ def subplot_fit(
source_plane_lines=None,
source_plane_line_colors=None,
title_prefix: str = None,
source_interpolated: bool = True,
):
"""
Produce a 12-panel subplot summarising an imaging fit.
Expand All @@ -212,6 +238,9 @@ def subplot_fit(
* Chi-squared map
* Source plane image (full extent)

With ``source_interpolated`` (default) and a Delaunay / kNN source, the
mid-zoom panel shows the interpolated reconstruction instead.

For single-plane tracers the function delegates to
:func:`subplot_fit_x1_plane`, which uses a simpler 2 × 3 layout.

Expand All @@ -230,6 +259,14 @@ def subplot_fit(
plane_index : int, optional
Index of the source plane to use for the source-scale panels.
Defaults to the final plane in the tracer.
source_interpolated : bool, optional
When the source is a Delaunay / kNN pixelization, the right-hand source
panels are Source Plane (Max Zoom) as flat triangles, which show the
mesh resolution, then "Source Plane (Interpolated)" -- the
reconstruction the likelihood uses, over the max-zoom extent -- in the
middle, then Source Plane (No Zoom) bottom right. When ``False`` (or for
rectangular / parametric sources) they are max, mid and no zoom. Set by
``plots.yaml`` ``fit: subplot_fit_source_interpolated`` (default ``True``).
"""
if len(fit.tracer.planes) == 1:
return subplot_fit_x1_plane(fit, output_path=output_path,
Expand Down Expand Up @@ -261,6 +298,16 @@ def subplot_fit(
plot_array(array=fit.signal_to_noise_map, ax=axes_flat[2],
title=_pf("Signal-To-Noise Map"), colormap=colormap)

# The right-hand column holds the three source panels. With
# `source_interpolated` (the default) and an irregular-mesh source they are:
# max zoom (3) as flat triangles, which show the mesh resolution, the
# likelihood's interpolant (7) over the max-zoom extent, so it compares
# directly with panel 3, and no zoom (11). Otherwise (switch off, or a
# rectangular / parametric source) they are max, mid and no zoom.
interpolated = source_interpolated and _source_has_interpolated_view(
fit, final_plane_index
)

# Source plane (max zoom)
_plot_source_plane(fit, axes_flat[3], final_plane_index, zoom_to_brightest=True,
colormap=colormap, title=_pf("Source Plane (Max Zoom)"),
Expand Down Expand Up @@ -302,11 +349,19 @@ def subplot_fit(
else:
axes_flat[6].axis("off")

# Source plane (mid zoom) — same centre as Max Zoom, 2.5x wider extent
_plot_source_plane(fit, axes_flat[7], final_plane_index, zoom_to_brightest=True,
colormap=colormap, title=_pf("Source Plane (Mid Zoom)"),
lines=source_plane_lines, line_colors=source_plane_line_colors,
vmax=source_vmax, zoom_extent_scale=2.0)
if interpolated:
# The reconstruction the likelihood uses, over the max-zoom extent (the
# mid-zoom panel is replaced, see above)
_plot_source_plane(fit, axes_flat[7], final_plane_index, zoom_to_brightest=True,
colormap=colormap, title=_pf("Source Plane (Interpolated)"),
lines=source_plane_lines, line_colors=source_plane_line_colors,
vmax=source_vmax, interpolated=True)
else:
# Source plane (mid zoom) — same centre as Max Zoom, 2.5x wider extent
_plot_source_plane(fit, axes_flat[7], final_plane_index, zoom_to_brightest=True,
colormap=colormap, title=_pf("Source Plane (Mid Zoom)"),
lines=source_plane_lines, line_colors=source_plane_line_colors,
vmax=source_vmax, zoom_extent_scale=2.0)

# Normalized residual map (symmetric)
norm_resid = fit.normalized_residual_map
Expand Down Expand Up @@ -410,6 +465,7 @@ def subplot_fit_log10(
source_plane_lines=None,
source_plane_line_colors=None,
title_prefix: str = None,
source_interpolated: bool = True,
):
"""
Produce a 12-panel subplot summarising an imaging fit with log10 colour scaling.
Expand All @@ -423,6 +479,10 @@ def subplot_fit_log10(
kept square and shrunk uniformly so all edges stay inside the No Zoom
extent.

With ``source_interpolated`` (default) and a Delaunay / kNN source, the
right-hand column matches :func:`subplot_fit`: Source Plane (Max Zoom),
Source Plane (Interpolated) and Source Plane (No Zoom), all log10.

For single-plane tracers the function delegates to
:func:`subplot_fit_log10_x1_plane`.

Expand All @@ -440,6 +500,14 @@ def subplot_fit_log10(
plane_index : int, optional
Index of the source plane to use for the source-scale panels.
Defaults to the final plane in the tracer.
source_interpolated : bool, optional
When the source is a Delaunay / kNN pixelization, the right-hand source
panels are Source Plane (Max Zoom) as flat triangles, then "Source Plane
(Interpolated)" -- the reconstruction the likelihood uses, over the
max-zoom extent -- in the middle, then Source Plane (No Zoom) bottom
right. When ``False`` (or for rectangular / parametric sources) they are
max, mid and no zoom. Set by ``plots.yaml``
``fit: subplot_fit_source_interpolated`` (default ``True``).
"""
if len(fit.tracer.planes) == 1:
return subplot_fit_log10_x1_plane(fit, output_path=output_path,
Expand Down Expand Up @@ -475,6 +543,14 @@ def subplot_fit_log10(
except ValueError:
axes_flat[2].axis("off")

# The right-hand column holds the three source panels, as in `subplot_fit`:
# max zoom (3), the likelihood's interpolant (7) and no zoom (11) for an
# irregular-mesh source with `source_interpolated`; otherwise max, mid and
# no zoom.
interpolated = source_interpolated and _source_has_interpolated_view(
fit, final_plane_index
)

# Source plane (max zoom)
_plot_source_plane(fit, axes_flat[3], final_plane_index, zoom_to_brightest=True,
colormap=colormap, use_log10=True,
Expand Down Expand Up @@ -504,12 +580,21 @@ def subplot_fit_log10(
except (IndexError, AttributeError):
axes_flat[6].axis("off")

# Source plane (mid zoom) — same centre as Max Zoom, 2.5x wider extent
_plot_source_plane(fit, axes_flat[7], final_plane_index, zoom_to_brightest=True,
colormap=colormap, use_log10=True,
title=_pf("Source Plane (Mid Zoom)"),
lines=source_plane_lines, line_colors=source_plane_line_colors,
vmax=source_vmax, zoom_extent_scale=2.0)
if interpolated:
# The reconstruction the likelihood uses, over the max-zoom extent (the
# mid-zoom panel is replaced, see above)
_plot_source_plane(fit, axes_flat[7], final_plane_index, zoom_to_brightest=True,
colormap=colormap, use_log10=True,
title=_pf("Source Plane (Interpolated)"),
lines=source_plane_lines, line_colors=source_plane_line_colors,
vmax=source_vmax, interpolated=True)
else:
# Source plane (mid zoom) — same centre as Max Zoom, 2.5x wider extent
_plot_source_plane(fit, axes_flat[7], final_plane_index, zoom_to_brightest=True,
colormap=colormap, use_log10=True,
title=_pf("Source Plane (Mid Zoom)"),
lines=source_plane_lines, line_colors=source_plane_line_colors,
vmax=source_vmax, zoom_extent_scale=2.0)

norm_resid = fit.normalized_residual_map
_abs_max = _symmetric_vmax(norm_resid)
Expand Down
4 changes: 4 additions & 0 deletions autolens/interferometer/model/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def should_plot(name):
image_plane_lines=ip_lines, image_plane_line_colors=ip_colors,
source_plane_lines=sp_lines, source_plane_line_colors=sp_colors,
title_prefix=self.title_prefix,
# `fit.png` shows the likelihood's interpolant in the middle source
# panel (Delaunay / kNN sources) when this is on (default); off
# restores the mid-zoom panel.
source_interpolated=should_plot("subplot_fit_source_interpolated"),
)

if quick_update:
Expand Down
Loading
Loading