From eb8b26cd085cf522b0c1659287266a0c6eae1267 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 9 Sep 2026 22:28:18 +0000 Subject: [PATCH] docs: draw the mask overlay in ch3 tutorial 3 by plotting after apply_mask MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two `aplt.plot_array` calls in chapter_3_pixelizations/tutorial_3_inversions.py sat above their `dataset.apply_mask(mask=mask)`, so the figure the prose introduces right after building an annular mask showed no mask at all. `plot_array` derives its overlay from the array's own mask one layer down (`auto_mask_edge`), which returns None for a fully-unmasked array. The tutorial runs green, which is why it went unnoticed. Each site now applies the mask before it plots, and each relocated figure is retitled "Image Data With Mask Applied" — the canonical idiom — instead of the bare "Data" it inherited. At the second site that also removes a duplicate: the two figures were byte-identical because `dataset` was unchanged between them. Site one reads better for the move: the docstring "We now create the masked source-plane grid via the tracer" was introducing `apply_mask`, and now sits directly above the tracer block it describes. The genuine raw-data figure before any mask exists is left in place. Notebook regenerated via PyAutoHands; the navigator catalogue is unchanged (it records paths, header summaries and __Contents__ names, none of which moved). Closes #78 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_0119sx8hEa8cDa8c2q55FtmM --- .../tutorial_3_inversions.ipynb | 29 ++++++++++++++----- .../tutorial_3_inversions.py | 16 +++++----- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/notebooks/chapter_3_pixelizations/tutorial_3_inversions.ipynb b/notebooks/chapter_3_pixelizations/tutorial_3_inversions.ipynb index 952769c..ae3629b 100644 --- a/notebooks/chapter_3_pixelizations/tutorial_3_inversions.ipynb +++ b/notebooks/chapter_3_pixelizations/tutorial_3_inversions.ipynb @@ -139,7 +139,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Lets create an annular mask which traces the strongly lensed source's ring of light." + "Lets create an annular mask which traces the strongly lensed source's ring of light, and apply it to the dataset." ] }, { @@ -153,8 +153,24 @@ " outer_radius=2.8,\n", ")\n", "\n", - "\n", - "aplt.plot_array(array=dataset.data, title=\"Data\")" + "dataset = dataset.apply_mask(mask=mask)" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now the mask is applied, plotting the data draws it over the image, letting us check the annulus traces the ring of\n", + "lensed source light." + ] + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "aplt.plot_array(array=dataset.data, title=\"Image Data With Mask Applied\")" ], "outputs": [], "execution_count": null @@ -170,8 +186,6 @@ "cell_type": "code", "metadata": {}, "source": [ - "dataset = dataset.apply_mask(mask=mask)\n", - "\n", "lens_galaxy = al.Galaxy(\n", " redshift=0.5,\n", " mass=al.mp.Isothermal(\n", @@ -355,11 +369,10 @@ " outer_radius=3.2,\n", ")\n", "\n", - "\n", - "aplt.plot_array(array=dataset.data, title=\"Data\")\n", - "\n", "dataset = dataset.apply_mask(mask=mask)\n", "\n", + "aplt.plot_array(array=dataset.data, title=\"Image Data With Mask Applied\")\n", + "\n", "lens_galaxy = al.Galaxy(\n", " redshift=0.5,\n", " mass=al.mp.Isothermal(\n", diff --git a/scripts/chapter_3_pixelizations/tutorial_3_inversions.py b/scripts/chapter_3_pixelizations/tutorial_3_inversions.py index d84d4dc..0e06b3b 100644 --- a/scripts/chapter_3_pixelizations/tutorial_3_inversions.py +++ b/scripts/chapter_3_pixelizations/tutorial_3_inversions.py @@ -64,7 +64,7 @@ ) """ -Lets create an annular mask which traces the strongly lensed source's ring of light. +Lets create an annular mask which traces the strongly lensed source's ring of light, and apply it to the dataset. """ mask = al.Mask2D.circular_annular( shape_native=dataset.shape_native, @@ -73,14 +73,17 @@ outer_radius=2.8, ) +dataset = dataset.apply_mask(mask=mask) -aplt.plot_array(array=dataset.data, title="Data") +""" +Now the mask is applied, plotting the data draws it over the image, letting us check the annulus traces the ring of +lensed source light. +""" +aplt.plot_array(array=dataset.data, title="Image Data With Mask Applied") """ We now create the masked source-plane grid via the tracer, as we did in the previous tutorial. """ -dataset = dataset.apply_mask(mask=mask) - lens_galaxy = al.Galaxy( redshift=0.5, mass=al.mp.Isothermal( @@ -187,11 +190,10 @@ outer_radius=3.2, ) - -aplt.plot_array(array=dataset.data, title="Data") - dataset = dataset.apply_mask(mask=mask) +aplt.plot_array(array=dataset.data, title="Image Data With Mask Applied") + lens_galaxy = al.Galaxy( redshift=0.5, mass=al.mp.Isothermal(