feat: make the colormap config lever loud and documented (#509) - #510
Merged
Merged
Conversation
The `visualize/general.yaml -> colormap` key already reached every 2D figure, but a typo'd or unknown value reverted silently to the bundled `autoarray` colormap and the user never learned their setting was ignored. - `_default_colormap()` now separates the two failure modes: an absent config (no autonerves, no `colormap` key) still falls back quietly to `autoarray`, while a value matplotlib cannot resolve raises a `ValueError` naming the config key, the offending value, and how to fix it. The bare `except Exception` is gone, replaced by `(KeyError, ConfigException)` / `ImportError`. - `_conf_imshow_origin()` and `_conf_output_format()` get the same narrow excepts; `imshow_origin` additionally rejects anything but `upper`/`lower`. - `config/visualize/README.md` gains a "Changing the colormap" section: the global config key, the per-figure `colormap=` argument, and the figures that deliberately fix their colormap (array_overlay `Greys`, the weak-lensing cyclic/diverging maps, the cluster and GUI maps). - 11 new unit tests in `test_autoarray/plot/test_utils.py` cover the config value, the quiet fallback, the loud failure, the per-figure override, and that one config edit moves both an imaging figure and an inversion reconstruction. No public API changes; the config key and every `colormap=` argument keep their existing names and defaults. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXGHBFryzQZMFvAskHe9sQ
Collaborator
Author
|
Workspace follow-up: PyAutoLabs/euclid_strong_lens_modeling_pipeline#42 (euclid_strong_lens_modeling_pipeline defaults to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The colormap lever (
visualize/general.yaml -> colormap) already reached every 2D figure, but it was invisible and it failed quietly:_default_colormap()wrapped the config read in a bareexcept Exception, so a typo'd colormap name reverted to the bundledautoarraymap with nothing said. This PR audits the lever end-to-end, makes malformed values loud, and documents both override routes._default_colormap()now separates the two cases. Noautonerves, or nocolormapkey on the config path (a bare install with no workspace) → quiet fallback toautoarray, as before. A value matplotlib cannot resolve →ValueErrornaming the key, the value, and the fix. The bareexcept Exceptionis replaced byImportError/(KeyError, ConfigException)._conf_imshow_origin()and_conf_output_format()get the same narrow excepts.imshow_originadditionally rejects anything butupper/lower;output_formatis left to matplotlib's ownsavefigerror, which already names the format and lists the supported ones.autoarray/config/visualize/README.mdgains a "Changing the colormap" section covering the global config key, the per-figurecolormap=argument, and the figures that deliberately ignore both.Reach audit (deliverable 1 of the issue)
Every 2D raster call in PyAutoArray resolves its colormap from the config, because all three drawing modules default
colormap=Noneand then call_default_colormap():autoarray/plot/array.pyimshowautoarray/plot/grid.pyscatterautoarray/plot/inversion.pyimshow/pcolormesh/tripcolorEverything above them —
autoarray/dataset/plot/,autoarray/fit/plot/,autoarray/inversion/plot/, PyAutoGalaxy's_resolve_colormap("default")(autogalaxy/util/plot_utils.py:97-102), PyAutoLens'stracer_plots.py/sensitivity_plots.py/imaging/plot/fit_imaging_plots.py— either threadscolormapthrough or leaves itNone, so the config value reaches the raster call on every path. No surface silently ignores the key.Callers that omit
colormap=(e.g.dataset/plot/imaging_plots.py:186-188) still honour the config — they just cannot be overridden per-figure from that level.plot_yxis a 1D line plot and takes no colormap.Deliberate exceptions, now documented in the README rather than left silent:
autoarray/plot/array.py:208—cmap="Greys"for thearray_overlay. The overlay is drawn on top of the main array, so it must contrast with whatever colormap the main array uses.autolens/weak/plot/weak_dataset_plots.py—viridis(ellipticities),twilight(position angles: cyclic data needs a cyclic map),magma(noise map).autolens/weak/plot/fit_weak_plots.py:119—RdBu_r(diverging, centred on the median residual).autolens/weak/plot/convergence_plots.py:202—magma.autolens/cluster/plot/cluster_plots.py:49—CLUSTER_CMAP = "gnuplot2".autolens/potential_correction/*,autogalaxy/gui/clicker.py—jetin research and interactive-GUI-only code paths.None of these are changed: the colormap carries meaning (cyclic, diverging, contrast) that a global preference should not silently override.
Per-figure override (deliverable 2)
The route already exists and is now documented and covered by a test:
colormap=on any plot function.The "use the config value" default is spelled
Nonein PyAutoArray and PyAutoLens,"default"in PyAutoGalaxy. No new code was needed.API Changes
None — internal changes only.
_default_colormap,_conf_imshow_originand_conf_output_formatare private; thecolormapconfig key and every publiccolormap=argument keep their names and defaults.One behaviour change is user-visible: a
colormap(orimshow_origin) config value that was previously ignored now raisesValueErrorat plot time instead of silently reverting. Any config that was actually working is unaffected.Test Plan
python -m pytest test_autoarray/plot -q— plot suite greenpython -m pytest test_autoarray -q -n auto— full suite greentest_autoarray/plot/test_utils.py: config value returned, absent key → quietautoarrayfallback + registration, unknown name →ValueError, non-string →ValueError, per-figurecolormap=beats config, and one config edit moves bothplot_arrayandplot_inversion_reconstructionimshowArray2Dfigure and a rectangular-mapper inversion reconstruction undercolormap: magma— both visually magma, from the one config edit — and a malformed value raised the new errorFull API Changes (for automation & release notes)
Changed Behaviour
visualize/general.yaml -> colormap— a value that is notautoarrayand not a registered matplotlib colormap now raisesValueErrorat plot time instead of silently falling back toautoarray.visualize/general.yaml -> general -> imshow_origin— a value other thanupper/lowernow raisesValueErrorinstead of silently falling back toupper.Added
autoarray.plot.utils._validate_colormap(name)(private) — raisesValueErrorunless name is a registered matplotlib colormap.Migration
Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PXGHBFryzQZMFvAskHe9sQ