Skip to content

Commit bdba286

Browse files
Jammy2211claude
authored andcommitted
docs(point): add module-level docstrings to point package
Add module-level docstrings to twelve modules in autolens/point/: - dataset.py: PointDataset and PointDict data structures - solver/point_solver.py: triangle-tiling image-position solver - solver/shape_solver.py: abstract triangle solver and ShapeSolver - fit/abstract.py: AbstractFitPoint shared base class - fit/dataset.py: FitPointDataset orchestrating all point observables - fit/fluxes.py: FitFluxes magnification-based flux-ratio fit - fit/times_delays.py: FitTimeDelays Fermat-potential time-delay fit - fit/positions/abstract.py: AbstractFitPositions base - fit/positions/image/abstract.py: image-plane pairing strategies - fit/positions/source/separations.py: source-plane convergence fit - max_separation.py: SourceMaxSeparation fast position statistic - model/analysis.py: AnalysisPoint log_likelihood_function Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ee980f7 commit bdba286

12 files changed

Lines changed: 184 additions & 0 deletions

File tree

autolens/point/dataset.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
"""
2+
Data structures for point-source strong lens observations.
3+
4+
Point-source lensing arises when the background source is compact enough to be treated
5+
as a point (e.g. a quasar, supernova, or compact radio source). Gravitational lensing
6+
splits the source into multiple images whose positions, fluxes, and time delays constrain
7+
the lens mass distribution.
8+
9+
Two concrete data classes are provided:
10+
11+
- ``PointDataset`` — holds the image-plane positions, fluxes, and time delays of a
12+
single named point source together with their noise maps. The ``name`` attribute is
13+
used to pair this dataset with the corresponding ``Point`` model component during
14+
fitting.
15+
- ``PointDict`` — a dictionary of ``PointDataset`` objects keyed by name, used when
16+
multiple point sources (e.g. different background quasars) are fitted simultaneously.
17+
"""
118
from typing import List, Tuple, Optional, Union
219

320
import autoarray as aa

autolens/point/fit/abstract.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
"""
2+
Abstract base class for all point-source fit components.
3+
4+
``AbstractFitPoint`` provides shared functionality that is common to all point-source fit
5+
classes (position fits, flux fits, time-delay fits):
6+
7+
- Solving for the image-plane positions of a source-plane coordinate using a
8+
``PointSolver``.
9+
- Computing the magnification at each image position from the tracer's mass model.
10+
- Computing deflection angles at each image position.
11+
- Providing the name-based pairing between a ``PointDataset`` and its ``Point`` model
12+
component.
13+
14+
Concrete subclasses implement ``figure_of_merit`` to compute the chi-squared or
15+
log-likelihood for the specific observable (positions, fluxes, time delays) being fitted.
16+
"""
117
from abc import ABC
218
import numpy as np
319
from typing import Optional, Tuple

