Skip to content

Commit 2f19ea5

Browse files
authored
Merge pull request #260 from PyAutoLabs/feature/title-prefix-subplots
feat: add title_prefix support to subplot_imaging_dataset
2 parents e1ec21e + db798ae commit 2f19ea5

File tree

4 files changed

+41
-27
lines changed

4 files changed

+41
-27
lines changed

autoarray/dataset/plot/imaging_plots.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def subplot_imaging_dataset(
1414
grid=None,
1515
positions=None,
1616
lines=None,
17+
title_prefix: str = None,
1718
):
1819
"""
1920
3×3 subplot of core ``Imaging`` dataset components.
@@ -50,13 +51,15 @@ def subplot_imaging_dataset(
5051

5152
from autoarray.plot.array import plot_array
5253

54+
_pf = (lambda t: f"{title_prefix.rstrip()} {t}") if title_prefix else (lambda t: t)
55+
5356
fig, axes = subplots(3, 3, figsize=conf_subplot_figsize(3, 3))
5457
axes = axes.flatten()
5558

5659
plot_array(
5760
dataset.data,
5861
ax=axes[0],
59-
title="Data",
62+
title=_pf("Data"),
6063
colormap=colormap,
6164
use_log10=use_log10,
6265
grid=grid,
@@ -66,7 +69,7 @@ def subplot_imaging_dataset(
6669
plot_array(
6770
dataset.data,
6871
ax=axes[1],
69-
title="Data (log10)",
72+
title=_pf("Data (log10)"),
7073
colormap=colormap,
7174
use_log10=True,
7275
grid=grid,
@@ -76,7 +79,7 @@ def subplot_imaging_dataset(
7679
plot_array(
7780
dataset.noise_map,
7881
ax=axes[2],
79-
title="Noise-Map",
82+
title=_pf("Noise-Map"),
8083
colormap=colormap,
8184
use_log10=use_log10,
8285
grid=grid,
@@ -88,15 +91,15 @@ def subplot_imaging_dataset(
8891
plot_array(
8992
dataset.psf.kernel,
9093
ax=axes[3],
91-
title="Point Spread Function",
94+
title=_pf("Point Spread Function"),
9295
colormap=colormap,
9396
use_log10=use_log10,
9497
cb_unit="",
9598
)
9699
plot_array(
97100
dataset.psf.kernel,
98101
ax=axes[4],
99-
title="PSF (log10)",
102+
title=_pf("PSF (log10)"),
100103
colormap=colormap,
101104
use_log10=True,
102105
cb_unit="",
@@ -105,7 +108,7 @@ def subplot_imaging_dataset(
105108
plot_array(
106109
dataset.signal_to_noise_map,
107110
ax=axes[5],
108-
title="Signal-To-Noise Map",
111+
title=_pf("Signal-To-Noise Map"),
109112
colormap=colormap,
110113
use_log10=use_log10,
111114
cb_unit="",
@@ -148,6 +151,7 @@ def subplot_imaging_dataset_list(
148151
output_path=None,
149152
output_filename: str = "dataset_combined",
150153
output_format=None,
154+
title_prefix: str = None,
151155
):
152156
"""
153157
n×3 subplot showing core components for each dataset in a list.
@@ -164,20 +168,24 @@ def subplot_imaging_dataset_list(
164168
Base filename without extension.
165169
output_format
166170
File format string or list, e.g. ``"png"`` or ``["png"]``.
171+
title_prefix
172+
Optional string prepended (with an automatic space) to every panel title.
167173
"""
168174
if isinstance(output_format, (list, tuple)):
169175
output_format = output_format[0]
170176

171177
from autoarray.plot.array import plot_array
172178

179+
_pf = (lambda t: f"{title_prefix.rstrip()} {t}") if title_prefix else (lambda t: t)
180+
173181
n = len(dataset_list)
174182
fig, axes = subplots(n, 3, figsize=conf_subplot_figsize(n, 3))
175183
if n == 1:
176184
axes = [axes]
177185
for i, dataset in enumerate(dataset_list):
178-
plot_array(dataset.data, ax=axes[i][0], title="Data")
179-
plot_array(dataset.noise_map, ax=axes[i][1], title="Noise Map")
180-
plot_array(dataset.signal_to_noise_map, ax=axes[i][2], title="Signal-To-Noise Map")
186+
plot_array(dataset.data, ax=axes[i][0], title=_pf("Data"))
187+
plot_array(dataset.noise_map, ax=axes[i][1], title=_pf("Noise Map"))
188+
plot_array(dataset.signal_to_noise_map, ax=axes[i][2], title=_pf("Signal-To-Noise Map"))
181189
tight_layout()
182190
subplot_save(fig, output_path, output_filename, output_format)
183191

autoarray/dataset/plot/interferometer_plots.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def subplot_interferometer_dataset(
1616
output_format: str = None,
1717
colormap=None,
1818
use_log10: bool = False,
19+
title_prefix: str = None,
1920
):
2021
"""
2122
2x3 subplot of interferometer dataset components.
@@ -38,25 +39,27 @@ def subplot_interferometer_dataset(
3839
use_log10
3940
Apply log10 normalisation to image panels.
4041
"""
42+
_pf = (lambda t: f"{title_prefix.rstrip()} {t}") if title_prefix else (lambda t: t)
43+
4144
fig, axes = subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
4245
axes = axes.flatten()
4346

44-
plot_grid(dataset.data.in_grid, ax=axes[0], title="Visibilities", xlabel="", ylabel="")
47+
plot_grid(dataset.data.in_grid, ax=axes[0], title=_pf("Visibilities"), xlabel="", ylabel="")
4548
plot_grid(
4649
Grid2DIrregular.from_yx_1d(
4750
y=dataset.uv_wavelengths[:, 1] / 10**3.0,
4851
x=dataset.uv_wavelengths[:, 0] / 10**3.0,
4952
),
5053
ax=axes[1],
51-
title="UV-Wavelengths",
54+
title=_pf("UV-Wavelengths"),
5255
xlabel="",
5356
ylabel="",
5457
)
5558
plot_yx(
5659
dataset.amplitudes,
5760
dataset.uv_distances / 10**3.0,
5861
ax=axes[2],
59-
title="Amplitudes vs UV-distances",
62+
title=_pf("Amplitudes vs UV-distances"),
6063
xtick_suffix='"',
6164
ytick_suffix="Jy",
6265
plot_axis_type="scatter",
@@ -65,22 +68,22 @@ def subplot_interferometer_dataset(
6568
dataset.phases,
6669
dataset.uv_distances / 10**3.0,
6770
ax=axes[3],
68-
title="Phases vs UV-distances",
71+
title=_pf("Phases vs UV-distances"),
6972
xtick_suffix='"',
7073
ytick_suffix="deg",
7174
plot_axis_type="scatter",
7275
)
7376
plot_array(
7477
dataset.dirty_image,
7578
ax=axes[4],
76-
title="Dirty Image",
79+
title=_pf("Dirty Image"),
7780
colormap=colormap,
7881
use_log10=use_log10,
7982
)
8083
plot_array(
8184
dataset.dirty_signal_to_noise_map,
8285
ax=axes[5],
83-
title="Dirty Signal-To-Noise Map",
86+
title=_pf("Dirty Signal-To-Noise Map"),
8487
colormap=colormap,
8588
use_log10=use_log10,
8689
)

autoarray/inversion/plot/inversion_plots.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def subplot_of_mapper(
2727
lines=None,
2828
grid=None,
2929
positions=None,
30+
title_prefix: str = None,
3031
):
3132
"""
3233
3×4 subplot showing all pixelization diagnostics for one mapper.
@@ -52,6 +53,8 @@ def subplot_of_mapper(
5253
"""
5354
mapper = inversion.cls_list_from(cls=Mapper)[mapper_index]
5455

56+
_pf = (lambda t: f"{title_prefix.rstrip()} {t}") if title_prefix else (lambda t: t)
57+
5558
fig, axes = subplots(3, 4, figsize=conf_subplot_figsize(3, 4))
5659
axes = axes.flatten()
5760

@@ -60,7 +63,7 @@ def subplot_of_mapper(
6063
plot_array(
6164
inversion.data_subtracted_dict[mapper],
6265
ax=axes[0],
63-
title="Data Subtracted",
66+
title=_pf("Data Subtracted"),
6467
colormap=colormap,
6568
use_log10=use_log10,
6669
grid=grid,
@@ -83,7 +86,7 @@ def _recon_array():
8386
plot_array(
8487
_recon_array(),
8588
ax=axes[1],
86-
title="Reconstructed Image",
89+
title=_pf("Reconstructed Image"),
8790
colormap=colormap,
8891
use_log10=use_log10,
8992
grid=grid,
@@ -93,7 +96,7 @@ def _recon_array():
9396
plot_array(
9497
_recon_array(),
9598
ax=axes[2],
96-
title="Reconstructed Image (log10)",
99+
title=_pf("Reconstructed Image (log10)"),
97100
colormap=colormap,
98101
use_log10=True,
99102
grid=grid,
@@ -103,7 +106,7 @@ def _recon_array():
103106
plot_array(
104107
_recon_array(),
105108
ax=axes[3],
106-
title="Mesh Pixel Grid Overlaid",
109+
title=_pf("Mesh Pixel Grid Overlaid"),
107110
colormap=colormap,
108111
use_log10=use_log10,
109112
grid=numpy_grid(mapper.image_plane_mesh_grid),
@@ -123,7 +126,7 @@ def _recon_array():
123126
mapper,
124127
solution_vector=pixel_values,
125128
ax=axes[4],
126-
title="Source Plane (Zoom)",
129+
title=_pf("Source Plane (Zoom)"),
127130
colormap=colormap,
128131
use_log10=use_log10,
129132
vmax=recon_vmax,
@@ -135,7 +138,7 @@ def _recon_array():
135138
mapper,
136139
solution_vector=pixel_values,
137140
ax=axes[5],
138-
title="Source Plane (No Zoom)",
141+
title=_pf("Source Plane (No Zoom)"),
139142
colormap=colormap,
140143
use_log10=use_log10,
141144
vmax=recon_vmax,
@@ -151,7 +154,7 @@ def _recon_array():
151154
mapper,
152155
solution_vector=nm,
153156
ax=axes[6],
154-
title="Noise-Map (Unzoomed)",
157+
title=_pf("Noise-Map (No Zoom)"),
155158
colormap=colormap,
156159
use_log10=use_log10,
157160
zoom_to_brightest=False,
@@ -168,7 +171,7 @@ def _recon_array():
168171
mapper,
169172
solution_vector=rw,
170173
ax=axes[7],
171-
title="Regularization Weights (Unzoomed)",
174+
title=_pf("Regularization (No Zoom)"),
172175
colormap=colormap,
173176
use_log10=use_log10,
174177
zoom_to_brightest=False,
@@ -186,7 +189,7 @@ def _recon_array():
186189
plot_array(
187190
sub_size,
188191
ax=axes[8],
189-
title="Sub Pixels Per Image Pixels",
192+
title=_pf("Sub Pixels Per Image Pixels"),
190193
colormap=colormap,
191194
use_log10=use_log10,
192195
)
@@ -198,7 +201,7 @@ def _recon_array():
198201
plot_array(
199202
mapper.mesh_pixels_per_image_pixels,
200203
ax=axes[9],
201-
title="Mesh Pixels Per Image Pixels",
204+
title=_pf("Mesh Pixels Per Image Pixels"),
202205
colormap=colormap,
203206
use_log10=use_log10,
204207
)
@@ -212,7 +215,7 @@ def _recon_array():
212215
mapper,
213216
solution_vector=pw,
214217
ax=axes[10],
215-
title="Image Pixels Per Source Pixel",
218+
title=_pf("Image Pixels Per Source Pixel"),
216219
colormap=colormap,
217220
use_log10=use_log10,
218221
zoom_to_brightest=True,

autoarray/plot/inversion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def plot_inversion_reconstruction(
136136

137137
apply_extent(ax, extent)
138138

139-
apply_labels(ax, title=title, xlabel="" if is_subplot else xlabel, ylabel="" if is_subplot else ylabel)
139+
apply_labels(ax, title=title, xlabel="" if is_subplot else xlabel, ylabel="" if is_subplot else ylabel, is_subplot=is_subplot)
140140

141141
if owns_figure:
142142
save_figure(

0 commit comments

Comments
 (0)