Skip to content

feat: tangential/cross shear profile + Kaiser-Squires map (weak series step 6) #581

Closed

Description

@Jammy2211

Overview

Step 6 of the weak-lensing series (PyAutoMind/z_features/weak_shear.md): add the two canonical cluster weak-lensing diagnostics missing from autolens/weak/plot/ — the azimuthally averaged tangential/cross shear radial profile (THE standard observable in cluster weak lensing; the cross component is the B-mode null test) and a Kaiser-Squires convergence-map reconstruction. Science anchors: Oguri et al. 2012 (SGAS), Medezinski et al. 2016 (A2744). Independent of the other queued series steps; step 7 (real-data A2744) will reuse both plotters.

Plan

  • Add shear-profile math + plotters to autolens/weak/plot/: shear_tangential_cross_from(shear_yx, centre) and plot_shear_profile (binned γ_t/γ_x vs radius with error bars).
  • Add convergence_via_kaiser_squires_from (grid the irregular shear field, FFT KS inversion) + plot_convergence_map.
  • Re-export both plotters into aplt alongside the existing nine weak helpers.
  • NumPy-only unit tests against the SIS analytic profile γ_t(r) = θ_E/2r, γ_x = 0.
  • Workspace follow-up: demo both in scripts/weak/fit.py (profile of data vs model) and simulator.py (KS map), navigator catalogue regeneration if summaries change.
Detailed implementation plan

Affected Repositories

  • PyAutoLens (primary — library)
  • autolens_workspace (follow-up — extend scripts/weak/{simulator,fit}.py demos)

Branch Survey

