lenstronomy.LensModel.MultiPlane package

Submodules

lenstronomy.LensModel.MultiPlane.decoupled_multi_plane module

class MultiPlaneDecoupled(z_source, lens_model_list, lens_redshift_list, cosmo=None, observed_convention_index=None, ignore_observed_positions=False, z_source_convention=None, z_lens_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, profile_kwargs_list=None, distance_ratio_sampling=False, cosmology_sampling=False, cosmology_model='FlatLambdaCDM', x0_interp=None, y0_interp=None, alpha_x_interp_foreground=None, alpha_y_interp_foreground=None, alpha_x_interp_background=None, alpha_y_interp_background=None, z_split=None, use_jax=False)[source]

Bases: MultiPlane

__init__(z_source, lens_model_list, lens_redshift_list, cosmo=None, observed_convention_index=None, ignore_observed_positions=False, z_source_convention=None, z_lens_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, profile_kwargs_list=None, distance_ratio_sampling=False, cosmology_sampling=False, cosmology_model='FlatLambdaCDM', x0_interp=None, y0_interp=None, alpha_x_interp_foreground=None, alpha_y_interp_foreground=None, alpha_x_interp_background=None, alpha_y_interp_background=None, z_split=None, use_jax=False)[source]

A class for multiplane lensing in which the deflection angles at certain coordinates are fixed through user-specified interpolation functions. These functions return fixed deflection angles that effectively decouple deflections by a group of deflectors at redshift Z from deflections produced by halos at redshift< Z.

This class breaks the recursive nature of the multi-plane lens equation, and can significantly speed up computations with a large number of line-of-sight halos.

Parameters:
  • lens_model_list – list of lens model strings

  • lens_redshift_list – list of floats with redshifts of the lens models indicated in lens_model_list

  • z_source_convention – float, redshift of a source to define the reduced deflection angles of the lens models. If None, ‘z_source’ is used.

  • cosmo – instance of astropy.cosmology

  • profile_kwargs_list – list of dicts, keyword arguments used to initialize profile classes in the same order of the lens_model_list. If any of the profile_kwargs are None, then that profile will be initialized using default settings.

  • x0_interp – a function that maps an angular coordinate on the sky to the x coordinate of a physical position [Mpc] at the first lens plane

  • y0_interp – same as x0_interp, but returns the y coordinate in Mpc

  • alpha_x_interp_list – a list of functions that take as input angular coordinates (x, y) and returns the x-component of the deflection angle at each coorindate

  • alpha_y_interp_list – same as alpha_x_interp_list, but returns the y-component of the deflection angle at (x,y)

  • z_interp_list – a list of redshifts corresponding to the alpha_x_interp_list and alpha_y_interp_list entries

  • use_jax – bool, if True, uses deflector profiles from jaxtronomy. Can also be a list of bools, selecting which models in the lens_model_list to use from jaxtronomy

geo_shapiro_delay(**kwargs)[source]

Geometric and Shapiro (gravitational) light travel time relative to a straight path through the coordinate (0,0) Negative sign means earlier arrival time.

Parameters:
  • theta_x – angle in x-direction on the image

  • theta_y – angle in y-direction on the image

  • kwargs_lens – lens model keyword argument list

  • check_convention – boolean, if True goes through the lens model list and checks whether the positional conventions are satisfied.

Returns:

geometric delay, gravitational delay [days]

ray_shooting_partial_comoving(*args, **kwargs)[source]

Ray-tracing through parts of the cone, starting with (x,y) in angular units as seen on the sky without lensing and angles (alpha_x, alpha_y) as seen at redshift z_start and then backwards to redshift z_stop.

Parameters:
  • theta_x – angular position on the sky [arcsec]

  • theta_y – angular position on the sky [arcsec]

  • alpha_x – ray angle at z_start [arcsec]

  • alpha_y – ray angle at z_start [arcsec]

  • z_start – redshift of start of computation

  • z_stop – redshift where output is computed

  • kwargs_lens – lens model keyword argument list

  • include_z_start – bool, if True, includes the computation of the deflection angle at the same redshift as the start of the ray-tracing. ATTENTION: deflection angles at the same redshift as z_stop will be computed always! This can lead to duplications in the computation of deflection angles.

  • T_ij_start – transverse angular distance between the starting redshift to the first lens plane to follow. If not set, will compute the distance each time this function gets executed.

  • T_ij_end – transverse angular distance between the last lens plane being computed and z_end. If not set, will compute the distance each time this function gets executed.

  • check_convention – flag to check the image position convention (leave this alone)

