From 778b2283efe1acfae13076adf567fefe83a8d403 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Wed, 30 Apr 2025 11:19:15 +0100 Subject: [PATCH 1/3] addded to config --- autolens/config/visualize/plots.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/autolens/config/visualize/plots.yaml b/autolens/config/visualize/plots.yaml index e43e492c8..b6e77b72d 100644 --- a/autolens/config/visualize/plots.yaml +++ b/autolens/config/visualize/plots.yaml @@ -34,6 +34,7 @@ tracer: # Settings for plots of tracers (e.g. 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? + fits_source_plane_images: false # Output source_plane_images.fits file of the source-plane image (light profiles only) of each galaxy in the tracer? 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)? From 87841d944af16894b80eef02733d3d9a47ad5601 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Wed, 30 Apr 2025 11:43:29 +0100 Subject: [PATCH 2/3] soruce plane image in plotter interface --- autolens/analysis/plotter_interface.py | 43 ++++++++++++++++++- autolens/imaging/plot/fit_imaging_plotters.py | 2 - 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/autolens/analysis/plotter_interface.py b/autolens/analysis/plotter_interface.py index d3f858cca..3a002d267 100644 --- a/autolens/analysis/plotter_interface.py +++ b/autolens/analysis/plotter_interface.py @@ -1,6 +1,9 @@ +import numpy as np + from autoconf.fitsable import hdu_list_for_output_from import autoarray as aa +import autogalaxy as ag import autogalaxy.plot as aplt from autogalaxy.analysis.plotter_interface import plot_setting @@ -86,11 +89,49 @@ def should_plot(name): "deflections_y", "deflections_x", ], - header_dict=grid.mask.header_dict, + header_dict=grid_zoom.mask.header_dict, ) hdu_list.writeto(self.image_path / "tracer.fits", overwrite=True) + if should_plot("fits_source_plane_images"): + + zoom = aa.Zoom2D(mask=grid.mask) + mask = zoom.mask_2d_from(buffer=1) + grid_source_plane = aa.Grid2D.from_extent( + extent=mask.geometry.extent, + shape_native=(100, 100) + ) + + image_list = [grid_source_plane.mask.astype("float")] + ext_name_list = ["mask"] + + for i, plane in enumerate(tracer.planes[1:]): + + if plane.has(cls=ag.LightProfile): + + image = plane.plane_image_2d_from( + grid=grid_source_plane, + zoom_to_brightest=False + ).native + + else: + + image = np.zeros(grid_source_plane.shape_native) + + image_list.append(image) + ext_name_list.append(f"source_plane_image_{i}") + + hdu_list = hdu_list_for_output_from( + values_list=image_list, + ext_name_list=ext_name_list, + header_dict=grid_source_plane.mask.header_dict, + ) + + hdu_list.writeto(self.image_path / "source_plane_images.fits", overwrite=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 diff --git a/autolens/imaging/plot/fit_imaging_plotters.py b/autolens/imaging/plot/fit_imaging_plotters.py index a3ec0bf68..e310c75ad 100644 --- a/autolens/imaging/plot/fit_imaging_plotters.py +++ b/autolens/imaging/plot/fit_imaging_plotters.py @@ -292,8 +292,6 @@ def figures_2d_of_planes( elif self.tracer.planes[plane_index].has(cls=aa.Pixelization): - pix = self.tracer.planes[plane_index].cls_list_from(cls=aa.Pixelization)[0] - inversion_plotter = self.inversion_plotter_of_plane( plane_index=plane_index ) From f19c7c7b5c00f0b13bbf5686e8212f99869188aa Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Wed, 30 Apr 2025 12:05:09 +0100 Subject: [PATCH 3/3] black --- autolens/analysis/plotter_interface.py | 23 +++++++++++++++-------- autolens/config/visualize/plots.yaml | 1 + test_autolens/config/visualize.yaml | 4 +++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/autolens/analysis/plotter_interface.py b/autolens/analysis/plotter_interface.py index 3a002d267..71bad3c7f 100644 --- a/autolens/analysis/plotter_interface.py +++ b/autolens/analysis/plotter_interface.py @@ -1,5 +1,7 @@ +import ast import numpy as np +from autoconf import conf from autoconf.fitsable import hdu_list_for_output_from import autoarray as aa @@ -96,13 +98,19 @@ def should_plot(name): if should_plot("fits_source_plane_images"): + shape_native = conf.instance["visualize"]["plots"]["tracer"][ + "fits_source_plane_shape" + ] + shape_native = ast.literal_eval(shape_native) + zoom = aa.Zoom2D(mask=grid.mask) mask = zoom.mask_2d_from(buffer=1) grid_source_plane = aa.Grid2D.from_extent( - extent=mask.geometry.extent, - shape_native=(100, 100) + extent=mask.geometry.extent, shape_native=tuple(shape_native) ) + print(grid_source_plane) + image_list = [grid_source_plane.mask.astype("float")] ext_name_list = ["mask"] @@ -110,9 +118,8 @@ def should_plot(name): if plane.has(cls=ag.LightProfile): - image = plane.plane_image_2d_from( + image = plane.image_2d_from( grid=grid_source_plane, - zoom_to_brightest=False ).native else: @@ -120,7 +127,7 @@ def should_plot(name): image = np.zeros(grid_source_plane.shape_native) image_list.append(image) - ext_name_list.append(f"source_plane_image_{i}") + ext_name_list.append(f"source_plane_image_{i+1}") hdu_list = hdu_list_for_output_from( values_list=image_list, @@ -128,9 +135,9 @@ def should_plot(name): header_dict=grid_source_plane.mask.header_dict, ) - hdu_list.writeto(self.image_path / "source_plane_images.fits", overwrite=True) - - + hdu_list.writeto( + self.image_path / "source_plane_images.fits", overwrite=True + ) def image_with_positions(self, image: aa.Array2D, positions: aa.Grid2DIrregular): """ diff --git a/autolens/config/visualize/plots.yaml b/autolens/config/visualize/plots.yaml index b6e77b72d..44509fa1d 100644 --- a/autolens/config/visualize/plots.yaml +++ b/autolens/config/visualize/plots.yaml @@ -35,6 +35,7 @@ tracer: # Settings for plots of tracers (e.g. 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? fits_source_plane_images: false # Output source_plane_images.fits file of the source-plane image (light profiles only) of each galaxy in the tracer? + fits_source_plane_shape: (100, 100) # The shape of the source-plane image output in the fits_source_plane_images.fits file. 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)? diff --git a/test_autolens/config/visualize.yaml b/test_autolens/config/visualize.yaml index 8e30ff854..aafc2f8c9 100644 --- a/test_autolens/config/visualize.yaml +++ b/test_autolens/config/visualize.yaml @@ -99,4 +99,6 @@ plots: tracer: subplot_tracer: true subplot_galaxies_images: true - fits_tracer: true # Output tracer.fits file of tracer's convergence, potential, deflections_y and deflections_x? \ No newline at end of file + fits_tracer: true # Output tracer.fits file of tracer's convergence, potential, deflections_y and deflections_x? + fits_source_plane_images: true # Output source_plane_images.fits file of the source-plane image (light profiles only) of each galaxy in the tracer? + fits_source_plane_shape: (3, 3) # The shape of the source-plane image output in the fits_source_plane_images.fits file.