Repository Current Branch Dirty?
./PyAutoLens main (post #580) clean
./autolens_workspace main (post #241) pre-existing regenerated dataset files only

Suggested branch: feature/weak-viz-profiles
Worktree: ~/Code/PyAutoLabs-wt/weak-viz-profiles/
Note: autolens_workspace remains claimed by lenstool-example; the workspace demo uses the parallel-worktree pattern (fourth use; scripts/weak/ has zero overlap).

Implementation Steps

  1. autolens/weak/plot/shear_profile_plots.py:
    • shear_tangential_cross_from(shear_yx, centre=(0.0, 0.0)) → (gamma_t, gamma_x, radii) per galaxy. Use ONLY the public accessors (.ellipticities for |γ|, .phis for the shear angle in degrees, .grid for positions) — never index the raw [γ₂, γ₁] storage (encapsulation rule from series step 2). γ_t = −Re[γ e^{−2iφ}], γ_x = −Im[γ e^{−2iφ}] with φ the position angle about centre.
    • plot_shear_profile(obj, centre=, bins=, ax=None, output_*=) accepting a WeakDataset or FitWeak (plot data profile; if a fit, overlay the model-shear profile). Radial bins: plain mean + standard error per bin; γ_x series expected consistent with zero.
  2. autolens/weak/plot/convergence_plots.py:
    • convergence_via_kaiser_squires_from(shear_yx, shape_native=(50, 50), smoothing_sigma_pixels=1.0) — bin the irregular (γ1, γ2) onto a regular grid over extent_from(), FFT inversion κ̂ = [(k1²−k2²)γ̂1 + 2k1k2 γ̂2]/k², optional Gaussian smoothing, return aa.Array2D.
    • plot_convergence_map(...) imshow-style with galaxy positions overlaid.
  3. Re-export both plot functions in autolens/plot/__init__.py (weak block, lines ~75-87).
  4. Tests test_autolens/weak/test_shear_profile.py + test_convergence.py (NumPy-only):
    • Noise-free SimulatorShearYX SIS dataset: binned γ_t matches θ_E/2r within bin tolerance; γ_x ≈ 0 (atol ~1e-10 noise-free).
    • KS map: peak within one grid pixel of the lens centre; κ positive at centre; B-mode (imaginary residual) negligible.
    • Direct module imports in tests (the al.plot pytest recursion gotcha).
  5. Full test_autolens/ suite.

Workspace follow-up (second PR, library-first gate)

  1. scripts/weak/fit.py: add a __Shear Profile__ section plotting data-vs-model γ_t/γ_x profiles.
  2. scripts/weak/simulator.py: add a __Convergence Map__ section with the KS reconstruction.
  3. Regenerate navigator catalogue (PyAutoBuild/autobuild/regenerate_navigator.py autolens) — Contents lines change.

Key Files

  • autolens/weak/plot/{weak_dataset_plots,fit_weak_plots}.py — existing helpers + save/subplot conventions to match.
  • autogalaxy/util/shear_field.py — ShearYX2DIrregular public accessors.
  • test_autolens/weak/test_fit.py — SIS fixture pattern to reuse.

Autonomy

--auto continuation (launch 2026-07-09), effective level supervised (header supervised, feature cap supervised): plan-to-issue, mechanical stretches proceed, ship sign-off parks as a batched question here, merge stays human. Brain Feature Agent failed to classify this prompt (no repos resolved, suggested research); classification emulated inline per WORKFLOW.md — recorded for post-hoc review.

Original Prompt

Click to expand starting prompt

Weak lensing shear profile and convergence map visualization. Add the two canonical cluster weak-lensing diagnostics missing from autolens/weak/plot: (1) an azimuthally averaged tangential and cross shear radial profile helper (binned gamma_t / gamma_x vs radius with error bars, cross-shear as the standard B-mode null test) computed about a chosen centre from a WeakDataset or FitWeak; (2) a Kaiser-Squires style convergence map reconstruction plotted from the shear field. Re-export into aplt alongside the existing nine quiver helpers and demo both in autolens_workspace/scripts/weak (extend simulator.py / fit.py outputs). Tangential shear profiles are THE standard observable in cluster weak lensing (Oguri 2012 SGAS; Medezinski 2016 A2744).

Activity

  1. Jammy2211 commented on Jul 9, 2026

    @Jammy2211
    CollaboratorAuthor

    Scope addition (user direction, 2026-07-09): the workspace half of this task also adopts the standard al.util.dataset.should_simulate auto-simulation pattern (the imaging-style __Dataset Auto-Simulation__ section, pointed at scripts/weak/simulator.py) in scripts/weak/fit.py and migrates scripts/weak/modeling.py's plain exists() check to it. Prompt 9 (PYAUTO_SMALL_DATASETS) updated to reference this rather than duplicate it.

  2. Jammy2211 commented on Jul 9, 2026

    @Jammy2211
    CollaboratorAuthor

    Ship sign-off requested (supervised checkpoint — run parked here)

    What was done. Both halves implemented, validated and committed locally on feature/weak-viz-profiles (nothing pushed). Library commit b508ffa8: shear_profile_plots.py (per-galaxy γ_t/γ_x + binned profiles + plot_shear_profile with model overlay for fits) and convergence_plots.py (Kaiser-Squires E/B-mode inversion + plot_convergence_map), both re-exported into aplt, plus 6 new unit tests. Workspace commit d6090b72: __Shear Profile__ section in fit.py, __Convergence Map__ section in simulator.py, the should_simulate auto-simulation adoption in fit.py + modeling.py (user-directed scope addition), navigator catalogue regenerated in-branch (so the staleness CI leg passes first time, unlike PR #241).

    Validation.

    • PyAutoLens full suite: 352 passed (38 weak, 6 new).
    • Convention checks: SIS field is pure-tangential (γ_t = |γ| to 1e-6, γ_x = 0); binned γ_t matches the SIS analytic θ_E/2r within bin discretisation; KS map peaks at the lens centre with E ≫ B.
    • Axis-parity check (the SIS tests are rotation-invariant and blind to mirror errors): a q=0.5 lens at 45° reconstructs with KS major axis 47.1° — added as a regression test.
    • End-to-end: simulator.py and fit.py ran in the worktree; figures attached to the PR after push. fit.py auto-simulated the dataset from scratch after rm -rf (proving the should_simulate path); χ² = 437.510 for 400 DoF — bit-identical to the series' known value.
    • Dataset regeneration churn (dataset.json) was restored, not committed.

    Heart: YELLOW, reason set unchanged from the list you acknowledged at the weak-modeling sign-off earlier today (stale 2026-07-08 workspace-validation report, stale parked scripts, assistant version pin, install verification, release validation, old Mind PR).

    The question. Approve shipping? On approval: push both branches, open the PyAutoLens PR (pending-release) and the autolens_workspace PR (library-first gate), append the autonomy-log row — same shape as #580/#241. Amendments welcome here; any session resumes from active.md.

  3. Jammy2211 commented on Jul 9, 2026

    @Jammy2211
    CollaboratorAuthor

    Ship approved — PRs open: #582 (library, pending-release) and PyAutoLabs/autolens_workspace#244 (workspace, merge after the library PR). Watching CI; will merge library-first on green and close this issue.

  4. Jammy2211 commented on Jul 9, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped ✅

    Both PRs merged library-first with all CI green on the first run (the in-branch catalogue regeneration avoided #241's staleness red):

    The weak series now has its full core visualization suite (11 aplt helpers). Continuing the home straight: step 5 (likelihood_function.py) next. Closing.

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