Skip to content

Commit 9a1ad05

Browse files
committed
Complete Visuals2D/Visuals1D removal from PyAutoLens plotters
- Remove Visuals1D/Visuals2D from all plotter __init__ signatures - Replace mat_plot_2d.plot_array/plot_grid/plot_yx calls with standalone functions - TracerPlotter: add cached critical-curve/caustic properties, pass curves directly to GalaxiesPlotter as tangential_critical_curves/radial_critical_curves - FitImagingPlotter, FitInterferometerPlotter: remove visuals_2d_of_planes_list - SubhaloPlotter: remove visuals_2d; use Array2DPlotter(array_overlay=) directly - SubhaloSensitivityPlotter: remove visuals_2d; use Array2DPlotter(array_overlay=) - analysis/plotter_interface: remove visuals_2d; use positions= directly - imaging/interferometer model visualizers: remove visuals_2d_of_planes_list calls - fit_point_plotters: fix plot_grid() call to not use removed positions= kwarg - PyAutoArray plot_array: guard colorbar creation against LogNorm vmin==vmax All 176 tests pass. https://claude.ai/code/session_01CzJBy8KvFXiNchoNdk5i9k
1 parent 9a34746 commit 9a1ad05

15 files changed

Lines changed: 363 additions & 1007 deletions

autolens/analysis/plotter_interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def tracer(
3636
self,
3737
tracer: Tracer,
3838
grid: aa.type.Grid2DLike,
39-
visuals_2d_of_planes_list: Optional[aplt.Visuals2D] = None,
4039
):
4140
"""
4241
Visualizes a `Tracer` object.
@@ -69,7 +68,6 @@ def should_plot(name):
6968
tracer=tracer,
7069
grid=grid,
7170
mat_plot_2d=mat_plot_2d,
72-
visuals_2d_of_planes_list=visuals_2d_of_planes_list,
7371
)
7472

7573
if should_plot("subplot_galaxies_images"):
@@ -170,12 +168,14 @@ def should_plot(name):
170168
mat_plot_2d = self.mat_plot_2d_from()
171169

172170
if positions is not None:
173-
visuals_2d = aplt.Visuals2D(positions=positions)
171+
pos_arr = np.array(
172+
positions.array if hasattr(positions, "array") else positions
173+
)
174174

175175
image_plotter = aplt.Array2DPlotter(
176176
array=image,
177177
mat_plot_2d=mat_plot_2d,
178-
visuals_2d=visuals_2d,
178+
positions=[pos_arr],
179179
)
180180

181181
image_plotter.set_filename("image_with_positions")

autolens/imaging/model/plotter_interface.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional
1+
from typing import List
22

33
import autoarray.plot as aplt
44

@@ -19,7 +19,7 @@ class PlotterInterfaceImaging(PlotterInterface):
1919
imaging_combined = AgPlotterInterfaceImaging.imaging_combined
2020

2121
def fit_imaging(
22-
self, fit: FitImaging, visuals_2d_of_planes_list : Optional[aplt.Visuals2D] = None, quick_update: bool = False
22+
self, fit: FitImaging, quick_update: bool = False
2323
):
2424
"""
2525
Visualizes a `FitImaging` object, which fits an imaging dataset.
@@ -46,7 +46,7 @@ def should_plot(name):
4646
mat_plot_2d = self.mat_plot_2d_from(quick_update=quick_update)
4747

4848
fit_plotter = FitImagingPlotter(
49-
fit=fit, mat_plot_2d=mat_plot_2d, visuals_2d_of_planes_list=visuals_2d_of_planes_list,
49+
fit=fit, mat_plot_2d=mat_plot_2d,
5050
)
5151

5252
plane_indexes_to_plot = [i for i in fit.tracer.plane_indexes_with_images if i != 0]
@@ -69,7 +69,7 @@ def should_plot(name):
6969
mat_plot_2d = self.mat_plot_2d_from()
7070

7171
fit_plotter = FitImagingPlotter(
72-
fit=fit, mat_plot_2d=mat_plot_2d, visuals_2d_of_planes_list=visuals_2d_of_planes_list,
72+
fit=fit, mat_plot_2d=mat_plot_2d,
7373
)
7474

