autogalaxy.AdaptImages#

class AdaptImages[source]#

Bases: object

Contains the adapt-images which are used to make a pixelization’s mesh and regularization adapt to the reconstructed galaxy’s morphology.

Pixelization image-mesh objects (e.g. KMeans, Hilbert) adapt the distribution of pixels to the observed image’s brightness and therefore to the reconstructed source’s morphology.

Certain regularization schemes (e.g. Adapt) adapt their regularization coefficients to the reconstructed source’s morphology.

These adaptive schemes use “adapt-images”, which are images of each galaxy (e.g. the lens and source of a strong lens) estimated via an earlier model-fit.

The adapt-images are stored as the model-image of each galaxy in a model (e.g. the lens and source for a strong lens). They are stored as a dictionary mapping each instance of the galaxy to its model-image.

For model-fitting, the galaxy instances are updated for every iteration of the non-linear search. This means an AdaptImages instance cannot be passed directly to an Analysis class, as the galaxy instances need to be updated for every iteration of the non-linear search.

A dictionary mapping the path name of each galaxy (e.g. “galaxies.lens”) to its model-image is therefore used which is called inside the log_likelihood_function o map the model-image of each galaxy to the galaxy instance of that iteration’s specific model.

Parameters:
  • galaxy_image_dict (Optional[Dict[Galaxy, Array2D]]) – A dictionary associating each galaxy instance to an image of only that galaxy (e.g. for a strong lens one entry will map an instance of the source galaxy entry to an image of the lensed source.

  • galaxy_name_image_dict (Optional[Dict[Tuple[str, ...], Array2D]]) – A dictionary associating each galaxy path name (e.g. “galaxies.source”) to an image of only that galaxy (e.g. for a strong lens the source entry is an image of the lensed source, without the lens light).

__init__(galaxy_image_dict=None, galaxy_name_image_dict=None, galaxy_image_plane_mesh_grid_dict=None, galaxy_name_image_plane_mesh_grid_dict=None, galaxy_path_list=None)[source]#

Contains the adapt-images which are used to make a pixelization’s mesh and regularization adapt to the reconstructed galaxy’s morphology.

Pixelization image-mesh objects (e.g. KMeans, Hilbert) adapt the distribution of pixels to the observed image’s brightness and therefore to the reconstructed source’s morphology.

Certain regularization schemes (e.g. Adapt) adapt their regularization coefficients to the reconstructed source’s morphology.

These adaptive schemes use “adapt-images”, which are images of each galaxy (e.g. the lens and source of a strong lens) estimated via an earlier model-fit.

The adapt-images are stored as the model-image of each galaxy in a model (e.g. the lens and source for a strong lens). They are stored as a dictionary mapping each instance of the galaxy to its model-image.

For model-fitting, the galaxy instances are updated for every iteration of the non-linear search. This means an AdaptImages instance cannot be passed directly to an Analysis class, as the galaxy instances need to be updated for every iteration of the non-linear search.

A dictionary mapping the path name of each galaxy (e.g. “galaxies.lens”) to its model-image is therefore used which is called inside the log_likelihood_function o map the model-image of each galaxy to the galaxy instance of that iteration’s specific model.

Parameters:
  • galaxy_image_dict (Optional[Dict[Galaxy, Array2D]]) – A dictionary associating each galaxy instance to an image of only that galaxy (e.g. for a strong lens one entry will map an instance of the source galaxy entry to an image of the lensed source.

  • galaxy_name_image_dict (Optional[Dict[Tuple[str, ...], Array2D]]) – A dictionary associating each galaxy path name (e.g. “galaxies.source”) to an image of only that galaxy (e.g. for a strong lens the source entry is an image of the lensed source, without the lens light).

Methods

__init__([galaxy_image_dict, ...])

Contains the adapt-images which are used to make a pixelization's mesh and regularization adapt to the reconstructed galaxy's morphology.

image_for_galaxy(galaxy[, galaxies])

Return the adapt image for galaxy, robust to JAX jit boundaries.

image_plane_mesh_grid_for_galaxy(galaxy[, ...])

Return the image-plane mesh grid for galaxy, robust to JAX jit boundaries.

updated_via_instance_from(instance[, ...])

Returns adapt-images which have been updated to map galaxy instances instead of galaxy names.

Attributes

mask

The mask of the adapt images.

model_image

A property that is only computed once per instance and then replaces itself with an ordinary attribute.

__init__(galaxy_image_dict=None, galaxy_name_image_dict=None, galaxy_image_plane_mesh_grid_dict=None, galaxy_name_image_plane_mesh_grid_dict=None, galaxy_path_list=None)[source]#

Contains the adapt-images which are used to make a pixelization’s mesh and regularization adapt to the reconstructed galaxy’s morphology.

Pixelization image-mesh objects (e.g. KMeans, Hilbert) adapt the distribution of pixels to the observed image’s brightness and therefore to the reconstructed source’s morphology.

Certain regularization schemes (e.g. Adapt) adapt their regularization coefficients to the reconstructed source’s morphology.

These adaptive schemes use “adapt-images”, which are images of each galaxy (e.g. the lens and source of a strong lens) estimated via an earlier model-fit.

The adapt-images are stored as the model-image of each galaxy in a model (e.g. the lens and source for a strong lens). They are stored as a dictionary mapping each instance of the galaxy to its model-image.

For model-fitting, the galaxy instances are updated for every iteration of the non-linear search. This means an AdaptImages instance cannot be passed directly to an Analysis class, as the galaxy instances need to be updated for every iteration of the non-linear search.

A dictionary mapping the path name of each galaxy (e.g. “galaxies.lens”) to its model-image is therefore used which is called inside the log_likelihood_function o map the model-image of each galaxy to the galaxy instance of that iteration’s specific model.

Parameters:
  • galaxy_image_dict (Optional[Dict[Galaxy, Array2D]]) – A dictionary associating each galaxy instance to an image of only that galaxy (e.g. for a strong lens one entry will map an instance of the source galaxy entry to an image of the lensed source.

  • galaxy_name_image_dict (Optional[Dict[Tuple[str, ...], Array2D]]) – A dictionary associating each galaxy path name (e.g. “galaxies.source”) to an image of only that galaxy (e.g. for a strong lens the source entry is an image of the lensed source, without the lens light).

property mask: Mask2D#

The mask of the adapt images.

model_image#

A property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property.

Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76

updated_via_instance_from(instance, dataset_model=None, mask=None, galaxies=None, xp=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/pyautogalaxy/envs/latest/lib/python3.11/site-packages/numpy/__init__.py'>)[source]#

Returns adapt-images which have been updated to map galaxy instances instead of galaxy names.

For model-fitting, the galaxy instances are updated for every iteration of the non-linear search. This means an AdaptImages instance cannot be passed directly to an Analysis class, as the galaxy instances need to be updated for every iteration of the non-linear search.

A dictionary mapping the path name of each galaxy (e.g. “galaxies.lens”) to its model-image is therefore used which is called inside the log_likelihood_function o map the model-image of each galaxy to the galaxy instance of that iteration’s specific model.

This function is also called when loading an AdaptImages instance from a PyAutoFit database, as the galaxy instances are also created on-fly from the database. Database images do not have a mask, so it is also applied to the adapt images on-the-fly during database loading.

When a dataset_model is supplied with a non-trivial grid_offset or grid_rotation_angle, the cached galaxy_name_image_plane_mesh_grid_dict entries are transformed into the same frame as the dataset’s image-plane grid (which FitDataset.grids rotates by the same amount). Without this transform the cached mesh and the data grid would sit in different frames, producing a misaligned source reconstruction.

Parameters:
  • instance – The instance of the model-fit (e.g. in a non-linear search) which is used to update the adapt images.

  • dataset_model (Optional[DatasetModel]) – The dataset model whose grid_offset and grid_rotation_angle are applied to cached mesh grids so they remain consistent with the rotated/shifted data grid produced by FitDataset.grids. If None, the cached mesh grids are passed through unchanged.

  • mask – A mask which can be applied to the adapt images, which is used when setting up the adaptive images via the aggregator and autofit database tools.

  • galaxies (Optional[List[Galaxy]]) – Optional list of galaxies in the order used by the calling Analysis (i.e. the list passed to FitImaging / Tracer). When provided, a parallel galaxy_path_list is populated so that image_for_galaxy can recover the path-tuple key for each galaxy after JAX has unflattened the galaxy instances into fresh objects. When None the path list is populated in path_instance_tuples_for_class order, which matches Analysis.galaxies_via_instance_from for the common case (no extra_galaxies / scaling_galaxies).

  • xp – Array backend (numpy or jax.numpy) used when transforming cached mesh grids.

image_for_galaxy(galaxy, galaxies=None)[source]#

Return the adapt image for galaxy, robust to JAX jit boundaries.

galaxy_image_dict is keyed by the trace-time Galaxy instances. After jax.jit has flattened and unflattened a FitImaging, the galaxies inside it are fresh Python objects whose __hash__ differs from the trace-time keys, so a direct lookup misses. This helper falls back to the path-tuple keyed galaxy_name_image_dict using galaxy_path_list to map the post-unflatten galaxy back to its trace-time path.

Returns None when no adapt image is associated with the galaxy.

image_plane_mesh_grid_for_galaxy(galaxy, galaxies=None)[source]#

Return the image-plane mesh grid for galaxy, robust to JAX jit boundaries.

Companion to image_for_galaxy for galaxy_image_plane_mesh_grid_dict / galaxy_name_image_plane_mesh_grid_dict.