Returns:

angular position and angles at redshift z_stop

ray_shooting(theta_x, theta_y, kwargs_lens, *args, **kwargs)[source]

Ray-shooting through the lens volume with fixed deflection angles at certain lens planes passed through the alpha_x_interp/alpha_y_interp lists. Starts with (x,y) co-moving distance passed through the x0_interp and y0_interp functions, then starts multi-plane ray-tracing through all subsequent lens planes.

Parameters:
  • theta_x – angular coordinate on the sky

  • theta_y – angular coordinate on the sky

  • kwargs_lens – keyword arguments for the main deflector

Returns:

coordinates on the source plane

lenstronomy.LensModel.MultiPlane.multi_plane module

class MultiPlane(z_source, lens_model_list, lens_redshift_list, cosmo=None, observed_convention_index=None, ignore_observed_positions=False, z_source_convention=None, z_lens_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, profile_kwargs_list=None, distance_ratio_sampling=False, cosmology_sampling=False, cosmology_model='FlatLambdaCDM', use_jax=False)[source]

Bases: object

Multi-plane lensing class with option to assign positions of a selected set of lens models in the observed plane.

The lens model deflection angles are in units of reduced deflections from the specified redshift of the lens to the source redshift of the class instance.

__init__(z_source, lens_model_list, lens_redshift_list, cosmo=None, observed_convention_index=None, ignore_observed_positions=False, z_source_convention=None, z_lens_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, profile_kwargs_list=None, distance_ratio_sampling=False, cosmology_sampling=False, cosmology_model='FlatLambdaCDM', use_jax=False)[source]
Parameters:
  • z_source – source redshift for default computation of reduced lensing quantities

  • lens_model_list – list of lens model strings

  • lens_redshift_list – list of floats with redshifts of the lens models indicated in lens_model_list

  • cosmo – instance of astropy.cosmology

  • numerical_alpha_class – an instance of a custom class for use in NumericalAlpha() lens model (see documentation in Profiles/numerical_alpha)

  • profile_kwargs_list – list of dicts, keyword arguments used to initialize profile classes in the same order of the lens_model_list. If any of the profile_kwargs are None, then that profile will be initialized using default settings.

  • observed_convention_index – a list of indices, corresponding to the lens_model_list element with same index, where the ‘center_x’ and ‘center_y’ kwargs correspond to observed (lensed) positions, not physical positions. The code will compute the physical locations when performing computations

  • ignore_observed_positions – bool, if True, will ignore the conversion between observed to physical position of deflectors

  • z_source_convention – float, redshift of a source to define the reduced deflection angles of the lens models. If None, ‘z_source’ is used.

  • z_lens_convention – float, redshift of a lens plane to define the effective time-delay distance. Only needed if distance ratios are sampled. If None, the first lens redshift is used.

  • cosmo_interp – bool, if True, will use interpolated cosmology

  • z_interp_stop – (only in multi-plane with cosmo_interp=True); maximum redshift for distance interpolation This number should be higher or equal the maximum of the source redshift and/or the z_source_convention

  • num_z_interp – (only in multi-plane with cosmo_interp=True); number of redshift bins for interpolating distances

  • kwargs_multiplane_model – keyword arguments for the MultiPlaneDecoupled class, if specified

  • distance_ratio_sampling – bool, if True, will use sampled distance ratios to update T_ij value in multi-lens plane computation.

  • cosmology_sampling – bool, if True, will use sampled cosmology

  • cosmology_model – str, name of the cosmology model to use for

  • use_jax – bool, if True, uses deflector profiles from jaxtronomy. Can also be a list of bools, selecting which models in the lens_model_list to use from jaxtronomy

update_source_redshift(z_source)[source]

Update instance of this class to compute reduced lensing quantities and time delays to a specific source redshift.

Parameters:

z_source – float; source redshift

Returns:

self variables update to new redshift

property multi_plane_base
property z_source
property z_source_convention
property z_lens_convention
property T_ij_start
property T_ij_stop
model_info()[source]

Shows what models are being initialized and what parameters are being requested for.

Returns:

None

set_background_cosmo(cosmo)[source]

Set the background cosmology.

Parameters:

cosmo – instance of astropy.cosmology

Returns:

None

observed2flat_convention(kwargs_lens)[source]
Parameters:

kwargs_lens – keyword argument list of lens model parameters in the observed convention

Returns:

kwargs_lens positions mapped into angular position without lensing along its LOS

ray_shooting(theta_x, theta_y, kwargs_lens, check_convention=True, k=None)[source]

