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
117 changes: 30 additions & 87 deletions autolens/analysis/plotter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ class PlotterInterface(AgPlotterInterface):
The path on the hard-disk to the `image` folder of the non-linear searches results.
"""

def tracer(self, tracer: Tracer, grid: aa.type.Grid2DLike, during_analysis: bool):
def tracer(self, tracer: Tracer, grid: aa.type.Grid2DLike):
"""
Visualizes a `Tracer` object.

Images are output to the `image` folder of the `image_path` in a subfolder called `tracer`. When
used with a non-linear search the `image_path` points to the search's results folder and this function
visualizes the maximum log likelihood `Tracer` inferred by the search so far.
Images are output to the `image` folder of the `image_path`. When used with a non-linear search the `image_path`
points to the search's results folder and this function visualizes the maximum log likelihood `Tracer`
inferred by the search so far.

Visualization includes individual images of attributes of the tracer (e.g. its image, convergence, deflection
angles) and a subplot of all these attributes on the same figure.
Visualization includes a subplot of individual images of attributes of the tracer (e.g. its image, convergence,
deflection angles) and .fits files containing its attributes grouped together.

The images output by the `PlotterInterface` are customized using the file `config/visualize/plots.yaml` under the
[tracer] header.
The images output by the `PlotterInterface` are customized using the file `config/visualize/plots.yaml` under
the `tracer` header.

Parameters
----------
Expand All @@ -47,14 +47,12 @@ def tracer(self, tracer: Tracer, grid: aa.type.Grid2DLike, during_analysis: bool
grid
A 2D grid of (y,x) arc-second coordinates used to perform ray-tracing, which is the masked grid tied to
the dataset.
during_analysis
Whether visualization is performed during a non-linear search or once it is completed.
"""

def should_plot(name):
return plot_setting(section="tracer", name=name)

mat_plot_2d = self.mat_plot_2d_from(subfolders="tracer")
mat_plot_2d = self.mat_plot_2d_from()

tracer_plotter = TracerPlotter(
tracer=tracer,
Expand All @@ -66,95 +64,38 @@ def should_plot(name):
if should_plot("subplot_galaxies_images"):
tracer_plotter.subplot_galaxies_images()

tracer_plotter.figures_2d(
image=should_plot("image"),
source_plane=should_plot("source_plane_image"),
deflections_y=should_plot("deflections"),
deflections_x=should_plot("deflections"),
magnification=should_plot("magnification"),
)

mat_plot_2d.use_log10 = True

tracer_plotter.figures_2d(
convergence=should_plot("convergence"),
potential=should_plot("potential"),
)

if should_plot("lens_image"):
tracer_plotter.figures_2d_of_planes(
plane_image=True, plane_index=0, zoom_to_brightest=False
)

mat_plot_2d.use_log10 = False

if not during_analysis and should_plot("all_at_end_png"):
mat_plot_2d = self.mat_plot_2d_from(
subfolders=path.join("tracer", "end"),
)

tracer_plotter = TracerPlotter(
tracer=tracer,
grid=grid,
mat_plot_2d=mat_plot_2d,
include_2d=self.include_2d,
)

tracer_plotter.figures_2d(
image=True,
source_plane=True,
deflections_y=True,
deflections_x=True,
magnification=True,
)

mat_plot_2d.use_log10 = True

tracer_plotter.figures_2d(
convergence=True,
potential=True,
)

tracer_plotter.figures_2d_of_planes(
plane_image=True, plane_index=0, zoom_to_brightest=False
)

mat_plot_2d.use_log10 = False
if should_plot("fits_tracer"):
number_plots = 4

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hardcoded variable looks a bit weird


if not during_analysis and should_plot("all_at_end_fits"):
mat_plot_2d = self.mat_plot_2d_from(
subfolders=path.join("tracer", "fits"), format="fits"
multi_plotter = aplt.MultiFigurePlotter(
plotter_list=[tracer_plotter] * number_plots
)

tracer_plotter = TracerPlotter(
tracer=tracer,
grid=grid,
mat_plot_2d=mat_plot_2d,
include_2d=self.include_2d,
)

tracer_plotter.figures_2d(
image=True,
source_plane=True,
convergence=True,
potential=True,
deflections_y=True,
deflections_x=True,
magnification=True,
multi_plotter.output_to_fits(
func_name_list=["figures_2d"] * number_plots,
figure_name_list=[
"convergence",
"potential",
"deflections_y",
"deflections_x",
],
tag_list=["convergence", "potential", "deflections_y", "deflections_x"],
filename="tracer",
remove_fits_first=True,
)

def image_with_positions(self, image: aa.Array2D, positions: aa.Grid2DIrregular):
"""
Visualizes the positions of a model-fit, where these positions are used to resample lens models where
the positions to do trace within an input threshold of one another in the source-plane.

Images are output to the `image` folder of the `image_path` in a subfolder called `positions`. When
used with a non-linear search the `image_path` is the output folder of the non-linear search.
Images are output to the `image` folder of the `image_path`. When used with a non-linear search the `image_path`
is the output folder of the non-linear search.

The visualization is an image of the strong lens with the positions overlaid.

The images output by the `PlotterInterface` are customized using the file `config/visualize/plots.yaml` under the
[tracer] header.
`positions` header.

Parameters
----------
Expand All @@ -167,7 +108,7 @@ def image_with_positions(self, image: aa.Array2D, positions: aa.Grid2DIrregular)
def should_plot(name):
return plot_setting(section=["positions"], name=name)

mat_plot_2d = self.mat_plot_2d_from(subfolders="positions")
mat_plot_2d = self.mat_plot_2d_from()

if positions is not None:
visuals_2d = aplt.Visuals2D(positions=positions)
Expand All @@ -178,6 +119,8 @@ def should_plot(name):
include_2d=self.include_2d,
visuals_2d=visuals_2d,
)