7575
fit_plotter.subplot_tracer()
@@ -99,7 +99,6 @@ def should_plot(name):
9999
def fit_imaging_combined(
100100
self,
101101
fit_list: List[FitImaging],
102-
visuals_2d_of_planes_list : Optional[aplt.Visuals2D] = None,
103102
quick_update: bool = False,
104103
):
105104
"""
@@ -128,7 +127,7 @@ def should_plot(name):
128127

129128
fit_plotter_list = [
130129
FitImagingPlotter(
131-
fit=fit, mat_plot_2d=mat_plot_2d, visuals_2d_of_planes_list=visuals_2d_of_planes_list,
130+
fit=fit, mat_plot_2d=mat_plot_2d,
132131
)
133132
for fit in fit_list
134133
]

autolens/imaging/model/visualizer.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from autolens.imaging.model.plotter_interface import PlotterInterfaceImaging
99

10-
from autolens.lens import tracer_util
1110
from autolens import exc
1211

1312
logger = logging.getLogger(__name__)
@@ -97,11 +96,6 @@ def visualize(
9796
fit = analysis.fit_from(instance=instance)
9897
tracer = fit.tracer_linear_light_profiles_to_light_profiles
9998

100-
visuals_2d_of_planes_list = tracer_util.visuals_2d_of_planes_list_from(
101-
tracer=fit.tracer,
102-
grid=fit.grids.lp.mask.derive_grid.all_false
103-
)
104-
10599
plotter_interface = PlotterInterfaceImaging(
106100
image_path=paths.image_path,
107101
title_prefix=analysis.title_prefix,
@@ -110,7 +104,6 @@ def visualize(
110104
try:
111105
plotter_interface.fit_imaging(
112106
fit=fit,
113-
visuals_2d_of_planes_list=visuals_2d_of_planes_list,
114107
quick_update=quick_update,
115108
)
116109
except exc.InversionException:
@@ -152,7 +145,6 @@ def visualize(
152145
plotter_interface.tracer(
153146
tracer=tracer,
154147
grid=grid,
155-
visuals_2d_of_planes_list=visuals_2d_of_planes_list
156148
)
157149
plotter_interface.galaxies(
158150
galaxies=tracer.galaxies,

autolens/imaging/plot/fit_imaging_plotters.py

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,19 @@ def __init__(
2222
self,
2323
fit: FitImaging,
2424
mat_plot_2d: aplt.MatPlot2D = None,
25-
visuals_2d: aplt.Visuals2D = None,
2625
residuals_symmetric_cmap: bool = True,
27-
visuals_2d_of_planes_list : Optional = None
2826
):
29-
"""
30-
Plots the attributes of `FitImaging` objects using the matplotlib method `imshow()` and many other matplotlib
31-
functions which customize the plot's appearance.
32-
33-
The `mat_plot_2d` attribute wraps matplotlib function calls to make the figure. By default, the settings
34-
passed to every matplotlib function called are those specified in the `config/visualize/mat_wrap/*.ini` files,
35-
but a user can manually input values into `MatPlot2d` to customize the figure's appearance.
36-
37-
Overlaid on the figure are visuals, contained in the `Visuals2D` object. Attributes may be extracted from
38-
the `FitImaging` and plotted via the visuals object.
39-
40-
Parameters
41-
----------
42-
fit
43-
The fit to an imaging dataset the plotter plots.
44-
mat_plot_2d
45-
Contains objects which wrap the matplotlib function calls that make the plot.
46-
visuals_2d
47-
Contains visuals that can be overlaid on the plot.
48-
residuals_symmetric_cmap
49-
If true, the `residual_map` and `normalized_residual_map` are plotted with a symmetric color map such
50-
that `abs(vmin) = abs(vmax)`.
51-
"""
52-
super().__init__(mat_plot_2d=mat_plot_2d, visuals_2d=visuals_2d)
27+
super().__init__(mat_plot_2d=mat_plot_2d)
5328

5429
self.fit = fit
5530

5631
self._fit_imaging_meta_plotter = FitImagingPlotterMeta(
5732
fit=self.fit,
5833
mat_plot_2d=self.mat_plot_2d,
59-
visuals_2d=self.visuals_2d,
6034
residuals_symmetric_cmap=residuals_symmetric_cmap,
6135
)
6236

6337
self.residuals_symmetric_cmap = residuals_symmetric_cmap
64-
65-
self._visuals_2d_of_planes_list = visuals_2d_of_planes_list
6638
self._lines_of_planes = None
6739

6840
@property
@@ -80,17 +52,6 @@ def lines_of_planes(self) -> List[List]:
8052
)
8153
return self._lines_of_planes
8254

83-
@property
84-
def visuals_2d_of_planes_list(self):
85-
"""Legacy property: returns Visuals2D objects per plane for backward-
86-
compatible callers (e.g. InversionPlotter)."""
87-
if self._visuals_2d_of_planes_list is None:
88-
self._visuals_2d_of_planes_list = tracer_util.visuals_2d_of_planes_list_from(
89-
tracer=self.fit.tracer,
90-
grid=self._lensing_grid,
91-
)
92-
return self._visuals_2d_of_planes_list
93-
9455
def _lines_for_plane(
9556
self, plane_index: int, remove_critical_caustic: bool = False
9657
) -> Optional[List]:
@@ -102,31 +63,6 @@ def _lines_for_plane(
10263
except IndexError:
10364
return None
10465

105-
def visuals_2d_from(
106-
self, plane_index: Optional[int] = None, remove_critical_caustic: bool = False
107-
) -> aplt.Visuals2D:
108-
"""
109-
Returns the `Visuals2D` of the plotter with critical curves and caustics added, which are used to plot
110-
the critical curves and caustics of the `Tracer` object.
111-
112-
If `remove_critical_caustic` is `True`, critical curves and caustics are not included in the visuals.
113-
114-
Parameters
115-
----------
116-
plane_index
117-
The index of the plane in the tracer which is used to extract quantities, as only one plane is plotted
118-
at a time.
119-
remove_critical_caustic
120-
Whether to remove critical curves and caustics from the visuals.
121-
"""
122-
if remove_critical_caustic:
123-
return self.visuals_2d
124-
125-
return (
126-
self.visuals_2d
127-
+ self.visuals_2d_of_planes_list[plane_index]
128-
)
129-
13066
@property
13167
def tracer(self):
13268
return self.fit.tracer_linear_light_profiles_to_light_profiles
@@ -135,7 +71,7 @@ def tracer_plotter_of_plane(
13571
self, plane_index: int, remove_critical_caustic: bool = False
13672
) -> TracerPlotter:
13773
"""
138-
Returns an `TracerPlotter` corresponding to the `Tracer` in the `FitImaging`.
74+
Returns a `TracerPlotter` corresponding to the `Tracer` in the `FitImaging`.
13975
"""
14076

14177
zoom = aa.Zoom2D(mask=self.fit.mask)
@@ -147,9 +83,6 @@ def tracer_plotter_of_plane(
14783
tracer=self.tracer,
14884
grid=grid,
14985
mat_plot_2d=self.mat_plot_2d,
150-
visuals_2d=self.visuals_2d_from(
151-
plane_index=plane_index, remove_critical_caustic=remove_critical_caustic
152-
),
15386
)
15487

15588
def inversion_plotter_of_plane(
@@ -170,12 +103,11 @@ def inversion_plotter_of_plane(
170103
An object that plots inversions which is used for plotting attributes of the inversion.
171104
"""
172105

