autolens.Galaxies#

class Galaxies[source]#

Bases: List, OperateImageGalaxies, OperateDeflections

A collection of galaxies, used to perform operations on the galaxies as a group.

It is common for a user to have multiple galaxies in a list, for which they may perform operations like creating the image of the light profiles or all galaxies or the potential of the mass profiles of all galaxies.

Many of these calculations are straight forward, for example for the image of all galaxies we simply sum the images of each galaxy.

However, there are more complex operations that can be performed on the galaxies as a group, for example computing the blured image of a group of galaxies where some galaxies have operated light profiles (meaning that PSF blurring is already applied to them and thus should be skipped) and another subset of galaxies have normal light profiles (meaning that PSF blurring should be applied to them).

This calculation requires a careful set of operations to ensure that the PSF blurring is only applied to the subset of galaxies that do not have operated light profiles. This is an example of a calculation that is performed by the Galaxies class, simplifing the code required to perform this operation.

Users may find that they often omit the Galaxies class and instead perform these operations in a more manual way. This is fine, but care must be taken to ensure that the operations are performed correctly.

Parameters:
  • galaxies (List[Galaxy]) – The list of galaxies whose calculations are performed by this class.

  • run_time_dict (Optional[Dict]) – A dictionary of information on the run-times of function calls, including the total time and time spent on different calculations.

Methods

append

Append object to the end of the list.

area_within_curve_list_from

blurred_image_2d_from

Evaluate the light object's 2D image from a input 2D grid of coordinates and convolve it with a PSF.

blurred_image_2d_list_from

Evaluate the light object's list of 2D images from a input 2D grid of coordinates and convolve each image with a PSF.

clear

Remove all items from list.

cls_list_from

Returns a list of objects in the galaxies which are an instance of the input cls.

contour_list_from

convergence_2d_from

Returns the summed 2D convergence of all galaxies from a 2D grid of Cartesian (y,x) coordinates.

convergence_2d_via_hessian_from

