Skip to content

Commit cfd1518

Browse files
Jammy2211claude
authored andcommitted
Add subplot_fit_quick for faster quick-update rendering
6-panel (2x3) subplot at 200 DPI for quick updates during sampling: Data, Model Image, Normalized Residual Map (top row); Lens Light Subtracted, Source Model Image, Source Plane Mid Zoom (bottom row). Quick updates now call subplot_fit_quick instead of the full 12-panel subplot_fit, cutting render time from ~9s to ~4s. Full updates continue to use the 12-panel subplot_fit at 300 DPI. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent b744801 commit cfd1518

2 files changed

Lines changed: 113 additions & 4 deletions

File tree

autolens/imaging/model/plotter.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from autolens.imaging.fit_imaging import FitImaging
1414
from autolens.imaging.plot.fit_imaging_plots import (
1515
subplot_fit,
16+
subplot_fit_quick,
1617
subplot_fit_log10,
1718
subplot_of_planes,
1819
subplot_tracer_from_fit,
@@ -75,7 +76,16 @@ def should_plot(name):
7576
source_plane_lines, source_plane_line_colors,
7677
)
7778

78-
if should_plot("subplot_fit") or quick_update:
79+
if quick_update:
80+
subplot_fit_quick(
81+
fit, output_path=output_path, output_format=fmt,
82+
image_plane_lines=ip_lines, image_plane_line_colors=ip_colors,
83+
source_plane_lines=sp_lines, source_plane_line_colors=sp_colors,
84+
title_prefix=self.title_prefix,
85+
)
86+
return
87+
88+
if should_plot("subplot_fit"):
7989

8090
if len(fit.tracer.planes) > 2:
8191
for plane_index in plane_indexes_to_plot:
@@ -94,9 +104,6 @@ def should_plot(name):
94104
title_prefix=self.title_prefix,
95105
)
96106

97-
if quick_update:
98-
return
99-
100107
if plot_setting(section="tracer", name="subplot_tracer"):
101108
subplot_tracer_from_fit(
102109
fit, output_path=output_path, output_format=fmt,

autolens/imaging/plot/fit_imaging_plots.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,108 @@ def subplot_fit(
358358
save_figure(fig, path=output_path, filename=f"fit{plane_index_tag}", format=output_format)
359359

360360

361+
def subplot_fit_quick(
362+
fit,
363+
output_path: Optional[str] = None,
364+
output_format: str = None,
365+
colormap: Optional[str] = None,
366+
image_plane_lines=None,
367+
image_plane_line_colors=None,
368+
source_plane_lines=None,
369+
source_plane_line_colors=None,
370+
title_prefix: str = None,
371+
):
372+
"""
373+
Produce a 6-panel quick-update subplot summarising an imaging fit.
374+
375+
Arranges the following panels in a 2 × 3 grid:
376+
377+
* Data
378+
* Model image
379+
* Normalised residual map (symmetric scale)
380+
* Lens-light-subtracted image
381+
* Source model image
382+
* Source plane image (mid zoom)
383+
384+
This is a lighter alternative to :func:`subplot_fit` (12 panels)
385+
intended for the quick-update visualization path during sampling,
386+
where render speed matters more than completeness.
387+
388+
For single-plane tracers the function delegates to
389+
:func:`subplot_fit_x1_plane`.
390+
"""
391+
if len(fit.tracer.planes) == 1:
392+
return subplot_fit_x1_plane(
393+
fit, output_path=output_path,
394+
output_format=output_format, colormap=colormap,
395+
title_prefix=title_prefix,
396+
)
397+
398+
final_plane_index = len(fit.tracer.planes) - 1
399+
source_vmax = _get_source_vmax(fit)
400+
401+
_pf = (lambda t: f"{title_prefix.rstrip()} {t}") if title_prefix else (lambda t: t)
402+
fig, axes = subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
403+
axes_flat = list(axes.flatten())
404+
405+
# Top row: Data, Model Image, Normalized Residual Map
406+
plot_array(
407+
array=fit.data, ax=axes_flat[0], title=_pf("Data"), colormap=colormap,
408+
)
409+
410+
plot_array(
411+
array=fit.model_data, ax=axes_flat[1], title=_pf("Model Image"),
412+
colormap=colormap, lines=image_plane_lines,
413+
line_colors=image_plane_line_colors,
414+
)
415+
416+
norm_resid = fit.normalized_residual_map
417+
_abs_max = _symmetric_vmax(norm_resid)
418+
plot_array(
419+
array=norm_resid, ax=axes_flat[2], title=_pf("Normalized Residual Map"),
420+
colormap=colormap, vmin=-_abs_max, vmax=_abs_max,
421+
)
422+
423+
# Bottom row: Lens Light Subtracted, Source Model Image, Source Plane (Mid Zoom)
424+
try:
425+
subtracted_img = fit.subtracted_images_of_planes_list[final_plane_index]
426+
except (IndexError, AttributeError):
427+
subtracted_img = None
428+
if subtracted_img is not None:
429+
plot_array(
430+
array=subtracted_img, ax=axes_flat[3],
431+
title=_pf("Lens Light Subtracted"), colormap=colormap,
432+
vmin=0.0 if source_vmax is not None else None, vmax=source_vmax,
433+
)
434+
else:
435+
axes_flat[3].axis("off")
436+
437+
try:
438+
source_model_img = fit.model_images_of_planes_list[final_plane_index]
439+
except (IndexError, AttributeError):
440+
source_model_img = None
441+
if source_model_img is not None:
442+
plot_array(
443+
array=source_model_img, ax=axes_flat[4],
444+
title=_pf("Source Model Image"), colormap=colormap,
445+
vmax=source_vmax, lines=image_plane_lines,
446+
line_colors=image_plane_line_colors,
447+
)
448+
else:
449+
axes_flat[4].axis("off")
450+
451+
_plot_source_plane(
452+
fit, axes_flat[5], final_plane_index, zoom_to_brightest=True,
453+
colormap=colormap, title=_pf("Source Plane (Mid Zoom)"),
454+
lines=source_plane_lines, line_colors=source_plane_line_colors,
455+
vmax=source_vmax, zoom_extent_scale=2.0,
456+
)
457+
458+
hide_unused_axes(axes_flat)
459+
tight_layout()
460+
save_figure(fig, path=output_path, filename="fit_quick", format=output_format, dpi=200)
461+
462+
361463
def subplot_fit_x1_plane(
362464
fit,
363465
output_path: Optional[str] = None,

0 commit comments

Comments
 (0)