From dc52044ceeeeede306b061a07b5a933f3ca914fd Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:01:10 +0000 Subject: [PATCH 01/19] remove during analysi from unit tests --- docs/installation/conda.rst | 2 +- docs/installation/pip.rst | 2 +- test_autolens/analysis/test_plotter_interface.py | 1 - test_autolens/imaging/model/test_plotter_interface_imaging.py | 2 +- .../model/test_plotter_interface_interferometer.py | 2 +- test_autolens/point/model/test_plotter_interface_point.py | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/installation/conda.rst b/docs/installation/conda.rst index 67fa5615c..8a765e348 100644 --- a/docs/installation/conda.rst +++ b/docs/installation/conda.rst @@ -46,7 +46,7 @@ You may get warnings which state something like: .. code-block:: bash - ERROR: autoarray 2024.11.6.1 has requirement numpy<=1.22.1, but you'll have numpy 1.22.2 which is incompatible. + ERROR: autoarray 2025.1.18.7 has requirement numpy<=1.22.1, but you'll have numpy 1.22.2 which is incompatible. ERROR: numba 0.53.1 has requirement llvmlite<0.37,>=0.36.0rc1, but you'll have llvmlite 0.38.0 which is incompatible. If you see these messages, they do not mean that the installation has failed and the instructions below will diff --git a/docs/installation/pip.rst b/docs/installation/pip.rst index e79ee015e..05a9cf968 100644 --- a/docs/installation/pip.rst +++ b/docs/installation/pip.rst @@ -27,7 +27,7 @@ You may get warnings which state something like: .. code-block:: bash - ERROR: autoarray 2024.11.6.1 has requirement numpy<=1.22.1, but you'll have numpy 1.22.2 which is incompatible. + ERROR: autoarray 2025.1.18.7 has requirement numpy<=1.22.1, but you'll have numpy 1.22.2 which is incompatible. ERROR: numba 0.53.1 has requirement llvmlite<0.37,>=0.36.0rc1, but you'll have llvmlite 0.38.0 which is incompatible. If you see these messages, they do not mean that the installation has failed and the instructions below will diff --git a/test_autolens/analysis/test_plotter_interface.py b/test_autolens/analysis/test_plotter_interface.py index 77b95d7d3..e07c206bc 100644 --- a/test_autolens/analysis/test_plotter_interface.py +++ b/test_autolens/analysis/test_plotter_interface.py @@ -25,7 +25,6 @@ def test__tracer( plotter_interface.tracer( tracer=tracer_x2_plane_7x7, grid=masked_imaging_7x7.grids.lp, - during_analysis=False, ) plot_path = path.join(plot_path, "tracer") diff --git a/test_autolens/imaging/model/test_plotter_interface_imaging.py b/test_autolens/imaging/model/test_plotter_interface_imaging.py index ca6e01d20..839ead26e 100644 --- a/test_autolens/imaging/model/test_plotter_interface_imaging.py +++ b/test_autolens/imaging/model/test_plotter_interface_imaging.py @@ -23,7 +23,7 @@ def test__fit_imaging( plotter_interface = PlotterInterfaceImaging(image_path=plot_path) plotter_interface.fit_imaging( - fit=fit_imaging_x2_plane_inversion_7x7, during_analysis=False + fit=fit_imaging_x2_plane_inversion_7x7, ) assert path.join(plot_path, "subplot_tracer.png") in plot_patch.paths diff --git a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py index be0d81fa9..20c1fe19e 100644 --- a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py +++ b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py @@ -22,7 +22,7 @@ def test__fit_interferometer( plotter_interface = PlotterInterfaceInterferometer(image_path=plot_path) plotter_interface.fit_interferometer( - fit=fit_interferometer_x2_plane_7x7, during_analysis=True + fit=fit_interferometer_x2_plane_7x7, ) assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths diff --git a/test_autolens/point/model/test_plotter_interface_point.py b/test_autolens/point/model/test_plotter_interface_point.py index 7d29802e0..a30973778 100644 --- a/test_autolens/point/model/test_plotter_interface_point.py +++ b/test_autolens/point/model/test_plotter_interface_point.py @@ -19,7 +19,7 @@ def test__fit_point(fit_point_dataset_x2_plane, include_2d_all, plot_path, plot_ plotter_interface = PlotterInterfacePoint(image_path=plot_path) - plotter_interface.fit_point(fit=fit_point_dataset_x2_plane, during_analysis=False) + plotter_interface.fit_point(fit=fit_point_dataset_x2_plane) assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths From d335a8ceb2c18b54df40780caec5137fdfae6d9c Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:10:03 +0000 Subject: [PATCH 02/19] remove use of subfolders --- autolens/analysis/plotter_interface.py | 59 +--------------- autolens/imaging/model/plotter_interface.py | 58 ++------------- .../interferometer/model/plotter_interface.py | 70 ++----------------- autolens/point/model/plotter_interface.py | 19 ++--- 4 files changed, 15 insertions(+), 191 deletions(-) diff --git a/autolens/analysis/plotter_interface.py b/autolens/analysis/plotter_interface.py index d62226e76..23bcfaece 100644 --- a/autolens/analysis/plotter_interface.py +++ b/autolens/analysis/plotter_interface.py @@ -54,7 +54,7 @@ def tracer(self, tracer: Tracer, grid: aa.type.Grid2DLike, during_analysis: bool 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, @@ -88,61 +88,6 @@ def should_plot(name): 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 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" - ) - - 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, - ) - 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 @@ -167,7 +112,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) diff --git a/autolens/imaging/model/plotter_interface.py b/autolens/imaging/model/plotter_interface.py index 3ae546fe9..5ccbb40bb 100644 --- a/autolens/imaging/model/plotter_interface.py +++ b/autolens/imaging/model/plotter_interface.py @@ -18,7 +18,7 @@ class PlotterInterfaceImaging(PlotterInterface): imaging_combined = AgPlotterInterfaceImaging.imaging_combined def fit_imaging( - self, fit: FitImaging, during_analysis: bool, subfolders: str = "fit_dataset" + self, fit: FitImaging, during_analysis: bool, ): """ Visualizes a `FitImaging` object, which fits an imaging dataset. @@ -46,7 +46,7 @@ def fit_imaging( if plot_setting(section="tracer", name="subplot_tracer"): - mat_plot_2d = self.mat_plot_2d_from(subfolders="") + mat_plot_2d = self.mat_plot_2d_from() fit_plotter = FitImagingPlotter( fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d @@ -57,7 +57,7 @@ def fit_imaging( def should_plot(name): return plot_setting(section=["fit", "fit_imaging"], name=name) - mat_plot_2d = self.mat_plot_2d_from(subfolders=subfolders) + mat_plot_2d = self.mat_plot_2d_from() fit_plotter = FitImagingPlotter( fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d @@ -79,7 +79,7 @@ def should_plot(name): plane_image=should_plot("plane_images_of_planes"), ) - mat_plot_2d = self.mat_plot_2d_from(subfolders="") + mat_plot_2d = self.mat_plot_2d_from() fit_plotter = FitImagingPlotter( fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d @@ -103,54 +103,6 @@ def should_plot(name): except IndexError: pass - if not during_analysis and should_plot("all_at_end_png"): - - mat_plot_2d = self.mat_plot_2d_from( - subfolders=path.join("fit_dataset", "end"), - ) - - fit_plotter = FitImagingPlotter( - fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d - ) - - fit_plotter.figures_2d( - data=True, - noise_map=True, - signal_to_noise_map=True, - model_image=True, - residual_map=True, - normalized_residual_map=True, - chi_squared_map=True, - ) - - fit_plotter.figures_2d_of_planes( - subtracted_image=True, model_image=True, plane_image=True - ) - - if not during_analysis and should_plot("all_at_end_fits"): - - mat_plot_2d = self.mat_plot_2d_from( - subfolders=path.join("fit_dataset", "fits"), format="fits" - ) - - fit_plotter = FitImagingPlotter( - fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d - ) - - fit_plotter.figures_2d( - data=True, - noise_map=True, - signal_to_noise_map=True, - model_image=True, - residual_map=True, - normalized_residual_map=True, - chi_squared_map=True, - ) - - fit_plotter.figures_2d_of_planes( - subtracted_image=True, model_image=True, plane_image=True, interpolate_to_uniform=True - ) - def fit_imaging_combined(self, fit_list: List[FitImaging]): """ Output visualization of all `FitImaging` objects in a summed combined analysis, typically during or after a @@ -174,7 +126,7 @@ def fit_imaging_combined(self, fit_list: List[FitImaging]): def should_plot(name): return plot_setting(section=["fit", "fit_imaging"], name=name) - mat_plot_2d = self.mat_plot_2d_from(subfolders="combined") + mat_plot_2d = self.mat_plot_2d_from() fit_plotter_list = [ FitImagingPlotter( diff --git a/autolens/interferometer/model/plotter_interface.py b/autolens/interferometer/model/plotter_interface.py index 3b7574605..d58e5f2e5 100644 --- a/autolens/interferometer/model/plotter_interface.py +++ b/autolens/interferometer/model/plotter_interface.py @@ -20,7 +20,6 @@ def fit_interferometer( self, fit: FitInterferometer, during_analysis: bool, - subfolders: str = "fit_dataset", ): """ Visualizes a `FitInterferometer` object, which fits an interferometer dataset. @@ -48,8 +47,8 @@ def fit_interferometer( def should_plot(name): return plot_setting(section=["fit", "fit_interferometer"], name=name) - mat_plot_1d = self.mat_plot_1d_from(subfolders="") - mat_plot_2d = self.mat_plot_2d_from(subfolders="") + mat_plot_1d = self.mat_plot_1d_from() + mat_plot_2d = self.mat_plot_2d_from() fit_plotter = FitInterferometerPlotter( fit=fit, @@ -67,8 +66,8 @@ def should_plot(name): if should_plot("subplot_fit_real_space"): fit_plotter.subplot_fit_real_space() - mat_plot_1d = self.mat_plot_1d_from(subfolders=subfolders) - mat_plot_2d = self.mat_plot_2d_from(subfolders=subfolders) + mat_plot_1d = self.mat_plot_1d_from() + mat_plot_2d = self.mat_plot_2d_from() fit_plotter = FitInterferometerPlotter( fit=fit, @@ -102,64 +101,3 @@ def should_plot(name): plane_index=len(fit.tracer.planes) - 1 ) - if not during_analysis and should_plot("all_at_end_png"): - mat_plot_1d = self.mat_plot_1d_from(subfolders=path.join(subfolders, "end")) - mat_plot_2d = self.mat_plot_2d_from(subfolders=path.join(subfolders, "end")) - - fit_plotter = FitInterferometerPlotter( - fit=fit, - include_2d=self.include_2d, - mat_plot_1d=mat_plot_1d, - mat_plot_2d=mat_plot_2d, - ) - - fit_plotter.figures_2d( - data=True, - noise_map=True, - signal_to_noise_map=True, - model_data=True, - residual_map_real=True, - chi_squared_map_real=True, - normalized_residual_map_real=True, - residual_map_imag=True, - chi_squared_map_imag=True, - normalized_residual_map_imag=True, - dirty_image=True, - dirty_noise_map=True, - dirty_signal_to_noise_map=True, - dirty_model_image=True, - dirty_residual_map=True, - dirty_normalized_residual_map=True, - dirty_chi_squared_map=True, - ) - - plane_index_max = len(fit.tracer.planes) - 1 - - fit_plotter.figures_2d_of_planes( - plane_index=plane_index_max, plane_image=True - ) - - if not during_analysis and should_plot("all_at_end_fits"): - mat_plot_2d = self.mat_plot_2d_from( - subfolders=path.join("fit_dataset", "fits"), format="fits" - ) - - fit_plotter = FitInterferometerPlotter( - fit=fit, include_2d=self.include_2d, mat_plot_2d=mat_plot_2d - ) - - fit_plotter.figures_2d( - dirty_image=True, - dirty_noise_map=True, - dirty_signal_to_noise_map=True, - dirty_model_image=True, - dirty_residual_map=True, - dirty_normalized_residual_map=True, - dirty_chi_squared_map=True, - ) - - plane_index_max = len(fit.tracer.planes) - 1 - - fit_plotter.figures_2d_of_planes( - plane_index=plane_index_max, plane_image=True - ) diff --git a/autolens/point/model/plotter_interface.py b/autolens/point/model/plotter_interface.py index 51417f66a..f98cb447a 100644 --- a/autolens/point/model/plotter_interface.py +++ b/autolens/point/model/plotter_interface.py @@ -32,7 +32,7 @@ def dataset_point(self, dataset: PointDataset): def should_plot(name): return plot_setting(section=["point_dataset"], name=name) - mat_plot_2d = self.mat_plot_2d_from(subfolders="dataset") + mat_plot_2d = self.mat_plot_2d_from() dataset_plotter = PointDatasetPlotter( dataset=dataset, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d @@ -43,7 +43,7 @@ def should_plot(name): fluxes=should_plot("fluxes"), ) - mat_plot_2d = self.mat_plot_2d_from(subfolders="") + mat_plot_2d = self.mat_plot_2d_from() dataset_plotter = PointDatasetPlotter( dataset=dataset, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d @@ -56,7 +56,6 @@ def fit_point( self, fit: FitPointDataset, during_analysis: bool, - subfolders: str = "fit_dataset", ): """ Visualizes a `FitPointDataset` object, which fits an imaging dataset. @@ -85,7 +84,7 @@ def fit_point( def should_plot(name): return plot_setting(section=["fit", "fit_point_dataset"], name=name) - mat_plot_2d = self.mat_plot_2d_from(subfolders=subfolders) + mat_plot_2d = self.mat_plot_2d_from() fit_plotter = FitPointDatasetPlotter( fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d @@ -96,7 +95,7 @@ def should_plot(name): fluxes=should_plot("fluxes"), ) - mat_plot_2d = self.mat_plot_2d_from(subfolders="") + mat_plot_2d = self.mat_plot_2d_from() fit_plotter = FitPointDatasetPlotter( fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d @@ -105,13 +104,3 @@ def should_plot(name): if should_plot("subplot_fit"): fit_plotter.subplot_fit() - if not during_analysis and should_plot("all_at_end_png"): - mat_plot_2d = self.mat_plot_2d_from( - subfolders=path.join("fit_dataset", "end"), - ) - - fit_plotter = FitPointDatasetPlotter( - fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d - ) - - fit_plotter.figures_2d(positions=True, fluxes=True) From 8140b09c0f4a20b68f8ca6b5d7ebd796682282d3 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:16:33 +0000 Subject: [PATCH 03/19] clean up base plotter interfasce --- autolens/analysis/plotter_interface.py | 28 +++----------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/autolens/analysis/plotter_interface.py b/autolens/analysis/plotter_interface.py index 23bcfaece..2872d0989 100644 --- a/autolens/analysis/plotter_interface.py +++ b/autolens/analysis/plotter_interface.py @@ -26,7 +26,7 @@ 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. @@ -47,8 +47,6 @@ 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): @@ -66,28 +64,6 @@ 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 - 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 @@ -123,6 +99,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() From f716ab2f004c070ed1814c3a47bed3ee57079148 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:16:58 +0000 Subject: [PATCH 04/19] unitt est --- test_autolens/analysis/test_plotter_interface.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test_autolens/analysis/test_plotter_interface.py b/test_autolens/analysis/test_plotter_interface.py index e07c206bc..7bd6640e5 100644 --- a/test_autolens/analysis/test_plotter_interface.py +++ b/test_autolens/analysis/test_plotter_interface.py @@ -30,20 +30,6 @@ def test__tracer( plot_path = path.join(plot_path, "tracer") assert path.join(plot_path, "subplot_galaxies_images.png") in plot_patch.paths - assert path.join(plot_path, "image_2d.png") in plot_patch.paths - assert path.join(plot_path, "plane_image_of_plane_1.png") in plot_patch.paths - assert path.join(plot_path, "convergence_2d.png") in plot_patch.paths - assert path.join(plot_path, "potential_2d.png") not in plot_patch.paths - assert path.join(plot_path, "deflections_y_2d.png") not in plot_patch.paths - assert path.join(plot_path, "deflections_x_2d.png") not in plot_patch.paths - assert path.join(plot_path, "magnification_2d.png") in plot_patch.paths - - convergence = al.util.array_2d.numpy_array_2d_via_fits_from( - file_path=path.join(plot_path, "fits", "convergence_2d.fits"), hdu=0 - ) - - assert convergence.shape == (7, 7) - def test__image_with_positions( image_7x7, positions_x2, include_2d_all, plot_path, plot_patch From 0697c4ed239357086995532f84fc77064f879d0b Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:19:01 +0000 Subject: [PATCH 05/19] fit imaging plotter interface --- autolens/imaging/model/plotter_interface.py | 39 ++++----------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/autolens/imaging/model/plotter_interface.py b/autolens/imaging/model/plotter_interface.py index 5ccbb40bb..c54e64fdc 100644 --- a/autolens/imaging/model/plotter_interface.py +++ b/autolens/imaging/model/plotter_interface.py @@ -18,7 +18,7 @@ class PlotterInterfaceImaging(PlotterInterface): imaging_combined = AgPlotterInterfaceImaging.imaging_combined def fit_imaging( - self, fit: FitImaging, during_analysis: bool, + self, fit: FitImaging, ): """ Visualizes a `FitImaging` object, which fits an imaging dataset. @@ -37,11 +37,6 @@ def fit_imaging( ---------- fit The maximum log likelihood `FitImaging` of the non-linear search which is used to plot the fit. - during_analysis - Whether visualization is performed during a non-linear search or once it is completed. - visuals_2d - An object containing attributes which may be plotted over the figure (e.g. the centres of mass and light - profiles). """ if plot_setting(section="tracer", name="subplot_tracer"): @@ -63,28 +58,6 @@ def should_plot(name): fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d ) - fit_plotter.figures_2d( - data=should_plot("data"), - noise_map=should_plot("noise_map"), - signal_to_noise_map=should_plot("signal_to_noise_map"), - model_image=should_plot("model_data"), - residual_map=should_plot("residual_map"), - chi_squared_map=should_plot("chi_squared_map"), - normalized_residual_map=should_plot("normalized_residual_map"), - ) - - fit_plotter.figures_2d_of_planes( - subtracted_image=should_plot("subtracted_images_of_planes"), - model_image=should_plot("model_images_of_planes"), - plane_image=should_plot("plane_images_of_planes"), - ) - - mat_plot_2d = self.mat_plot_2d_from() - - fit_plotter = FitImagingPlotter( - fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d - ) - if should_plot("subplot_fit"): fit_plotter.subplot_fit() @@ -220,9 +193,9 @@ def make_subplot_fit(filename_suffix): open_subplot=False, ) - make_subplot_fit(filename_suffix="fit") + make_subplot_fit(filename_suffix="fit_combined") + + for plotter in multi_plotter.plotter_list: + plotter.mat_plot_2d.use_log10 = True - # for plotter in multi_plotter.plotter_list: - # plotter.mat_plot_2d.use_log10 = True - # - # make_subplot_fit(filename_suffix="fit_log10") \ No newline at end of file + make_subplot_fit(filename_suffix="fit_combined_log10") \ No newline at end of file From dcaad0dd464a8c1b195629aa907b0b3bec19b80d Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:19:53 +0000 Subject: [PATCH 06/19] interferometer --- .../interferometer/model/plotter_interface.py | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/autolens/interferometer/model/plotter_interface.py b/autolens/interferometer/model/plotter_interface.py index d58e5f2e5..0741c79c6 100644 --- a/autolens/interferometer/model/plotter_interface.py +++ b/autolens/interferometer/model/plotter_interface.py @@ -19,7 +19,6 @@ class PlotterInterfaceInterferometer(PlotterInterface): def fit_interferometer( self, fit: FitInterferometer, - during_analysis: bool, ): """ Visualizes a `FitInterferometer` object, which fits an interferometer dataset. @@ -37,11 +36,6 @@ def fit_interferometer( ---------- fit The maximum log likelihood `FitInterferometer` of the non-linear search which is used to plot the fit. - during_analysis - Whether visualization is performed during a non-linear search or once it is completed. - visuals_2d - An object containing attributes which may be plotted over the figure (e.g. the centres of mass and light - profiles). """ def should_plot(name): @@ -76,26 +70,6 @@ def should_plot(name): mat_plot_2d=mat_plot_2d, ) - fit_plotter.figures_2d( - data=should_plot("data"), - noise_map=should_plot("noise_map"), - signal_to_noise_map=should_plot("signal_to_noise_map"), - model_data=should_plot("model_data"), - residual_map_real=should_plot("residual_map"), - chi_squared_map_real=should_plot("chi_squared_map"), - normalized_residual_map_real=should_plot("normalized_residual_map"), - residual_map_imag=should_plot("residual_map"), - chi_squared_map_imag=should_plot("chi_squared_map"), - normalized_residual_map_imag=should_plot("normalized_residual_map"), - dirty_image=should_plot("data"), - dirty_noise_map=should_plot("noise_map"), - dirty_signal_to_noise_map=should_plot("signal_to_noise_map"), - dirty_model_image=should_plot("model_data"), - dirty_residual_map=should_plot("residual_map"), - dirty_normalized_residual_map=should_plot("normalized_residual_map"), - dirty_chi_squared_map=should_plot("chi_squared_map"), - ) - if plot_setting(section="inversion", name="subplot_mappings"): fit_plotter.subplot_mappings_of_plane( plane_index=len(fit.tracer.planes) - 1 From 04308dc500838fda330b0ff0eea68bf4eff0b519 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:20:33 +0000 Subject: [PATCH 07/19] point plotter interface --- autolens/point/model/plotter_interface.py | 28 ----------------------- 1 file changed, 28 deletions(-) diff --git a/autolens/point/model/plotter_interface.py b/autolens/point/model/plotter_interface.py index f98cb447a..5696c1409 100644 --- a/autolens/point/model/plotter_interface.py +++ b/autolens/point/model/plotter_interface.py @@ -38,24 +38,12 @@ def should_plot(name): dataset=dataset, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d ) - dataset_plotter.figures_2d( - positions=should_plot("positions"), - fluxes=should_plot("fluxes"), - ) - - mat_plot_2d = self.mat_plot_2d_from() - - dataset_plotter = PointDatasetPlotter( - dataset=dataset, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d - ) - if should_plot("subplot_dataset"): dataset_plotter.subplot_dataset() def fit_point( self, fit: FitPointDataset, - during_analysis: bool, ): """ Visualizes a `FitPointDataset` object, which fits an imaging dataset. @@ -74,11 +62,6 @@ def fit_point( ---------- fit The maximum log likelihood `FitPointDataset` of the non-linear search which is used to plot the fit. - during_analysis - Whether visualization is performed during a non-linear search or once it is completed. - visuals_2d - An object containing attributes which may be plotted over the figure (e.g. the centres of mass and light - profiles). """ def should_plot(name): @@ -90,17 +73,6 @@ def should_plot(name): fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d ) - fit_plotter.figures_2d( - positions=should_plot("positions"), - fluxes=should_plot("fluxes"), - ) - - mat_plot_2d = self.mat_plot_2d_from() - - fit_plotter = FitPointDatasetPlotter( - fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d - ) - if should_plot("subplot_fit"): fit_plotter.subplot_fit() From 7a3559d2bb998e865778a63a8f86b1398a204b09 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:21:38 +0000 Subject: [PATCH 08/19] imaging unit testts --- .../model/test_plotter_interface_imaging.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/test_autolens/imaging/model/test_plotter_interface_imaging.py b/test_autolens/imaging/model/test_plotter_interface_imaging.py index 839ead26e..30c5e2f14 100644 --- a/test_autolens/imaging/model/test_plotter_interface_imaging.py +++ b/test_autolens/imaging/model/test_plotter_interface_imaging.py @@ -30,22 +30,6 @@ def test__fit_imaging( assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths assert path.join(plot_path, "subplot_fit_log10.png") in plot_patch.paths - plot_path = path.join(plot_path, "fit_dataset") - - assert path.join(plot_path, "data.png") in plot_patch.paths - assert path.join(plot_path, "noise_map.png") not in plot_patch.paths - - assert path.join(plot_path, "lens_subtracted_image.png") in plot_patch.paths - assert path.join(plot_path, "source_model_image.png") not in plot_patch.paths - - assert path.join(plot_path, "reconstruction.png") in plot_patch.paths - - image = al.util.array_2d.numpy_array_2d_via_fits_from( - file_path=path.join(plot_path, "fits", "data.fits"), hdu=0 - ) - - assert image.shape == (7, 7) - def test__fit_imaging_combined( fit_imaging_x2_plane_inversion_7x7, plot_path, plot_patch ): From 8032abbcdaa0b4c7dd0eb4ac40aa124f152e4ff6 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:21:47 +0000 Subject: [PATCH 09/19] interferometer unit tests --- .../model/test_plotter_interface_interferometer.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py index 20c1fe19e..2f9ef2166 100644 --- a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py +++ b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py @@ -27,9 +27,4 @@ def test__fit_interferometer( assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths assert path.join(plot_path, "subplot_fit_real_space.png") in plot_patch.paths - assert path.join(plot_path, "subplot_fit_dirty_images.png") in plot_patch.paths - - plot_path = path.join(plot_path, "fit_dataset") - - assert path.join(plot_path, "data.png") in plot_patch.paths - assert path.join(plot_path, "noise_map.png") not in plot_patch.paths + assert path.join(plot_path, "subplot_fit_dirty_images.png") in plot_patch.paths \ No newline at end of file From 170de6c71e80faf7a9150b2bbbf28adbea992f06 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:22:09 +0000 Subject: [PATCH 10/19] point unit tests --- test_autolens/point/model/test_plotter_interface_point.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test_autolens/point/model/test_plotter_interface_point.py b/test_autolens/point/model/test_plotter_interface_point.py index a30973778..eed1a8007 100644 --- a/test_autolens/point/model/test_plotter_interface_point.py +++ b/test_autolens/point/model/test_plotter_interface_point.py @@ -21,8 +21,4 @@ def test__fit_point(fit_point_dataset_x2_plane, include_2d_all, plot_path, plot_ plotter_interface.fit_point(fit=fit_point_dataset_x2_plane) - assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths - - plot_path = path.join(plot_path, "fit_dataset") - - assert path.join(plot_path, "fit_point_positions.png") in plot_patch.paths + assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths \ No newline at end of file From 55f66c497975fe6f259f57bd6eca3049317db734 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 13:32:37 +0000 Subject: [PATCH 11/19] interface clean with unit tests passing --- autolens/interferometer/model/plotter_interface.py | 1 - autolens/point/fit/positions/abstract.py | 2 +- autolens/point/fit/positions/source/separations.py | 14 +++++++++++--- autolens/point/model/plotter_interface.py | 1 - test_autolens/analysis/test_plotter_interface.py | 5 +---- .../model/test_plotter_interface_imaging.py | 4 +--- .../model/test_plotter_interface_interferometer.py | 2 +- .../point/fit/positions/source/test_separations.py | 9 ++++++--- .../point/model/test_plotter_interface_point.py | 2 +- 9 files changed, 22 insertions(+), 18 deletions(-) diff --git a/autolens/interferometer/model/plotter_interface.py b/autolens/interferometer/model/plotter_interface.py index 0741c79c6..de4780d34 100644 --- a/autolens/interferometer/model/plotter_interface.py +++ b/autolens/interferometer/model/plotter_interface.py @@ -74,4 +74,3 @@ def should_plot(name): fit_plotter.subplot_mappings_of_plane( plane_index=len(fit.tracer.planes) - 1 ) - diff --git a/autolens/point/fit/positions/abstract.py b/autolens/point/fit/positions/abstract.py index 7ac074216..5b3d176a3 100644 --- a/autolens/point/fit/positions/abstract.py +++ b/autolens/point/fit/positions/abstract.py @@ -69,4 +69,4 @@ def __init__( @property def positions(self): - return self.data \ No newline at end of file + return self.data diff --git a/autolens/point/fit/positions/source/separations.py b/autolens/point/fit/positions/source/separations.py index 155202047..2c35269b8 100644 --- a/autolens/point/fit/positions/source/separations.py +++ b/autolens/point/fit/positions/source/separations.py @@ -117,18 +117,26 @@ def chi_squared_map(self) -> float: multiplied by the magnifications squared, divided by the noise-map values squared. """ - return self.residual_map**2.0 / (self.magnifications_at_positions**-2.0 * self.noise_map**2.0) + return self.residual_map**2.0 / ( + self.magnifications_at_positions**-2.0 * self.noise_map**2.0 + ) @property def noise_normalization(self) -> float: """ Returns the normalization of the noise-map, which is the sum of the noise-map values squared. """ - return npw.sum(npw.log(2 * np.pi * (self.magnifications_at_positions**-2.0 *self.noise_map**2.0))) + return npw.sum( + npw.log( + 2 + * np.pi + * (self.magnifications_at_positions**-2.0 * self.noise_map**2.0) + ) + ) @property def log_likelihood(self) -> float: """ Returns the log likelihood of the point-source source-plane fit, which is the sum of the chi-squared values. """ - return -0.5 * (sum(self.chi_squared_map) + self.noise_normalization) \ No newline at end of file + return -0.5 * (sum(self.chi_squared_map) + self.noise_normalization) diff --git a/autolens/point/model/plotter_interface.py b/autolens/point/model/plotter_interface.py index 5696c1409..69d92d039 100644 --- a/autolens/point/model/plotter_interface.py +++ b/autolens/point/model/plotter_interface.py @@ -75,4 +75,3 @@ def should_plot(name): if should_plot("subplot_fit"): fit_plotter.subplot_fit() - diff --git a/test_autolens/analysis/test_plotter_interface.py b/test_autolens/analysis/test_plotter_interface.py index 7bd6640e5..6d2792a62 100644 --- a/test_autolens/analysis/test_plotter_interface.py +++ b/test_autolens/analysis/test_plotter_interface.py @@ -27,10 +27,9 @@ def test__tracer( grid=masked_imaging_7x7.grids.lp, ) - plot_path = path.join(plot_path, "tracer") - assert path.join(plot_path, "subplot_galaxies_images.png") in plot_patch.paths + def test__image_with_positions( image_7x7, positions_x2, include_2d_all, plot_path, plot_patch ): @@ -41,6 +40,4 @@ def test__image_with_positions( plotter_interface.image_with_positions(image=image_7x7, positions=positions_x2) - plot_path = path.join(plot_path, "positions") - assert path.join(plot_path, "image_with_positions.png") in plot_patch.paths diff --git a/test_autolens/imaging/model/test_plotter_interface_imaging.py b/test_autolens/imaging/model/test_plotter_interface_imaging.py index 30c5e2f14..7ee06fe76 100644 --- a/test_autolens/imaging/model/test_plotter_interface_imaging.py +++ b/test_autolens/imaging/model/test_plotter_interface_imaging.py @@ -40,6 +40,4 @@ def test__fit_imaging_combined( visualizer.fit_imaging_combined(fit_list=2 * [fit_imaging_x2_plane_inversion_7x7]) - plot_path = path.join(plot_path, "combined") - - assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths \ No newline at end of file + assert path.join(plot_path, "subplot_fit_combined.png") in plot_patch.paths \ No newline at end of file diff --git a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py index 2f9ef2166..64fdc74e5 100644 --- a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py +++ b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py @@ -27,4 +27,4 @@ def test__fit_interferometer( assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths assert path.join(plot_path, "subplot_fit_real_space.png") in plot_patch.paths - assert path.join(plot_path, "subplot_fit_dirty_images.png") in plot_patch.paths \ No newline at end of file + assert path.join(plot_path, "subplot_fit_dirty_images.png") in plot_patch.paths diff --git a/test_autolens/point/fit/positions/source/test_separations.py b/test_autolens/point/fit/positions/source/test_separations.py index cb8c9ed26..68b5ef2a9 100644 --- a/test_autolens/point/fit/positions/source/test_separations.py +++ b/test_autolens/point/fit/positions/source/test_separations.py @@ -37,11 +37,14 @@ def test__two_sets_of_positions__residuals_likelihood_correct(): name="point_0", data=positions, noise_map=noise_map, tracer=tracer, solver=None ) - assert fit.magnifications_at_positions.in_list == pytest.approx([1.1111049387688177, 1.0526308864400329], 1.0e-4) + assert fit.magnifications_at_positions.in_list == pytest.approx( + [1.1111049387688177, 1.0526308864400329], 1.0e-4 + ) assert fit.model_data.in_list == [(0.0, 0.9), (0.0, 1.9)] - - assert fit.chi_squared_map.in_list == pytest.approx([3.9999555592589244, 3.9999947369459807], 1.0e-4) + assert fit.chi_squared_map.in_list == pytest.approx( + [3.9999555592589244, 3.9999947369459807], 1.0e-4 + ) assert fit.log_likelihood == pytest.approx(-5.144705033951853, 1.0e-4) diff --git a/test_autolens/point/model/test_plotter_interface_point.py b/test_autolens/point/model/test_plotter_interface_point.py index eed1a8007..ebe613bec 100644 --- a/test_autolens/point/model/test_plotter_interface_point.py +++ b/test_autolens/point/model/test_plotter_interface_point.py @@ -21,4 +21,4 @@ def test__fit_point(fit_point_dataset_x2_plane, include_2d_all, plot_path, plot_ plotter_interface.fit_point(fit=fit_point_dataset_x2_plane) - assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths \ No newline at end of file + assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths From 71db6efa3b21d1ba504a3e3ca9421c950ea87b14 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 19 Feb 2025 15:19:02 +0000 Subject: [PATCH 12/19] during analysis removed --- autolens/config/visualize/plots.yaml | 147 ++++++-------------- autolens/imaging/model/visualizer.py | 10 +- autolens/interferometer/model/visualizer.py | 10 +- autolens/point/model/visualizer.py | 8 +- autolens/quantity/model/visualizer.py | 4 - test_autolens/config/visualize.yaml | 71 +--------- 6 files changed, 56 insertions(+), 194 deletions(-) diff --git a/autolens/config/visualize/plots.yaml b/autolens/config/visualize/plots.yaml index 372d27db6..2ef20b15e 100644 --- a/autolens/config/visualize/plots.yaml +++ b/autolens/config/visualize/plots.yaml @@ -1,105 +1,42 @@ - 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? + +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)? diff --git a/autolens/imaging/model/visualizer.py b/autolens/imaging/model/visualizer.py index 66caf6c67..22611f7fd 100644 --- a/autolens/imaging/model/visualizer.py +++ b/autolens/imaging/model/visualizer.py @@ -76,9 +76,6 @@ def visualize( instance An instance of the model that is being fitted to the data by this analysis (whose parameters have been set via a non-linear search). - during_analysis - If True the visualization is being performed midway through the non-linear search before it is finished, - which may change which images are output. """ fit = analysis.fit_from(instance=instance) @@ -99,7 +96,7 @@ def visualize( ) try: - plotter_interface.fit_imaging(fit=fit, during_analysis=during_analysis) + plotter_interface.fit_imaging(fit=fit) except exc.InversionException: pass @@ -111,17 +108,16 @@ def visualize( grid = ag.Grid2D.from_extent(extent=extent, shape_native=shape_native) plotter_interface.tracer( - tracer=tracer, grid=grid, during_analysis=during_analysis + tracer=tracer, grid=grid, ) plotter_interface.galaxies( galaxies=tracer.galaxies, grid=fit.grids.lp, - during_analysis=during_analysis, ) if fit.inversion is not None: if fit.inversion.has(cls=ag.AbstractMapper): plotter_interface.inversion( - inversion=fit.inversion, during_analysis=during_analysis + inversion=fit.inversion, ) @staticmethod diff --git a/autolens/interferometer/model/visualizer.py b/autolens/interferometer/model/visualizer.py index c1dc14ae0..8331f496d 100644 --- a/autolens/interferometer/model/visualizer.py +++ b/autolens/interferometer/model/visualizer.py @@ -78,9 +78,6 @@ def visualize( instance An instance of the model that is being fitted to the data by this analysis (whose parameters have been set via a non-linear search). - during_analysis - If True the visualization is being performed midway through the non-linear search before it is finished, - which may change which images are output. """ fit = analysis.fit_from(instance=instance) @@ -101,7 +98,7 @@ def visualize( try: plotter_interface.fit_interferometer( - fit=fit, during_analysis=during_analysis + fit=fit, ) except exc.InversionException: pass @@ -109,17 +106,16 @@ def visualize( tracer = fit.tracer_linear_light_profiles_to_light_profiles plotter_interface.tracer( - tracer=tracer, grid=fit.grids.lp, during_analysis=during_analysis + tracer=tracer, grid=fit.grids.lp, ) plotter_interface.galaxies( galaxies=tracer.galaxies, grid=fit.grids.lp, - during_analysis=during_analysis, ) if fit.inversion is not None: try: plotter_interface.inversion( - inversion=fit.inversion, during_analysis=during_analysis + inversion=fit.inversion, ) except IndexError: pass diff --git a/autolens/point/model/visualizer.py b/autolens/point/model/visualizer.py index fe86e98f8..58c6932cc 100644 --- a/autolens/point/model/visualizer.py +++ b/autolens/point/model/visualizer.py @@ -61,9 +61,6 @@ def visualize( instance An instance of the model that is being fitted to the data by this analysis (whose parameters have been set via a non-linear search). - during_analysis - If True the visualization is being performed midway through the non-linear search before it is finished, - which may change which images are output. """ fit = analysis.fit_from(instance=instance) @@ -71,7 +68,7 @@ def visualize( image_path=paths.image_path, title_prefix=analysis.title_prefix ) - plotter_interface.fit_point(fit=fit, during_analysis=during_analysis) + plotter_interface.fit_point(fit=fit) tracer = fit.tracer @@ -80,10 +77,9 @@ def visualize( ) plotter_interface.tracer( - tracer=tracer, grid=grid, during_analysis=during_analysis + tracer=tracer, grid=grid, ) plotter_interface.galaxies( galaxies=tracer.galaxies, grid=grid, - during_analysis=during_analysis, ) diff --git a/autolens/quantity/model/visualizer.py b/autolens/quantity/model/visualizer.py index 69b6d0426..70aa13e49 100644 --- a/autolens/quantity/model/visualizer.py +++ b/autolens/quantity/model/visualizer.py @@ -38,9 +38,6 @@ def visualize( instance An instance of the model that is being fitted to the data by this analysis (whose parameters have been set via a non-linear search). - during_analysis - If True the visualization is being performed midway through the non-linear search before it is finished, - which may change which images are output. """ if os.environ.get("PYAUTOFIT_TEST_MODE") == "1": @@ -57,5 +54,4 @@ def visualize( plotter_interface.tracer( tracer=fit.tracer, grid=analysis.dataset.grids.lp, - during_analysis=during_analysis, ) diff --git a/test_autolens/config/visualize.yaml b/test_autolens/config/visualize.yaml index f4d4bd3b9..340f4e53c 100644 --- a/test_autolens/config/visualize.yaml +++ b/test_autolens/config/visualize.yaml @@ -71,87 +71,28 @@ mat_wrap_2d: s: 17 plots: dataset: - data: true - noise_map: false - signal_to_noise_map: false subplot_dataset: true - uv_wavelengths: false fit: - all_at_end_fits: true - all_at_end_png: false - chi_squared_map: true - data: true - model_data: true - model_images_of_planes: false - noise_map: false - normalized_residual_map: true - plane_images_of_planes: true - residual_map: false - signal_to_noise_map: false subplot_fit: true subplots_of_planes: false - subtracted_images_of_planes: true fit_imaging: {} fit_interferometer: subplot_fit_real_space: true subplot_fit_dirty_images: true - amplitudes_vs_uv_distances: false - dirty_chi_squared_map: false - dirty_image: false - dirty_noise_map: false - dirty_normalized_residual_map: false - dirty_residual_map: false - dirty_signal_to_noise_map: false - phases_vs_uv_distances: false - uv_wavelengths: false - fit_point_dataset: # Settings for plots of fits to point source datasets (e.g. FitPointDatasetPlotter). - positions: true # Plot the positions of th multiple images of the point source in the image plane? - fluxes: true # Plot the fluxes of the multiple images of the point source in the image plane? + fit_point_dataset: {} fit_quantity: - all_at_end_fits: true - all_at_end_png: true - chi_squared_map: false - image: true - model_image: false - noise_map: false - residual_map: false subplot_fit: true galaxies: - convergence: false - image: false - potential: false + subplot_galaxies: true + subplot_galaxy_images: true + subplot_galaxies_1d: true + subplot_galaxies_1d_decomposed: true adapt: - images_of_galaxies: true - model_image: true - imaging: - psf: true - interferometer: - amplitudes_vs_uv_distances: false - dirty_image: false - dirty_noise_map: false - dirty_signal_to_noise_map: false - phases_vs_uv_distances: false - uv_wavelengths: false + subplot_adapt_images: true inversion: - all_at_end_png: false - chi_squared_map: true - errors: false - normalized_residual_map: false - reconstructed_image: true - reconstruction: true - regularization_weights: false - residual_map: false subplot_inversion: true positions: image_with_positions: true tracer: - all_at_end_fits: true - all_at_end_png: false - convergence: true - deflections: false - image: true - magnification: true - potential: false - source_plane_image: true subplot_tracer: true subplot_galaxies_images: true \ No newline at end of file From 0fef95679518a2229860be2c06bbd7d3d8eef3a4 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Thu, 20 Feb 2025 17:09:33 +0000 Subject: [PATCH 13/19] tracer.fits output --- autolens/analysis/plotter_interface.py | 19 +++++++++++++++++++ autolens/config/visualize/plots.yaml | 1 + autolens/imaging/model/plotter_interface.py | 2 +- .../analysis/test_plotter_interface.py | 6 ++++++ test_autolens/config/visualize.yaml | 3 ++- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/autolens/analysis/plotter_interface.py b/autolens/analysis/plotter_interface.py index 2872d0989..5ab4f2804 100644 --- a/autolens/analysis/plotter_interface.py +++ b/autolens/analysis/plotter_interface.py @@ -64,6 +64,25 @@ def should_plot(name): if should_plot("subplot_galaxies_images"): tracer_plotter.subplot_galaxies_images() + if should_plot("fits_tracer"): + + number_plots = 4 + + multi_plotter = aplt.MultiFigurePlotter( + plotter_list=[tracer_plotter] * number_plots + ) + + 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 diff --git a/autolens/config/visualize/plots.yaml b/autolens/config/visualize/plots.yaml index 2ef20b15e..7739397b0 100644 --- a/autolens/config/visualize/plots.yaml +++ b/autolens/config/visualize/plots.yaml @@ -24,6 +24,7 @@ fit_point_dataset: {} # Settings for plots of fits to point 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)? diff --git a/autolens/imaging/model/plotter_interface.py b/autolens/imaging/model/plotter_interface.py index c54e64fdc..57938e66b 100644 --- a/autolens/imaging/model/plotter_interface.py +++ b/autolens/imaging/model/plotter_interface.py @@ -1,4 +1,4 @@ -from os import path + from typing import List import autoarray.plot as aplt diff --git a/test_autolens/analysis/test_plotter_interface.py b/test_autolens/analysis/test_plotter_interface.py index 6d2792a62..27506324a 100644 --- a/test_autolens/analysis/test_plotter_interface.py +++ b/test_autolens/analysis/test_plotter_interface.py @@ -29,6 +29,12 @@ def test__tracer( assert path.join(plot_path, "subplot_galaxies_images.png") in plot_patch.paths + image = al.util.array_2d.numpy_array_2d_via_fits_from( + file_path=path.join(plot_path, "tracer.fits"), hdu=0 + ) + + assert image.shape == (5, 5) + def test__image_with_positions( image_7x7, positions_x2, include_2d_all, plot_path, plot_patch diff --git a/test_autolens/config/visualize.yaml b/test_autolens/config/visualize.yaml index 340f4e53c..ca771331c 100644 --- a/test_autolens/config/visualize.yaml +++ b/test_autolens/config/visualize.yaml @@ -95,4 +95,5 @@ plots: image_with_positions: true tracer: subplot_tracer: true - subplot_galaxies_images: true \ No newline at end of file + 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 From b6f5077c7ac7e69c95461b356443ec31492ebf84 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Thu, 20 Feb 2025 17:13:33 +0000 Subject: [PATCH 14/19] model_galaxy_images.fits --- autolens/imaging/model/plotter_interface.py | 20 ++++++++++++++++++- test_autolens/config/visualize.yaml | 3 ++- .../model/test_plotter_interface_imaging.py | 6 ++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/autolens/imaging/model/plotter_interface.py b/autolens/imaging/model/plotter_interface.py index 57938e66b..35f2fe61e 100644 --- a/autolens/imaging/model/plotter_interface.py +++ b/autolens/imaging/model/plotter_interface.py @@ -1,4 +1,3 @@ - from typing import List import autoarray.plot as aplt @@ -76,6 +75,25 @@ def should_plot(name): except IndexError: pass + if should_plot("fits_model_galaxy_images"): + multi_plotter = aplt.MultiFigurePlotter( + plotter_list=[ + aplt.Array2DPlotter(array=image, mat_plot_2d=mat_plot_2d) + for (galaxy, image) in fit.galaxy_model_image_dict.items() + ], + ) + + multi_plotter.output_to_fits( + func_name_list=["figure_2d"] * len(multi_plotter.plotter_list), + figure_name_list=[None] * len(multi_plotter.plotter_list), + # tag_list=[name for name, galaxy in galaxies.items()], + tag_list=[ + f"galaxy_{i}" for i in range(len(multi_plotter.plotter_list)) + ], + filename="model_galaxy_images", + remove_fits_first=True, + ) + def fit_imaging_combined(self, fit_list: List[FitImaging]): """ Output visualization of all `FitImaging` objects in a summed combined analysis, typically during or after a diff --git a/test_autolens/config/visualize.yaml b/test_autolens/config/visualize.yaml index ca771331c..27c97938b 100644 --- a/test_autolens/config/visualize.yaml +++ b/test_autolens/config/visualize.yaml @@ -75,7 +75,8 @@ plots: fit: subplot_fit: true subplots_of_planes: false - fit_imaging: {} + fit_imaging: + fits_model_galaxy_images : true # Output a .fits file containing the model images of every galaxy? fit_interferometer: subplot_fit_real_space: true subplot_fit_dirty_images: true diff --git a/test_autolens/imaging/model/test_plotter_interface_imaging.py b/test_autolens/imaging/model/test_plotter_interface_imaging.py index 7ee06fe76..976d5aaec 100644 --- a/test_autolens/imaging/model/test_plotter_interface_imaging.py +++ b/test_autolens/imaging/model/test_plotter_interface_imaging.py @@ -30,6 +30,12 @@ def test__fit_imaging( assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths assert path.join(plot_path, "subplot_fit_log10.png") in plot_patch.paths + image = al.util.array_2d.numpy_array_2d_via_fits_from( + file_path=path.join(plot_path, "model_galaxy_images.fits"), hdu=0 + ) + + assert image.shape == (5, 5) + def test__fit_imaging_combined( fit_imaging_x2_plane_inversion_7x7, plot_path, plot_patch ): From 76ec52890149e67a6b5117b9f681a9faf06a2182 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Thu, 20 Feb 2025 17:18:36 +0000 Subject: [PATCH 15/19] fit.fits --- autolens/analysis/plotter_interface.py | 7 ++++--- autolens/imaging/model/plotter_interface.py | 21 +++---------------- autolens/interferometer/model/visualizer.py | 3 ++- autolens/point/model/visualizer.py | 3 ++- test_autolens/config/visualize.yaml | 1 + .../model/test_plotter_interface_imaging.py | 6 ++++++ 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/autolens/analysis/plotter_interface.py b/autolens/analysis/plotter_interface.py index 5ab4f2804..6282c68b9 100644 --- a/autolens/analysis/plotter_interface.py +++ b/autolens/analysis/plotter_interface.py @@ -65,7 +65,6 @@ def should_plot(name): tracer_plotter.subplot_galaxies_images() if should_plot("fits_tracer"): - number_plots = 4 multi_plotter = aplt.MultiFigurePlotter( @@ -75,14 +74,16 @@ def should_plot(name): multi_plotter.output_to_fits( func_name_list=["figures_2d"] * number_plots, figure_name_list=[ - "convergence", "potential", "deflections_y", "deflections_x" + "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 diff --git a/autolens/imaging/model/plotter_interface.py b/autolens/imaging/model/plotter_interface.py index 35f2fe61e..6510f76a4 100644 --- a/autolens/imaging/model/plotter_interface.py +++ b/autolens/imaging/model/plotter_interface.py @@ -4,6 +4,8 @@ from autogalaxy.imaging.model.plotter_interface import PlotterInterfaceImaging as AgPlotterInterfaceImaging +from autogalaxy.imaging.model.plotter_interface import fits_to_fits + from autolens.analysis.plotter_interface import PlotterInterface from autolens.imaging.fit_imaging import FitImaging from autolens.imaging.plot.fit_imaging_plotters import FitImagingPlotter @@ -75,24 +77,7 @@ def should_plot(name): except IndexError: pass - if should_plot("fits_model_galaxy_images"): - multi_plotter = aplt.MultiFigurePlotter( - plotter_list=[ - aplt.Array2DPlotter(array=image, mat_plot_2d=mat_plot_2d) - for (galaxy, image) in fit.galaxy_model_image_dict.items() - ], - ) - - multi_plotter.output_to_fits( - func_name_list=["figure_2d"] * len(multi_plotter.plotter_list), - figure_name_list=[None] * len(multi_plotter.plotter_list), - # tag_list=[name for name, galaxy in galaxies.items()], - tag_list=[ - f"galaxy_{i}" for i in range(len(multi_plotter.plotter_list)) - ], - filename="model_galaxy_images", - remove_fits_first=True, - ) + fits_to_fits(should_plot=should_plot, fit=fit, mat_plot_2d=mat_plot_2d, fit_plotter_cls=FitImagingPlotter) def fit_imaging_combined(self, fit_list: List[FitImaging]): """ diff --git a/autolens/interferometer/model/visualizer.py b/autolens/interferometer/model/visualizer.py index 8331f496d..74cb75eb7 100644 --- a/autolens/interferometer/model/visualizer.py +++ b/autolens/interferometer/model/visualizer.py @@ -106,7 +106,8 @@ def visualize( tracer = fit.tracer_linear_light_profiles_to_light_profiles plotter_interface.tracer( - tracer=tracer, grid=fit.grids.lp, + tracer=tracer, + grid=fit.grids.lp, ) plotter_interface.galaxies( galaxies=tracer.galaxies, diff --git a/autolens/point/model/visualizer.py b/autolens/point/model/visualizer.py index 58c6932cc..216421629 100644 --- a/autolens/point/model/visualizer.py +++ b/autolens/point/model/visualizer.py @@ -77,7 +77,8 @@ def visualize( ) plotter_interface.tracer( - tracer=tracer, grid=grid, + tracer=tracer, + grid=grid, ) plotter_interface.galaxies( galaxies=tracer.galaxies, diff --git a/test_autolens/config/visualize.yaml b/test_autolens/config/visualize.yaml index 27c97938b..8817904ed 100644 --- a/test_autolens/config/visualize.yaml +++ b/test_autolens/config/visualize.yaml @@ -76,6 +76,7 @@ plots: subplot_fit: true subplots_of_planes: false fit_imaging: + fits_fit: true # Output a .fits file containing the fit model data, residual map, normalized residual map and chi-squared? fits_model_galaxy_images : true # Output a .fits file containing the model images of every galaxy? fit_interferometer: subplot_fit_real_space: true diff --git a/test_autolens/imaging/model/test_plotter_interface_imaging.py b/test_autolens/imaging/model/test_plotter_interface_imaging.py index 976d5aaec..c3cb38ea4 100644 --- a/test_autolens/imaging/model/test_plotter_interface_imaging.py +++ b/test_autolens/imaging/model/test_plotter_interface_imaging.py @@ -30,6 +30,12 @@ def test__fit_imaging( assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths assert path.join(plot_path, "subplot_fit_log10.png") in plot_patch.paths + image = al.util.array_2d.numpy_array_2d_via_fits_from( + file_path=path.join(plot_path, "fit.fits"), hdu=0 + ) + + assert image.shape == (5, 5) + image = al.util.array_2d.numpy_array_2d_via_fits_from( file_path=path.join(plot_path, "model_galaxy_images.fits"), hdu=0 ) From 446dc4c1d7ebbb7815f8b705a90f62a460fce799 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Thu, 20 Feb 2025 17:58:01 +0000 Subject: [PATCH 16/19] interferometer fits files --- .../interferometer/model/plotter_interface.py | 4 ++++ test_autolens/config/visualize.yaml | 3 ++- .../test_plotter_interface_interferometer.py | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/autolens/interferometer/model/plotter_interface.py b/autolens/interferometer/model/plotter_interface.py index de4780d34..3a332bad4 100644 --- a/autolens/interferometer/model/plotter_interface.py +++ b/autolens/interferometer/model/plotter_interface.py @@ -4,6 +4,8 @@ PlotterInterfaceInterferometer as AgPlotterInterfaceInterferometer, ) +from autogalaxy.interferometer.model.plotter_interface import fits_to_fits + from autolens.interferometer.fit_interferometer import FitInterferometer from autolens.interferometer.plot.fit_interferometer_plotters import ( FitInterferometerPlotter, @@ -74,3 +76,5 @@ def should_plot(name): fit_plotter.subplot_mappings_of_plane( plane_index=len(fit.tracer.planes) - 1 ) + + fits_to_fits(should_plot=should_plot, fit=fit, mat_plot_2d=mat_plot_2d, fit_plotter_cls=FitInterferometerPlotter) \ No newline at end of file diff --git a/test_autolens/config/visualize.yaml b/test_autolens/config/visualize.yaml index 8817904ed..389d4ca5e 100644 --- a/test_autolens/config/visualize.yaml +++ b/test_autolens/config/visualize.yaml @@ -75,12 +75,13 @@ plots: fit: subplot_fit: true subplots_of_planes: false - fit_imaging: fits_fit: true # Output a .fits file containing the fit model data, residual map, normalized residual map and chi-squared? fits_model_galaxy_images : true # Output a .fits file containing the model images of every galaxy? + fit_imaging: {} fit_interferometer: subplot_fit_real_space: true subplot_fit_dirty_images: true + fits_dirty_images: true # output dirty_images.fits showing the dirty image, noise-map, model-data, resiual-map, normalized residual map and chi-squared map? fit_point_dataset: {} fit_quantity: subplot_fit: true diff --git a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py index 64fdc74e5..9a92f1e3d 100644 --- a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py +++ b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py @@ -1,6 +1,9 @@ from os import path import pytest + +import autolens as al + from autolens.interferometer.model.plotter_interface import ( PlotterInterfaceInterferometer, ) @@ -28,3 +31,21 @@ def test__fit_interferometer( assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths assert path.join(plot_path, "subplot_fit_real_space.png") in plot_patch.paths assert path.join(plot_path, "subplot_fit_dirty_images.png") in plot_patch.paths + + # visibilities = ag.util.array_2d.numpy_array_2d_via_fits_from( + # file_path=path.join(plot_path, "fit.fits"), hdu=0 + # ) + # + # assert visibilities.shape == (5, 5) + + image = al.util.array_2d.numpy_array_2d_via_fits_from( + file_path=path.join(plot_path, "model_galaxy_images.fits"), hdu=0 + ) + + assert image.shape == (5, 5) + + image = al.util.array_2d.numpy_array_2d_via_fits_from( + file_path=path.join(plot_path, "dirty_images.fits"), hdu=0 + ) + + assert image.shape == (5, 5) \ No newline at end of file From 2e0be5bd3fd5b1f6c8fe2277627193b3990859e8 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Thu, 20 Feb 2025 18:48:26 +0000 Subject: [PATCH 17/19] black --- autolens/interferometer/model/plotter_interface.py | 7 ++++++- .../model/test_plotter_interface_interferometer.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/autolens/interferometer/model/plotter_interface.py b/autolens/interferometer/model/plotter_interface.py index 3a332bad4..bd18fb158 100644 --- a/autolens/interferometer/model/plotter_interface.py +++ b/autolens/interferometer/model/plotter_interface.py @@ -77,4 +77,9 @@ def should_plot(name): plane_index=len(fit.tracer.planes) - 1 ) - fits_to_fits(should_plot=should_plot, fit=fit, mat_plot_2d=mat_plot_2d, fit_plotter_cls=FitInterferometerPlotter) \ No newline at end of file + fits_to_fits( + should_plot=should_plot, + fit=fit, + mat_plot_2d=mat_plot_2d, + fit_plotter_cls=FitInterferometerPlotter, + ) diff --git a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py index 9a92f1e3d..8a883c4fd 100644 --- a/test_autolens/interferometer/model/test_plotter_interface_interferometer.py +++ b/test_autolens/interferometer/model/test_plotter_interface_interferometer.py @@ -48,4 +48,4 @@ def test__fit_interferometer( file_path=path.join(plot_path, "dirty_images.fits"), hdu=0 ) - assert image.shape == (5, 5) \ No newline at end of file + assert image.shape == (5, 5) From ef09565cf68cdb8697bf91e98283994f145d9c6b Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Thu, 20 Feb 2025 19:01:20 +0000 Subject: [PATCH 18/19] fix unit test --- test_autolens/point/fit/positions/source/test_separations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_autolens/point/fit/positions/source/test_separations.py b/test_autolens/point/fit/positions/source/test_separations.py index cb8c9ed26..11a2d4330 100644 --- a/test_autolens/point/fit/positions/source/test_separations.py +++ b/test_autolens/point/fit/positions/source/test_separations.py @@ -42,7 +42,7 @@ def test__two_sets_of_positions__residuals_likelihood_correct(): assert fit.chi_squared_map.in_list == pytest.approx([3.9999555592589244, 3.9999947369459807], 1.0e-4) - assert fit.log_likelihood == pytest.approx(-5.144705033951853, 1.0e-4) + assert fit.log_likelihood == pytest.approx(-4.98805743691215, 1.0e-4) def test__multi_plane_position_solving(): From 4cbc4b5c5215480e76835f0f2fa0eea51fd8861d Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Fri, 21 Feb 2025 10:19:56 +0000 Subject: [PATCH 19/19] docstrings --- autolens/analysis/plotter_interface.py | 20 ++++++------- autolens/imaging/model/plotter_interface.py | 28 +++++++++---------- .../interferometer/model/plotter_interface.py | 12 ++++---- autolens/point/model/plotter_interface.py | 16 +++++------ 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/autolens/analysis/plotter_interface.py b/autolens/analysis/plotter_interface.py index 6282c68b9..112cce7a4 100644 --- a/autolens/analysis/plotter_interface.py +++ b/autolens/analysis/plotter_interface.py @@ -30,15 +30,15 @@ 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 ---------- @@ -89,13 +89,13 @@ 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 ---------- diff --git a/autolens/imaging/model/plotter_interface.py b/autolens/imaging/model/plotter_interface.py index 6510f76a4..fbf023b3b 100644 --- a/autolens/imaging/model/plotter_interface.py +++ b/autolens/imaging/model/plotter_interface.py @@ -24,15 +24,15 @@ def fit_imaging( """ Visualizes a `FitImaging` object, which fits an imaging dataset. - Images are output to the `image` folder of the `image_path` in a subfolder called `fit`. 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 `FitImaging` 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 `FitImaging` + inferred by the search so far. - Visualization includes individual images of attributes of the `FitImaging` (e.g. the model data, residual map) - and a subplot of all `FitImaging`'s images on the same figure. + Visualization includes a subplot of individual images of attributes of the `FitImaging` (e.g. the model data, + residual map) 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 - [fit] header. + The images output by the `PlotterInterface` are customized using the file `config/visualize/plots.yaml` under + the `fit` and `fit_imaging` header. Parameters ---------- @@ -84,18 +84,18 @@ def fit_imaging_combined(self, fit_list: List[FitImaging]): Output visualization of all `FitImaging` objects in a summed combined analysis, typically during or after a model-fit is performed. - Images are output to the `image` folder of the `image_path` in a subfolder called `combined`. When used - with a non-linear search the `image_path` is the output folder of the non-linear search. - `. - Visualization includes individual images of attributes of each fit (e.g. data, normalized residual-map) on - a single subplot, such that the full suite of multiple datasets can be viewed on the same figure. + 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. + + Visualization includes a subplot of individual images of attributes of each fit (e.g. data, normalized + residual-map) on a single subplot, such that the full suite of multiple datasets can be viewed on the same figure. The images output by the `PlotterInterface` are customized using the file `config/visualize/plots.yaml` under - the `fit` header. + the `fit` and `fit_imaging` headers. Parameters ---------- - fit + fit_list The list of imaging fits which are visualized. """ diff --git a/autolens/interferometer/model/plotter_interface.py b/autolens/interferometer/model/plotter_interface.py index bd18fb158..96c6e014c 100644 --- a/autolens/interferometer/model/plotter_interface.py +++ b/autolens/interferometer/model/plotter_interface.py @@ -25,14 +25,14 @@ def fit_interferometer( """ Visualizes a `FitInterferometer` object, which fits an interferometer dataset. - Images are output to the `image` folder of the `image_path` in a subfolder called `fit`. 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. - Visualization includes individual images of attributes of the `FitInterferometer` (e.g. the model data, - residual map) and a subplot of all `FitInterferometer`'s images on the same figure. + Visualization includes a subplot of individual images of attributes of the `FitInterferometer` (e.g. the model + data,residual map) 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 - [fit] header. + The images output by the `PlotterInterface` are customized using the file `config/visualize/plots.yaml` under + the `fit` and `fit_interferometer` headers. Parameters ---------- diff --git a/autolens/point/model/plotter_interface.py b/autolens/point/model/plotter_interface.py index 69d92d039..8d4d8e04e 100644 --- a/autolens/point/model/plotter_interface.py +++ b/autolens/point/model/plotter_interface.py @@ -15,13 +15,13 @@ def dataset_point(self, dataset: PointDataset): """ Output visualization of an `PointDataset` dataset, typically before a model-fit is performed. - Images are output to the `image` folder of the `image_path` in a subfolder called `dataset`. 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. + Visualization includes individual images of the different points of the dataset (e.g. the positions and fluxes) The images output by the `PlotterInterface` are customized using the file `config/visualize/plots.yaml` under - the `dataset` header. + the `point_dataset` header. Parameters ---------- @@ -52,11 +52,11 @@ def fit_point( used with a non-linear search the `image_path` points to the search's results folder and this function visualizes the maximum log likelihood `FitImaging` inferred by the search so far. - Visualization includes individual images of attributes of the `FitPointDataset` (e.g. the model data and data) - and a subplot of all `FitPointDataset`'s images on the same figure. + Visualization includes a subplot of individual images of attributes of the `FitPointDataset` (e.g. the model + data and data) 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 - [fit] header. + The images output by the `PlotterInterface` are customized using the file `config/visualize/plots.yaml` under + the `fit` and `fit_point_dataset` headers. Parameters ----------