Skip to content

Commit 6fe090c

Browse files
Jammy2211claude
authored andcommitted
Add subplot_imaging and subplot_imaging_dataset_list standalone plot functions
Extracts inline matplotlib code from AG PlotterImaging into two new standalone functions in autoarray so they live at the lowest reusable level in the stack. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 366c736 commit 6fe090c

File tree

12 files changed

+153
-68
lines changed

12 files changed

+153
-68
lines changed

autoarray/dataset/plot/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from autoarray.dataset.plot.imaging_plots import subplot_imaging_dataset
1+
from autoarray.dataset.plot.imaging_plots import (
2+
subplot_imaging_dataset,
3+
subplot_imaging,
4+
subplot_imaging_dataset_list,
5+
)
26
from autoarray.dataset.plot.interferometer_plots import (
37
subplot_interferometer_dataset,
48
subplot_interferometer_dirty_images,

autoarray/dataset/plot/imaging_plots.py

Lines changed: 105 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ def subplot_imaging_dataset(
1818
lines=None,
1919
):
2020
"""
21-
3×3 subplot of all ``Imaging`` dataset components.
21+
3×3 subplot of core ``Imaging`` dataset components.
2222
2323
Panels (row-major):
2424
0. Data
2525
1. Data (log10)
2626
2. Noise-Map
2727
3. PSF (if present)
28-
4. PSF log10 (if present)
28+
4. PSF (log10, if present)
2929
5. Signal-To-Noise Map
30-
6. Over-sample size (light profiles)
31-
7. Over-sample size (pixelization)
30+
6. Over Sample Size (Light Profiles, if present)
31+
7. Over Sample Size (Pixelization, if present)
3232
3333
Parameters
3434
----------
@@ -107,20 +107,107 @@ def subplot_imaging_dataset(
107107
positions=positions,
108108
lines=lines,
109109
)
110-
plot_array(
111-
dataset.grids.over_sample_size_lp,
112-
ax=axes[6],
113-
title="Over Sample Size (Light Profiles)",
114-
colormap=colormap,
115-
use_log10=use_log10,
116-
)
117-
plot_array(
118-
dataset.grids.over_sample_size_pixelization,
119-
ax=axes[7],
120-
title="Over Sample Size (Pixelization)",
121-
colormap=colormap,
122-
use_log10=use_log10,
123-
)
124110

111+
over_sample_size_lp = getattr(getattr(dataset, "grids", None), "over_sample_size_lp", None)
112+
if over_sample_size_lp is not None:
113+
plot_array(
114+
over_sample_size_lp,
115+
ax=axes[6],
116+
title="Over Sample Size (Light Profiles)",
117+
colormap=colormap,
118+
use_log10=use_log10,
119+
)
120+
121+
over_sample_size_pix = getattr(getattr(dataset, "grids", None), "over_sample_size_pixelization", None)
122+
if over_sample_size_pix is not None:
123+
plot_array(
124+
over_sample_size_pix,
125+
ax=axes[7],
126+
title="Over Sample Size (Pixelization)",
127+
colormap=colormap,
128+
use_log10=use_log10,
129+
)
130+
131+
plt.tight_layout()
132+
subplot_save(fig, output_path, output_filename, output_format)
133+
134+
135+
def subplot_imaging(
136+
dataset,
137+
output_path=None,
138+
output_filename: str = "subplot_dataset",
139+
output_format="png",
140+
):
141+
"""
142+
1×n subplot of core ``Imaging`` dataset components.
143+
144+
Panels: Data | Noise Map | Signal-To-Noise Map | PSF (if present)
145+
146+
Parameters
147+
----------
148+
dataset
149+
An ``Imaging`` dataset instance.
150+
output_path
151+
Directory to save the figure. ``None`` calls ``plt.show()``.
152+
output_filename
153+
Base filename without extension.
154+
output_format
155+
File format string or list, e.g. ``"png"`` or ``["png"]``.
156+
"""
157+
if isinstance(output_format, (list, tuple)):
158+
output_format = output_format[0]
159+
160+
panels = [
161+
(dataset.data, "Data"),
162+
(dataset.noise_map, "Noise Map"),
163+
(dataset.signal_to_noise_map, "Signal-To-Noise Map"),
164+
]
165+
try:
166+
panels.append((dataset.psf.kernel, "PSF"))
167+
except Exception:
168+
pass
169+
170+
n = len(panels)
171+
fig, axes = plt.subplots(1, n, figsize=(7 * n, 7))
172+
axes_flat = list(axes.flatten()) if n > 1 else [axes]
173+
for i, (array, title) in enumerate(panels):
174+
plot_array(array, ax=axes_flat[i], title=title)
175+
plt.tight_layout()
176+
subplot_save(fig, output_path, output_filename, output_format)
177+
178+
179+
def subplot_imaging_dataset_list(
180+
dataset_list,
181+
output_path=None,
182+
output_filename: str = "subplot_dataset_combined",
183+
output_format="png",
184+
):
185+
"""
186+
n×3 subplot showing core components for each dataset in a list.
187+
188+
Each row shows: Data | Noise Map | Signal-To-Noise Map
189+
190+
Parameters
191+
----------
192+
dataset_list
193+
List of ``Imaging`` dataset instances.
194+
output_path
195+
Directory to save the figure. ``None`` calls ``plt.show()``.
196+
output_filename
197+
Base filename without extension.
198+
output_format
199+
File format string or list, e.g. ``"png"`` or ``["png"]``.
200+
"""
201+
if isinstance(output_format, (list, tuple)):
202+
output_format = output_format[0]
203+
204+
n = len(dataset_list)
205+
fig, axes = plt.subplots(n, 3, figsize=(21, 7 * n))
206+
if n == 1:
207+
axes = [axes]
208+
for i, dataset in enumerate(dataset_list):
209+
plot_array(dataset.data, ax=axes[i][0], title="Data")
210+
plot_array(dataset.noise_map, ax=axes[i][1], title="Noise Map")
211+
plot_array(dataset.signal_to_noise_map, ax=axes[i][2], title="Signal-To-Noise Map")
125212
plt.tight_layout()
126213
subplot_save(fig, output_path, output_filename, output_format)

test_autoarray/plot/mat_plot/__init__.py

Whitespace-only changes.

test_autoarray/plot/mat_plot/test_mat_plot.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

test_autoarray/plot/test_multi_plotters.py

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
import autoarray.plot as aplt
2-
3-
from os import path
4-
5-
import shutil
6-
7-
directory = path.dirname(path.realpath(__file__))
8-
9-
10-
def test__constructor():
11-
output = aplt.Output()
12-
13-
assert output.path == None
14-
assert output._format == None
15-
assert output.format == "show"
16-
assert output.filename == None
17-
18-
output = aplt.Output(path="Path", format="png", filename="file")
19-
20-
assert output.path == "Path"
21-
assert output._format == "png"
22-
assert output.format == "png"
23-
assert output.filename == "file"
24-
25-
if path.exists(output.path):
26-
shutil.rmtree(output.path)
27-
28-
29-
def test__input_path_is_created():
30-
test_path = path.join(directory, "files", "output_path")
31-
32-
if path.exists(test_path):
33-
shutil.rmtree(test_path)
34-
35-
assert not path.exists(test_path)
36-
37-
output = aplt.Output(
38-
path=test_path,
39-
format="png",
40-
)
41-
output.to_figure(structure=None, auto_filename="test")
42-
43-
assert path.exists(test_path)
1+
import autoarray.plot as aplt
2+
3+
from os import path
4+
5+
import shutil
6+
7+
directory = path.dirname(path.realpath(__file__))
8+
9+
10+
def test__constructor():
11+
output = aplt.Output()
12+
13+
assert output.path == None
14+
assert output._format == None
15+
assert output.format == "show"
16+
assert output.filename == None
17+
18+
output = aplt.Output(path="Path", format="png", filename="file")
19+
20+
assert output.path == "Path"
21+
assert output._format == "png"
22+
assert output.format == "png"
23+
assert output.filename == "file"
24+
25+
if path.exists(output.path):
26+
shutil.rmtree(output.path)
27+
28+
29+
def test__input_path_is_created():
30+
test_path = path.join(directory, "files", "output_path")
31+
32+
if path.exists(test_path):
33+
shutil.rmtree(test_path)
34+
35+
assert not path.exists(test_path)
36+
37+
output = aplt.Output(
38+
path=test_path,
39+
format="png",
40+
)
41+
output.to_figure(structure=None, auto_filename="test")
42+
43+
assert path.exists(test_path)

test_autoarray/plot/visuals/__init__.py

Whitespace-only changes.

test_autoarray/plot/visuals/test_visuals.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

test_autoarray/plot/wrap/__init__.py

Whitespace-only changes.

test_autoarray/plot/wrap/base/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)