106+
lines = None if remove_critical_caustic else self._lines_for_plane(plane_index)
173107
inversion_plotter = aplt.InversionPlotter(
174108
inversion=self.fit.inversion,
175109
mat_plot_2d=self.mat_plot_2d,
176-
visuals_2d=self.visuals_2d_from(
177-
plane_index=plane_index, remove_critical_caustic=remove_critical_caustic
178-
),
110+
lines=lines,
179111
)
180112
return inversion_plotter
181113

@@ -331,7 +263,6 @@ def figures_2d_of_planes(
331263
plane_image=True,
332264
plane_index=plane_index,
333265
zoom_to_brightest=zoom_to_brightest,
334-
retain_visuals=True,
335266
)
336267

337268
elif self.tracer.planes[plane_index].has(cls=aa.Pixelization):
@@ -774,7 +705,6 @@ def subplot_tracer(self):
774705
)
775706

776707
tracer_plotter = self.tracer_plotter_of_plane(plane_index=0)
777-
778708
tracer_plotter._subplot_lens_and_mass()
779709

780710
self.mat_plot_2d.output.subplot_to_figure(auto_filename="subplot_tracer")
@@ -814,18 +744,10 @@ def subplot_mappings_of_plane(
814744
total_pixels=total_pixels, filter_neighbors=True
815745
)
816746

