fix: make the GUI helpers' colour scale constructible through the public API - #586
Merged
Merged
Conversation
`Cmap` is no longer exported by any public plot namespace (autoarray.plot, autogalaxy.plot, autolens.plot, autocti.plot). Both GUI helpers still required one, so their colour scale could only be supplied via a private-path import: - `Clicker.start()` built `aplt.Cmap(...)` on `autoarray.plot` itself (clicker.py:31), so it raised `AttributeError: module 'autoarray.plot' has no attribute 'Cmap'` for every caller. - `Scribbler.__init__` took a `Cmap`-shaped object as its `cmap=` argument, leaving callers no public way to colour the GUI. Replace the object with flat arguments matching the `plot_array` convention: - Add `norm_from(array, use_log10, vmin, vmax)` to `util/plot_utils.py`, mirroring the normalisation `autoarray.plot.array.plot_array` applies, so code drawing its own axes scales colour the same way the plot functions do. - `Scribbler.__init__` gains `norm` / `vmin` / `vmax` and accepts a colormap name for `cmap`. A legacy `Cmap`-style object still works, so any caller holding an instance is not broken. - `Clicker.start()` uses the helper directly; its hardcoded scale is unchanged. - Drop the duplicate `Scribbler` import in `__init__.py` (it appeared at both line 76 and line 124), keeping the one grouped with `Clicker`. Adds `test_autogalaxy/gui/`, which did not exist: nine tests over the norm construction, the new signature, and a regression guard asserting `Cmap` stays absent from the public namespaces. `Scribbler.__init__` itself is not covered because it needs TkAgg and a display; the extracted helper carries the logic. Full suite green on Python 3.12 (1122 passed); 3.13 is left to CI. Note for a follow-up, not fixed here: autoarray duplicates this same normalisation inline in `plot/array.py` and `plot/inversion.py`. A shared helper there would be the real fix; this adds one copy in autogalaxy serving both GUIs rather than a third inline copy. Refs PyAutoGalaxy#585 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LN2Qsx6JjVKV45o17EKGtB
`plot_array` auto-derives its mask outline from `array.mask`, which yields nothing for an unmasked array. The autogalaxy wrapper did not forward autoarray's `mask=` parameter, so a caller wanting to outline a *different* mask — the common preprocessing case of showing a candidate mask radius over unmasked data — had no way to ask for it through the public API. Add the `mask=` passthrough plus `_mask_edge`, which accepts a `Mask2D` (or coordinates already in edge form) and mirrors `auto_mask_edge`'s contract of returning None when there is no edge to draw. Verified by rendering: on an unmasked array `auto_mask_edge` returns None and the outline is absent, while passing `mask=` changes 2436 pixels of the output PNG. Seven tests added in test_autogalaxy/plot/test_plot_array_mask.py. Full suite green on Python 3.12 (1129 passed). Refs PyAutoGalaxy#585 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LN2Qsx6JjVKV45o17EKGtB
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.
Closes part of #585.
Cmapis no longer exported by any public plot namespace — notautoarray.plot,autogalaxy.plot,autolens.plotorautocti.plot. Two GUIhelpers in this repo still required one, so their colour scale could only be
supplied via a private-path import. A third gap surfaced while migrating the
downstream caller.
API Changes
Scribbler.__init__— new arguments, backward compatible.norm,vminandvmaxare added andcmapnow accepts a colormap name. Alegacy
Cmap-style object exposingnorm_fromis still accepted and takesprecedence, so any caller holding an instance keeps working. Passing nothing is
unchanged.
plot_array— new optionalmask=argument.The wrapper delegates to
autoarray.plot.plot_arraybut was silently droppingthat function's
mask=parameter. Because the outline is otherwise auto-derivedfrom
array.mask, a caller wanting to outline a different mask — the ordinarypreprocessing case of showing a candidate mask radius over unmasked data — had
no way to ask for it. Purely additive; omitting it preserves current behaviour.
Clicker.start()— bug fix, no signature change. It builtaplt.Cmap(...)onautoarray.plotunconditionally, so it raised for everycaller:
Removed: nothing. Deprecated: nothing.
Changes
util/plot_utils.py— addsnorm_from(array, use_log10, vmin, vmax),mirroring the normalisation
autoarray.plot.array.plot_arrayapplies so codedrawing its own axes scales colour identically; adds
_mask_edgeand themask=passthrough.gui/scribbler.py— flat colour arguments, legacy object path retained.gui/clicker.py— uses the helper; its hardcoded scale is unchanged.__init__.py— drops a duplicateScribblerimport present at both line 76and line 124.
Testing
test_autogalaxy/gui/is new (the directory did not exist). 16 tests addedacross two files: norm construction, the new signature,
_mask_edge's contract,and a regression guard asserting
Cmapstays absent from the public namespaces.The mask passthrough is verified by rendering, not just binding: on an
unmasked array
auto_mask_edgereturnsNoneand no outline appears, whilepassing
mask=changes 2436 pixels of the output PNG.Full suite green locally: 1129 passed on Python 3.12. CI covers 3.13.
Limitations, stated plainly
Scribbler.__init__has no direct test. It callsmatplotlib.use("TkAgg")and
mng.window.wm_geometry, so it cannot run headless. The extractednorm_fromhelper carries the logic and is fully tested; the constructor'sbranching is covered only by signature binding.
3.13 is unverified until CI runs.
Follow-up, not fixed here
autoarrayduplicates this same normalisation inline inplot/array.pyandplot/inversion.py. A shared helper there would be the real fix; this adds onecopy in autogalaxy serving both GUIs rather than a third inline copy.
Downstream
euclid_strong_lens_modeling_pipelinehas a companion branch of the same namethat depends on both API changes. It must merge after this PR, per the
library-first gate.
Generated by Claude Code