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
14 changes: 11 additions & 3 deletions GALLERY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- Generated by gallery/gallery_build.py from scripts/<domain>/images/. Do not edit by hand: rerun `bash gallery/gallery_run.sh --all`. -->

Rendered with PyAutoLens `2026.8.17.1` · 64 figures.
Rendered with PyAutoLens `2026.8.17.1` · 66 figures.

Every figure below is what the PyAutoLens visualizers (`VisualizerImaging`, `VisualizerInterferometer`, `VisualizerPoint`, `VisualizerWeak`) write to a model-fit's `image/` folder, rendered on this repo's datasets with the true model. See [README.md](README.md) for how to improve one.

Expand Down Expand Up @@ -38,10 +38,10 @@ Every figure below is what the PyAutoLens visualizers (`VisualizerImaging`, `Vis
- [visualization](#multi_galaxy--visualization) (2 figures)
- [top level](#multi_galaxy--visualization--top-level)
- [point_source_image_chi_squared](#point_source_image_chi_squared)
- [visualization](#point_source_image_chi_squared--visualization) (2 figures)
- [visualization](#point_source_image_chi_squared--visualization) (3 figures)
- [top level](#point_source_image_chi_squared--visualization--top-level)
- [point_source_source_chi_squared](#point_source_source_chi_squared)
- [visualization](#point_source_source_chi_squared--visualization) (2 figures)
- [visualization](#point_source_source_chi_squared--visualization) (3 figures)
- [top level](#point_source_source_chi_squared--visualization--top-level)
- [weak](#weak)
- [visualization](#weak--visualization) (2 figures)
Expand Down Expand Up @@ -351,6 +351,10 @@ Every figure below is what the PyAutoLens visualizers (`VisualizerImaging`, `Vis

![fit](scripts/point_source_image_chi_squared/images/visualization/fit.png)

##### image_with_points

![image_with_points](scripts/point_source_image_chi_squared/images/visualization/image_with_points.png)

## point_source_source_chi_squared

### point_source_source_chi_squared / visualization
Expand All @@ -365,6 +369,10 @@ Every figure below is what the PyAutoLens visualizers (`VisualizerImaging`, `Vis

![fit](scripts/point_source_source_chi_squared/images/visualization/fit.png)

##### image_with_points

![image_with_points](scripts/point_source_source_chi_squared/images/visualization/image_with_points.png)

## weak

### weak / visualization
Expand Down
12 changes: 10 additions & 2 deletions _viz_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def dataset_path(dataset_type: str, instrument: str) -> Path:
"type": "point_source",
"name": "simple",
"simulator": "point_source",
"sentinel": "point_dataset.json",
"sentinel": "data.fits",
},
"multi_galaxy": {
"type": "multi_galaxy",
Expand Down Expand Up @@ -173,13 +173,16 @@ def keep_dataset_and_fit(
*,
dataset_png: str = "dataset.png",
fit_png: str = "fit.png",
extra_pngs: tuple[str, ...] = (),
) -> list[Path]:
"""Reduce a visualizer's output folder to exactly ``dataset.png`` + ``fit.png``.

``dataset_png`` / ``fit_png`` name the files the plotter actually wrote (e.g. the point
plotter's ``dataset_point.png``); they are renamed to ``dataset.png`` / ``fit.png``. Every
other file (other PNGs, FITS, CSV, JSON) and any sub-folder is deleted, so the newer
domains track only the two figures. Raises if either expected figure is missing.
domains track only the two figures. ``extra_pngs`` names further figures to keep under their
own names (e.g. the point plotter's ``image_with_points.png``). Raises if any expected figure
is missing.
"""
image_dir = Path(image_dir)
kept = []
Expand All @@ -191,6 +194,11 @@ def keep_dataset_and_fit(
if src != dst:
src.replace(dst)
kept.append(dst)
for written in extra_pngs:
src = image_dir / written
if not src.is_file():
raise FileNotFoundError(f"expected visualizer output {src} was not written")
kept.append(src)
for p in sorted(image_dir.iterdir()):
if p in kept:
continue
Expand Down
Binary file added dataset/point_source/simple/data.fits
Binary file not shown.
Binary file added dataset/point_source/simple/noise_map.fits
Binary file not shown.
Binary file added dataset/point_source/simple/psf.fits
Binary file not shown.
14 changes: 13 additions & 1 deletion gallery/viz_manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rendered_with:
autogalaxy: 2026.8.17.1
autoarray: 2026.8.17.1
autofit: 2026.8.17.1
figure_count: 64
figure_count: 66
figures:
- file: scripts/cluster/images/visualization/point_0/dataset.png
producer: scripts/cluster/visualization.py
Expand Down Expand Up @@ -370,6 +370,12 @@ figures:
source: ''
bytes: 28952
sha256: 6b52412bb75eab16a3dc4ae4e0a4925d5f23c2ff7ed8bb9a6199f406f201cfed
- file: scripts/point_source_image_chi_squared/images/visualization/image_with_points.png
producer: scripts/point_source_image_chi_squared/visualization.py
domain: point_source_image_chi_squared
source: ''
bytes: 78200
sha256: 5972b44e38db7c42e93a108d53530b83a1103cde5a06989c5947eb9e86871114
- file: scripts/point_source_source_chi_squared/images/visualization/dataset.png
producer: scripts/point_source_source_chi_squared/visualization.py
domain: point_source_source_chi_squared
Expand All @@ -382,6 +388,12 @@ figures:
source: ''
bytes: 28823
sha256: caf49de216f6f80553e6c79b03231fd51ee626bd5939dd6864489e56a134320c
- file: scripts/point_source_source_chi_squared/images/visualization/image_with_points.png
producer: scripts/point_source_source_chi_squared/visualization.py
domain: point_source_source_chi_squared
source: ''
bytes: 75639
sha256: 76c6fa188a4bb9ca4d66fe95e42429ec7d9c900df85de0e00bae345be68146a0
- file: scripts/weak/images/visualization/dataset.png
producer: scripts/weak/visualization.py
domain: weak
Expand Down
52 changes: 48 additions & 4 deletions scripts/misc/simulators/point_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
Simulates the point-source dataset of ``true_models.point_source`` — the image-plane positions
of one point source (``point_0``) behind an isothermal lens — and writes
``point_dataset.json`` (the ``PointDataset``, positions only) and ``tracer.json`` into
``dataset/point_source/simple/``.
``dataset/point_source/simple/``, plus the accompanying imaging (``data.fits``, ``psf.fits``,
``noise_map.fits``) the producers plot the positions over (``image_with_points.png``).

Adapted from ``autolens_workspace/scripts/point_source/simulator.py``: same lens, source and
5 mas position noise, but the noise is seeded so the dataset regenerates identically, and the
flux / time-delay / imaging variants are not written (the producers fit positions only).
The imaging places one unlensed ``al.lp.PointSource`` per noisy image position on an
image-plane galaxy at the lens redshift (a delta function is not lensed: its multiple images
come from the ``PointSolver``), with flux ``SOURCE_FLUX`` x |magnification|, convolved with a
normalized Gaussian PSF.

Adapted from ``autolens_workspace/scripts/point_source/simulator.py``: same lens, source,
5 mas position noise and imaging recipe, but all noise is seeded so the dataset regenerates
identically, and the flux / time-delay variants are not written (the producers fit positions
only).

Usage
-----
Expand Down Expand Up @@ -38,6 +45,7 @@ def _repo_root() -> _Path:

def simulate(output_root: Path | None = None) -> Path:
import autolens as al
import autolens.plot as aplt
import numpy as np

from true_models import point_source as tm
Expand Down Expand Up @@ -68,6 +76,42 @@ def simulate(output_root: Path | None = None) -> Path:

al.output_to_json(obj=dataset, file_path=dataset_path / "point_dataset.json")
al.output_to_json(obj=tracer, file_path=dataset_path / "tracer.json")

magnifications = al.LensCalc.from_tracer(tracer=tracer).magnification_2d_via_hessian_from(
grid=al.Grid2DIrregular(values=positions_with_noise)
)
image_plane_galaxy = al.Galaxy(
redshift=lens.redshift,
**{
f"image_{i}": al.lp.PointSource(
centre=tuple(position), intensity=tm.SOURCE_FLUX * float(np.abs(magnification))
)
for i, (position, magnification) in enumerate(zip(positions_with_noise, magnifications))
},
)
grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=tm.IMAGE_PIXEL_SCALES)
psf = al.Convolver.from_gaussian(
convolve_over_sample_size=1,
shape_native=(11, 11),
sigma=0.1,
pixel_scales=grid.pixel_scales,
normalize=True,
)
simulator = al.SimulatorImaging(
exposure_time=300.0,
psf=psf,
background_sky_level=0.1,
add_poisson_noise_to_data=True,
noise_seed=1,
)
imaging = simulator.via_tracer_from(tracer=al.Tracer(galaxies=[image_plane_galaxy]), grid=grid)
aplt.fits_imaging(
dataset=imaging,
data_path=dataset_path / "data.fits",
psf_path=dataset_path / "psf.fits",
noise_map_path=dataset_path / "noise_map.fits",
overwrite=True,
)
print(f" wrote {dataset_path} ({len(positions)} images)")
return dataset_path

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 17 additions & 3 deletions scripts/point_source_image_chi_squared/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
scripts/point_source_image_chi_squared/images/visualization/
dataset.png <- visualize_before_fit (the plotter writes dataset_point.png; renamed)
fit.png <- visualize(quick_update=True)
image_with_points.png <- visualize(quick_update=True): the observed positions and the
model's positions + critical curves over ``data.fits``

Every other file the visualizer writes is deleted: this domain tracks only the dataset and
the fit (bespoke point-source figures are a follow-up).
Every other file the visualizer writes is deleted: this domain tracks only these three
figures. ``image_with_points.png`` is written before and after the fit to the same file;
the kept one is the after-fit version, with the model positions.

Dataset: ``dataset/point_source/simple`` (four image-plane positions, 5 mas noise; shared by
both point-source chi-squared producers), from
Expand Down Expand Up @@ -66,6 +69,14 @@ def _repo_root() -> Path:
dataset_path = ensure_dataset("point_source", workspace_root=REPO_ROOT)
dataset = al.from_json(file_path=dataset_path / "point_dataset.json")

"""
The accompanying imaging, used only for visualization (``image_with_points.png``), not in the
likelihood.
"""
data = al.Array2D.from_fits(
file_path=dataset_path / "data.fits", hdu=0, pixel_scales=tm.IMAGE_PIXEL_SCALES
)

"""
__True Model__

Expand All @@ -86,6 +97,7 @@ def _repo_root() -> Path:
analysis = al.AnalysisPoint(
dataset=dataset,
solver=solver,
image=data,
fit_positions_cls=al.FitPositionsImagePair,
use_jax=False,
)
Expand Down Expand Up @@ -117,7 +129,9 @@ def _repo_root() -> Path:
during_analysis=False,
quick_update=True,
)
keep_dataset_and_fit(image_path, dataset_png="dataset_point.png")
keep_dataset_and_fit(
image_path, dataset_png="dataset_point.png", extra_pngs=("image_with_points.png",)
)
print(f"visualize: {time.perf_counter() - t0:.1f}s")
print(
f"Wrote {sorted(p.name for p in image_path.iterdir())} under {image_path.relative_to(REPO_ROOT)}"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 17 additions & 3 deletions scripts/point_source_source_chi_squared/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
scripts/point_source_source_chi_squared/images/visualization/
dataset.png <- visualize_before_fit (the plotter writes dataset_point.png; renamed)
fit.png <- visualize(quick_update=True)
image_with_points.png <- visualize(quick_update=True): the observed positions and the
model's positions + critical curves over ``data.fits``

Every other file the visualizer writes is deleted: this domain tracks only the dataset and
the fit (bespoke point-source figures are a follow-up).
Every other file the visualizer writes is deleted: this domain tracks only these three
figures. ``image_with_points.png`` is written before and after the fit to the same file;
the kept one is the after-fit version, with the model positions.

Dataset: ``dataset/point_source/simple`` (four image-plane positions, 5 mas noise; shared by
both point-source chi-squared producers), from
Expand Down Expand Up @@ -66,6 +69,14 @@ def _repo_root() -> Path:
dataset_path = ensure_dataset("point_source", workspace_root=REPO_ROOT)
dataset = al.from_json(file_path=dataset_path / "point_dataset.json")

"""
The accompanying imaging, used only for visualization (``image_with_points.png``), not in the
likelihood.
"""
data = al.Array2D.from_fits(
file_path=dataset_path / "data.fits", hdu=0, pixel_scales=tm.IMAGE_PIXEL_SCALES
)

"""
__True Model__

Expand All @@ -87,6 +98,7 @@ def _repo_root() -> Path:
analysis = al.AnalysisPoint(
dataset=dataset,
solver=solver,
image=data,
fit_positions_cls=al.FitPositionsSource,
use_jax=False,
)
Expand Down Expand Up @@ -118,7 +130,9 @@ def _repo_root() -> Path:
during_analysis=False,
quick_update=True,
)
keep_dataset_and_fit(image_path, dataset_png="dataset_point.png")
keep_dataset_and_fit(
image_path, dataset_png="dataset_point.png", extra_pngs=("image_with_points.png",)
)
print(f"visualize: {time.perf_counter() - t0:.1f}s")
print(
f"Wrote {sorted(p.name for p in image_path.iterdir())} under {image_path.relative_to(REPO_ROOT)}"
Expand Down
2 changes: 2 additions & 0 deletions true_models/point_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
POINT_NAME = "point_0"
POSITION_NOISE = 0.005 # arcsec, HST-like point-source astrometry
SOURCE_CENTRE = (0.07, 0.07)
SOURCE_FLUX = 1.0 # each image of data.fits has flux SOURCE_FLUX x |magnification|
IMAGE_PIXEL_SCALES = 0.05 # arcsec / pixel of data.fits


def lens():
Expand Down
Loading