817-
indexes = mapper.slim_indexes_for_pix_indexes(pix_indexes=pix_indexes)
818-
819-
inversion_plotter.visuals_2d.indexes = indexes
820-
821747
inversion_plotter.figures_2d_of_pixelization(
822748
pixelization_index=pixelization_index, reconstructed_operated_data=True
823749
)
824750

825-
self.visuals_2d.source_plane_mesh_indexes = [
826-
[index] for index in pix_indexes[pixelization_index]
827-
]
828-
829751
self.figures_2d_of_planes(
830752
plane_index=plane_index, plane_image=True, use_source_vmax=True
831753
)
@@ -839,8 +761,6 @@ def subplot_mappings_of_plane(
839761
)
840762
self.set_title(label=None)
841763

842-
self.visuals_2d.source_plane_mesh_indexes = None
843-
844764
inversion_plotter.mat_plot_2d.output.subplot_to_figure(
845765
auto_filename=f"{auto_filename}_{pixelization_index}"
846766
)

autolens/interferometer/model/plotter_interface.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from typing import Optional
2-
3-
import autoarray.plot as aplt
4-
51
from autogalaxy.interferometer.model.plotter_interface import (
62
PlotterInterfaceInterferometer as AgPlotterInterfaceInterferometer,
73
)
@@ -23,7 +19,6 @@ class PlotterInterfaceInterferometer(PlotterInterface):
2319
def fit_interferometer(
2420
self,
2521
fit: FitInterferometer,
26-
visuals_2d_of_planes_list: Optional[aplt.Visuals2D] = None,
2722
quick_update: bool = False,
2823
):
2924
"""
@@ -75,7 +70,6 @@ def should_plot(name):
7570
fit=fit,
7671
mat_plot_1d=mat_plot_1d,
7772
mat_plot_2d=mat_plot_2d,
78-
visuals_2d_of_planes_list=visuals_2d_of_planes_list,
7973
)
8074

8175
if plot_setting(section="inversion", name="subplot_mappings"):

autolens/interferometer/model/visualizer.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from autolens.interferometer.model.plotter_interface import (
77
PlotterInterfaceInterferometer,
88
)
9-
from autolens.lens import tracer_util
109
from autogalaxy import exc
1110

1211
logger = logging.getLogger(__name__)
@@ -95,18 +94,13 @@ def visualize(
9594
"""
9695
fit = analysis.fit_from(instance=instance)
9796

98-
visuals_2d_of_planes_list = tracer_util.visuals_2d_of_planes_list_from(
99-
tracer=fit.tracer, grid=fit.grids.lp.mask.derive_grid.all_false
100-
)
101-
10297
plotter_interface = PlotterInterfaceInterferometer(
10398
image_path=paths.image_path, title_prefix=analysis.title_prefix
10499
)
105100

106101
try:
107102
plotter_interface.fit_interferometer(
108103
fit=fit,
109-
visuals_2d_of_planes_list=visuals_2d_of_planes_list,
110104
quick_update=quick_update,
111105
)
112106
except exc.InversionException:
@@ -146,17 +140,13 @@ def visualize(
146140
grid = ag.Grid2D.from_extent(extent=extent, shape_native=shape_native)
147141

148142
try:
149-
plotter_interface.fit_interferometer(
150-
fit=fit,
151-
visuals_2d_of_planes_list=visuals_2d_of_planes_list,
152-
)
143+
plotter_interface.fit_interferometer(fit=fit)
153144
except exc.InversionException:
154145
pass
155146

156147
plotter_interface.tracer(
157148
tracer=tracer,
158149
grid=grid,
159-
visuals_2d_of_planes_list=visuals_2d_of_planes_list,
160150
)
161151
plotter_interface.galaxies(
162152
galaxies=tracer.galaxies,

0 commit comments

Comments
 (0)