Skip to content

Commit 2927f9a

Browse files
committed
Replace _save_subplot with autoarray's save_figure
- Remove _save_subplot from plot_utils.py (now just 3 autolens-specific helpers: _to_lines, _critical_curves_from, _caustics_from) - All callers now import save_figure from autoarray.plot.plots.utils - autoarray's save_figure updated to accept format as list or single string https://claude.ai/code/session_01CzJBy8KvFXiNchoNdk5i9k
1 parent c154673 commit 2927f9a

8 files changed

Lines changed: 27 additions & 49 deletions

File tree

autolens/imaging/plot/fit_imaging_plots.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import autogalaxy as ag
77

88
from autoarray.plot.plots.array import plot_array, _zoom_array_2d
9+
from autoarray.plot.plots.utils import save_figure
910
from autolens.plot.plot_utils import (
1011
_to_lines,
11-
_save_subplot,
1212
_critical_curves_from,
1313
_caustics_from,
1414
)
@@ -139,7 +139,7 @@ def subplot_fit(
139139
colormap=colormap)
140140

141141
plt.tight_layout()
142-
_save_subplot(fig, output_path, f"subplot_fit{plane_index_tag}", output_format)
142+
save_figure(fig, path=output_path, filename=f"subplot_fit{plane_index_tag}", format=output_format)
143143

144144