image_plotter.set_filename("image_with_positions")

if should_plot("image_with_positions"):
image_plotter.figure_2d()
148 changes: 43 additions & 105 deletions autolens/config/visualize/plots.yaml
Original file line number Diff line number Diff line change
@@ -1,105 +1,43 @@
dataset: # Settings for plots of all datasets (e.g. ImagingPlotter, InterferometerPlotter).
subplot_dataset: true # Plot subplot containing all dataset quantities (e.g. the data, noise-map, etc.)?
data: false
noise_map: false
signal_to_noise_map: false
imaging: # Settings for plots of imaging datasets (e.g. ImagingPlotter)
psf: false
positions: # Settings for plots with resampling image-positions on (e.g. the image).
image_with_positions: true
point_dataset: # Settings for plots of point source datasets (e.g. PointDatasetPlotter).
subplot_dataset: true # Plot subplot containing all dataset quantities (e.g. the data, noise-map, etc.)?
positions: false # Plot the positions of th multiple images of the point source in the image plane?
fluxes: false # Plot the fluxes of the multiple images of the point source in the image plane?
fit: # Settings for plots of all fits (e.g. FitImagingPlotter, FitInterferometerPlotter).
subplot_fit: true # Plot subplot of all fit quantities for any dataset (e.g. the model data, residual-map, etc.)?
all_at_end_png: true # Plot all individual plots listed below as .png (even if False)?
all_at_end_fits: true # Plot all individual plots listed below as .fits (even if False)?
all_at_end_pdf: false # Plot all individual plots listed below as publication-quality .pdf (even if False)?
subplot_of_planes: false # Plot subplot of the model-image, subtracted image and other quantities of each plane?
subplot_galaxies_images: false # Plot subplot of the image of each plane in the model?
data: false
noise_map: false
signal_to_noise_map: false
model_data: false
residual_map: false
chi_squared_map: false # Plot individual plots of the chi-squared-map?
residual_flux_fraction: false # Plot individual plots of the residual_flux_fraction?
model_images_of_planes: false # Plot individual plots of each plane's model image?
subtracted_images_of_planes: false # Plot individual plots of each plane's subtracted image?
plane_images_of_planes: false # Plot individual plots of each plane's image (e.g. in the source plane)?
fit_imaging: {} # Settings for plots of fits to imaging datasets (e.g. FitImagingPlotter).
fit_point_dataset: # Settings for plots of fits to point source datasets (e.g. FitPointDatasetPlotter).
positions: false # Plot the positions of th multiple images of the point source in the image plane?
fluxes: false # Plot the fluxes of the multiple images of the point source in the image plane?
tracer: # Settings for plots of tracers (e.g. TracerPlotter).
subplot_tracer: true # Plot subplot of all quantities in each tracer (e.g. images, convergence)?
all_at_end_png: true # Plot all individual plots listed below as .png (even if False)?
all_at_end_fits: true # Plot all individual plots listed below as .fits (even if False)?
all_at_end_pdf: false # Plot all individual plots listed below as publication-quality .pdf (even if False)?
subplot_galaxies_images: false # Plot subplot of the image of each plane in the tracer?
image: false # Plot image of the tracer (e.g. lens and lensed source in the image-plane)?
source_plane_image: false # Plot image of the tracer's source-plane?
lens_image: false # Plot image of the foreground lens galaxy (log10)?
convergence: false # Plot image of the tracer's convergence (log10)?
potential: false # Plot image of the tracer's potential (log10)?
deflections: false # Plot images of the tracer's y and x deflections?
magnification: false # Plot image of the tracer's magnification?
galaxies_1d: # Settings for 1D plots of galaxies (e.g. GalaxiesPlotter).
image: false
convergence: false
potential: false
inversion: # Settings for plots of inversions (e.g. InversionPlotter).
subplot_inversion: true # Plot subplot of all quantities in each inversion (e.g. reconstrucuted image, reconstruction)?
subplot_mappings: true # Plot subplot of the image-to-source pixels mappings of each pixelization?
all_at_end_png: true # Plot all individual plots listed below as .png (even if False)?
all_at_end_fits: true # Plot all individual plots listed below as .fits (even if False)?
all_at_end_pdf: false # Plot all individual plots listed below as publication-quality .pdf (even if False)?
reconstruction_noise_map: false
reconstructed_image: false
reconstruction: false
regularization_weights: false
adapt: # Settings for plots of adapt images used by adaptive pixelizations.
images_of_galaxies: true
model_image: true
interferometer: # Settings for plots of interferometer datasets (e.g. InterferometerPlotter).
amplitudes_vs_uv_distances: false
phases_vs_uv_distances: false
uv_wavelengths: false
dirty_image: false
dirty_noise_map: false
dirty_signal_to_noise_map: false
fit_interferometer: # Settings for plots of fits to interferometer datasets (e.g. FitInterferometerPlotter).
subplot_fit_dirty_images: false # Plot subplot of the dirty-images of all interferometer datasets?
subplot_fit_real_space: false # Plot subplot of the real-space images of all interferometer datasets?
amplitudes_vs_uv_distances: false
phases_vs_uv_distances: false
uv_wavelengths: false
dirty_image: false
dirty_noise_map: false
dirty_signal_to_noise_map: false
dirty_residual_map: false
dirty_normalized_residual_map: false
dirty_chi_squared_map: false
fit_quantity: # Settings for plots of fit quantities (e.g. FitQuantityPlotter).
all_at_end_png: true # Plot all individual plots listed below as .png (even if False)?
all_at_end_fits: true # Plot all individual plots listed below as .fits (even if False)?
all_at_end_pdf: false # Plot all individual plots listed below as publication-quality .pdf (even if False)?
chi_squared_map: false
image: true
model_image: false
noise_map: false
residual_map: false
normalized_residual_map: false
galaxies: # Settings for plots of galaxies (e.g. GalaxiesPlotter).
subplot_galaxies: true # Plot subplot of all quantities in each galaxies group (e.g. images, convergence)?
all_at_end_png: true # Plot all individual plots listed below as .png (even if False)?
all_at_end_fits: true # Plot all individual plots listed below as .fits (even if False)?
all_at_end_pdf: false # Plot all individual plots listed below as publication-quality .pdf (even if False)?
subplot_galaxy_images: false # Plot subplot of the image of each galaxy in the model?
image: false
source_plane_image: false
convergence: false
deflections: false
potential: false
magnification: false
dataset: # Settings for plots of all datasets (e.g. ImagingPlotter, InterferometerPlotter).
subplot_dataset: true # Plot subplot containing all dataset quantities (e.g. the data, noise-map, etc.)?

