autolens.Tracer#

class Tracer[source]#

Bases: ABC, OperateImageGalaxies, OperateDeflections

Ray-tracer for a lens system with any number of planes.

The redshift of these planes are specified by the redshits of the galaxies; there is a unique plane redshift for every unique galaxy redshift (galaxies with identical redshifts are put in the same plane).

To perform multi-plane ray-tracing, a cosmology must be supplied so that deflection-angles can be rescaled according to the lens-geometry of the multi-plane system. All galaxies input to the tracer must therefore have redshifts.

This tracer has only one grid (see gridStack) which is used for ray-tracing.

Parameters:
  • galaxies ([Galaxy]) – The list of galaxies in the ray-tracing calculation.

  • image_plane_grid (grid_stacks.GridStack) – The image-plane grid which is traced. (includes the grid, sub-grid, blurring-grid, etc.).

  • border (masks.GridBorder) – The border of the grid, which is used to relocate demagnified traced pixels to the source-plane borders.

  • cosmology (astropy.cosmology) – The cosmology of the ray-tracing calculation.

Methods

area_within_curve_list_from

rtype:

List[float]

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.

cls_list_from

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

convergence_2d_from

rtype:

Array2D

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

convolve_via_convolver

deflections_between_planes_from

rtype:

Union[VectorYX2D, VectorYX2DIrregular]

deflections_of_planes_summed_from

rtype:

Union[VectorYX2D, VectorYX2DIrregular]

deflections_yx_2d_from

rtype:

Union[VectorYX2D, VectorYX2DIrregular]

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.

extract_attribute

Returns an attribute of a class in the tracer as a ValueIrregular or Grid2DIrregular object.

extract_attributes_of_galaxies

Returns an attribute of a class in the tracer as a list of ValueIrregular or Grid2DIrregular objects, where the indexes of the list correspond to the tracer's galaxies.

extract_attributes_of_planes

Returns an attribute of a class in the tracer as a list of ValueIrregular or Grid2DIrregular objects, where the indexes of the list correspond to the tracer's planes.

extract_plane_index_of_profile