Ray-tracing (backwards light cone) to the default z_source redshift.

Parameters:
  • theta_x – angle in x-direction on the image (usually arc seconds, in the same convention as lensing deflection angles)

  • theta_y – angle in y-direction on the image (usually arc seconds, in the same convention as lensing deflection angles)

  • kwargs_lens – lens model keyword argument list

  • check_convention – flag to check the image position convention (leave this alone)

Returns:

angles in the source plane

ray_shooting_partial(theta_x, theta_y, alpha_x, alpha_y, z_start, z_stop, kwargs_lens, include_z_start=False, T_ij_start=None, T_ij_end=None, check_convention=True)[source]

Ray-tracing through parts of the cone, starting with (x,y) in angular units as seen on the sky without lensing and angles (alpha_x, alpha_y) as seen at redshift z_start and then backwards to redshift z_stop.

Parameters:
  • theta_x – angular position on the sky [arcsec]

  • theta_y – angular position on the sky [arcsec]

  • alpha_x – ray angle at z_start [arcsec]

  • alpha_y – ray angle at z_start [arcsec]

  • z_start – redshift of start of computation

  • z_stop – redshift where output is computed

  • kwargs_lens – lens model keyword argument list

  • include_z_start – bool, if True, includes the computation of the deflection angle at the same redshift as the start of the ray-tracing. ATTENTION: deflection angles at the same redshift as z_stop will be computed always! This can lead to duplications in the computation of deflection angles.

  • T_ij_start – transverse angular distance between the starting redshift to the first lens plane to follow. If not set, will compute the distance each time this function gets executed.

  • T_ij_end – transverse angular distance between the last lens plane being computed and z_end. If not set, will compute the distance each time this function gets executed.

  • check_convention – flag to check the image position convention (leave this alone)

Returns:

angular position and angles at redshift z_stop

ray_shooting_partial_comoving(x, y, alpha_x, alpha_y, z_start, z_stop, kwargs_lens, include_z_start=False, T_ij_start=None, T_ij_end=None, check_convention=True)[source]

Ray-tracing through parts of the cone, starting with (x,y) in angular units as seen on the sky without lensing and angles (alpha_x, alpha_y) as seen at redshift z_start and then backwards to redshift z_stop.

Parameters:
  • theta_x – angular position on the sky [arcsec]

  • theta_y – angular position on the sky [arcsec]

  • alpha_x – ray angle at z_start [arcsec]

  • alpha_y – ray angle at z_start [arcsec]

  • z_start – redshift of start of computation

  • z_stop – redshift where output is computed

  • kwargs_lens – lens model keyword argument list

  • include_z_start – bool, if True, includes the computation of the deflection angle at the same redshift as the start of the ray-tracing. ATTENTION: deflection angles at the same redshift as z_stop will be computed always! This can lead to duplications in the computation of deflection angles.

  • T_ij_start – transverse angular distance between the starting redshift to the first lens plane to follow. If not set, will compute the distance each time this function gets executed.

  • T_ij_end – transverse angular distance between the last lens plane being computed and z_end. If not set, will compute the distance each time this function gets executed.

  • check_convention – flag to check the image position convention (leave this alone)

Returns:

angular position and angles at redshift z_stop

transverse_distance_start_stop(z_start, z_stop, include_z_start=False)[source]

Computes the transverse distance (T_ij) that is required by the ray-tracing between the starting redshift and the first deflector afterwards and the last deflector before the end of the ray-tracing.

Parameters:
  • z_start – redshift of the start of the ray-tracing

  • z_stop – stop of ray-tracing

  • include_z_start – bool, i

Returns:

T_ij_start, T_ij_end

arrival_time(theta_x, theta_y, kwargs_lens, check_convention=True)[source]

Light travel time relative to a straight path through the coordinate (0,0) Negative sign means earlier arrival time.

Parameters:
  • theta_x – angle in x-direction on the image

  • theta_y – angle in y-direction on the image

  • kwargs_lens – lens model keyword argument list

  • kwargs_cosmo – cosmo keyword argument

Returns:

travel time in unit of days

geo_shapiro_delay(theta_x, theta_y, kwargs_lens, check_convention=True)[source]

Geometric and Shapiro (gravitational) light travel time relative to a straight path through the coordinate (0,0) Negative sign means earlier arrival time.

Parameters:
  • theta_x – angle in x-direction on the image

  • theta_y – angle in y-direction on the image

  • kwargs_lens – lens model keyword argument list

  • check_convention – boolean, if True goes through the lens model list and checks whether the positional conventions are satisfied.

Returns:

