Skip to content

docs: ch3 tutorial 3 plots the mask overlay before apply_mask, so no mask is drawn #78

Closed

Description

@Jammy2211

Overview

scripts/chapter_3_pixelizations/tutorial_3_inversions.py introduces an annular mask in the prose and then shows the reader a figure with no mask on it. Two aplt.plot_array(array=dataset.data, title="Data") calls sit above their dataset.apply_mask(mask=mask), and plot_array derives its overlay from the array's own mask one layer down (autoarray/plot/array.py → if mask is None: mask = auto_mask_edge(array)), which returns None for a fully-unmasked array. The tutorial runs green, which is exactly why this has gone unnoticed.

Measured on the installed stack (recorded when the sibling HowToGalaxy tutorial was fixed under plot-array-stale-kwargs, HowToGalaxy#56):

unmasked   -> mask.is_all_false: True  | auto_mask_edge: None
after mask -> mask.is_all_false: False | auto_mask_edge: (156, 2)

The chapter was renamed from chapter_4_pixelizations in the 2026-08 restructure, so the line references in the originating prompt predate it.

Plan

  • Move each of the two pre-apply_mask plot_array calls to sit below its apply_mask, so the figure the prose promises actually carries the mask overlay.
  • Re-read the surrounding prose in both places and adjust wording/ordering where the sentence now runs ahead of or behind the figure — this is a teaching notebook, so sentence order matters as much as the code.
  • Leave the second site's first plot_array (the genuine "here is the raw data" figure, before any mask exists) alone; only the post-mask-creation duplicate moves.
  • Regenerate notebooks/ and the navigator catalogue via PyAutoHands; never hand-edit .ipynb.

Reference idiom

Matches what HowToGalaxy ch4 t3 now does and the canonical form in autogalaxy_workspace/markdown/ellipse/fit.md ("Image Data With Mask Applied").

Detailed implementation plan

Affected Repositories

  • HowToLens (primary)

Work Classification

Workspace (tutorial scripts + generated notebooks)

Branch Survey

Repository Current Branch Dirty?
./HowToLens main clean

Suggested branch: feature/howtolens-ch3-mask-overlay

The two sites (current main, bb356fa)

Site A — scripts/chapter_3_pixelizations/tutorial_3_inversions.py

  • L69–74: mask = al.Mask2D.circular_annular(inner_radius=0.5, outer_radius=2.8)
  • L77: aplt.plot_array(array=dataset.data, title="Data") ← draws no mask
  • L82: dataset = dataset.apply_mask(mask=mask)

The plot sits between the docstring "Lets create an annular mask which traces the strongly lensed source's ring of light." and the docstring "We now create the masked source-plane grid via the tracer, as we did in the previous tutorial." Moving the plot below L82 puts it after the mask is applied; check the second docstring still leads correctly into the plot that now follows it.

Site B — same file

  • L178: aplt.plot_array(array=dataset.data, title="Data") ← legitimate raw-data figure, keep in place
  • L183–189: mask = al.Mask2D.circular_annular(inner_radius=0.1, outer_radius=3.2)
  • L191: aplt.plot_array(array=dataset.data, title="Data") ← draws no mask, and is byte-identical to L178's figure because dataset is unchanged between them
  • L193: dataset = dataset.apply_mask(mask=mask)

Moving L191 below L193 both fixes the overlay and removes a duplicated figure.

Implementation Steps

  1. On feature/howtolens-ch3-mask-overlay cut from origin/main, move site A's plot_array below its apply_mask.
  2. Move site B's second plot_array (L191) below its apply_mask; leave L178 alone.
  3. Give each relocated figure a title that says what it now shows (the canonical idiom is "Image Data With Mask Applied") rather than the bare "Data" it inherited, so the reader can tell the two figures apart.
  4. Re-read the docstring prose around both sites; adjust only where the change makes a sentence read wrong.
  5. Regenerate: PYTHONPATH=../PyAutoHands/autohands python3 ../PyAutoHands/autohands/generate.py howtolens from the repo root, and commit the notebook + catalogue diff alongside the script change.

Key Files

  • scripts/chapter_3_pixelizations/tutorial_3_inversions.py — the only script edited
  • notebooks/chapter_3_pixelizations/tutorial_3_inversions.ipynb — generated, committed
  • llms-full.txt, workspace_index.json — navigator catalogue, regenerated

Acceptance

  • Both relocated figures sit below their apply_mask.
  • notebooks/ + catalogue regenerated, second regeneration a no-op.
  • smoke_tests.yml and navigator_check.yml green on the PR.

Original Prompt

Click to expand starting prompt
# HowToLens ch4 tutorial 3: mask overlay is never actually drawn

Type: docs
Target: howtolens
Repos:
- HowToLens
Themes:
- notebooks
- visualization
Difficulty: small
Autonomy: supervised
Priority: low
Status: formalised
Consequence: judge
Review-minutes: 20
Unattended: ready
Filed: 2026-08-04 (backfilled from git)

Spotted 2026-08-04 while fixing the sibling HowToGalaxy tutorial under
`plot-array-stale-kwargs` (HowToGalaxy#56). **Not a crash** — the tutorial runs
green, which is exactly why it has gone unnoticed.

## The gap

`HowToLens/scripts/chapter_3_pixelizations/tutorial_3_inversions.py` (chapter renamed from chapter_4_pixelizations in the 2026-08 restructure; line refs predate it) and
`:190` both do:

```python
aplt.plot_array(array=dataset.data, title="Data")
...
dataset = dataset.apply_mask(mask=mask)

The plot sits before apply_mask. aplt.plot_array derives its mask overlay
one layer down at autoarray/plot/array.py:128
(if mask is None: mask = auto_mask_edge(array)), and auto_mask_edge returns
None for a fully-unmasked array. Measured on the installed stack:

unmasked   -> mask.is_all_false: True  | auto_mask_edge: None
after mask -> mask.is_all_false: False | auto_mask_edge: (156, 2)

So the figure the prose introduces right after creating an annular mask shows
no mask at all. The reader is told about the mask and then shown a plain
image.

Fix

Move each call below its apply_mask, matching what HowToGalaxy ch4 t3 now
does and the canonical idiom in
autogalaxy_workspace/markdown/ellipse/fit.md:158 ("Image Data With Mask
Applied"). Check the surrounding prose still reads correctly in both places —
this is a teaching notebook, so the sentence order matters as much as the code.

Notebooks are generated: edit scripts/ only, then regenerate
notebooks/ + the navigator catalogue via PyAutoHands. Never hand-edit .ipynb.


</details>

Activity

  1. Jammy2211 commented on Sep 9, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    • PR: docs: draw the mask overlay in ch3 tutorial 3 by plotting after apply_mask #79 — merged 2026-09-09 as 5b51731 (head eb8b26c, branch feature/howtolens-ch3-mask-overlay).
    • CI at merge: 7/7 check runs green — smoke (3.12), smoke (3.13), smoke / changes, navigator / Catalogue staleness, navigator / Navigator paths + banner lint, navigator / Unbatched multi-start search check, tutorials-complete. mergeable_state: clean.

    What changed

    scripts/chapter_3_pixelizations/tutorial_3_inversions.py — both pre-apply_mask plot_array calls now sit below their apply_mask and are retitled "Image Data With Mask Applied". The notebook was regenerated via PyAutoHands; the navigator catalogue regenerated byte-identical (it records paths, header summaries and __Contents__ names, none of which moved).

    Notes worth keeping

    • Site one was fixed by moving apply_mask up, not the figure down. That also repaired a pre-existing prose/code mismatch: the docstring "We now create the masked source-plane grid via the tracer" was introducing apply_mask, and now sits directly above the lens_galaxy/tracer/source_plane_grid block it actually describes.
    • Site two also lost a duplicate. Its two figures were byte-identical — dataset was unchanged between them — so the second one was both mask-less and redundant. The genuine raw-data figure before any mask exists is untouched.
    • Mechanism confirmed on a live stack (autolens 2026.9.8.1), not taken on trust: with the tutorial's own 0.5″/2.8″ annulus, auto_mask_edge goes None → (264, 2) across apply_mask. The edge count differs from the (156, 2) in the original report only because that was measured under PYAUTO_SMALL_DATASETS.
    • Not verified: the rendered PNG was not eyeballed. What was verified is that auto_mask_edge returns a real edge array at the point each relocated call now runs, which is the mechanism the overlay depends on.
    • The pending-release label stays on docs: draw the mask overlay in ch3 tutorial 3 by plotting after apply_mask #79 — HowToLens is not a library repo, so there is no pending-release: obligation on the Mind row; the label is the release build's own tracking and /prm never clears it.

    Shipped as the sole implementation member of the notebooks bundle. Its two siblings closed without PRs: multi_galaxy_package is still blocked (MAST 403s from cloud sessions), and notebook_setup_notebook_drift_siblings turned out already-shipped since 2026-08-07 and was retired to the Mind's completion ledger.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions