autolens.AnalysisImaging#

class AnalysisImaging[source]#

Bases: AnalysisDataset

Fits a lens model to a dataset via a non-linear search.

This abstract Analysis class has attributes and methods for all model-fits which fit the model to a dataset (e.g. imaging or interferometer data).

This class stores the Cosmology used for the analysis and settings that control aspects of the calculation, including how pixelizations, inversions and lensing calculations are performed.

Parameters:
  • dataset – The imaging, interferometer or other dataset that the model if fitted too.

  • positions_likelihood_list (Optional[List[PositionsLH]]) – Alters the likelihood function to include a term which accounts for whether image-pixel coordinates in arc-seconds corresponding to the multiple images of each lensed source galaxy trace close to one another in their source-plane. This is a list, as it may support multiple planes, where a positions likelihood object is input for each plane (e.g. double source plane lensing).

  • adapt_images (Optional[AdaptImages]) – Contains the adapt-images which are used to make a pixelization’s mesh and regularization adapt to the reconstructed galaxy’s morphology.

  • cosmology (LensingCosmology) – The Cosmology assumed for this analysis.

  • settings (Settings) – Settings controlling how an inversion is fitted during the model-fit, for example which linear algebra formalism is used.

  • raise_inversion_positions_likelihood_exception (bool) – If an inversion is used without the positions_likelihood_list it is likely a systematic solution will be inferred, in which case an Exception is raised before the model-fit begins to inform the user of this. This exception is not raised if this input is False, allowing the user to perform the model-fit anyway.

Methods

adapt_images_via_instance_from

compute_latent_samples

Compute latent variables from a model instance.

compute_latent_variables

Compute the catalogue of lensing latent variables enabled in config/latent.yaml for the given parameter vector.

dataset_model_via_instance_from

Create a dataset model from a model instance, which is used to fit the dataset.

fit_for_visualization

Build the fit used by the visualizer.

fit_from

Given a model instance create a FitImaging object.

galaxies_via_instance_from

Create a list of galaxies from a model instance, which is used to fit the dataset.

log_likelihood_function

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.

log_likelihood_penalty_from

Call the positions overwrite log likelihood function, which add a penalty term to the likelihood if the positions of the multiple images of the lensed source do not trace close to one another in the source plane.

make_result

After the non-linear search is complete create its Result, which includes:

modify_after_fit

Overwrite this method to modify the attributes of the Analysis class before the non-linear search begins.

modify_before_fit

This function is called immediately before the non-linear search begins and performs final tasks and checks before it begins.

modify_model

perform_quick_update

Perform a quick visualization update during non-linear search fitting.

print_vram_use

Print JAX VRAM use for a given batch size.

raise_exceptions

save_attributes

Before the model-fit via 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_results

At 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_combined

tracer_via_instance_from

Create a Tracer from the galaxies contained in a model instance.

with_model

Associate an explicit model with this analysis.

Attributes

LATENT_BATCH_MODE

LATENT_KEYS

Built-in mutable sequence.

supports_background_update

Whether this analysis supports background quick updates.

supports_jax_visualization

Whether the visualizer can work directly with JAX arrays.

Result#

alias of ResultImaging

Visualizer#

alias of VisualizerImaging

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.

compute_latent_variables(parameters, model)[source]#

Compute the catalogue of lensing latent variables enabled in config/latent.yaml for the given parameter vector.

Returns a tuple positionally aligned with LATENT_KEYS — PyAutoFit zips it with the keys at autofit/non_linear/analysis/analysis.py:285 and stacks per sample for the JIT batch path at lines 223-234.

Raises NotImplementedError when no latents are enabled so PyAutoFit’s outer except NotImplementedError short-circuits the latent pipeline cleanly (no empty latent.csv written).

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:

  1. If the analysis has a adapt image, associated the model galaxy images of this dataset to the galaxies in the model instance.

  2. Extract attributes which model aspects of the data reductions, like the scaling the background sky and background noise.

  3. Extracts all galaxies from the model instance and set up a Tracer, which includes ordering the galaxies by redshift to set up each Plane.

  4. Use the Tracer and other attributes to create a FitImaging object, which performs steps such as creating model images of every galaxy in the tracer, 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:

float

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).

  • check_positions – Whether the multiple image positions of the lensed source should be checked, i.e. whether they trace within the position threshold of one another in the source plane.

Returns:

The fit of the plane to the imaging dataset, which includes the log likelihood.

Return type:

FitImaging