autolens/point/fit/dataset.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
Top-level fit class for a complete point-source dataset.
3+
4+
``FitPointDataset`` orchestrates fitting of all observables in a ``PointDataset``
5+
(image-plane positions, fluxes, and/or time delays) simultaneously. It creates and
6+
stores individual fit objects for each component that is present in the dataset:
7+
8+
- ``FitPositionsImagePair`` (or another positions fit class) — fits image-plane positions.
9+
- ``FitFluxes`` — fits flux ratios (if fluxes are in the dataset).
10+
- ``FitTimeDelays`` — fits time delays (if time delays are in the dataset).
11+
12+
The ``log_likelihood`` is the sum of the individual component log likelihoods. This
13+
class is used by ``AnalysisPoint`` as the evaluation engine inside the
14+
``log_likelihood_function``.
15+
"""
116
import numpy as np
217

318
from autolens.point.dataset import PointDataset

autolens/point/fit/fluxes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
"""
2+
Flux-ratio fit component for point-source lensing.
3+
4+
``FitFluxes`` computes the likelihood of the observed image-plane fluxes given the
5+
predicted magnification ratios from the tracer's mass model.
6+
7+
The predicted fluxes are proportional to the absolute magnification at each solved image
8+
position, normalised so that the brightest image has flux 1.0 (flux ratios). A chi-squared
9+
is computed against the observed flux values and noise map, contributing to the total
10+
``FitPointDataset`` log likelihood.
11+
"""
112
import numpy as np
213
from typing import Optional
314

autolens/point/fit/positions/abstract.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
"""
2+
Abstract base class for position-based point-source fit components.
3+
4+
``AbstractFitPositions`` extends ``AbstractFitPoint`` with shared logic for all position
5+
fitting strategies (image-plane pair fits and source-plane separation fits). It provides
6+
common attributes — observed positions, solved image positions, deflection angles — and
7+
leaves ``figure_of_merit`` to be implemented by each concrete subclass.
8+
9+
The concrete subclasses (in the ``image/`` and ``source/`` sub-packages) implement
10+
different statistical approaches for fitting image positions:
11+
12+
- **Image-plane pair fits** — compare each observed position to the nearest predicted
13+
image position, computing a chi-squared from the separation in arcseconds.
14+
- **Source-plane separation fits** — trace each observed image back to the source plane
15+
and compute the scatter of the traced positions around their mean, penalising poor
16+
source-plane convergence.
17+
"""
118
from abc import ABC
219
import numpy as np
320
from typing import Optional

autolens/point/fit/positions/image/abstract.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
"""
2+
Abstract base for image-plane position fitting strategies.
3+
4+
``AbstractFitPositionsImagePair`` solves for the predicted image positions using a
5+
``PointSolver`` and then pairs each observed position with the closest predicted image,
6+
computing a chi-squared from their separation.
7+
8+
Three concrete pairing strategies are provided in this sub-package:
9+
10+
- ``FitPositionsImagePair`` — pairs each observed to its nearest predicted image via
11+
the Hungarian (linear sum assignment) algorithm.
12+
- ``FitPositionsImagePairAll`` — computes the chi-squared for every observed/predicted
13+
pair combination and takes the minimum.
14+
- ``FitPositionsImagePairRepeat`` — allows predicted images to be paired to more than
15+
one observed position, useful for highly magnified systems where some images may be
16+
too close to separate.
17+
"""
118
from abc import ABC
219
import numpy as np
320
from typing import Optional

autolens/point/fit/positions/source/separations.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
Source-plane position fitting via traced-position separations.
3+
4+
Instead of comparing predicted and observed positions in the image plane,
5+
``FitPositionsSourcePlane`` traces each *observed* image position back to the source
6+
plane via the tracer's deflection angles and measures how tightly they converge.
7+
8+
If the lens model is correct, all observed images of the same source should trace back
9+
to (approximately) the same source-plane coordinate. The figure of merit is the mean
10+
squared separation of the back-traced positions from their common centroid, normalised by
11+
the position noise map.
12+
13+
This approach avoids the need for a ``PointSolver`` (no forward-solving is required) and
14+
is well-suited to JAX-accelerated model fits.
15+
"""
116
import numpy as np
217
from typing import Optional
318

autolens/point/fit/times_delays.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
Time-delay fit component for point-source lensing.
3+
4+
``FitTimeDelays`` computes the likelihood of the observed time delays between multiple
5+
images of a point source given the Fermat potential predicted by the tracer's mass and
6+
light models.
7+
8+
The time delay between images i and j is:
9+
10+
Δt_{ij} = (D_Δt / c) × [φ(θ_i) − φ(θ_j)]
11+
12+
where D_Δt is the time-delay distance computed from the cosmology and φ is the Fermat
13+
potential. A chi-squared is computed against the observed delays and their noise map,
14+
contributing to the total ``FitPointDataset`` log likelihood.
15+
"""
116
import numpy as np
217
from typing import Optional
318

autolens/point/max_separation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
"""
2+
Maximum source-plane separation statistic for point-source position fitting.
3+
4+
``SourceMaxSeparation`` computes the maximum separation between the source-plane
5+
positions obtained by tracing each observed image-plane position through the lens model.
6+
For a perfect lens model all images of the same source trace back to exactly the same
7+
source-plane coordinate, so this maximum separation should be zero.
8+
9+
This statistic is used as a fast figure-of-merit in settings where a full chi-squared
10+
calculation is not required, or as a hard prior threshold that rejects models for which
11+
the back-traced positions diverge by more than a user-specified amount.
12+
"""
113
import numpy as np
214
from typing import Optional
315

autolens/point/model/analysis.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
"""
2+
Analysis class for fitting a ``Tracer`` model to a point-source dataset.
3+
4+
``AnalysisPoint`` implements the ``log_likelihood_function`` called by a ``PyAutoFit``
5+
non-linear search at each iteration. It:
6+
7+
1. Constructs a ``Tracer`` from the current model instance.
8+
2. Calls ``FitPointDataset`` to fit the point-source positions (and optionally fluxes
9+
and time delays) using the ``PointSolver`` to find predicted image positions.
10+
3. Optionally adds a position-based prior via ``PositionsLH`` that penalises models
11+
where image positions are not self-consistent.
12+
4. Returns the total log likelihood as the figure of merit.
13+
14+
It also manages result output (``ResultPoint``) and on-the-fly visualisation
15+
(``VisualizerPoint``).
16+
"""
117
import numpy as np
218

319
import autofit as af

0 commit comments

Comments
 (0)