From 00a049919097f687c1932b9f8d73cd90461c12d7 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 24 Aug 2026 22:55:45 +0000 Subject: [PATCH] refactor: delegate norm_from to the shared autoarray helper (PyAutoArray#488) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `norm_from` was added by #586 as a faithful copy of the colour-norm block in autoarray's plot_array. PyAutoArray#488 makes that block one shared helper (autoarray.plot.utils.norm_from), so this becomes a thin delegate rather than a third copy: autogalaxy may import autoarray, and the name stays autogalaxy's so the Clicker/Scribbler callers added in #586 keep working unchanged. Behaviour is unchanged here — the autoarray helper's log10-floor path is the one this function already implemented. test_autogalaxy/gui/test_plot_norm.py, which pins that behaviour, is green untouched (9 passed); full suite 1119 passed, 1 skipped against the PyAutoArray#488 branch. Library-first: PyAutoArray#488 merges before this. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01DamasCoRrENvgiRkU5WHHW --- autogalaxy/util/plot_utils.py | 41 ++++++++--------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/autogalaxy/util/plot_utils.py b/autogalaxy/util/plot_utils.py index c9902e93..06b97a51 100644 --- a/autogalaxy/util/plot_utils.py +++ b/autogalaxy/util/plot_utils.py @@ -133,13 +133,17 @@ def norm_from(array, use_log10=False, vmin=None, vmax=None): ``plot_*`` functions do, without needing a plotter object that the public namespaces no longer export. - The behaviour mirrors the normalisation applied inside - ``autoarray.plot.array.plot_array``. + The behaviour is not defined here: this is a thin delegate to + ``autoarray.plot.utils.norm_from``, the one implementation every PyAuto + colour scale is built from. It used to be a third copy of that logic, and + the copies had diverged — see the autoarray helper's docstring for the + behaviour and for which divergence was resolved which way. Only the name + is autogalaxy's, so the GUI callers keep working. Parameters ---------- array - The image being normalised. Only read when *use_log10* is ``True`` and + The values being coloured. Only read when *use_log10* is ``True`` and no explicit *vmax* is given. use_log10 When ``True`` a ``LogNorm`` is applied, with values clipped at the @@ -152,36 +156,9 @@ def norm_from(array, use_log10=False, vmin=None, vmax=None): ------- matplotlib.colors.Normalize or None """ - if use_log10: - try: - from autonerves import conf as _conf - - log10_min = _conf.instance["visualize"]["general"]["general"][ - "log10_min_value" - ] - except Exception: - log10_min = 1.0e-4 - - clipped = np.clip(array, log10_min, None) - vmin_log = vmin if (vmin is not None and np.isfinite(vmin)) else log10_min - if vmax is not None and np.isfinite(vmax): - vmax_log = vmax - else: - with np.errstate(all="ignore"): - vmax_log = np.nanmax(clipped) - if not np.isfinite(vmax_log) or vmax_log <= vmin_log: - vmax_log = vmin_log * 10.0 - - from matplotlib.colors import LogNorm - - return LogNorm(vmin=vmin_log, vmax=vmax_log) - - if vmin is not None or vmax is not None: - from matplotlib.colors import Normalize - - return Normalize(vmin=vmin, vmax=vmax) + from autoarray.plot.utils import norm_from as _norm_from - return None + return _norm_from(array=array, use_log10=use_log10, vmin=vmin, vmax=vmax) def _resolve_format(output_format):