geometric delay, gravitational delay [days]

alpha(theta_x, theta_y, kwargs_lens, check_convention=True, k=None)[source]

Reduced deflection angle.

Parameters:
  • theta_x – angle in x-direction

  • theta_y – angle in y-direction

  • kwargs_lens – lens model kwargs

  • check_convention – flag to check the image position convention (leave this alone)

Returns:

deflection angles in x and y directions

hessian(theta_x, theta_y, kwargs_lens, k=None, diff=1e-08, check_convention=True)[source]

Computes the hessian components f_xx, f_yy, f_xy from f_x and f_y with numerical differentiation.

Parameters:
  • theta_x (numpy array) – x-position (preferentially arcsec)

  • theta_y (numpy array) – y-position (preferentially arcsec)

  • kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes

  • diff – numerical differential step (float)

  • check_convention – boolean, if True goes through the lens model list and checks whether the positional conventions are satisfied.

Returns:

f_xx, f_xy, f_yx, f_yy

hessian_z1z2(z1, z2, theta_x, theta_y, kwargs_lens, diff=1e-08)[source]

Computes Hessian matrix when Observed at z1 with rays going to z2 with z1 < z2.

Parameters:
  • z1 – Observer redshift

  • z2 – source redshift

  • theta_x – angular position and direction of the ray

  • theta_y – angular position and direction of the ray

  • kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes

  • diff – numerical differential step (float)

Returns:

f_xx, f_xy, f_yx, f_yy

co_moving2angle_z1_z2(x, y, z1, z2)[source]

Computes angle for co-moving distance at z=z2 when seen from z=z1.

Parameters:
  • x – co-moving distance at z=z2

  • y – co-moving distance at z=z2

  • z1 – redshift of observer

  • z2 – redshift of source

Returns:

theta_z, theta_y

co_moving2angle_source(x, y)[source]

Special case of the co_moving2angle definition at the source redshift.

Parameters:
  • x – co-moving distance

  • y – co-moving distance

Returns:

angles on the sky at the nominal source plane

set_static(kwargs)[source]
Parameters:

kwargs – lens model keyword argument list

Returns:

lens model keyword argument list with positional parameters all in flat sky coordinates

set_dynamic()[source]
Returns:

class PhysicalLocation[source]

Bases: object

center_x and center_y kwargs correspond to angular location of deflectors without lensing along the LOS.

class LensedLocation(multiplane_instance, observed_convention_index)[source]

Bases: object

center_x and center_y kwargs correspond to observed (lensed) locations of deflectors given a model for the line of sight structure, compute the angular position of the deflector without lensing contribution along the LOS.

__init__(multiplane_instance, observed_convention_index)[source]
Parameters:
  • multiplane_instance – instance of the MultiPlane class

  • observed_convention_index – list of lens model indexes to be modelled in the observed plane

lenstronomy.LensModel.MultiPlane.multi_plane_base module

class MultiPlaneBase(lens_model_list, lens_redshift_list, z_source_convention, cosmo=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, profile_kwargs_list=None, use_jax=False)[source]

Bases: ProfileListBase

Multi-plane lensing class.

The lens model deflection angles are in units of reduced deflections from the specified redshift of the lens to the source redshift of the class instance.

__init__(lens_model_list, lens_redshift_list, z_source_convention, cosmo=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, profile_kwargs_list=None, use_jax=False)[source]

A description of the recursive multi-plane formalism can be found e.g. here: https://arxiv.org/abs/1312.1536

Parameters:
  • lens_model_list – list of lens model strings

  • lens_redshift_list – list of floats with redshifts of the lens models indicated in lens_model_list

  • z_source_convention – float, redshift of a source to define the reduced deflection angles of the lens models. If None, ‘z_source’ is used.

  • cosmo – instance of astropy.cosmology

  • cosmo_interp – bool, if True, will use interpolated cosmology

  • z_interp_stop – (only in multi-plane with cosmo_interp=True); maximum redshift for distance interpolation This number should be higher or equal the maximum of the source redshift and/or the z_source_convention

  • num_z_interp – (only in multi-plane with cosmo_interp=True); number of redshift bins for interpolating distances

  • profile_kwargs_list – list of dicts, keyword arguments used to initialize profile classes in the same order of the lens_model_list. If any of the profile_kwargs are None, then that profile will be initialized using default settings.

  • use_jax – bool, if True, uses deflector profiles from jaxtronomy. Can also be a list of bools, selecting which models in the lens_model_list to use from jaxtronomy

set_T_zs_and_T_ijs()[source]