Returns the plane index of a LightProfile`, MassProfile or Point from the Tracer using the name of that component.

extract_profile

Returns a LightProfile, MassProfile or Point from the Tracer using the name of that component.

from_galaxies

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_image_2d_dict_from

Returns a dictionary associating every Galaxy object in the Tracer 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.

grid_2d_at_redshift_from

For an input grid of (y,x) arc-second image-plane coordinates, ray-trace the coordinates to any redshift in the strong lens configuration.

has

rtype:

bool

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

rtype:

Array2D

image_2d_list_from

rtype:

List[Array2D]

image_2d_via_input_plane_image_from

Returns the lensed image of a plane or galaxy, where the input image is uniform and interpolated to compute the lensed image.

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_with_galaxy

rtype:

Plane

potential_2d_from

rtype:

Array2D

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:

set_snr_of_snr_light_profiles

Iterate over every LightProfileSNR in the tracer and set their intensity values to values which give their input signal_to_noise_ratio value, which is performed as follows:

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

sliced_tracer_from

Ray-tracer for a lens system with any number of planes.

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_list_from

Performs multi-plane ray tracing on a 2D grid of Cartesian (y,x) coordinates using the mass profiles of the galaxies and planes contained within the tracer.

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

all_planes_have_redshifts

rtype:

bool

galaxies

rtype:

List[Galaxy]

image_plane

rtype:

Plane

perform_inversion

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

plane_indexes_with_pixelizations

source_plane

rtype:

Plane

total_planes

rtype:

int

upper_plane_index_with_light_profile

rtype:

int

classmethod sliced_tracer_from(lens_galaxies, line_of_sight_galaxies, source_galaxies, planes_between_lenses, cosmology=Planck15(name='Planck15', H0=<Quantity 67.74 km / (Mpc s)>, Om0=0.3075, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.0486))[source]#

Ray-tracer for a lens system with any number of planes.

The redshift of these planes are specified by the input parameters lens_redshifts and slices_between_main_planes. Every galaxy is placed in its closest plane in redshift-space.

To perform multi-plane ray-tracing, a cosmology must be supplied so that deflection-angles can be rescaled according to the lens-geometry of the multi-plane system. All galaxies input to the tracer must therefore have redshifts.

This tracer has only one grid (see gridStack) which is used for ray-tracing.

Parameters:
  • lens_galaxies ([Galaxy]) – The list of galaxies in the ray-tracing calculation.

  • image_plane_grid (grid_stacks.GridStack) – The image-plane grid which is traced. (includes the grid, sub-grid, blurring-grid, etc.).

  • planes_between_lenses ([int]) – The number of slices between each main plane. The first entry in this list determines the number of slices between Earth (redshift 0.0) and main plane 0, the next between main planes 0 and 1, etc.

  • border (masks.GridBorder) – The border of the grid, which is used to relocate demagnified traced pixels to the source-plane borders.

  • cosmology (astropy.cosmology) – The cosmology of the ray-tracing calculation.

cls_list_from(cls)[source]#

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

For example:

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

Return type:

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

traced_grid_2d_list_from(grid, plane_index_limit=None)[source]#

Performs multi-plane ray tracing on a 2D grid of Cartesian (y,x) coordinates using the mass profiles of the galaxies and planes contained within the tracer.

see autolens.lens.ray_tracing.ray_tracing_util.traced_grid_2d_list_from() for a full description of the calculation.

Parameters:
  • grid (Union[ndarray, Grid2D, Grid2DIterate, Grid2DIrregular]) – The 2D (y, x) coordinates on which multi-plane ray-tracing calculations are performed.

  • plane_index_limit – The integer index of the last plane which is used to perform ray-tracing, all planes with an index above this value are omitted.

Returns:

A list of 2D (y,x) grids each of which are the input grid ray-traced to a redshift of the input list of planes.

Return type:

traced_grid_list

grid_2d_at_redshift_from(grid, redshift)[source]#

For an input grid of (y,x) arc-second image-plane coordinates, ray-trace the coordinates to any redshift in the strong lens configuration.

This is performed using multi-plane ray-tracing and the existing redshifts and planes of the tracer. However, any redshift can be input even if a plane does not exist there, including redshifts before the first plane of the lens system.

Parameters:
  • grid (ndsrray or aa.Grid2D) – The image-plane grid which is traced to the redshift.

  • redshift (float) – The redshift the image-plane grid is traced to.

Return type:

Union[ndarray, Grid2D, Grid2DIterate, Grid2DIrregular]

image_2d_via_input_plane_image_from(grid, plane_image, plane_index=-1, include_other_planes=True)[source]#

Returns the lensed image of a plane or galaxy, where the input image is uniform and interpolated to compute the lensed image.

The typical use case is inputting the image of an irregular galaxy in the source-plane (whose values are on a uniform array) and using this function computing the lensed image of this source galaxy.

By default, this function computes the lensed image of the final plane, which is the source-plane, by using plane_index=-1. For multi-plane lens systems, the lensed image of any planes can be computed by setting plane_index to the index of the plane in the lens system.

The emission of all other planes and galaxies can be included or omitted setting the include_other_planes bool. If there are multiple planes in a multi-plane lens system, the emission of the other planes are fully lensed.

__Source Plane Interpolation__

We use the scipy interpolation function griddata to create the lensed source galaxy image.

In brief, we trace light rays to the source plane and calculate values based on where those light rays land in the source plane via interpolation.

In more detail:

  • points: The 2D grid of (y,x) coordinates representing the location of every pixel of the source galaxy image in the source-plane, from which we are creating the lensed source image. These coordinates are the uniform source-plane grid computed after interpolating the irregular mesh the original source reconstruction used.

  • values: The intensity values of the source galaxy image which is used to create the lensed source image.

    These values are the flux values of the interpolated source galaxy image computed after interpolating the irregular mesh the original source reconstruction used.

  • xi: The image-plane grid ray traced to the source-plane. This evaluates the flux of each image-plane lensed source-pixel by ray-tracing it to the source-plane grid and computing its value by interpolating the source galaxy image.

Parameters:
  • grid (Union[ndarray, Grid2D, Grid2DIterate, Grid2DIrregular]) – The image-plane grid which is traced to the plane where the image is computed, where these values are used to perform the interpolation.

  • plane_image (Array2D) – The image of the plane or galaxy which is interpolated to compute the lensed image.

  • plane_index (int) – The index of the plane the image is computed, where the default (-1) computes the image in the last plane and therefore the source-plane.

Return type:

The lensed image of the plane or galaxy computed by interpolating its image to the image-plane.

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

Returns a dictionary associating every Galaxy object in the Tracer 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, Grid2DIterate, Grid2DIrregular]) – The 2D (y,x) coordinates of the (masked) grid, in its original geometric reference frame.

Return type:

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

property perform_inversion: bool#

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

This is based on whether any of the galaxies in the model_obj 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.

extract_attribute(cls, attr_name)[source]#

Returns an attribute of a class in the tracer as a ValueIrregular or Grid2DIrregular object.

For example, if a tracer has an image-plane with a galaxy with two light profiles, the following:

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

would return:

ArrayIrregular(values=[axis_ratio_0, axis_ratio_1])

If the image plane has has two galaxies with two mass profiles and the source plane another galaxy with a mass profile, the following:

tracer.extract_attribute(cls=MassProfile, name=”centre”)

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.

extract_attributes_of_planes(cls, attr_name, filter_nones=False)[source]#

Returns an attribute of a class in the tracer as a list of ValueIrregular or Grid2DIrregular objects, where the indexes of the list correspond to the tracer’s planes.

For example, if a tracer has an image-plane with a galaxy with a light profile and a source-plane with a galaxy with a light profile, the following:

tracer.extract_attributes_of_planes(cls=LightProfile, name=”axis_ratio”)

would return:

[ArrayIrregular(values=[axis_ratio_0]), ArrayIrregular(values=[axis_ratio_1])]

If the image plane has two galaxies with a mass profile each and the source plane another galaxy with a mass profile, the following:

tracer.extract_attributes_of_planes(cls=MassProfile, name=”centres”)

would return:

[

Grid2DIrregular(values=[(centre_y_0, centre_x_0)]), Grid2DIrregular(values=[(centre_y_0, centre_x_0), (centre_y_1, centre_x_1)])

]

If a Profile does not have a certain entry, it is replaced with a None, although the nones can be removed by setting filter_nones=True.

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

extract_attributes_of_galaxies(cls, attr_name, filter_nones=False)[source]#

Returns an attribute of a class in the tracer as a list of ValueIrregular or Grid2DIrregular objects, where the indexes of the list correspond to the tracer’s galaxies. If a plane has multiple galaxies they are split into separate indexes int he list.

For example, if a tracer has an image-plane with a galaxy with a light profile and a source-plane with a galaxy with a light profile, the following:

tracer.extract_attributes_of_galaxies(cls=LightProfile, name=”axis_ratio”)

would return:

[ArrayIrregular(values=[axis_ratio_0]), ArrayIrregular(values=[axis_ratio_1])]

If the image plane has two galaxies with a mass profile each and the source plane another galaxy with a mass profile, the following:

tracer.extract_attributes_of_galaxies(cls=MassProfile, name=”centres”)

would return:

[

Grid2DIrregular(values=[(centre_y_0, centre_x_0)]), Grid2DIrregular(values=[(centre_y_0, centre_x_0)]) Grid2DIrregular(values=[(centre_y_0, centre_x_0)])

]

If the first galaxy in the image plane in the example above had two mass profiles as well as the galaxy in the source plane it would return:

[

Grid2DIrregular(values=[(centre_y_0, centre_x_0), (centre_y_1, centre_x_1)]), Grid2DIrregular(values=[(centre_y_0, centre_x_0)]) Grid2DIrregular(values=[(centre_y_0, centre_x_0, (centre_y_1, centre_x_1))])

]

If a Profile does not have a certain entry, it is replaced with a None, although the nones can be removed by setting filter_nones=True.

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

extract_profile(profile_name)[source]#

Returns a LightProfile, MassProfile or Point from the Tracer using the name of that component.

For example, if a tracer has two galaxies, lens and source with LightProfile’s name light_0 and light_1, the following:

tracer.extract_profile(profile_name=”light_1”)

Would return the LightProfile of the source plane.

extract_plane_index_of_profile(profile_name)[source]#

Returns the plane index of a LightProfile`, MassProfile or Point from the Tracer using the name of that component.

