diff --git a/GALLERY.md b/GALLERY.md index b79274b..ffbbc12 100644 --- a/GALLERY.md +++ b/GALLERY.md @@ -2,7 +2,7 @@ -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. @@ -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) @@ -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 @@ -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 diff --git a/_viz_cli.py b/_viz_cli.py index 3f9077b..06f3ce6 100644 --- a/_viz_cli.py +++ b/_viz_cli.py @@ -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", @@ -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 = [] @@ -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 diff --git a/dataset/point_source/simple/data.fits b/dataset/point_source/simple/data.fits new file mode 100644 index 0000000..91fbffe Binary files /dev/null and b/dataset/point_source/simple/data.fits differ diff --git a/dataset/point_source/simple/noise_map.fits b/dataset/point_source/simple/noise_map.fits new file mode 100644 index 0000000..8061621 Binary files /dev/null and b/dataset/point_source/simple/noise_map.fits differ diff --git a/dataset/point_source/simple/psf.fits b/dataset/point_source/simple/psf.fits new file mode 100644 index 0000000..2b0396e Binary files /dev/null and b/dataset/point_source/simple/psf.fits differ diff --git a/gallery/viz_manifest.yaml b/gallery/viz_manifest.yaml index 1287011..dfdaa45 100644 --- a/gallery/viz_manifest.yaml +++ b/gallery/viz_manifest.yaml @@ -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 @@ -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 @@ -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 diff --git a/scripts/misc/simulators/point_source.py b/scripts/misc/simulators/point_source.py index 226b5f3..1a5505d 100644 --- a/scripts/misc/simulators/point_source.py +++ b/scripts/misc/simulators/point_source.py @@ -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 ----- @@ -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 @@ -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 diff --git a/scripts/point_source_image_chi_squared/images/visualization/image_with_points.png b/scripts/point_source_image_chi_squared/images/visualization/image_with_points.png new file mode 100644 index 0000000..85f639f Binary files /dev/null and b/scripts/point_source_image_chi_squared/images/visualization/image_with_points.png differ diff --git a/scripts/point_source_image_chi_squared/visualization.py b/scripts/point_source_image_chi_squared/visualization.py index b85e24a..f406636 100644 --- a/scripts/point_source_image_chi_squared/visualization.py +++ b/scripts/point_source_image_chi_squared/visualization.py @@ -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 @@ -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__ @@ -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, ) @@ -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)}" diff --git a/scripts/point_source_source_chi_squared/images/visualization/image_with_points.png b/scripts/point_source_source_chi_squared/images/visualization/image_with_points.png new file mode 100644 index 0000000..4ae6fa4 Binary files /dev/null and b/scripts/point_source_source_chi_squared/images/visualization/image_with_points.png differ diff --git a/scripts/point_source_source_chi_squared/visualization.py b/scripts/point_source_source_chi_squared/visualization.py index 0b627d7..44b8550 100644 --- a/scripts/point_source_source_chi_squared/visualization.py +++ b/scripts/point_source_source_chi_squared/visualization.py @@ -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 @@ -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__ @@ -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, ) @@ -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)}" diff --git a/true_models/point_source.py b/true_models/point_source.py index 96e770e..67fe2c6 100644 --- a/true_models/point_source.py +++ b/true_models/point_source.py @@ -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():