Skip to content

Commit afa1e8c

Browse files
Jammy2211Jammy2211claude
authored
docs: add module docstrings and improve method docstrings in galaxy package (#293)
- Add module-level docstrings to galaxy.py, galaxies.py, redshift.py, and to_inversion.py explaining what each module contains and its role in the modeling pipeline - Add docstring to Galaxy.traced_grid_2d_from explaining the lensing ray-tracing equation β = θ − α(θ) - Move Galaxy.half_light_radius property to sit with the traced grid method and add a docstring explaining why it returns None - Add docstring to Galaxies.redshift property - Add module docstring to to_inversion explaining how linear profiles and pixelizations are converted to inversion objects Co-authored-by: Jammy2211 <JNightingale2211@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 91c39d6 commit afa1e8c

4 files changed

Lines changed: 85 additions & 5 deletions

File tree

autogalaxy/galaxy/galaxies.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
"""
2+
The `Galaxies` class groups a list of `Galaxy` objects and exposes aggregate methods that operate across all
3+
galaxies simultaneously.
4+
5+
Common operations — summing images, deflection angles, convergence, and potential — are trivial (simply sum
6+
each galaxy's contribution). More complex operations, such as computing a PSF-blurred image that correctly
7+
handles a mix of standard and operated (PSF-already-applied) light profiles, require careful bookkeeping that
8+
`Galaxies` handles automatically.
9+
10+
In a typical modeling workflow, a list of fitted galaxies is always wrapped in a `Galaxies` object, which is
11+
then passed to a `Fit*` class (e.g. `FitImaging`) for comparison against the observed data.
12+
"""
113
import numpy as np
214
from typing import Dict, List, Optional, Tuple, Type, Union
315

@@ -46,6 +58,13 @@ def __init__(
4658

4759
@property
4860
def redshift(self):
61+
"""
62+
The redshift of the first galaxy in the collection.
63+
64+
This is used when all galaxies in the collection are at the same redshift (e.g. a group of galaxies
65+
at the lens plane). For multi-plane lensing with galaxies at different redshifts, individual galaxy
66+
redshifts should be accessed directly via `galaxies[i].redshift`.
67+
"""
4968
return self[0].redshift
5069

5170
def image_2d_list_from(

autogalaxy/galaxy/galaxy.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
"""
2+
The `Galaxy` class is the central object in **PyAutoGalaxy** that groups light profiles, mass profiles, and
3+
other components (e.g. pixelizations) at a given redshift.
4+
5+
A `Galaxy` holds its components as named keyword-argument attributes, so the user can access them by name
6+
(e.g. `galaxy.bulge`, `galaxy.disk`). It then provides aggregate methods — `image_2d_from`,
7+
`deflections_yx_2d_from`, `convergence_2d_from`, `potential_2d_from` — that sum the contributions of all
8+
matching component types.
9+
10+
The `Galaxies` class (in `galaxies.py`) wraps a list of `Galaxy` objects and provides the same aggregate
11+
interface over the whole ensemble.
12+
"""
113
from typing import Dict, List, Optional, Type, Union
214

315
import numpy as np
@@ -295,12 +307,41 @@ def convergence_2d_from(
295307

296308
return xp.zeros((grid.shape[0],))
297309

310+
@property
311+
def half_light_radius(self):
312+
"""
313+
The half-light radius of the galaxy.
314+
315+
Returns `None` because a `Galaxy` may contain multiple light profiles with different effective radii;
316+
there is no single half-light radius that characterises the whole galaxy. Individual light profile
317+
components expose their own `half_light_radius` / `effective_radius` attributes.
318+
"""
319+
return None
320+
298321
@aa.grid_dec.to_grid
299322
def traced_grid_2d_from(
300323
self, grid: aa.type.Grid2DLike, xp=np
301324
) -> aa.type.Grid2DLike:
302325
"""
303-
Trace an input grid using the galaxy's its deflection angles.
326+
Trace an input grid of (y,x) coordinates through the galaxy's deflection angles.
327+
328+
The traced grid is computed as:
329+
330+
β = θ − α(θ)
331+
332+
where θ is the image-plane grid and α(θ) are the deflection angles from the galaxy's mass profiles.
333+
334+
This is the lensing ray-tracing step that maps image-plane positions to source-plane positions.
335+
336+
Parameters
337+
----------
338+
grid
339+
The 2D (y, x) image-plane coordinates to be traced to the source plane.
340+
341+
Returns
342+
-------
343+
aa.type.Grid2DLike
344+
The source-plane (y, x) coordinates after deflection.
304345
"""
305346
if isinstance(grid, aa.Grid2D):
306347
return aa.Grid2D(
@@ -343,10 +384,6 @@ def potential_2d_from(
343384
)
344385
return xp.zeros((grid.shape[0],))
345386

346-
@property
347-
def half_light_radius(self):
348-
return None
349-
350387
def extract_attribute(self, cls, attr_name):
351388
"""
352389
Returns an attribute of a class and its children profiles in the galaxy as a `ValueIrregular`

autogalaxy/galaxy/redshift.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
"""
2+
Provides the `Redshift` class, a thin float subclass used when the redshift of a `Galaxy` is treated as a
3+
free parameter in a model fit.
4+
5+
In standard use, galaxy redshifts are fixed scalars passed directly to `Galaxy(redshift=0.5, ...)`.
6+
When the redshift itself needs to be inferred by the non-linear search, **PyAutoFit** requires every model
7+
parameter to be wrapped in a Python class. The `Redshift` class satisfies this requirement while behaving
8+
identically to a plain Python `float` in all arithmetic and comparison contexts.
9+
"""
10+
11+
112
class Redshift(float):
213
"""
314
Class used when assigning a redshift to a `Galaxy` object.

autogalaxy/galaxy/to_inversion.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
Classes that convert a list of galaxies (some of which may contain linear light profiles or pixelizations) into
3+
the inversion objects required by **PyAutoArray** to perform the linear algebra solve.
4+
5+
The key class is `GalaxiesToInversion`, which:
6+
7+
1. Extracts all linear light profiles across all galaxies and computes their mapping matrices.
8+
2. Extracts all pixelization objects and constructs the `Mapper` objects they require.
9+
3. Passes these to `autoarray.inversion_from` to perform the linear algebra inversion.
10+
11+
Standard (non-linear) light profiles are handled separately by the `Fit*` classes, which subtract them from
12+
the data before passing the residuals to this inversion pipeline.
13+
"""
114
from __future__ import annotations
215
import numpy as np
316
from typing import Dict, List, Optional, Type, Union

0 commit comments

Comments
 (0)