Skip to content

feat: add WeakDataset and SimulatorShearYX for weak lensing shear catalogs #476

@Jammy2211

Description

@Jammy2211

Overview

First step in a multi-prompt series adding weak gravitational lensing analysis to PyAutoLens. This task introduces a WeakDataset class (shear field + noise map) and a SimulatorShearYX class that evaluates shear at a set of background-galaxy positions using shear_yx_2d_via_hessian_from, with Gaussian per-component noise. Visualization is intentionally deferred to a follow-up prompt (2_visualization.md).

Plan

  • Add WeakDataset (PyAutoLens) modelled on PointDataset: holds a ShearYX2DIrregular, a per-component noise_map, and an optional source redshift; JSON I/O for now, CSV layer flagged as future extension.
  • Add SimulatorShearYX (PyAutoLens) modelled on SimulatorImaging: takes a Tracer/galaxies + grid, evaluates shear via the Hessian path, adds Gaussian noise, returns a WeakDataset. Convenience constructor draws a uniform random grid of background galaxies.
  • Verify the existing test__shear_yx_2d_from__matches_via_hessian cross-check in PyAutoGalaxy already pins the convention between the analytic Isothermal path and the Hessian path; extend grid coverage if too narrow.
  • Add unit tests for WeakDataset (shapes, round-trip) and SimulatorShearYX (seeded determinism, agreement with Isothermal.shear_yx_2d_from within noise tolerance, random-grid extent).
  • Add a workspace simulator script under scripts/weak/simulator.py using an Isothermal lens, with a # TODO: 2_visualization.md placeholder for plots.
  • Drop the 2_visualization.md follow-up prompt describing matplotlib-quiver shear plotting so the next series prompt is queued.
Detailed implementation plan

Affected Repositories

  • PyAutoLens (primary — library)
  • autolens_workspace (follow-up — workspace simulator script)
  • PyAutoGalaxy (verify-only; new test only if existing coverage is too narrow)
  • PyAutoPrompt (drop 2_visualization.md follow-up)

Work Classification

Both — library work first (PyAutoLens), workspace follows after the library PR ships, per the library-first merge gate.

Branch Survey

Repository Current Branch Dirty?
PyAutoLens main clean
autolens_workspace main clean
PyAutoGalaxy main clean
PyAutoPrompt main (only prompt-file edits)

Suggested branch: feature/weak-shear-simulator
Worktree root: ~/Code/PyAutoLabs-wt/weak-shear-simulator/ (created later by /start_library)

Implementation Steps

  1. PyAutoLens — autolens/weak/__init__.py — re-export WeakDataset, SimulatorShearYX.
  2. PyAutoLens — autolens/weak/dataset.pyWeakDataset(shear_yx, noise_map, redshift=None). JSON I/O via autoconf.output_to_json. CSV layer left as TODO comment.
  3. PyAutoLens — autolens/weak/simulator.pySimulatorShearYX(noise_sigma, seed=-1) with via_tracer_from, via_galaxies_from, via_random_grid_from.
  4. PyAutoLens — autolens/__init__.py — wire al.WeakDataset and al.SimulatorShearYX.
  5. PyAutoGalaxy — test_autogalaxy/profiles/mass/total/test_isothermal.py:183 — verify cross-check coverage; extend grid only if narrow.
  6. PyAutoLens — test_autolens/weak/test_dataset.py — shapes, JSON round-trip.
  7. PyAutoLens — test_autolens/weak/test_simulator.py — seeded determinism, shear values vs. analytic Isothermal within noise tolerance, via_random_grid_from extent.
  8. autolens_workspace — scripts/weak/simulator.py — Isothermal lens, ~200 random background sources, save WeakDataset JSON to dataset/weak/simple/, placeholder for visualization.
  9. PyAutoPrompt — weak/2_visualization.md — follow-up prompt for WeakDatasetPlotter / ShearYX2DPlotter using matplotlib.pyplot.quiver (note AbstractShearField.elliptical_patches as an ellipse-overlay alternative).

Key Files

  • PyAutoLens/autolens/weak/dataset.py — new WeakDataset class
  • PyAutoLens/autolens/weak/simulator.py — new SimulatorShearYX class
  • PyAutoLens/autolens/__init__.py — register exports
  • PyAutoLens/test_autolens/weak/test_dataset.py — new unit tests
  • PyAutoLens/test_autolens/weak/test_simulator.py — new unit tests
  • PyAutoGalaxy/test_autogalaxy/profiles/mass/total/test_isothermal.py:183-205 — verify, extend if narrow
  • autolens_workspace/scripts/weak/simulator.py — new example script (post-library-ship)
  • PyAutoPrompt/weak/2_visualization.md — follow-up prompt

Original Prompt

Click to expand starting prompt

Do deep research and think hard on planning this one.

I am going to add weak gravitational lens analysis to autolens, whcih is going to be a series of 5 or so
claude prompts to get us there.

First, we need to be able to simulate weak lensing data. The good news is, the ability to generate a shear catalogue
from the source code is already possible. All we need to do is use the shear_yx_2d_via_hessian_from in the
module @PyAutoGalaxy/autogalaxy/operate/lens_calc.py. This returns the shear field which can then be the data
in a simulator.

However, we still need to add noise and do other steps required for a simulator. Thus, can you inspect
@autolens_workspace/scripts/imaging/simulator.py and see how simulations are performed (in this case for CCD imaging
and adapt this to a simulation of a weak lensing shear catalogue?

This returns a shear field defined in @PyAutoGalaxy/autogalaxy/util/shear_field.py, which is how we store
shear fields of data in general.

Can you use an Isothermal profile, which means you can use the method shear_yx_2d_from in the profiles/mass/total/isothermal.py
module. This should have the same outptu as shear_yx_2d_via_hessian_from, but if there is no unit test afgainst that
please add one.

This request will likely require you to add noise sources to the simualted shear field. please look up how to do
this and give me suggestions, I suspect its just random noise. However, we all need a random distribution of background
galaxies whose weak lensing shears we are measuring. Have a look at how to do this, but just drawing a uniform
random is fine for now if needs be. I guess we may end up adding a SimulatorShearYX to the source code to match
the API of other dataset types (e.g. imaging).

This therefore means a Dataset class for the ShearYX2D field will also probably need to be made, which will include
the noise_map of the dataset. I think for now you can look to @PyAutoLens/autolens/point/dataset.py for inspiriation
on the format, noting that we will likely extend this soon to include a .csv layer for large shear fields
(and maybe point dataset). SO, its a good API to base this on. We should call this WeakDataset, noting it contains
ShearYX things.

The simulator script wont be able to output visualization as those tools dont yet exists. Dont put them in this
chunk of work, but create a prompt 2_visualization.md which based on the simulator creates the visualization tools.
So put place holders ready to replace in the simulator. Put in the prompt that visualization will like user the
matplotlib quiver method to best represent weak lesning ellipticities and shears.

Can we also put some unit tests and integration tests on this?

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