Skip to content

Commit cbb7ffb

Browse files
Jammy2211claude
authored andcommitted
docs(lens): add module-level docstrings to lens package
Add module-level docstrings to all five substantive modules in autolens/lens/: - tracer.py: core Tracer class — multi-plane ray tracing, lensed images, convergence/shear/magnification maps, critical curves, lens modeling role - tracer_util.py: plane redshift derivation and position propagation utilities - to_inversion.py: TracerToInversion — bridges Tracer to autoarray's linear algebra inversion for linear light profiles and pixelizations - sensitivity.py: SubhaloSensitivityResult — sensitivity mapping workflow for dark-matter subhalo detectability - subhalo.py: SubhaloGridSearchResult — grid-search detection pipeline for dark-matter subhalos Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ee980f7 commit cbb7ffb

5 files changed

Lines changed: 84 additions & 2 deletions

File tree

autolens/lens/sensitivity.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
"""
2+
Sensitivity mapping for dark-matter subhalo detection.
3+
4+
Sensitivity mapping asks: *given a lens model, how detectable would a dark-matter subhalo
5+
of mass M at position (y, x) be?* It works by:
6+
7+
1. Fixing the smooth lens model to the best-fit result.
8+
2. Simulating many lens datasets, each with a subhalo at a different position and mass,
9+
using the smooth model plus a perturbation.
10+
3. Fitting each simulated dataset with the smooth model (no subhalo) to measure the change
11+
in log-evidence caused by the subhalo.
12+
13+
``SubhaloSensitivityResult`` wraps the generic ``PyAutoFit`` ``SensitivityResult`` with
14+
convenience properties for the subhalo grid positions (``y``, ``x``), the detection
15+
significance map, and Matplotlib visualisation helpers.
16+
"""
117
import numpy as np
218
from typing import Optional, List, Tuple
319

autolens/lens/subhalo.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
Dark-matter subhalo detection via grid searches of non-linear searches.
3+
4+
This module provides result containers and visualisation helpers for a subhalo detection
5+
workflow in which a grid of ``PyAutoFit`` non-linear searches is run. Each cell of the
6+
grid confines the subhalo's (y, x) centre to a small sub-region of the image plane using
7+
uniform priors and fits the lens model with a subhalo included.
8+
9+
``SubhaloGridSearchResult`` wraps ``af.GridSearchResult`` with:
10+
11+
- ``y`` / ``x`` — the physical centre coordinates of each grid cell.
12+
- ``log_evidence_differences`` — the Bayesian evidence improvement from adding a subhalo
13+
relative to a smooth-model fit, useful for building a detection significance map.
14+
- Plotting helpers that overlay the detection map on the lens image.
15+
"""
116
import numpy as np
217
from typing import List, Optional, Tuple
318

autolens/lens/to_inversion.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
"""
2+
Interface between a ``Tracer`` and the linear-algebra inversion module.
3+
4+
``TracerToInversion`` extends the ``autogalaxy`` ``GalaxiesToInversion`` pattern to the
5+
multi-plane lensing setting. It is responsible for:
6+
7+
- Extracting every ``LightProfileLinear`` and ``Pixelization`` from the tracer's galaxies.
8+
- Ray-tracing each linear profile's grid to the correct source plane using the tracer's
9+
multi-plane deflection calculations.
10+
- Assembling the ``mapping_matrix`` that maps source-plane parameters (intensities, mesh
11+
coefficients) to image-plane pixels.
12+
- Passing the assembled objects to ``autoarray``'s ``inversion_from`` factory so that the
13+
linear system ``F x = d`` can be solved for the best-fit intensities / reconstructed
14+
image.
15+
16+
This class is not used directly by the user; it is instantiated inside
17+
``FitImaging`` / ``FitInterferometer`` whenever the tracer contains linear components.
18+
"""
119
from typing import Dict, List, Optional, Tuple, Type, Union
220

321
import numpy as np

autolens/lens/tracer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
"""
2+
The core gravitational-lensing ray-tracing module for **PyAutoLens**.
3+
4+
The central class is ``Tracer``, which groups a list of ``Galaxy`` objects by redshift
5+
into a series of *planes* and performs multi-plane gravitational lensing calculations.
6+
Key capabilities:
7+
8+
- **Multi-plane ray tracing** — images are traced from the source plane through
9+
intermediate lens planes to the observer using the cosmology-dependent angular
10+
diameter distances between each pair of planes.
11+
- **Lensed images** — the light of each galaxy is ray-traced to its correct position
12+
and the contributions from all planes are summed.
13+
- **Lensing maps** — convergence, shear, magnification, deflection angles, and potential
14+
maps can all be computed on arbitrary ``Grid2D`` grids.
15+
- **Critical curves & caustics** — the image-plane loci where magnification diverges and
16+
their source-plane counterparts.
17+
- **Lens modeling** — the ``Tracer`` is the core object used by
18+
``FitImaging`` / ``FitInterferometer`` / ``FitPointDataset`` when performing a
19+
Bayesian model fit via a ``PyAutoFit`` non-linear search.
20+
"""
121
from abc import ABC
222
import numpy as np
323
from scipy.interpolate import griddata

autolens/lens/tracer_util.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
Utility functions supporting the ``Tracer`` ray-tracing calculations.
3+
4+
This module contains lower-level helpers that are called by ``Tracer`` but kept separate
5+
to avoid cluttering the main class. Key functions:
6+
7+
- ``plane_redshifts_from`` — derives the list of unique plane redshifts from a list of
8+
galaxies, collapsing multiple galaxies at the same redshift into a single plane.
9+
- ``ordered_plane_redshifts_with_slicing_from`` — extends the above with optional
10+
redshift slicing for multi-plane calculations that include intermediate planes.
11+
- ``positions_in_ordered_planes_from`` — distributes a set of image-plane positions
12+
across the ordered plane list so that multi-plane tracing can propagate them.
13+
"""
114
import numpy as np
215
from typing import List, Optional
316

@@ -145,7 +158,7 @@ def traced_grid_2d_list_from(
145158

146159
for plane_index, galaxies in enumerate(planes):
147160

148-
scaled_grid = grid.array
161+
scaled_grid = xp.asarray(grid.array)
149162

150163
if plane_index > 0:
151164

@@ -164,7 +177,7 @@ def traced_grid_2d_list_from(
164177
scaled_grid = scaled_grid - scaled_deflections
165178

166179
scaled_grid = aa.Grid2DIrregular(
167-
values=scaled_grid,
180+
values=scaled_grid, xp=xp
168181
)
169182

170183
traced_grid_list.append(scaled_grid)

0 commit comments

Comments
 (0)