145145
def subplot_fit_x1_plane(
@@ -177,7 +177,7 @@ def subplot_fit_x1_plane(
177177
colormap=colormap, vmin=-_abs_max, vmax=_abs_max)
178178

179179
plt.tight_layout()
180-
_save_subplot(fig, output_path, "subplot_fit_x1_plane", output_format)
180+
save_figure(fig, path=output_path, filename="subplot_fit_x1_plane", format=output_format)
181181

182182

183183
def subplot_fit_log10(
@@ -260,7 +260,7 @@ def subplot_fit_log10(
260260
colormap=colormap, use_log10=True)
261261

262262
plt.tight_layout()
263-
_save_subplot(fig, output_path, f"subplot_fit_log10{plane_index_tag}", output_format)
263+
save_figure(fig, path=output_path, filename=f"subplot_fit_log10{plane_index_tag}", format=output_format)
264264

265265

266266
def subplot_fit_log10_x1_plane(
@@ -300,7 +300,7 @@ def subplot_fit_log10_x1_plane(
300300
colormap=colormap, use_log10=True)
301301

302302
plt.tight_layout()
303-
_save_subplot(fig, output_path, "subplot_fit_log10", output_format)
303+
save_figure(fig, path=output_path, filename="subplot_fit_log10", format=output_format)
304304

305305

306306
def subplot_of_planes(
@@ -339,7 +339,7 @@ def subplot_of_planes(
339339
_plot_source_plane(fit, axes_flat[3], pidx, colormap=colormap)
340340

341341
plt.tight_layout()
342-
_save_subplot(fig, output_path, f"subplot_of_plane_{pidx}", output_format)
342+
save_figure(fig, path=output_path, filename=f"subplot_of_plane_{pidx}", format=output_format)
343343

344344

345345
def subplot_tracer_from_fit(
@@ -389,7 +389,7 @@ def subplot_tracer_from_fit(
389389
axes_flat[i].axis("off")
390390

391391
plt.tight_layout()
392-
_save_subplot(fig, output_path, "subplot_tracer", output_format)
392+
save_figure(fig, path=output_path, filename="subplot_tracer", format=output_format)
393393

394394

395395
def subplot_fit_combined(
@@ -444,7 +444,7 @@ def subplot_fit_combined(
444444
title="Normalized Residual Map", colormap=colormap)
445445

446446
plt.tight_layout()
447-
_save_subplot(fig, output_path, "subplot_fit_combined", output_format)
447+
save_figure(fig, path=output_path, filename="subplot_fit_combined", format=output_format)
448448

449449

450450
def subplot_fit_combined_log10(
@@ -501,7 +501,7 @@ def subplot_fit_combined_log10(
501501
title="Normalized Residual Map", colormap=colormap)
502502

503503
plt.tight_layout()
504-
_save_subplot(fig, output_path, "fit_combined_log10", output_format)
504+
save_figure(fig, path=output_path, filename="fit_combined_log10", format=output_format)
505505

506506

507507
def _symmetric_vmax(array) -> float:

autolens/interferometer/plot/fit_interferometer_plots.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import autogalaxy as ag
77

88
from autoarray.plot.plots.array import plot_array
9+
from autoarray.plot.plots.utils import save_figure
910
from autolens.plot.plot_utils import (
1011
_to_lines,
11-
_save_subplot,
1212
_critical_curves_from,
1313
)
1414

@@ -115,7 +115,7 @@ def subplot_fit(
115115
zoom_to_brightest=False, colormap=colormap)
116116

117117
plt.tight_layout()
118-
_save_subplot(fig, output_path, "subplot_fit", output_format)
118+
save_figure(fig, path=output_path, filename="subplot_fit", format=output_format)
119119

120120

121121
def subplot_fit_real_space(
@@ -158,4 +158,4 @@ def subplot_fit_real_space(
158158
axes_flat[1].set_title("Source Reconstruction")
159159

160160
plt.tight_layout()
161-
_save_subplot(fig, output_path, "subplot_fit_real_space", output_format)
161+
save_figure(fig, path=output_path, filename="subplot_fit_real_space", format=output_format)

autolens/lens/plot/sensitivity_plots.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import autoarray as aa
77

88
from autoarray.plot.plots.array import plot_array
9-
from autolens.plot.plot_utils import _save_subplot
9+
from autoarray.plot.plots.utils import save_figure
1010

1111

1212
def subplot_tracer_images(
@@ -73,7 +73,7 @@ def subplot_tracer_images(
7373
colormap=colormap, use_log10=use_log10, lines=no_perturb_cc_lines)
7474

7575
plt.tight_layout()
76-
_save_subplot(fig, output_path, "subplot_lensed_images", output_format)
76+
save_figure(fig, path=output_path, filename="subplot_lensed_images", format=output_format)
7777

7878

7979
def subplot_sensitivity(
@@ -162,7 +162,7 @@ def subplot_sensitivity(
162162
pass
163163

164164
plt.tight_layout()
165-
_save_subplot(fig, output_path, "subplot_sensitivity", output_format)
165+
save_figure(fig, path=output_path, filename="subplot_sensitivity", format=output_format)
166166

167167

168168
def subplot_figures_of_merit_grid(
@@ -183,4 +183,4 @@ def subplot_figures_of_merit_grid(
183183
plot_array(array=figures_of_merit, ax=ax, title="Increase in Log Evidence",
184184
colormap=colormap)
185185
plt.tight_layout()
186-
_save_subplot(fig, output_path, "sensitivity", output_format)
186+
save_figure(fig, path=output_path, filename="sensitivity", format=output_format)

autolens/lens/plot/subhalo_plots.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Optional
44

55
from autoarray.plot.plots.array import plot_array
6-
from autolens.plot.plot_utils import _save_subplot
6+
from autoarray.plot.plots.utils import save_figure
77
from autolens.imaging.plot.fit_imaging_plots import _plot_source_plane
88

99

@@ -57,7 +57,7 @@ def subplot_detection_imaging(
5757
)
5858

5959
plt.tight_layout()
60-
_save_subplot(fig, output_path, "subplot_detection_imaging", output_format)
60+
save_figure(fig, path=output_path, filename="subplot_detection_imaging", format=output_format)
6161

6262

6363
def subplot_detection_fits(
@@ -101,4 +101,4 @@ def subplot_detection_fits(
101101
colormap=colormap)
102102

103103
plt.tight_layout()
104-
_save_subplot(fig, output_path, "subplot_detection_fits", output_format)
104+
save_figure(fig, path=output_path, filename="subplot_detection_fits", format=output_format)

autolens/lens/plot/tracer_plots.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import autogalaxy as ag
77

88
from autoarray.plot.plots.array import plot_array
9+
from autoarray.plot.plots.utils import save_figure
910
from autolens.plot.plot_utils import (
1011
_to_lines,
1112
_to_positions,
12-
_save_subplot,
1313
_critical_curves_from,
1414
_caustics_from,
1515
)
@@ -90,7 +90,7 @@ def subplot_tracer(
9090
lines=image_plane_lines, colormap=colormap)
9191

9292
plt.tight_layout()
93-
_save_subplot(fig, output_path, "subplot_tracer", output_format)
93+
save_figure(fig, path=output_path, filename="subplot_tracer", format=output_format)
9494

9595

9696
def subplot_lensed_images(
@@ -120,7 +120,7 @@ def subplot_lensed_images(
120120
)
121121

122122
plt.tight_layout()
123-
_save_subplot(fig, output_path, "subplot_lensed_images", output_format)
123+
save_figure(fig, path=output_path, filename="subplot_lensed_images", format=output_format)
124124

125125

126126
def subplot_galaxies_images(
@@ -177,4 +177,4 @@ def subplot_galaxies_images(
177177
idx += 1
178178

179179
plt.tight_layout()
180-
_save_subplot(fig, output_path, "subplot_galaxies_images", output_format)
180+
save_figure(fig, path=output_path, filename="subplot_galaxies_images", format=output_format)

autolens/plot/plot_utils.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import os
21
import numpy as np
3-
import matplotlib.pyplot as plt
42

53

64
def _to_lines(*items):
@@ -32,26 +30,6 @@ def _to_positions(*items):
3230
return _to_lines(*items)
3331

3432

35-
def _save_subplot(fig, output_path, filename, output_format="png"):
36-
"""Save a subplot figure to disk (or show it when output_path is None)."""
37-
if isinstance(output_format, (list, tuple)):
38-
fmts = output_format
39-
else:
40-
fmts = [output_format]
41-
42-
if output_path:
43-
os.makedirs(output_path, exist_ok=True)
44-
for fmt in fmts:
45-
fig.savefig(
46-
os.path.join(output_path, f"{filename}.{fmt}"),
47-
bbox_inches="tight",
48-
pad_inches=0.1,
49-
)
50-
else:
51-
plt.show()
52-
plt.close(fig)
53-
54-
5533
def _critical_curves_from(tracer, grid):
5634
"""Return (tangential_critical_curves, radial_critical_curves) as lists of arrays."""
5735
from autolens.lens import tracer_util

autolens/point/plot/fit_point_plots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
from typing import Optional
44

5-
from autolens.plot.plot_utils import _save_subplot
5+
from autoarray.plot.plots.utils import save_figure
66

77

88
def subplot_fit(
@@ -57,4 +57,4 @@ def subplot_fit(
5757
)
5858

5959
plt.tight_layout()
60-
_save_subplot(fig, output_path, "subplot_fit", output_format)
60+
save_figure(fig, path=output_path, filename="subplot_fit", format=output_format)

autolens/point/plot/point_dataset_plots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
from typing import Optional
44

5-
from autolens.plot.plot_utils import _save_subplot
5+
from autoarray.plot.plots.utils import save_figure
66

77

88
def subplot_dataset(
@@ -49,4 +49,4 @@ def subplot_dataset(
4949
)
5050

5151
plt.tight_layout()
52-
_save_subplot(fig, output_path, "subplot_dataset_point", output_format)
52+
save_figure(fig, path=output_path, filename="subplot_dataset_point", format=output_format)

0 commit comments

Comments
 (0)