Skip to content

Commit 862a34a

Browse files
Jammy2211claude
authored andcommitted
Visualization cleanup: critical curves once, interferometer/point passdown
- Lift critical curve computation to visualizer level in interferometer and point so it is computed once and passed through the plotter call chain - Add image_plane_lines/source_plane_lines parameters to interferometer subplot_fit, subplot_fit_dirty_images, subplot_fit_real_space and point subplot_fit - Thread critical curve parameters through PlotterInterferometer.fit_interferometer, Plotter.tracer, PlotterPoint.fit_point and VisualizerPoint.visualize - Sync fit_imaging_plots with interferometer equivalent for consistency Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fcf875e commit 862a34a

7 files changed

Lines changed: 328 additions & 123 deletions

File tree

autolens/analysis/plotter.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def tracer(
3737
self,
3838
tracer: Tracer,
3939
grid: aa.type.Grid2DLike,
40+
image_plane_lines=None,
41+
image_plane_line_colors=None,
42+
source_plane_lines=None,
43+
source_plane_line_colors=None,
4044
):
4145
"""
4246
Visualizes a `Tracer` object.
@@ -47,6 +51,14 @@ def tracer(
4751
The maximum log likelihood `Tracer` of the non-linear search.
4852
grid
4953
A 2D grid of (y,x) arc-second coordinates used to perform ray-tracing.
54+
image_plane_lines
55+
Pre-computed critical-curve lines to overlay on image-plane panels.
56+
image_plane_line_colors
57+
Colours for each image-plane line.
58+
source_plane_lines
59+
Pre-computed caustic lines to overlay on source-plane panels.
60+
source_plane_line_colors
61+
Colours for each source-plane line.
5062
"""
5163

5264
def should_plot(name):
@@ -55,6 +67,18 @@ def should_plot(name):
5567
output_path = str(self.image_path)
5668
fmt = self.fmt
5769

