autogalaxy.AdaptImages#
- class AdaptImages[source]#
Bases:
objectContains 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 JAXjitboundaries.image_plane_mesh_grid_for_galaxy(galaxy[, ...])Return the image-plane mesh grid for
galaxy, robust to JAXjitboundaries.updated_via_instance_from(instance[, ...])Returns adapt-images which have been updated to map galaxy instances instead of galaxy names.
Attributes
The mask of the adapt images.
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).
- 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_modelis supplied with a non-trivialgrid_offsetorgrid_rotation_angle, the cachedgalaxy_name_image_plane_mesh_grid_dictentries are transformed into the same frame as the dataset’s image-plane grid (whichFitDataset.gridsrotates 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 whosegrid_offsetandgrid_rotation_angleare applied to cached mesh grids so they remain consistent with the rotated/shifted data grid produced byFitDataset.grids. IfNone, 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 callingAnalysis(i.e. the list passed toFitImaging/Tracer). When provided, a parallelgalaxy_path_listis populated so thatimage_for_galaxycan recover the path-tuple key for each galaxy after JAX has unflattened the galaxy instances into fresh objects. WhenNonethe path list is populated inpath_instance_tuples_for_classorder, which matchesAnalysis.galaxies_via_instance_fromfor the common case (noextra_galaxies/scaling_galaxies).xp – Array backend (
numpyorjax.numpy) used when transforming cached mesh grids.
- image_for_galaxy(galaxy, galaxies=None)[source]#
Return the adapt image for
galaxy, robust to JAXjitboundaries.galaxy_image_dictis keyed by the trace-timeGalaxyinstances. Afterjax.jithas flattened and unflattened aFitImaging, 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 keyedgalaxy_name_image_dictusinggalaxy_path_listto map the post-unflatten galaxy back to its trace-time path.Returns
Nonewhen 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 JAXjitboundaries.Companion to
image_for_galaxyforgalaxy_image_plane_mesh_grid_dict/galaxy_name_image_plane_mesh_grid_dict.