Set the transverse angular diameter distances between the observer and the lens planes and between the lens planes.

set_background_cosmo(cosmo)[source]

Set the cosmology instance of the background class.

Parameters:

cosmo – instance of astropy.cosmology

property z_source_convention

Redshift of the source to define the reduced deflection angles of the lens models.

property sorted_redshift_index

List of lens indices in the sorted redshift order.

property T_z_list

List of transverse angular diameter distances between the observer and the lens planes.

property T_ij_list

List of transverse angular diameter distances between the lens planes.

ray_shooting_partial_comoving(x, y, alpha_x, alpha_y, z_start, z_stop, kwargs_lens, include_z_start=False, T_ij_start=None, T_ij_end=None)[source]

Ray-tracing through parts of the cone, starting with (x,y) co-moving distances and angles (alpha_x, alpha_y) at redshift z_start and then backwards to redshift z_stop.

Parameters:
  • x – co-moving position [Mpc]

  • y – co-moving position [Mpc]

  • alpha_x – ray angle at z_start [arcsec]

  • alpha_y – ray angle at z_start [arcsec]

  • z_start – redshift of start of computation

  • z_stop – redshift where output is computed

  • kwargs_lens – lens model keyword argument list

  • include_z_start – bool, if True, includes the computation of the deflection angle at the same redshift as the start of the ray-tracing. ATTENTION: deflection angles at the same redshift as z_stop will be computed always! This can lead to duplications in the computation of deflection angles.

  • T_ij_start – transverse angular distance between the starting redshift to the first lens plane to follow. If not set, will compute the distance each time this function gets executed.

  • T_ij_end – transverse angular distance between the last lens plane being computed and z_end. If not set, will compute the distance each time this function gets executed.

Returns:

co-moving position and angles at redshift z_stop

ray_shooting_partial(theta_x, theta_y, alpha_x, alpha_y, z_start, z_stop, kwargs_lens, include_z_start=False, T_ij_start=None, T_ij_end=None, T_z_start=None, T_z_stop=None)[source]

Ray-tracing through parts of the coin, starting with (x,y) in angular units as seen on the sky without lensing and angles (alpha_x, alpha_y) as seen at redshift z_start and then backwards to redshift z_stop.

Parameters:
  • theta_x – angular position on the sky [arcsec]

  • theta_y – angular position on the sky [arcsec]

  • alpha_x – ray angle at z_start [arcsec]

  • alpha_y – ray angle at z_start [arcsec]

  • z_start – redshift of start of computation

  • z_stop – redshift where output is computed

  • kwargs_lens – lens model keyword argument list

  • include_z_start – bool, if True, includes the computation of the deflection angle at the same redshift as the start of the ray-tracing. ATTENTION: deflection angles at the same redshift as z_stop will be computed always! This can lead to duplications in the computation of deflection angles.

  • T_ij_start – transverse angular distance between the starting redshift to the first lens plane to follow. If not set, will compute the distance each time this function gets executed.

  • T_ij_end – transverse angular distance between the last lens plane being computed and z_end. If not set, will compute the distance each time this function gets executed.

  • T_z_start – transverse angular distance up to z_start. If not set, will compute the distance each time this function gets executed.

  • T_z_stop – transverse angular distance up to z_stop. If not set, will compute the distance each time this function gets executed.

Returns:

angular position and angles at redshift z_stop

transverse_distance_start_stop(z_start, z_stop, include_z_start=False)[source]

Computes the transverse distance (T_ij) that is required by the ray-tracing between the starting redshift and the first deflector afterwards and the last deflector before the end of the ray-tracing.

Parameters:
  • z_start – redshift of the start of the ray-tracing

  • z_stop – stop of ray-tracing

  • include_z_start – boolean, if True includes the computation of the starting position if the first deflector is at z_start

Returns:

T_ij_start, T_ij_end

geo_shapiro_delay(theta_x, theta_y, kwargs_lens, z_stop, T_z_stop=None, T_ij_end=None)[source]

Geometric and Shapiro (gravitational) light travel time relative to a straight path through the coordinate (0,0) Negative sign means earlier arrival time.

Parameters:
  • theta_x – angle in x-direction on the image

  • theta_y – angle in y-direction on the image

  • kwargs_lens – lens model keyword argument list

  • z_stop – redshift of the source to stop the backwards ray-tracing

  • T_z_stop – optional, transversal angular distance from z=0 to z_stop

  • T_ij_end – optional, transversal angular distance between the last lensing plane and the source plane

Returns:

dt_geo, dt_shapiro, [days]

Module contents