70+
if should_plot("subplot_tracer"):
71+
subplot_tracer(
72+
tracer=tracer,
73+
grid=grid,
74+
output_path=output_path,
75+
output_format=fmt,
76+
image_plane_lines=image_plane_lines,
77+
image_plane_line_colors=image_plane_line_colors,
78+
source_plane_lines=source_plane_lines,
79+
source_plane_line_colors=source_plane_line_colors,
80+
)
81+
5882
if should_plot("subplot_galaxies_images"):
5983
subplot_galaxies_images(
6084
tracer=tracer,

autolens/imaging/plot/fit_imaging_plots.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ def _compute_critical_curve_lines(tracer, grid):
5353
return None, None, None, None
5454

5555

56+
def _compute_critical_curves_from_fit(fit):
57+
"""Compute critical-curve and caustic lines from a FitImaging object.
58+
59+
Convenience wrapper around :func:`_compute_critical_curve_lines` that
60+
derives the tracer and grid from *fit* directly, using the fully unmasked
61+
image-plane grid so the curves cover the whole image extent.
62+
63+
Returns the same 4-tuple as :func:`_compute_critical_curve_lines`.
64+
"""
65+
tracer = fit.tracer_linear_light_profiles_to_light_profiles
66+
return _compute_critical_curve_lines(tracer, fit.mask.derive_grid.all_false)
67+
68+
5669
def _get_source_vmax(fit):
5770
"""
5871
Return the colour-scale maximum for source-plane panels.
@@ -217,14 +230,8 @@ def subplot_fit(
217230
source_vmax = _get_source_vmax(fit)
218231

219232
if image_plane_lines is None and source_plane_lines is None:
220-
tracer = fit.tracer_linear_light_profiles_to_light_profiles
221-
_zoom = aa.Zoom2D(mask=fit.mask)
222-
_cc_grid = aa.Grid2D.from_extent(
223-
extent=_zoom.extent_from(buffer=0),
224-
shape_native=_zoom.shape_native,
225-
)
226233
image_plane_lines, image_plane_line_colors, source_plane_lines, source_plane_line_colors = (
227-
_compute_critical_curve_lines(tracer, _cc_grid)
234+
_compute_critical_curves_from_fit(fit)
228235
)
229236

230237
fig, axes = plt.subplots(3, 4, figsize=conf_subplot_figsize(3, 4))
@@ -422,14 +429,8 @@ def subplot_fit_log10(
422429
source_vmax = _get_source_vmax(fit)
423430

424431
if image_plane_lines is None and source_plane_lines is None:
425-
tracer = fit.tracer_linear_light_profiles_to_light_profiles
426-
_zoom = aa.Zoom2D(mask=fit.mask)
427-
_cc_grid = aa.Grid2D.from_extent(
428-
extent=_zoom.extent_from(buffer=0),
429-
shape_native=_zoom.shape_native,
430-
)
431432
image_plane_lines, image_plane_line_colors, source_plane_lines, source_plane_line_colors = (
432-
_compute_critical_curve_lines(tracer, _cc_grid)
433+
_compute_critical_curves_from_fit(fit)
433434
)
434435

435436
fig, axes = plt.subplots(3, 4, figsize=conf_subplot_figsize(3, 4))
@@ -673,14 +674,11 @@ def subplot_tracer_from_fit(
673674
tracer = fit.tracer_linear_light_profiles_to_light_profiles
674675

675676
# --- grid ---
676-
zoom = aa.Zoom2D(mask=fit.mask)
677-
grid = aa.Grid2D.from_extent(
678-
extent=zoom.extent_from(buffer=0), shape_native=zoom.shape_native
679-
)
677+
grid = fit.mask.derive_grid.all_false
680678

681679
if image_plane_lines is None and source_plane_lines is None:
682680
image_plane_lines, image_plane_line_colors, source_plane_lines, source_plane_line_colors = (
683-
_compute_critical_curve_lines(tracer, grid)
681+
_compute_critical_curves_from_fit(fit)
684682
)
685683

686684
source_vmax = _get_source_vmax(fit)
@@ -689,7 +687,7 @@ def subplot_tracer_from_fit(
689687
lens_galaxies = ag.Galaxies(galaxies=tracer.planes[0])
690688
lens_image = lens_galaxies.image_2d_from(grid=traced_grids[0])
691689

692-
deflections = lens_galaxies.deflections_yx_2d_from(grid=grid)
690+
deflections = tracer.deflections_yx_2d_from(grid=grid)
693691
deflections_y = aa.Array2D(values=deflections.slim[:, 0], mask=grid.mask)
694692
deflections_x = aa.Array2D(values=deflections.slim[:, 1], mask=grid.mask)
695693

autolens/interferometer/model/plotter.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import autoarray as aa
2+
13
from autogalaxy.interferometer.model.plotter import (
24
PlotterInterferometer as AgPlotterInterferometer,
35
)
46

5-
from autogalaxy.interferometer.plot import fit_interferometer_plots as ag_fit_interferometer_plots
67
from autogalaxy.interferometer.plot.fit_interferometer_plots import (
78
fits_galaxy_images,
89
fits_dirty_images,
@@ -11,7 +12,9 @@
1112
from autolens.interferometer.fit_interferometer import FitInterferometer
1213
from autolens.interferometer.plot.fit_interferometer_plots import (
1314
subplot_fit,
15+
subplot_fit_dirty_images,
1416
subplot_fit_real_space,
17+
_compute_critical_curve_lines,
1518
)
1619
from autolens.analysis.plotter import Plotter
1720

@@ -41,21 +44,35 @@ def should_plot(name):
4144
output_path = str(self.image_path)
4245
fmt = self.fmt
4346

47+
# Compute critical curves and caustics once for all subplot functions.
48+
tracer = fit.tracer_linear_light_profiles_to_light_profiles
49+
_zoom = aa.Zoom2D(mask=fit.dataset.real_space_mask)
50+
_cc_grid = aa.Grid2D.from_extent(
51+
extent=_zoom.extent_from(buffer=0), shape_native=_zoom.shape_native
52+
)
53+
ip_lines, ip_colors, sp_lines, sp_colors = _compute_critical_curve_lines(tracer, _cc_grid)
54+
4455
if should_plot("subplot_fit"):
45-
subplot_fit(fit, output_path=output_path, output_format=fmt)
56+
subplot_fit(
57+
fit, output_path=output_path, output_format=fmt,
58+
image_plane_lines=ip_lines, image_plane_line_colors=ip_colors,
59+
source_plane_lines=sp_lines, source_plane_line_colors=sp_colors,
60+
)
4661

4762
if should_plot("subplot_fit_dirty_images") or quick_update:
48-
ag_fit_interferometer_plots.subplot_fit_dirty_images(
49-
fit=fit,
50-
output_path=self.image_path,
51-
output_format=self.fmt,
63+
subplot_fit_dirty_images(
64+
fit, output_path=output_path, output_format=fmt,
65+
image_plane_lines=ip_lines, image_plane_line_colors=ip_colors,
5266
)
5367

5468
if quick_update:
5569
return
5670

5771
if should_plot("subplot_fit_real_space"):
58-
subplot_fit_real_space(fit, output_path=output_path, output_format=fmt)
72+
subplot_fit_real_space(
73+
fit, output_path=output_path, output_format=fmt,
74+
source_plane_lines=sp_lines, source_plane_line_colors=sp_colors,
75+
)
5976

6077
if should_plot("fits_galaxy_images"):
6178
fits_galaxy_images(fit=fit, output_path=self.image_path)

0 commit comments

Comments
 (0)