From 4b82e6fddea20a82e24a2b07f6b1fdb34f22b448 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Mon, 7 Apr 2025 13:39:39 +0100 Subject: [PATCH 1/4] update plots.yaml --- autolens/config/visualize/plots.yaml | 32 ++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/autolens/config/visualize/plots.yaml b/autolens/config/visualize/plots.yaml index 7739397b0..5eb270f7a 100644 --- a/autolens/config/visualize/plots.yaml +++ b/autolens/config/visualize/plots.yaml @@ -1,5 +1,20 @@ +# The `plots` section customizes every image that is output to hard-disk during a model-fit. + +# For example, if `plots: fit: subplot_fit=True``, the ``subplot_fit.png`` subplot file will +# be plotted every time visualization is performed. + +# There are two settings which are important for inspecting results via the dataset after a fit is complete which are: + +# - `fits_dataset`: This outputs `dataset.fits` which the database functionality may use to reperform fits. +# -`fits_adapt_images`, This outputs `adapt_images.fits` which the database functionality may use to reperform fits. + +# These can be disabled to save on hard-disk space but will lead to certain database functionality being disabled. + +subplot_format: [png] # Output format of all subplots, can be png, pdf or both (e.g. [png, pdf]) + 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.)? + fits_dataset: true # Output a .fits file containing the dataset data, noise-map and other quantities? positions: # Settings for plots with resampling image-positions on (e.g. the image). image_with_positions: true @@ -12,15 +27,11 @@ fit: # Settings for plots of all fits (e.g 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? + fits_fit: false # Output a .fits file containing the fit model data, residual map, normalized residual map and chi-squared? + fits_model_galaxy_images : false # Output a .fits file containing the model images of every galaxy? 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? @@ -29,9 +40,18 @@ tracer: # Settings for plots of tracers (e.g. 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? + fits_reconstruction: false # output reconstruction.fits containing the reconstructed pixelization and noise map on the adaptive mesh? 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? + fits_adapt_images: true # Output a .fits file containing the adapt images used for adaptive pixelization? + +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? + fits_dirty_images: false # output dirty_images.fits showing the dirty image, noise-map, model-data, resiual-map, normalized residual map and chi-squared map? + +fit_point_dataset: {} # Settings for plots of fits to point source datasets (e.g. FitPointDatasetPlotter). fit_quantity: # Settings for plots of fit quantities (e.g. FitQuantityPlotter). subplot_fit: true From 0ef17aa9c168139359b6eb0e33953b3df357abcb Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Mon, 7 Apr 2025 13:39:53 +0100 Subject: [PATCH 2/4] add output.yaml --- autolens/config/output.yaml | 96 +++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 autolens/config/output.yaml diff --git a/autolens/config/output.yaml b/autolens/config/output.yaml new file mode 100644 index 000000000..8721dfc5d --- /dev/null +++ b/autolens/config/output.yaml @@ -0,0 +1,96 @@ +# Determines whether files saved by the search are output to the hard-disk. This is true both when saving to the +# directory structure and when saving to database. + +default: true # If true then files which are not explicitly listed here are output anyway. If false then they are not. + +### Samples ### + +# The `samples.csv`file contains every sampled value of every free parameter with its log likelihood and weight. + +# This file is often large, therefore disabling it can significantly reduce hard-disk space use. + +# `samples.csv` is used to perform marginalization, infer model parameter errors and do other analysis of the search +# chains. Even if output of `samples.csv` is disabled, these tasks are still performed by the fit and output to +# the `samples_summary.json` file. However, without a `samples.csv` file these types of tasks cannot be performed +# after the fit is complete, for example via the database. + +samples: true + +# The `samples.csv` file contains every accepted sampled value of every free parameter with its log likelihood and +# weight. For certain searches, the majority of samples have a very low weight and have no numerical impact on the +# results of the model-fit. However, these samples are still output to the `samples.csv` file, taking up hard-disk +# space and slowing down analysis of the samples (e.g. via the database). + +# The `samples_weight_threshold` below specifies the threshold value of the weight such that samples with a weight +# below this value are not output to the `samples.csv` file. This can be used to reduce the size of the `samples.csv` +# file and speed up analysis of the samples. + +# For many searches (e.g. MCMC) all samples have an equal weight of 1.0, and this threshold therefore has no impact. +# For these searches, there is no simple way to save hard-disk space. This input is more suited to nested sampling, +# where the majority of samples have a very low weight.. + +# Set value to empty (e.g. delete 1.0e-10 below) to disable this feature. + +samples_weight_threshold: 1.0e-10 + +### Search Internal ### + +# The search internal folder which contains a saved state of the non-linear search in its internal reprsenetation, +# as a .pickle or .dill file. + +# For example, for the nested sampling dynesty, this .dill file is the `DynestySampler` object which is used to +# perform sampling, and it therefore contains all internal dynesty representations of the results, samples, weights, etc. + +# If the entry below is false, the folder is still output during the model-fit, as it is required to resume the fit +# from where it left off. Therefore, settings `false` below does not impact model-fitting checkpointing and resumption. +# Instead, the search internal folder is deleted once the fit is completed. + +# The search internal folder file is often large, therefore deleting it after a fit is complete can significantly +# reduce hard-disk space use. + +# The search internal representation that can be loaded from the .dill file has many additional quantities specific to +# the non-linear search that the standardized autofit forms do not. For example, for emcee, it contains information on +# every walker. This information is required to do certain analyes and make certain plots, therefore deleting the +# folder means this information is list. + +search_internal: false + +### Start Point ### + +# If an Initalizer is used to provide a start point for the non-linear search, visualization of that start point can be +# output to hard-disk to show the user the initial model-fit that is used to start the search. This visualization is +# the visualizer wrapped in the Analysis class, and therefore should show things like the quality of the fit +# to the data and the residuals at the start point. + +start_point: true + +### Latent Variables ### + +# A latent variable is not a model parameter but can be derived from the model. Its value and errors may be of interest +# and aid in the interpretation of a model-fit. + +# For example, for the simple 1D Gaussian example, it could be the full-width half maximum (FWHM) of the Gaussian. This +# is not included in the model but can be easily derived from the Gaussian's sigma value. + +# By overwriting an Analysis class's `compute_latent_variables` method we can manually specify latent variables that +# are calculated and output to a `latent.csv` file, which mirrors the `samples.csv` file. The `latent.csv` file has +# the same weight resampling performed on the `samples.csv` file, controlled via the `samples_weight_threshold` above. + +# There may also be a `latent.results` and `latent_summary.json` files output, which the inputs below control whether +# they are output and how often. + +# Outputting latent variables manually after a fit is complete is simple, just call +# the `analysis.compute_latent_variables()` function. + +# For many use cases, the best set up may be to disable autofit latent variable output during the fit and perform it +# manually after completing a successful model-fit. This will save computational run time by not computing latent +# variables during a any model-fit which is unsuccessful. + +latent_during_fit: true # Whether to output the `latent.csv`, `latent.results` and `latent_summary.json` files during the fit when it performs on-the-fly output. +latent_after_fit: true # If `latent_during_fit` is False, whether to output the `latent.csv`, `latent.results` and `latent_summary.json` files after the fit is complete. +latent_csv: true # Whether to ouptut the `latent.csv` file. +latent_results: true # Whether to output the `latent.results` file. + +# Other Files: + +search_log: true # `search.log`: logging produced whilst running the fit or fit_sequential method \ No newline at end of file From 70a3d11b1a6372b3bbd8685a8ba4e3dd8fd09101 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Mon, 7 Apr 2025 13:44:27 +0100 Subject: [PATCH 3/4] more config stuff --- autolens/config/visualize/plots.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/autolens/config/visualize/plots.yaml b/autolens/config/visualize/plots.yaml index 5eb270f7a..9cf6dd61b 100644 --- a/autolens/config/visualize/plots.yaml +++ b/autolens/config/visualize/plots.yaml @@ -19,9 +19,6 @@ dataset: # Settings for plots of all datasets 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.)? @@ -51,8 +48,15 @@ fit_interferometer: # Settings for plots of fits to inter subplot_fit_real_space: false # Plot subplot of the real-space images of all interferometer datasets? fits_dirty_images: false # output dirty_images.fits showing the dirty image, noise-map, model-data, resiual-map, normalized residual map and chi-squared map? +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_point_dataset: {} # Settings for plots of fits to point source datasets (e.g. FitPointDatasetPlotter). +fit_ellipse: # Settings for plots of ellipse fitting fits (e.g. FitEllipse) + data : true # Plot the data of the ellipse fit? + data_no_ellipse: true # Plot the data without the black data ellipses, which obscure noisy data? + fit_quantity: # Settings for plots of fit quantities (e.g. FitQuantityPlotter). subplot_fit: true From 4767a08088d909984a2be06bde65c9e8240781cb Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 9 Apr 2025 18:52:39 +0100 Subject: [PATCH 4/4] finish --- test_autolens/imaging/model/test_analysis_imaging.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test_autolens/imaging/model/test_analysis_imaging.py b/test_autolens/imaging/model/test_analysis_imaging.py index 54c4b99ef..170ab566c 100644 --- a/test_autolens/imaging/model/test_analysis_imaging.py +++ b/test_autolens/imaging/model/test_analysis_imaging.py @@ -67,8 +67,8 @@ def test__positions__resample__raises_exception(masked_imaging_7x7): def test__positions__likelihood_overwrites__changes_likelihood(masked_imaging_7x7): - lens = al.Galaxy(redshift=0.5, mass=al.mp.IsothermalSph()) - source = al.Galaxy(redshift=1.0, light=al.lp.SersicSph()) + lens = al.Galaxy(redshift=0.5, mass=al.mp.IsothermalSph(centre=(0.05, 0.05))) + source = al.Galaxy(redshift=1.0, light=al.lp.SersicSph(centre=(0.05, 0.05))) model = af.Collection(galaxies=af.Collection(lens=lens, source=source)) @@ -82,7 +82,7 @@ def test__positions__likelihood_overwrites__changes_likelihood(masked_imaging_7x fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) assert fit.log_likelihood == pytest.approx(analysis_log_likelihood, 1.0e-4) - assert analysis_log_likelihood == pytest.approx(-6258.043397009, 1.0e-4) + assert analysis_log_likelihood == pytest.approx(-14.79034680979, 1.0e-4) positions_likelihood = al.PositionsLHPenalty( positions=al.Grid2DIrregular([(1.0, 100.0), (200.0, 2.0)]), threshold=0.01