Returns the convergence of the lensing object, which is computed from the 2D deflection angle map via the Hessian using the expression (see equation 56 https://inspirehep.net/literature/419263):

convergence_2d_via_jacobian_from

Returns the convergence of the lensing object, which is computed from the 2D deflection angle map via the Jacobian using the expression (see equation 58 https://inspirehep.net/literature/419263):

copy

Return a shallow copy of the list.

count

Return number of occurrences of value.

deflections_yx_2d_from

Returns the summed 2D deflections angles of all galaxies from a 2D grid of Cartesian (y,x) coordinates.

einstein_mass_angular_from

Returns the Einstein radius corresponding to the area within the tangential critical curve.

einstein_mass_angular_list_from

Returns a list of the angular Einstein massses corresponding to the area within each tangential critical curve.

einstein_radius_from

Returns the Einstein radius corresponding to the area within the tangential critical curve.

einstein_radius_list_from

Returns a list of the Einstein radii corresponding to the area within each tangential critical curve.

extend

Extend list by appending elements from the iterable.

extract_attribute

Returns an attribute of a class in all galaxies as a ValueIrregular or Grid2DIrregular object.

galaxies_with_cls_list_from

galaxy_blurred_image_2d_dict_from

Evaluate the light object's dictionary mapping galaixes to their corresponding 2D images and convolve each image with a PSF.

galaxy_has_cls

galaxy_image_2d_dict_from

Returns a dictionary associating every Galaxy object with its corresponding 2D image, using the instance of each galaxy as the dictionary keys.

galaxy_visibilities_dict_from

Evaluate the light object's dictionary mapping galaixes to their corresponding 2D images and transform each image to arrays of visibilities using a autoarray.operators.transformer.Transformer object and therefore a Fourier Transform.

has

Returns a bool specifying whether any of the galaxies has a certain class type.

hessian_from

Returns the Hessian of the lensing object, where the Hessian is the second partial derivatives of the potential (see equation 55 https://inspirehep.net/literature/419263):

image_2d_from

Returns the 2D image of all galaxies summed from a 2D grid of Cartesian (y,x) coordinates.

image_2d_list_from

Returns a list of the 2D images for each galaxy from a 2D grid of Cartesian (y,x) coordinates.

index

Return first index of value.

insert

Insert object before index.

jacobian_from

Returns the Jacobian of the lensing object, which is computed by taking the gradient of the 2D deflection angle map in four direction (positive y, negative y, positive x, negative x).

magnification_2d_from

Returns the 2D magnification map of lensing object, which is computed as the inverse of the determinant of the jacobian.

magnification_2d_via_hessian_from

Returns the 2D magnification map of lensing object, which is computed from the 2D deflection angle map via the Hessian using the expressions (see equation 60 https://inspirehep.net/literature/419263):

padded_image_2d_from

Evaluate the light object's 2D image from a input 2D grid of padded coordinates, where this padding is sufficient to encapsulate all surrounding pixels that will blur light into the original image given the 2D shape of the PSF's kernel.

plane_image_2d_from

pop

Remove and return item at index (default last).

potential_2d_from

Returns the summed 2D potential of all galaxies from a 2D grid of Cartesian (y,x) coordinates.

radial_caustic_list_from

Returns all radial caustics of the lensing system, which are computed as follows:

radial_critical_curve_area_list_from

Returns the surface area within each radial critical curve as a list, the calculation of which is described in the function radial_critical_curve_list_from().

radial_critical_curve_list_from

Returns all radial critical curves of the lensing system, which are computed as follows:

radial_eigen_value_from

Returns the radial eigen values of lensing jacobian, which are given by the expression:

remove

Remove first occurrence of value.

reverse

Reverse IN PLACE.

shear_yx_2d_via_hessian_from

Returns the 2D (y,x) shear vectors of the lensing object, which are computed from the 2D deflection angle map via the Hessian using the expressions (see equation 57 https://inspirehep.net/literature/419263):

shear_yx_2d_via_jacobian_from

Returns the 2D (y,x) shear vectors of the lensing object, which are computed from the 2D deflection angle map via the Jacobian using the expression (see equation 58 https://inspirehep.net/literature/419263):

sort

Sort the list in ascending order and return None.

tangential_caustic_list_from

Returns all tangential caustics of the lensing system, which are computed as follows:

tangential_critical_curve_area_list_from

Returns the surface area within each tangential critical curve as a list, the calculation of which is described in the function tangential_critical_curve_list_from().

tangential_critical_curve_list_from

Returns all tangential critical curves of the lensing system, which are computed as follows:

tangential_eigen_value_from

Returns the tangential eigen values of lensing jacobian, which are given by the expression:

traced_grid_2d_from

Trace this plane's grid_stacks to the next plane, using its deflection angles.

unmasked_blurred_image_2d_from

Evaluate the light object's 2D image from a input 2D grid of coordinates and convolve it with a PSF, using a grid which is not masked.

unmasked_blurred_image_2d_list_from

Evaluate the light object's list of 2D images from a input 2D grid of coordinates and convolve it with a PSF, using a grid which is not masked.

visibilities_from

Evaluate the light object's 2D image from a input 2D grid of coordinates and transform this to an array of visibilities using a autoarray.operators.transformer.Transformer object and therefore a Fourier Transform.

visibilities_list_from

Evaluate the light object's list of 2D image from a input 2D grid of coordinates and transform each image to arrays of visibilities using a autoarray.operators.transformer.Transformer object and therefore a Fourier Transform.

Attributes

perform_inversion

Returns a bool specifying whether this fit object performs an inversion.

redshift

image_2d_list_from(grid, operated_only=None)[source]#

Returns a list of the 2D images for each galaxy from a 2D grid of Cartesian (y,x) coordinates.

The image of each galaxy is computed by summing the images of all light profiles in that galaxy. If a galaxy has no light profiles, a numpy array of zeros is returned.

For example, if there are 3 galaxies and only the first two have light profiles, the returned list of images will be the image of the first two galaxies. The image of the third galaxies will be a numpy array of zeros.

The images output by this function do not include instrument operations, such as PSF convolution (for imaging data) or a Fourier transform (for interferometer data).

Inherited methods in the autogalaxy.operate.image package can apply these operations to the images. These functions may have the operated_only input passed to them, which is why this function includes the operated_only input.

If the operated_only input is included, the function omits light profiles which are parents of the LightProfileOperated object, which signifies that the light profile represents emission that has already had the instrument operations (e.g. PSF convolution, a Fourier transform) applied to it and therefore that operation is not performed again.

See the autogalaxy.profiles.light package for details of how images are computed from a light profile.

Parameters:
  • grid (Union[ndarray, Grid2D, Grid2DIrregular]) – The 2D (y, x) coordinates where values of the image are evaluated.

  • operated_only (Optional[bool]) – The returned list from this function contains all light profile images, and they are never operated on (e.g. via the imaging PSF). However, inherited methods in the autogalaxy.operate.image package can apply these operations to the images, which may have the operated_only input passed to them. This input therefore is used to pass the operated_only input to these methods.

Return type:

List[Array2D]

image_2d_from(grid, operated_only=None)[source]#

Returns the 2D image of all galaxies summed from a 2D grid of Cartesian (y,x) coordinates.

This function first computes the image of each galaxy, via the function image_2d_list_from. The images are then summed to give the overall image of the galaxies.

Refer to the function image_2d_list_from for a full description of the calculation and how the operated_only input is used.

Parameters:
  • grid (Union[ndarray, Grid2D, Grid2DIrregular]) – The 2D (y, x) coordinates where values of the image are evaluated.

  • operated_only (Optional[bool]) – The returned list from this function contains all light profile images, and they are never operated on (e.g. via the imaging PSF). However, inherited methods in the autogalaxy.operate.image package can apply these operations to the images, which may have the operated_only input passed to them. This input therefore is used to pass the operated_only input to these methods.

Return type:

Array2D

galaxy_image_2d_dict_from(grid, operated_only=None)[source]#

Returns a dictionary associating every Galaxy object with its corresponding 2D image, using the instance of each galaxy as the dictionary keys.

This object is used for adaptive-features, which use the image of each galaxy in a model-fit in order to adapt quantities like a pixelization or regularization scheme to the surface brightness of the galaxies being fitted.

By inheriting from OperateImageGalaxies functions which apply operations of this dictionary are accessible, for example convolving every image with a PSF or applying a Fourier transform to create a galaxy-visibilities dictionary.

Parameters:

grid (Union[ndarray, Grid2D, Grid2DIrregular]) – The 2D (y,x) coordinates of the (masked) grid, in its original geometric reference frame.

Return type:

A dictionary associated every galaxy with its corresponding 2D image.

deflections_yx_2d_from(grid, **kwargs)[source]#

Returns the summed 2D deflections angles of all galaxies from a 2D grid of Cartesian (y,x) coordinates.

The deflections of each galaxy is computed by summing the deflections of all mass profiles in that galaxy. If a galaxy has no mass profiles, a numpy array of zeros is returned.

This calculation does not account for multi-plane ray-tracing effects, it is simply the sum of the deflections of all galaxies. The Tracer class in PyAutoLens is required for this.

For example, if there are 3 galaxies and only the first two have mass profiles, the returned list of deflections will be the deflections of the first two galaxies. The deflections of the third galaxies will be a numpy array of zeros.

See the autogalaxy.profiles.mass package for details of how deflections are computed from a mass profile.

Parameters:

grid (Union[ndarray, Grid2D, Grid2DIrregular]) – The 2D (y, x) coordinates where values of the deflections are evaluated.

Return type:

ndarray

traced_grid_2d_from(grid)[source]#

Trace this plane’s grid_stacks to the next plane, using its deflection angles.

Return type:

Union[ndarray, Grid2D, Grid2DIrregular]

convergence_2d_from(grid, **kwargs)[source]#

Returns the summed 2D convergence of all galaxies from a 2D grid of Cartesian (y,x) coordinates.

The convergence of each galaxy is computed by summing the convergence of all mass profiles in that galaxy. If a galaxy has no mass profiles, a numpy array of zeros is returned.

This calculation does not account for multi-plane ray-tracing effects, it is simply the sum of the convergence of all galaxies. The Tracer class in PyAutoLens is required for this.

For example, if there are 3 galaxies and only the first two have mass profiles, the returned list of convergence will be the convergence of the first two galaxies. The convergence of the third galaxies will be a numpy array of zeros.

See the autogalaxy.profiles.mass package for details of how convergence are computed from a mass profile.

Parameters:

grid (Union[ndarray, Grid2D, Grid2DIrregular]) – The 2D (y, x) coordinates where values of the convergence are evaluated.

Return type:

ndarray

potential_2d_from(grid, **kwargs)[source]#

Returns the summed 2D potential of all galaxies from a 2D grid of Cartesian (y,x) coordinates.

The potential of each galaxy is computed by summing the potential of all mass profiles in that galaxy. If a galaxy has no mass profiles, a numpy array of zeros is returned.

This calculation does not account for multi-plane ray-tracing effects, it is simply the sum of the potential of all galaxies. The Tracer class in PyAutoLens is required for this.

For example, if there are 3 galaxies and only the first two have mass profiles, the returned list of potential will be the potential of the first two galaxies. The potential of the third galaxies will be a numpy array of zeros.

See the autogalaxy.profiles.mass package for details of how potential are computed from a mass profile.

Parameters:

grid (Union[ndarray, Grid2D, Grid2DIrregular]) – The 2D (y, x) coordinates where values of the potential are evaluated.

Return type:

ndarray

has(cls)[source]#

Returns a bool specifying whether any of the galaxies has a certain class type.

For example, for the input cls=ag.LightProfile, this function returns True if any galaxy has a light profile and false if no galaxy has a light profile.

This function is used to check for mass profiles and specific types of profiles, like the linear light profile.

Parameters:

cls (Union[Type, Tuple[Type]]) – The class type of the galaxy which is checked for in the tracer.

Return type:

True if any galaxy in the tracer has the input class type, else False.

cls_list_from(cls)[source]#

Returns a list of objects in the galaxies which are an instance of the input cls.

For example:

  • If the input is cls=ag.LightProfile, a list containing all light profiles of all galaxies is returned.

Return type:

List

Returns:

The list of objects in the galaxies that inherit from input cls.

extract_attribute(cls, attr_name)[source]#

Returns an attribute of a class in all galaxies as a ValueIrregular or Grid2DIrregular object.

For example, if there is one galaxy with two light profiles and we want its axis-ratios, the following:

galaxies.extract_attribute(cls=LightProfile, name=”axis_ratio”)

would return:

ArrayIrregular(values=[axis_ratio_0, axis_ratio_1])

If a galaxy has three mass profiles and we want their centres, the following:

galaxies.extract_attribute(cls=MassProfile, name=”centres”)

would return:

GridIrregular2D(grid=[(centre_y_0, centre_x_0), (centre_y_1, centre_x_1), (centre_y_2, centre_x_2)])

This is used for visualization, for example plotting the centres of all mass profiles colored by their profile.

property perform_inversion: bool#

Returns a bool specifying whether this fit object performs an inversion.

This is based on whether any of the galaxies have a Pixelization or LightProfileLinear object, in which case an inversion is performed.

Return type:

A bool which is True if an inversion is performed.