autogalaxy.AnalysisImaging#
- class AnalysisImaging[source]#
Bases:
AnalysisDatasetFits a galaxy model to an imaging dataset via a non-linear search.
The Analysis class defines the log_likelihood_function which fits the model to the dataset and returns the log likelihood value defining how well the model fitted the data.
It handles many other tasks, such as visualization, outputting results to hard-disk and storing results in a format that can be loaded after the model-fit is complete.
This class is used for model-fits which fit galaxies to an imaging dataset.
This class stores the settings used to perform the model-fit for certain components of the model (e.g. a pixelization or inversion), the Cosmology used for the analysis and adapt images used for certain model classes.
- Parameters:
dataset (
Imaging) – The Imaging dataset that the model is fitted to.adapt_images (
Optional[AdaptImages]) – The adapt-model image and galaxies images of a previous result in a model-fitting pipeline, which are used by certain classes for adapting the analysis to the properties of the dataset.cosmology (
LensingCosmology) – The Cosmology assumed for this analysis.settings (
Settings) – Settings controlling how an inversion is fitted for example which linear algebra formalism is used.title_prefix (
str) – A string that is added before the title of all figures output by visualization, for example to put the name of the dataset and galaxy in the title.
Methods
adapt_images_via_instance_fromcompute_latent_samplesCompute latent variables from a model instance.
Compute the catalogue of latent variables enabled in
config/latent.yamlfor the given parameter vector.dataset_model_via_instance_fromCreate a dataset model from a model instance, which is used to fit the dataset.
fit_for_visualizationBuild the fit used by the visualizer.
Given a model instance create a FitImaging object.
galaxies_via_instance_fromCreate a list of galaxies from a model instance, which is used to fit the dataset.
Given an instance of the model, where the model parameters are set via a non-linear search, fit the model instance to the imaging dataset.
make_resultAfter the non-linear search is complete create its Result, which includes:
modify_after_fitOverwrite this method to modify the attributes of the Analysis class before the non-linear search begins.
modify_before_fitThis function is called immediately before the non-linear search begins and performs final tasks and checks before it begins.
modify_modelperform_quick_updatePerform a quick visualization update during non-linear search fitting.
print_vram_usePrint JAX VRAM use for a given batch size.
Before the non-linear search begins, this routine saves attributes of the Analysis object to the files folder such that they can be loaded after the analysis using PyAutoFit's database and aggregator tools.
save_resultsAt the end of a model-fit, this routine saves attributes of the Analysis object to the files folder such that they can be loaded after the analysis using PyAutoFit's database and aggregator tools.
save_results_combinedwith_modelAssociate an explicit model with this analysis.
Attributes
LATENT_BATCH_MODEBuilt-in mutable sequence.
supports_background_updateWhether this analysis supports background quick updates.
supports_jax_visualizationWhether the visualizer can work directly with JAX arrays.
- Result#
alias of
ResultImaging
- Visualizer#
alias of
VisualizerImaging
- property imaging#
- property LATENT_KEYS#
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
- log_likelihood_function(instance)[source]#
Given an instance of the model, where the model parameters are set via a non-linear search, fit the model instance to the imaging dataset.
This function returns a log likelihood which is used by the non-linear search to guide the model-fit.
For this analysis class, this function performs the following steps:
If the analysis has a adapt image, associated the model galaxy images of this dataset to the galaxies in the model instance.
Extract attributes which model aspects of the data reductions, like the scaling the background sky and background noise.
Extracts all galaxies from the model instance.
Use the galaxies and other attributes to create a FitImaging object, which performs steps such as creating model images of every galaxy, blurring them with the imaging dataset’s PSF and computing residuals, a chi-squared statistic and the log likelihood.
Certain models will fail to fit the dataset and raise an exception. For example if an Inversion is used, the linear algebra calculation may be invalid and raise an Exception. In such circumstances the model is discarded and its likelihood value is passed to the non-linear search in a way that it ignores it (for example, using a value of -1.0e99).
- Parameters:
instance (
ModelInstance) – 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).- Returns:
The log likelihood indicating how well this model instance fitted the imaging data.
- Return type:
- fit_from(instance)[source]#
Given a model instance create a FitImaging object.
This function is used in the log_likelihood_function to fit the model to the imaging data and compute the log likelihood.
- Parameters:
instance (
ModelInstance) – 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).- Returns:
The fit of the galaxies to the imaging dataset, which includes the log likelihood.
- Return type:
- compute_latent_variables(parameters, model)[source]#
Compute the catalogue of latent variables enabled in
config/latent.yamlfor the given parameter vector.Returns a tuple positionally aligned with
LATENT_KEYS— PyAutoFit zips it with the keys atautofit/non_linear/analysis/analysis.py:285and stacks per sample for the JIT batch path at lines 223-234.Raises
NotImplementedErrorwhen no latents are enabled so PyAutoFit’s outerexcept NotImplementedErrorshort-circuits the latent pipeline cleanly (no emptylatent.csvwritten).
- save_attributes(paths)[source]#
Before the non-linear search begins, this routine saves attributes of the Analysis object to the files folder such that they can be loaded after the analysis using PyAutoFit’s database and aggregator tools.
For this analysis, it uses the AnalysisDataset object’s method to output the following:
The settings associated with the inversion.
The settings associated with the pixelization.
The Cosmology.
The adapt image’s model image and galaxy images, as adapt_images.fits, if used.
The following .fits files are also output via the plotter interface:
The mask applied to the dataset, in the PrimaryHDU of dataset.fits.
The imaging dataset as dataset.fits (data / noise-map / psf / over sampler / etc.).
It is common for these attributes to be loaded by many of the template aggregator functions given in the aggregator modules. For example, when using the database tools to perform a fit, the default behaviour is for the dataset, settings and other attributes necessary to perform the fit to be loaded via the pickle files output by this function.
- Parameters:
paths (
DirectoryPaths) – The paths object which manages all paths, e.g. where the non-linear search outputs are stored, visualization, and the pickled objects used by the aggregator output by this function.