For example, if a tracer has two galaxies, lens and source with LightProfile’s name light_0 and light_1, the following:

tracer.extract_profile(profile_name=”light_1”)

Would return plane_index=1 given the profile is in the source plane.

set_snr_of_snr_light_profiles(grid, exposure_time, background_sky_level=0.0, psf=None)[source]#

Iterate over every LightProfileSNR in the tracer and set their intensity values to values which give their input signal_to_noise_ratio value, which is performed as follows:

  • Evaluate the image of each light profile on the input grid.

  • Blur this image with a PSF, if included.

  • Take the value of the brightest pixel.

  • Use an input exposure_time and background_sky (e.g. from the SimulatorImaging object) to determine what value of intensity gives the desired signal to noise ratio for the image.

The intensity is set using an input grid, meaning that for strong lensing calculations the ray-traced grid can be used such that the S/N accounts for the magnification of a source galaxy.

Parameters:
  • grid (Union[ndarray, Grid2D, Grid2DIterate, Grid2DIrregular]) – The (y, x) coordinates in the original reference frame of the grid.

  • exposure_time (float) – The exposure time of the simulated imaging.

  • background_sky_level (float) – The level of the background sky of the simulated imaging.

  • psf (Optional[Kernel2D]) – The psf of the simulated imaging which can change the S/N of the light profile due to spreading out the emission.