From c73def5f6f1146dc2910f9648dd82b47da3c2daa Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Fri, 3 Apr 2026 14:43:28 +0100 Subject: [PATCH] Use configurable output_format default from autoarray config Change all output_format defaults from "png" to None, resolved at runtime via autoarray's _conf_output_format() which reads from general.yaml. Co-Authored-By: Claude Opus 4.6 (1M context) --- autogalaxy/ellipse/plot/fit_ellipse_plots.py | 8 +++---- autogalaxy/galaxy/plot/adapt_plots.py | 2 +- autogalaxy/galaxy/plot/galaxies_plots.py | 4 ++-- autogalaxy/galaxy/plot/galaxy_plots.py | 4 ++-- autogalaxy/imaging/plot/fit_imaging_plots.py | 6 ++--- .../plot/fit_interferometer_plots.py | 6 ++--- autogalaxy/plot/plot_utils.py | 22 ++++++++++--------- autogalaxy/profiles/plot/basis_plots.py | 2 +- .../quantity/plot/fit_quantity_plots.py | 2 +- 9 files changed, 29 insertions(+), 27 deletions(-) diff --git a/autogalaxy/ellipse/plot/fit_ellipse_plots.py b/autogalaxy/ellipse/plot/fit_ellipse_plots.py index eb4e3197..e2cc626f 100644 --- a/autogalaxy/ellipse/plot/fit_ellipse_plots.py +++ b/autogalaxy/ellipse/plot/fit_ellipse_plots.py @@ -17,7 +17,7 @@ def _plot_data( fit_list: List[FitEllipse], output_path=None, output_filename="ellipse_fit", - output_format="png", + output_format=None, colormap="default", use_log10=False, disable_data_contours: bool = False, @@ -80,7 +80,7 @@ def _plot_data( def _plot_ellipse_residuals( fit_list: List[FitEllipse], output_path=None, - output_format="png", + output_format=None, for_subplot: bool = False, suffix: str = "", ax=None, @@ -122,7 +122,7 @@ def _plot_ellipse_residuals( def subplot_fit_ellipse( fit_list: List[FitEllipse], output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, disable_data_contours: bool = False, @@ -166,7 +166,7 @@ def subplot_fit_ellipse( def subplot_ellipse_errors( fit_pdf_list: List[List[FitEllipse]], output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, sigma: Optional[float] = 3.0, diff --git a/autogalaxy/galaxy/plot/adapt_plots.py b/autogalaxy/galaxy/plot/adapt_plots.py index e2991282..a00e8dba 100644 --- a/autogalaxy/galaxy/plot/adapt_plots.py +++ b/autogalaxy/galaxy/plot/adapt_plots.py @@ -12,7 +12,7 @@ def subplot_adapt_images( adapt_galaxy_name_image_dict: Dict[Galaxy, aa.Array2D], output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, ): diff --git a/autogalaxy/galaxy/plot/galaxies_plots.py b/autogalaxy/galaxy/plot/galaxies_plots.py index 7a5a6a12..bc83529c 100644 --- a/autogalaxy/galaxy/plot/galaxies_plots.py +++ b/autogalaxy/galaxy/plot/galaxies_plots.py @@ -64,7 +64,7 @@ def subplot_galaxies( galaxies, grid: aa.type.Grid1D2DLike, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, positions=None, @@ -164,7 +164,7 @@ def subplot_galaxy_images( galaxies, grid: aa.type.Grid1D2DLike, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, tangential_critical_curves=None, diff --git a/autogalaxy/galaxy/plot/galaxy_plots.py b/autogalaxy/galaxy/plot/galaxy_plots.py index 191dd64f..f97a9b94 100644 --- a/autogalaxy/galaxy/plot/galaxy_plots.py +++ b/autogalaxy/galaxy/plot/galaxy_plots.py @@ -15,7 +15,7 @@ def subplot_of_light_profiles( galaxy: Galaxy, grid: aa.type.Grid1D2DLike, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, positions=None, @@ -72,7 +72,7 @@ def subplot_of_mass_profiles( deflections_y: bool = False, deflections_x: bool = False, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, ): diff --git a/autogalaxy/imaging/plot/fit_imaging_plots.py b/autogalaxy/imaging/plot/fit_imaging_plots.py index 9e9280dc..57516fef 100644 --- a/autogalaxy/imaging/plot/fit_imaging_plots.py +++ b/autogalaxy/imaging/plot/fit_imaging_plots.py @@ -12,7 +12,7 @@ def subplot_fit( fit: FitImaging, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, positions=None, @@ -72,7 +72,7 @@ def subplot_of_galaxy( fit: FitImaging, galaxy_index: int, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, positions=None, @@ -136,7 +136,7 @@ def subplot_fit_imaging_list( fit_list, output_path=None, output_filename: str = "fit_combined", - output_format="png", + output_format=None, ): """ nĂ—5 subplot summarising a list of ``FitImaging`` objects. diff --git a/autogalaxy/interferometer/plot/fit_interferometer_plots.py b/autogalaxy/interferometer/plot/fit_interferometer_plots.py index f8aaba73..c7ffa4c9 100644 --- a/autogalaxy/interferometer/plot/fit_interferometer_plots.py +++ b/autogalaxy/interferometer/plot/fit_interferometer_plots.py @@ -15,7 +15,7 @@ def subplot_fit( fit: FitInterferometer, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, residuals_symmetric_cmap: bool = True, @@ -61,7 +61,7 @@ def subplot_fit( def subplot_fit_dirty_images( fit: FitInterferometer, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, residuals_symmetric_cmap: bool = True, @@ -117,7 +117,7 @@ def subplot_fit_dirty_images( def subplot_fit_real_space( fit: FitInterferometer, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, ): diff --git a/autogalaxy/plot/plot_utils.py b/autogalaxy/plot/plot_utils.py index a5041fb0..b95f8b2c 100644 --- a/autogalaxy/plot/plot_utils.py +++ b/autogalaxy/plot/plot_utils.py @@ -68,24 +68,24 @@ def _to_positions(*items): return _to_lines(*items) -def _save_subplot(fig, output_path, output_filename, output_format="png", +def _save_subplot(fig, output_path, output_filename, output_format=None, dpi=300): - """Save a subplot figure to disk (or show it if output_path is falsy). + """Save a subplot figure to disk (or show it if output_format/output_path say so). For FITS output use the dedicated ``fits_*`` functions instead. """ - from autoarray.plot.utils import _output_mode_save + from autoarray.plot.utils import _output_mode_save, _conf_output_format if _output_mode_save(fig, output_filename): return - fmt = output_format[0] if isinstance(output_format, (list, tuple)) else (output_format or "png") - if output_path: + fmt = output_format[0] if isinstance(output_format, (list, tuple)) else (output_format or _conf_output_format()) + if fmt == "show" or not output_path: + plt.show() + else: os.makedirs(str(output_path), exist_ok=True) fpath = os.path.join(str(output_path), f"{output_filename}.{fmt}") fig.savefig(fpath, dpi=dpi, bbox_inches="tight", pad_inches=0.1) - else: - plt.show() plt.close(fig) @@ -99,9 +99,11 @@ def _resolve_colormap(colormap): def _resolve_format(output_format): """Normalise output_format: accept a list/tuple or a plain string.""" + from autoarray.plot.utils import _conf_output_format + if isinstance(output_format, (list, tuple)): return output_format[0] - return output_format or "png" + return output_format or _conf_output_format() def _numpy_grid(grid): @@ -119,7 +121,7 @@ def plot_array( title="", output_path=None, output_filename="array", - output_format="png", + output_format=None, colormap="default", use_log10=False, vmin=None, @@ -276,7 +278,7 @@ def plot_grid( title="", output_path=None, output_filename="grid", - output_format="png", + output_format=None, lines=None, ax=None, ): diff --git a/autogalaxy/profiles/plot/basis_plots.py b/autogalaxy/profiles/plot/basis_plots.py index 25134cb4..d125dddf 100644 --- a/autogalaxy/profiles/plot/basis_plots.py +++ b/autogalaxy/profiles/plot/basis_plots.py @@ -13,7 +13,7 @@ def subplot_image( basis: Basis, grid: aa.type.Grid1D2DLike, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, positions=None, diff --git a/autogalaxy/quantity/plot/fit_quantity_plots.py b/autogalaxy/quantity/plot/fit_quantity_plots.py index 5f5bf836..a26e66d7 100644 --- a/autogalaxy/quantity/plot/fit_quantity_plots.py +++ b/autogalaxy/quantity/plot/fit_quantity_plots.py @@ -63,7 +63,7 @@ def _subplot_fit_array(fit, output_path, output_format, colormap, use_log10, pos def subplot_fit( fit: FitQuantity, output_path=None, - output_format="png", + output_format=None, colormap="default", use_log10=False, positions=None,