Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ AUTO-GENERATED by PyAutoBuild — do not edit by hand; regenerate with generate.
## weak

- [Fit: Weak Lensing](scripts/weak/fit.py): This script shows how to fit a strong-lens mass model to a weak gravitational lensing shear catalogue. Where the `imaging` and `interferometer` workflows fit a 2D image of a lensed source, the weak-lensing workflow fits a set of (gamma_2, gamma_1) shear measurements at the (y, x) positions of background source galaxies — a ``WeakDataset`` produced by the simulator script in `scripts/weak/simulator.py`.
- Contents: Dataset, Model, Fit, Visualization, Notes
- Contents: Dataset, Model, Fit, Visualization, Shear Profile, Notes
- [Modeling: Weak Lensing](scripts/weak/modeling.py): This script fits a lens mass model to a weak gravitational lensing shear catalogue using a non-linear search. It is the weak-lensing analogue of `scripts/imaging/modeling.py`: where that script infers a lens model from a 2D image of a lensed source, this script infers one from the (gamma_2, gamma_1) shear measurements of background source galaxies — a `WeakDataset` produced by `scripts/weak/simulator.py`.
- Contents: Dataset, Model, Search, Analysis, Run Times, Model-Fit, Output Folder Layout, Result
- [Simulator: Weak Lensing](scripts/weak/simulator.py): This script simulates a weak gravitational lensing shear catalogue. Unlike the imaging simulator (which produces a 2D image of the lensed source) the weak-lensing simulator produces a *catalogue* of (gamma_2, gamma_1) shear measurements at the (y, x) positions of a population of background source galaxies.
Expand Down
37 changes: 36 additions & 1 deletion scripts/weak/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- **Model:** Build a lens-model `Tracer` whose mass profiles produce the model shear field.
- **Fit:** Construct a `FitWeak` and inspect its derived quantities (residuals, chi-squared, log-likelihood).
- **Visualization:** Plot the fit as a 2x2 mosaic of data, model, overlay, and chi-squared map.
- **Shear Profile:** Bin the tangential/cross shear about the lens centre and compare data to model.
- **Notes:** What a "good" fit looks like and how this script relates to the upcoming modeling tutorial.
"""

Expand All @@ -38,10 +39,22 @@
vector and per-galaxy noise standard deviation 0.3. The shear field carries the signature of the
foreground lens's mass distribution.

If `dataset.json` does not yet exist, run `scripts/weak/simulator.py` first.
__Dataset Auto-Simulation__

If the dataset does not already exist on your system, it will be created by running the corresponding
simulator script. This ensures that all example scripts can be run without manually simulating data first.
"""
dataset_path = Path("dataset") / "weak" / "simple"

if al.util.dataset.should_simulate(str(dataset_path)):
import subprocess
import sys

subprocess.run(
[sys.executable, "scripts/weak/simulator.py"],
check=True,
)

dataset = al.from_json(file_path=dataset_path / "dataset.json")

print(dataset.info)
Expand Down Expand Up @@ -123,6 +136,28 @@
output_format="png",
)

"""
__Shear Profile__

The panels above show the fit galaxy by galaxy; cluster weak-lensing results are usually shown instead as
the azimuthally averaged *tangential shear profile* `gamma_t(r)` — the mean tangential stretching of
background galaxies in radial bins about the lens centre, which traces the projected mass profile (this is
the standard observable of analyses such as the Sloan Giant Arcs Survey and the Frontier Fields clusters).

`aplt.plot_shear_profile` bins the catalogue about a chosen centre and, because we pass it the `FitWeak`,
overlays the model shear's tangential profile as a line. The plot also shows the *cross* component
`gamma_x` (the 45-degree rotated component): gravitational lensing produces none at leading order, so the
cross points scattering around zero is the standard "B-mode" null test — a systematic contaminating the
measurement would show up here.
"""
aplt.plot_shear_profile(
fit,
centre=(0.0, 0.0),
bins=8,
output_path=dataset_path,
output_format="png",
)

"""
__Notes__

Expand Down
2 changes: 1 addition & 1 deletion scripts/weak/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
dataset_name = "simple"
dataset_path = Path("dataset") / "weak" / dataset_name

if not (dataset_path / "dataset.json").exists():
if al.util.dataset.should_simulate(str(dataset_path)):
import subprocess
import sys

Expand Down
22 changes: 22 additions & 0 deletions scripts/weak/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,27 @@
output_format="png",
)

"""
__Convergence Map__

The shear field can be inverted directly into a map of the convergence `kappa` (the dimensionless projected
mass density) using the Kaiser-Squires (1993) technique: in Fourier space shear and convergence are related
algebraically, so two FFTs turn the catalogue into a "dark matter map" with no mass model assumed. This is
the classic visualization used for merging clusters (e.g. the Bullet cluster) and survey mass maps.

`aplt.plot_convergence_map` bins the irregular catalogue onto a regular grid, applies a small Gaussian
smoothing (raw per-cell shears are shape-noise dominated) and plots the E-mode reconstruction. For this
Isothermal lens the map peaks at the lens centre at (0.0", 0.0"). Two caveats to remember: the mean of the
map is unconstrained (the mass-sheet degeneracy) and FFT periodicity causes artefacts near the field edges —
for quantitative masses, fit a mass model with `scripts/weak/modeling.py` instead.
"""
aplt.plot_convergence_map(
shear_yx=dataset.shear_yx,
shape_native=(30, 30),
smoothing_sigma_pixels=1.0,
output_path=dataset_path,
output_format="png",
)

print(dataset.info)
print(f"Wrote dataset to {dataset_path}")
5 changes: 4 additions & 1 deletion workspace_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -5791,6 +5791,7 @@
"Model",
"Fit",
"Visualization",
"Shear Profile",
"Notes"
],
"cross_refs": [
Expand Down Expand Up @@ -5836,7 +5837,9 @@
"Output",
"Visualize"
],
"cross_refs": [],
"cross_refs": [
"scripts/weak/modeling.py"
],
"notebook": "notebooks/weak/simulator.ipynb",
"path": "scripts/weak/simulator.py",
"summary": "This script simulates a weak gravitational lensing shear catalogue. Unlike the imaging simulator (which produces a 2D image of the lensed source) the weak-lensing simulator produces a *catalogue* of (gamma_2, gamma_1) shear measurements at the (y, x) positions of a population of background source galaxies.",
Expand Down
Loading