positions: # Settings for plots with resampling image-positions on (e.g. the image).
image_with_positions: true

point_dataset: # Settings for plots of point source datasets (e.g. PointDatasetPlotter).
subplot_dataset: true # Plot subplot containing all dataset quantities (e.g. the data, noise-map, etc.)?

fit: # Settings for plots of all fits (e.g. FitImagingPlotter, FitInterferometerPlotter).
subplot_fit: true # Plot subplot of all fit quantities for any dataset (e.g. the model data, residual-map, etc.)?
subplot_fit_log10: true # Plot subplot of all fit quantities for any dataset using log10 color maps (e.g. the model data, residual-map, etc.)?
subplot_of_planes: false # Plot subplot of the model-image, subtracted image and other quantities of each plane?
subplot_galaxies_images: false # Plot subplot of the image of each plane in the model?

fit_imaging: {} # Settings for plots of fits to imaging datasets (e.g. FitImagingPlotter).

fit_interferometer: # Settings for plots of fits to interferometer datasets (e.g. FitInterferometerPlotter).
subplot_fit_dirty_images: false # Plot subplot of the dirty-images of all interferometer datasets?
subplot_fit_real_space: false # Plot subplot of the real-space images of all interferometer datasets?

fit_point_dataset: {} # Settings for plots of fits to point source datasets (e.g. FitPointDatasetPlotter).

tracer: # Settings for plots of tracers (e.g. TracerPlotter).
subplot_tracer: true # Plot subplot of all quantities in each tracer (e.g. images, convergence)?
subplot_galaxies_images: false # Plot subplot of the image of each plane in the tracer?
fits_tracer: false # Output tracer.fits file of tracer's convergence, potential, deflections_y and deflections_x?

inversion: # Settings for plots of inversions (e.g. InversionPlotter).
subplot_inversion: true # Plot subplot of all quantities in each inversion (e.g. reconstrucuted image, reconstruction)?
subplot_mappings: true # Plot subplot of the image-to-source pixels mappings of each pixelization?

adapt: # Settings for plots of adapt images used by adaptive pixelizations.
subplot_adapt_images: true # Plot subplot showing each adapt image used for adaptive pixelization?

fit_quantity: # Settings for plots of fit quantities (e.g. FitQuantityPlotter).
subplot_fit: true

galaxies: # Settings for plots of galaxies (e.g. GalaxiesPlotter).
subplot_galaxies: true # Plot subplot of all quantities in each galaxies group (e.g. images, convergence)?
subplot_galaxy_images: false # Plot subplot of the image of each galaxy in the model?
subplot_galaxies_1d: false # Plot subplot of all quantities in 1D of each galaxies group (e.g. images, convergence)?
subplot_galaxies_1d_decomposed: false # Plot subplot of all quantities in 1D decomposed of each galaxies group (e.g. images, convergence)?
Loading