From 9a1266dec6558f2b382be2f61405117aff9e1a77 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Thu, 12 Nov 2026 19:31:29 +0000 Subject: [PATCH] docs: clarify API reference guidance Apply reviewed Pixelizations, Plotting and Galaxy reference drafts. Preserve existing URLs, section anchors and API entries. Agent: Codex; model: GPT-6 --- docs/api/galaxy.rst | 120 ++++++++++++++++++++++++++----------- docs/api/pixelization.rst | 84 ++++++++++++++++++-------- docs/api/plot.rst | 121 ++++++++++++++++++++++---------------- 3 files changed, 219 insertions(+), 106 deletions(-) diff --git a/docs/api/galaxy.rst b/docs/api/galaxy.rst index 1145ad727..e8a0dff77 100644 --- a/docs/api/galaxy.rst +++ b/docs/api/galaxy.rst @@ -1,22 +1,16 @@ -=============== -Galaxy / Tracer -=============== - -Galaxy / Tracer ---------------- - -``Galaxy`` and ``Galaxies`` model individual galaxies with light and mass profiles at a -given redshift. ``Tracer`` groups galaxies by redshift into planes and performs -multi-plane gravitational lensing ray-tracing, computing lensed images, convergence, -deflection angles, magnification, critical curves, and caustics. - -``MassField`` holds the mass of everything *outside* the modelled system — an external -shear, a mass sheet, an external potential — at its own redshift and with no light of its -own; pass a list of them as ``Tracer(galaxies=..., fields=[field])`` and each is placed in -the plane at its redshift, contributing its mass to every lensing calculation while every -per-galaxy surface still sees galaxies alone. Attaching these components to a ``Galaxy`` -instead remains fully supported. For one field, ``Tracer(galaxies=..., fields=field)`` -is also accepted; ``tracer.fields`` is always stored as a list. +.. _galaxy-tracer: + +Galaxies and ray tracing +======================== + +Build galaxies from light and mass profiles, then use a ``Tracer`` to calculate how their light is gravitationally lensed. The objects below separate individual galaxies, collections of galaxies and multi-plane ray tracing. + +.. _id1: + +Galaxies and collections +------------------------ + +``Galaxy`` holds components at a specified redshift. Component names such as ``bulge``, ``disk`` and ``mass`` let you identify their contributions. ``Galaxies`` evaluates a collection, combining its light or mass quantities as appropriate. .. currentmodule:: autolens @@ -27,35 +21,95 @@ is also accepted; ``tracer.fields`` is always stored as a list. Galaxy Galaxies - MassField + +Use ``Tracer`` for lensing between redshift planes; a ``Galaxies`` collection alone does not perform multi-plane ray tracing. + +Ray tracing +----------- + +``Tracer`` groups galaxies into planes by redshift and propagates coordinates through those planes using the lensing cosmology. It provides lensed images and lensing quantities including deflections, convergence, magnification, critical curves and caustics. + +.. code-block:: python + + import autolens as al + + lens = al.Galaxy( + redshift=0.5, + mass=al.mp.Isothermal(einstein_radius=1.0), + ) + source = al.Galaxy( + redshift=1.0, + bulge=al.lp.Sersic(intensity=1.0, effective_radius=0.2), + ) + tracer = al.Tracer(galaxies=[lens, source]) + +This constructs a model; it does not fit data. The `ray-tracing guide `_ shows how to evaluate and plot it. + +.. currentmodule:: autolens + +.. autosummary:: + :toctree: _autosummary + :template: custom-class-template.rst + :recursive: + Tracer -To treat the redshift of a galaxy as a free parameter in a model, the ``Redshift`` object must -be used. +External mass fields +-------------------- + +``MassField`` holds mass components at their own redshift without assigning them galaxy light. Use it for environmental contributions such as external shear, a mass sheet or an external potential. It also accepts other mass profiles when they represent the environment. -This is because **PyAutoFit** (which handles model-fitting), requires all parameters to be a Python class. +Pass fields through ``Tracer(galaxies=..., fields=[field])``. Each field is placed at its redshift and contributes to the lensing calculations, while remaining separate from the galaxies. A single ``fields=field`` is also accepted; ``tracer.fields`` is stored as a list. -The ``Redshift`` object does not need to be used for general **PyAutoGalaxy** use. +Attaching external mass components directly to a ``Galaxy`` remains supported. + +.. currentmodule:: autolens .. autosummary:: :toctree: _autosummary :template: custom-class-template.rst :recursive: - Redshift + MassField + +Fixed and fitted redshifts +-------------------------- + +For a known redshift, pass a number directly to ``Galaxy(redshift=...)``. When the redshift itself is to be inferred, ``Redshift`` provides a model component whose value can be assigned a prior. + +.. code-block:: python -Galaxy Catalogues (CSV) ------------------------ + import autofit as af -Load many galaxies from a ``y, x, luminosity`` CSV catalogue — the input format of the -scaling-relation galaxy tier used at multi-galaxy, group and cluster scale (see the -``multi_galaxy``, ``group`` and ``cluster`` packages of the ``autolens_workspace``). -``galaxy_table_from_csv`` reads the catalogue; the two ``*_from_csv_tables`` functions -build instances or model components from it. + redshift = af.Model(al.Redshift) + redshift.redshift = af.UniformPrior(lower_limit=0.8, upper_limit=1.2) + galaxy_model = af.Model(al.Galaxy, redshift=redshift) + +The prior limits are illustrative, not a default recommendation. For lensing, choose redshifts and priors consistent with the intended ordering of lens and source planes. Add the light or mass components required by your model before fitting. + +.. currentmodule:: autolens + +.. autosummary:: + :toctree: _autosummary + :template: custom-class-template.rst + :recursive: + + Redshift + +.. _galaxy-catalogues-csv: + +Galaxy catalogues +----------------- + +Load catalogue entries with ``y``, ``x`` and ``luminosity`` columns to construct populations of galaxies. ``galaxy_table_from_csv`` reads a table; ``galaxies_from_csv_tables`` and ``galaxy_af_models_from_csv_tables`` build galaxy instances or model components from the supplied tables. + +The `scaling-relation examples `_ explain how measured luminosities can constrain the mass model of a companion population. The `multi-galaxy `_, `group `_ and `cluster `_ introductions show the different modelling workflows. + +.. currentmodule:: autolens .. autosummary:: :toctree: _autosummary galaxy_table_from_csv galaxies_from_csv_tables - galaxy_af_models_from_csv_tables \ No newline at end of file + galaxy_af_models_from_csv_tables diff --git a/docs/api/pixelization.rst b/docs/api/pixelization.rst index c4770616e..6de2ff4c9 100644 --- a/docs/api/pixelization.rst +++ b/docs/api/pixelization.rst @@ -1,17 +1,29 @@ -============= Pixelizations ============= -Pixelization ------------- +Reconstruct the extended background source on a mesh when a small set of analytic light profiles cannot describe its structure. The lens model maps image-plane coordinates to the source plane, where the reconstruction is defined. + +The reconstruction values are solved by a linear inversion for each proposed model. Regularization constrains their variation, balancing the fit to the data against the smoothness of the reconstruction. + +.. _pixelization: + +Build a pixelization +-------------------- + +A ``Pixelization`` combines a ``mesh`` with a ``regularization`` scheme. This example constructs an adaptive rectangular mesh with constant regularization; it does not run a fit. -Groups all of the individual components used to reconstruct a galaxy via a -pixelization (an ``ImageMesh``, ``Mesh`` and ``Regularization``) +.. code-block:: python -The ``Pixelization`` API documentation provides a comprehensive description of how pixelizaiton objects work and -their associated API. + import autolens as al -**It is recommended you read this documentation before using pixelizations**. + pixelization = al.Pixelization( + mesh=al.mesh.RectangularBilinearAdaptDensity(shape=(20, 20)), + regularization=al.reg.Constant(coefficient=1.0), + ) + +The shape and regularization coefficient are illustrative choices. Their suitable values depend on the data and model. Attach the pixelization to the source galaxy and use the `worked pixelization examples `_ for the complete fitting workflow. + +The detailed ``Pixelization`` reference below explains the coordinate mappings, masking and image-plane versus source-plane reconstruction with diagrams. .. currentmodule:: autolens @@ -22,22 +34,18 @@ their associated API. Pixelization -Image Mesh [ag.image_mesh] --------------------------- +.. _mesh-ag-mesh: -.. currentmodule:: autoarray.inversion.mesh.image_mesh +Choose a mesh +------------- -.. autosummary:: - :toctree: _autosummary - :template: custom-class-template.rst - :recursive: +Access these classes through ``al.mesh``. The generated pages show their implementation in **PyAutoArray**, which supplies the mesh classes to both libraries. - Overlay - Hilbert - KMeans +- **Density-adaptive rectangular meshes** allocate resolution according to the spatial density of the coordinates used for reconstruction, after ray tracing in a lens model. +- **Image-adaptive rectangular meshes** use an adapt image to concentrate resolution according to the estimated light distribution. Supply the adapt-image information required by the fitting workflow. +- **Delaunay** uses a triangular mesh and barycentric interpolation between its vertices. Its adaptive setup requires an image-plane mesh grid. -Mesh [ag.mesh] --------------- +The Bilinear and RTU rectangular families use different coordinate transforms. RTU uses a smooth kernel-based transform; Bilinear uses ranks of the sampled coordinates. This distinction matters for gradient-based fitting. Consult the class-specific gradient and over-sampling notes before choosing a mesh for a JAX analysis. .. currentmodule:: autoarray.inversion.mesh.mesh @@ -52,8 +60,16 @@ Mesh [ag.mesh] RectangularRTUAdaptImage Delaunay -Regularization [ag.reg] ------------------------ +.. _regularization-ag-reg: + +Choose regularization +--------------------- + +Access these classes through ``al.reg``. Regularization controls how strongly the reconstruction is smoothed; it does not set the mesh resolution. + +``Constant`` applies a shared coefficient, while adaptive schemes vary the smoothing using estimated signal. The ``Split`` variants use a different construction of the regularization constraints. Choose a scheme compatible with the mesh, as described in the detailed references. + +``AdaptPower`` and ``AdaptSplitPower`` expose a coefficient-power convention that differs from the legacy adaptive classes. Coefficients and their priors are therefore not interchangeable across these families; check the definitions when changing scheme. .. currentmodule:: autoarray.inversion.regularization @@ -69,9 +85,29 @@ Regularization [ag.reg] AdaptPower AdaptSplitPower +.. _image-mesh-ag-image-mesh: + +Image-mesh utilities +-------------------- + +These lower-level utilities place sampling points in the image plane for workflows that require an image-plane mesh. They are not a third argument to ``Pixelization``: its constructor takes ``mesh`` and ``regularization``. Follow the selected mesh’s setup and adapt-image requirements. + +.. currentmodule:: autoarray.inversion.mesh.image_mesh + +.. autosummary:: + :toctree: _autosummary + :template: custom-class-template.rst + :recursive: + + Overlay + Hilbert + KMeans + Settings -------- +``Settings`` controls numerical choices used when constructing and solving an inversion. Keep the defaults unless your analysis needs a particular option, and consult the parameter descriptions before changing them. + .. currentmodule:: autolens .. autosummary:: @@ -84,6 +120,8 @@ Settings Mapper ------ +A ``Mapper`` describes how reconstruction values contribute at the sampled coordinates. For lensing, those coordinates have been traced to the source plane. Mappers are normally built by the fitting machinery; their reference is useful when inspecting mappings or developing a custom calculation. + .. currentmodule:: autolens .. autosummary:: @@ -91,4 +129,4 @@ Mapper :template: custom-class-template.rst :recursive: - Mapper \ No newline at end of file + Mapper diff --git a/docs/api/plot.rst b/docs/api/plot.rst index bf9d2fc9e..e9b185a85 100644 --- a/docs/api/plot.rst +++ b/docs/api/plot.rst @@ -1,25 +1,34 @@ -======== Plotting ======== -**PyAutoLens** custom visualization library. +Use ``autolens.plot`` to inspect datasets, models and fits. Functions produce individual figures or diagnostic subplots; pass plotting options directly to the function you call. + +For a runnable introduction and customization examples, open the `plotting guide `_. + +Plot an image +------------- -Step-by-step Juypter notebook guides illustrating all objects listed on this page are -provided on the `autolens_workspace: plot tutorials `_ and -it is strongly recommended you use those to learn plot customization. +Given an existing ``Array2D`` called ``image``: -**Examples / Tutorials:** +.. code-block:: python + + import autolens.plot as aplt -- `autolens_workspace: plot tutorials `_ + aplt.plot_array(array=image, title="Image", colormap="gray") -Plotters [aplt] ---------------- +.. _plotters-aplt: -Create figures and subplots showing quantities of standard **PyAutoLens** objects. +Choose a plot +------------- + +Choose the group that matches the object or result you want to inspect. The linked references give each function’s arguments. .. currentmodule:: autolens.plot -**Basic Plot Functions:** +Basic plots +~~~~~~~~~~~ + +Display an array or a grid of coordinates. .. autosummary:: :toctree: _autosummary @@ -27,7 +36,10 @@ Create figures and subplots showing quantities of standard **PyAutoLens** object plot_array plot_grid -**Tracer and Galaxies Subplots:** +Tracer and Galaxies subplots +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Inspect the lens model, its lensed images and the contributions from its galaxies. .. autosummary:: :toctree: _autosummary @@ -36,7 +48,10 @@ Create figures and subplots showing quantities of standard **PyAutoLens** object subplot_lensed_images subplot_galaxies_images -**Imaging Fit Subplots:** +Imaging Fit subplots +~~~~~~~~~~~~~~~~~~~~ + +Compare the image data and fitted model, and inspect residuals and other fit diagnostics. .. autosummary:: :toctree: _autosummary @@ -50,7 +65,10 @@ Create figures and subplots showing quantities of standard **PyAutoLens** object subplot_fit_combined subplot_fit_combined_log10 -**Interferometer Subplots:** +Interferometer subplots +~~~~~~~~~~~~~~~~~~~~~~~ + +Inspect visibilities, fits and reconstructed images. Dirty images are useful diagnostics; the interferometer fit is evaluated in visibility space. .. autosummary:: :toctree: _autosummary @@ -61,7 +79,10 @@ Create figures and subplots showing quantities of standard **PyAutoLens** object subplot_fit_interferometer_dirty_images subplot_fit_interferometer_combined -**Point Source Subplots:** +Point Source subplots +~~~~~~~~~~~~~~~~~~~~~ + +Inspect the observed point-source positions, fitted predictions and solver output. .. autosummary:: :toctree: _autosummary @@ -70,7 +91,10 @@ Create figures and subplots showing quantities of standard **PyAutoLens** object subplot_point_dataset plot_point_solver -**Subhalo Detection Subplots:** +Subhalo Detection subplots +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Compare subhalo-search results and their associated fits. .. autosummary:: :toctree: _autosummary @@ -78,7 +102,10 @@ Create figures and subplots showing quantities of standard **PyAutoLens** object subplot_detection_imaging subplot_detection_fits -**Sensitivity Mapping Subplots:** +Sensitivity Mapping subplots +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Inspect sensitivity results and their figures of merit across the lens. .. autosummary:: :toctree: _autosummary @@ -87,10 +114,12 @@ Create figures and subplots showing quantities of standard **PyAutoLens** object subplot_sensitivity subplot_sensitivity_figures_of_merit -Non-linear Search Plot Functions [aplt] ---------------------------------------- +.. _non-linear-search-plot-functions-aplt: -Module-level functions for visualizing non-linear search results. +Search results +-------------- + +These functions visualize samples and search progress. They are implemented by **PyAutoFit** and re-exported through ``aplt``. .. currentmodule:: autofit.plot @@ -102,47 +131,39 @@ Module-level functions for visualizing non-linear search results. subplot_parameters log_likelihood_vs_iteration -Plot Customization [aplt] -------------------------- +.. _plot-customization-aplt: -The plotting API is **functional**: customization is done by passing keyword -arguments directly to any ``aplt`` plotting function. There is no ``MatPlot2D`` -object anymore (nor the old ``Cmap`` / ``Visuals`` / ``Units`` / matplotlib-wrapper -classes) — these were removed in favour of the keyword-argument interface below. +Customize a plot +---------------- -Every figure and subplot function accepts: +Options depend on the function. For ``plot_array``, you can set: -- ``title`` — the figure title. -- ``colormap`` — the matplotlib colormap name (e.g. ``"jet"``, ``"hot"``, ``"gray"``). -- ``use_log10`` — if ``True``, plot the colormap on a ``log10`` scale. -- ``output_path`` — directory to save the figure to (omit to display it interactively). -- ``output_filename`` — the saved file's name. -- ``output_format`` — the saved file's format, e.g. ``"png"`` or ``"pdf"``. +- ``title``: the figure title. +- ``colormap``: a Matplotlib colormap, such as ``"gray"`` or ``"viridis"``. +- ``use_log10``: request logarithmic colour scaling. Use a linear or suitable signed scale when inspecting quantities that can be negative, such as residuals. +- ``output_path``, ``output_filename`` and ``output_format``: the output directory, filename and format. -For example: +Subplot functions may use different options. For example, ``subplot_tracer`` accepts ``title_prefix`` rather than ``title`` and does not expose ``output_filename``. Check the linked signature before transferring options between functions. -.. code-block:: python +Defaults such as figure size, fonts and colours are configured through the workspace’s ``config/visualize`` YAML files. See `Configuration `_ for the configuration workflow. - import autolens.plot as aplt +.. _figure-output-aplt: - # Customize the appearance: - aplt.plot_array(array=image, title="Image", colormap="jet", use_log10=True) +Save figures +------------ - # Save to disk instead of displaying: - aplt.plot_array( - array=image, output_path="output", output_filename="image", output_format="png" - ) +For ``plot_array``, save the existing image to ``output/image.png`` with: -Default plotting values (figure size, fonts, colormaps, ticks, labels, ...) are set -via the workspace ``config/visualize`` YAML files rather than in code, so most figures -need no customization at all. +.. code-block:: python -Figure Output [aplt] --------------------- + aplt.plot_array( + array=image, + output_path="output", + output_filename="image", + output_format="png", + ) -The ``Output`` object gives lower-level control of how and where figures are written -to disk, and is accepted by the plotting functions in place of the individual -``output_*`` keyword arguments. +The functions above use the output keywords documented in their signatures. ``Output`` is a lower-level **PyAutoArray** helper; it is not a replacement argument for these public plotting functions. Its reference remains available for code that uses it directly. .. currentmodule:: autoarray.plot