Repository navigation
Description
Overview
Step 2 of the weak gravitational lensing series. Step 1 (PyAutoLens #472) added the WeakDataset class and SimulatorShearYX simulator, plus the workspace simulator script autolens_workspace/scripts/weak/simulator.py with two # TODO(2_visualization.md) placeholders. This task adds the visualization layer that fills those placeholders — module-level aplt.subplot_weak_dataset and aplt.plot_shear_yx_2d helpers, drawn as quivers of headless line segments (the standard weak-lensing-paper convention since shear is a spin-2 quantity).
Plan
- Add a
weak/plot/package inside PyAutoLens with module-level plot helpers for shear catalogues (single-panel and a 2×2 subplot mosaic). - Re-export the new helpers into the
apltnamespace throughautolens.plot.__init__, mirroring howsubplot_imaging_datasetis exposed. - Replace the
# TODO(2_visualization.md)placeholders inautolens_workspace/scripts/weak/simulator.pywith realapltcalls and a docstring prose block. - Add unit tests under
PyAutoLens/test_autolens/weak/plot/that assert the plotters run and write the expected output files, mirroringtest_imaging_plotters.py.
Detailed implementation plan
Affected Repositories
- PyAutoLens (primary — new plot module + tests)
- autolens_workspace (follow-up — replace TODO placeholders in
weak/simulator.py)
Work Classification
Library, with workspace follow-up after the library PR merges.
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| PyAutoLens | main | clean |
| autolens_workspace | main | dirty (unrelated dataset/** / start_here.py noise — scripts/weak/ clean) |
Suggested branch: feature/weak-visualization
Worktree root: ~/Code/PyAutoLabs-wt/weak-visualization/ (created later by /start_library, once use-pathlib ships)
Blocked by
use-pathlib currently holds PyAutoLens via ~/Code/PyAutoLabs-wt/use-pathlib (along with PyAutoConf, PyAutoFit, PyAutoArray, PyAutoGalaxy). This task is queued in PyAutoPrompt/planned.md and can start once use-pathlib ships and releases the PyAutoLens worktree.
Design choice: functions, not a class
The prompt asks for a WeakDatasetPlotter "analogous to ImagingPlotter", but ImagingPlotter is not a class in this codebase — it's a set of module-level functions in PyAutoArray/autoarray/dataset/plot/imaging_plots.py (subplot_imaging_dataset, subplot_imaging_dataset_list, fits_imaging) re-exported into the aplt namespace via PyAutoLens/autolens/plot/__init__.py:14. The point analogue (autolens/point/plot/point_dataset_plots.py:7) follows the same functional pattern. We match that — module-level functions, not a class.
Implementation Steps
-
New plot module —
PyAutoLens/autolens/weak/plot/(matchingautolens/point/plot/):weak_dataset_plots.pywith module-level functions:plot_shear_yx_2d(shear_yx, ax=None, ...)— single-panel quiver. Useshear_yx.ellipticities+shear_yx.phisto derive(u, v) = (mag·cos(phi), mag·sin(phi)), thenax.quiver(x, y, u, v, mag, pivot="middle", headwidth=0, headlength=0, headaxislength=0). Do not index[:, 0]/[:, 1]directly —phis/ellipticitiesare the abstraction (per prompt point 5, insulating against theShearYX2D[:,0]=γ₂, [:,1]=γ₁storage convention pinned by PyAutoGalaxy PR Jax to Main! #366).plot_ellipticities(shear_yx, ax=None, ...)— color-coded scatter of|γ|, reusesautoarray.plot.grid.plot_gridwithcolor_array.plot_phis(shear_yx, ax=None, ...)— color-coded scatter ofφ, cyclic colormap.plot_noise_map(noise_map, positions, ax=None, ...)— color-coded scatter of per-galaxy noise σ.subplot_weak_dataset(dataset, ...)— 2×2 mosaic: shear field | noise map /|γ||φ. Usessubplots,subplot_save,conf_subplot_figsize,tight_layoutfromautoarray.plot.utils.
-
apltnamespace wiring — editPyAutoLens/autolens/plot/__init__.pyto import the 5 new helpers (insert next tosubplot_point_datasetat line 66). -
Workspace script update — replace the TODO block at
autolens_workspace/scripts/weak/simulator.py:109-113with a"""__Visualize__"""docstring (which is the workspace's notebook-cell convention —PyAutoBuild/autobuild/generate.pyconverts these to# %%markdown cells) followed byaplt.subplot_weak_dataset(dataset=dataset, output_path=dataset_path, output_format="png")andaplt.plot_shear_yx_2d(shear_yx=dataset.shear_yx, output_path=str(dataset_path), output_filename="shear_yx", output_format="png"). Keep the existingprint(dataset.info)line. -
Unit tests —
PyAutoLens/test_autolens/weak/plot/test_weak_dataset_plots.py. Build a small 4-galaxyShearYX2DIrregularfixture, then assert each plot helper writes the expected file underplot_patch.paths(theplot_patchfixture comes fromPyAutoLens/test_autolens/conftest.py, already used bytest_autolens/lens/plot/andtest_autolens/point/plot/). Five tests total — one per helper.
Key Files
- New:
PyAutoLens/autolens/weak/plot/__init__.py— empty package marker. - New:
PyAutoLens/autolens/weak/plot/weak_dataset_plots.py— 5 functions described above. - New:
PyAutoLens/test_autolens/weak/plot/__init__.py— empty. - New:
PyAutoLens/test_autolens/weak/plot/test_weak_dataset_plots.py— 5 tests. - Edit:
PyAutoLens/autolens/plot/__init__.py— add 5 imports. - Edit:
autolens_workspace/scripts/weak/simulator.py:109-113— replace TODO block.
Reused utilities (no need to re-implement)
subplots,subplot_save,save_figure,conf_subplot_figsize,tight_layout,apply_labels,apply_extent—autoarray.plot.utilsplot_grid—autoarray.plot.grid(scalar-coloured scatter for the|γ|/φ/ noise panels)AbstractShearField.{ellipticities, phis, semi_major_axes, semi_minor_axes}—autogalaxy/util/shear_field.py:55WeakDataset.{positions, extent_from}—autolens/weak/dataset.py:75,95
Verification
NUMBA_CACHE_DIR=/tmp/numba_cache MPLCONFIGDIR=/tmp/matplotlib python -m pytest test_autolens/weak/ -v— all 5 new plot tests + existing dataset/simulator tests pass.- After workspace follow-up:
cd autolens_workspace && python scripts/weak/simulator.py— producesdataset/weak/simple/dataset_weak.pngandshear_yx.png. Visually confirm tangential alignment around the lens centre at (0, 0) (consistent with the Isothermal mass profile). - JAX cleanliness:
grep "^import jax\|^from jax" PyAutoLens/autolens/weak/plot/*.py— no matches (thexpopt-in pattern; the plotters don't need JAX). - Library-first merge gate: workspace edit ships only after the PyAutoLens PR merges (
/ship_library→/ship_workspace).
Original Prompt
Click to expand starting prompt
Step 2 of the weak gravitational lensing series. Step 1 (1_simulator.md, shipped via PyAutoLens issue #472) added the WeakDataset data class and the SimulatorShearYX simulator, plus a workspace simulator script at @autolens_workspace/scripts/weak/simulator.py with # TODO(2_visualization.md) placeholders where the plots should go. This prompt adds the visualization layer.
The natural matplotlib primitive for shear fields is plt.quiver — each shear vector (gamma_2, gamma_1) at position (y, x) becomes an arrow whose length is the shear magnitude |gamma| = sqrt(gamma_1**2 + gamma_2**2) and whose orientation is the position angle phi = 0.5 * arctan2(gamma_2, gamma_1). For weak-lensing science papers the convention is usually to draw "headless" line segments rather than arrows (since shear is a spin-2 quantity, not a vector — a 180-degree rotation maps shear to itself). Quiver supports this via headwidth=0, headlength=0.
The ShearYX2D data structures already expose what you need: .ellipticities, .semi_major_axes, .semi_minor_axes, .phis, and .elliptical_patches. Use these directly where useful.
Please:
-
Look at how plotters are structured in
@PyAutoLens/autolens/plotand howaplt.subplot_imaging_dataset,aplt.plot_array, and similar helpers are wired throughautolens.plotandautoarray.plot. The same module structure should host weak-lensing visualization. -
Add a
WeakDatasetPlotter(analogous toImagingPlotter) which can produce:- A scatter / quiver plot of the shear field on top of the source-galaxy positions.
- A subplot mosaic showing the shear, its noise map, and (if useful) the ellipticities and position angles.
- A
subplot_weak_datasethelper at theapltnamespace level mirroringaplt.subplot_imaging_dataset.
-
Replace the
# TODO(2_visualization.md)placeholders in@autolens_workspace/scripts/weak/simulator.pywith real calls to the new plotters, plus a# %%markdown cell explaining what's being shown. -
Add unit tests for the plotter (just check it runs without raising under the workspace test mode flags, like the existing
ImagingPlottertests do). -
The
ShearYX2D[:, 0] = gamma_2,[:, 1] = gamma_1storage convention pinned by PyAutoGalaxy PR Jax to Main! #366 must be respected by the plotters. Use.phis/.ellipticitiesrather than indexing directly, so the plotters keep working if downstream we ever swap the storage order.
Good prior art outside the codebase: most weak-lensing papers (e.g. KiDS, DES) draw shear fields as a regular grid of headless line segments scaled by |gamma|. The quiver arguments pivot="middle", headwidth=0, headlength=0, headaxislength=0 produce exactly that.
Activity
Jammy2211 commentedon May 18, 2026
Library PR Created — 2026-05-18
PR
Status
Workspace changes needed. Next: /start_workspace
API Changes
Five new module-level helpers in
autolens.weak.plot.weak_dataset_plots, re-exported into theapltnamespace:plot_shear_yx_2d— headless-quiver of the shear fieldplot_ellipticities,plot_phis— scalar-coloured scatterplot_noise_map— per-galaxy noise scattersubplot_weak_dataset— 2×2 mosaicPure additions, no removals or signature changes. The workspace follow-up replaces two
# TODO(2_visualization.md)placeholders inautolens_workspace/scripts/weak/simulator.pywith realapltcalls.Merge pull request #523 from PyAutoLabs/feature/weak-visualization
Jammy2211 commentedon May 18, 2026
Shipped — 2026-05-18
PRs
Summary
Step 2 of the weak-lensing series. Added a new
autolens.weak.plotpackage with five module-level matplotlib helpers (plot_shear_yx_2d,plot_ellipticities,plot_phis,plot_noise_map,subplot_weak_dataset), all re-exported into theapltnamespace. The plotters render shear vectors as headless quiver segments — the spin-2 convention used across weak-lensing papers (KiDS, DES) since shear is unchanged under 180° rotation. The workspace simulator script's two# TODO(2_visualization.md)placeholders were filled with realapltcalls;scripts/weak/simulator.pynow writessubplot_weak_dataset.pngandshear_yx.pngalongside the existing dataset / tracer JSON outputs.Session Notes
.ellipticitiesand.phis— never raw[:, 0]/[:, 1]indexing — so the[γ₂, γ₁]storage convention pinned by PyAutoGalaxy PR Jax to Main! #366 stays encapsulated. If the storage order ever changes, only the property definitions inAbstractShearFieldneed updating..phisreturns degrees (not radians), soplot_shear_yx_2dconverts vianp.deg2radbefore passing to quiver.from autolens.weak.plot.weak_dataset_plots import ...) becauseal.plot.Xhits a pre-existing recursion inautolens/__init__.py's__getattr__under pytest's attribute-access flow. The point/imaging tests already follow this pattern; aplt-via-namespace still works fine from workspace scripts and notebooks.cluster-scaling-members(which held the registered claim). Zero file overlap (scripts/weak/vsscripts/cluster/), so the parallelism was safe — bypassed the helper's task-level conflict check for the ~30-min window.weak/3_fit.md(FitWeak class),weak/4_modeling.md(AnalysisWeak),weak/5_likelihood_function.md(tutorial). Each will be issued one at a time when its predecessor is close to shipping (per [[feedback_no_bulk_issue_queues]]).feat(weak): aplt plotters for WeakDataset shear catalogues