lenstronomy.LensModel package

Subpackages

Submodules

lenstronomy.LensModel.convergence_integrals module

lenstronomy.LensModel.convergence_integrals.potential_from_kappa_grid(kappa, grid_spacing)[source]

lensing potential on the convergence grid the computation is performed as a convolution of the Green’s function with the convergence map using FFT

Parameters:
  • kappa – 2d grid of convergence values
  • grid_spacing – pixel size of grid
Returns:

lensing potential in a 2d grid at positions x_grid, y_grid

lenstronomy.LensModel.convergence_integrals.potential_from_kappa_grid_adaptive(kappa_high_res, grid_spacing, low_res_factor, high_res_kernel_size)[source]

lensing potential on the convergence grid the computation is performed as a convolution of the Green’s function with the convergence map using FFT

Parameters:
  • kappa_high_res – 2d grid of convergence values
  • grid_spacing – pixel size of grid
  • low_res_factor – lower resolution factor of larger scale kernel.
  • high_res_kernel_size – int, size of high resolution kernel in units of degraded pixels
Returns:

lensing potential in a 2d grid at positions x_grid, y_grid

lenstronomy.LensModel.convergence_integrals.deflection_from_kappa_grid(kappa, grid_spacing)[source]

deflection angles on the convergence grid the computation is performed as a convolution of the Green’s function with the convergence map using FFT

Parameters:
  • kappa – convergence values for each pixel (2-d array)
  • grid_spacing – pixel size of grid
Returns:

numerical deflection angles in x- and y- direction

lenstronomy.LensModel.convergence_integrals.deflection_from_kappa_grid_adaptive(kappa_high_res, grid_spacing, low_res_factor, high_res_kernel_size)[source]

deflection angles on the convergence grid with adaptive FFT the computation is performed as a convolution of the Green’s function with the convergence map using FFT The grid is returned in the lower resolution grid

Parameters:
  • kappa_high_res – convergence values for each pixel (2-d array)
  • grid_spacing – pixel size of high resolution grid
  • low_res_factor – lower resolution factor of larger scale kernel.
  • high_res_kernel_size – int, size of high resolution kernel in units of degraded pixels
Returns:

numerical deflection angles in x- and y- direction

lenstronomy.LensModel.convergence_integrals.potential_kernel(num_pix, delta_pix)[source]

numerical gridded integration kernel for convergence to lensing kernel with given pixel size

Parameters:
  • num_pix – integer; number of pixels of kernel per axis
  • delta_pix – pixel size (per dimension in units of angle)
Returns:

kernel for lensing potential

lenstronomy.LensModel.convergence_integrals.deflection_kernel(num_pix, delta_pix)[source]

numerical gridded integration kernel for convergence to deflection angle with given pixel size

Parameters:
  • num_pix – integer; number of pixels of kernel per axis, should be odd number to have a defined center
  • delta_pix – pixel size (per dimension in units of angle)
Returns:

kernel for x-direction and kernel of y-direction deflection angles

lenstronomy.LensModel.lens_model module

class lenstronomy.LensModel.lens_model.LensModel(lens_model_list, z_lens=None, z_source=None, lens_redshift_list=None, cosmo=None, multi_plane=False, numerical_alpha_class=None, observed_convention_index=None, z_source_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100)[source]

Bases: object

class to handle an arbitrary list of lens models. This is the main lenstronomy LensModel API for all other modules.

alpha(x, y, kwargs, k=None, diff=None)[source]

deflection angles

Parameters:
  • x (numpy array) – x-position (preferentially arcsec)
  • y (numpy array) – y-position (preferentially arcsec)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • k – only evaluate the k-th lens model
  • diff – None or float. If set, computes the deflection as a finite numerical differential of the lensing potential. This differential is only applicable in the single lensing plane where the form of the lensing potential is analytically known
Returns:

deflection angles in units of arcsec

arrival_time(x_image, y_image, kwargs_lens, kappa_ext=0)[source]
Parameters:
  • x_image – image position
  • y_image – image position
  • kwargs_lens – lens model parameter keyword argument list
  • kappa_ext – external convergence contribution not accounted in the lens model that leads to the same observables in position and relative fluxes but rescales the time delays
Returns:

arrival time of image positions in units of days

curl(x, y, kwargs, k=None, diff=None, diff_method='square')[source]

curl computation F_xy - F_yx

Parameters:
  • x (numpy array) – x-position (preferentially arcsec)
  • y (numpy array) – y-position (preferentially arcsec)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • k – only evaluate the k-th lens model
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
Returns:

curl at position (x, y)

fermat_potential(x_image, y_image, kwargs_lens, x_source=None, y_source=None)[source]

fermat potential (negative sign means earlier arrival time) for Multi-plane lensing, it computes the effective Fermat potential (derived from the arrival time and subtracted off the time-delay distance for the given cosmology). The units are given in arcsecond square.

Parameters:
  • x_image – image position
  • y_image – image position
  • x_source – source position
  • y_source – source position
  • kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes
Returns:

fermat potential in arcsec**2 without geometry term (second part of Eqn 1 in Suyu et al. 2013) as a list

flexion(x, y, kwargs, k=None, diff=1e-06, hessian_diff=True)[source]

third derivatives (flexion)

Parameters:
  • x (numpy array) – x-position (preferentially arcsec)
  • y (numpy array) – y-position (preferentially arcsec)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • k – int or None, if set, only evaluates the differential from one model component
  • diff – numerical differential length of Flexion
  • hessian_diff – boolean, if true also computes the numerical differential length of Hessian (optional)
Returns:

f_xxx, f_xxy, f_xyy, f_yyy

gamma(x, y, kwargs, k=None, diff=None, diff_method='square')[source]

shear computation g1 = 1/2(d^2phi/dx^2 - d^2phi/dy^2) g2 = d^2phi/dxdy

Parameters:
  • x (numpy array) – x-position (preferentially arcsec)
  • y (numpy array) – y-position (preferentially arcsec)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • k – only evaluate the k-th lens model
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
Returns:

gamma1, gamma2

hessian(x, y, kwargs, k=None, diff=None, diff_method='square')[source]

hessian matrix

Parameters:
  • x (numpy array) – x-position (preferentially arcsec)
  • y (numpy array) – y-position (preferentially arcsec)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • k – only evaluate the k-th lens model
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
Returns:

f_xx, f_xy, f_yx, f_yy components

kappa(x, y, kwargs, k=None, diff=None, diff_method='square')[source]

lensing convergence k = 1/2 laplacian(phi)

Parameters:
  • x (numpy array) – x-position (preferentially arcsec)
  • y (numpy array) – y-position (preferentially arcsec)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • k – only evaluate the k-th lens model
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
Returns:

lensing convergence

magnification(x, y, kwargs, k=None, diff=None, diff_method='square')[source]

mag = 1/det(A) A = 1 - d^2phi/d_ij

Parameters:
  • x (numpy array) – x-position (preferentially arcsec)
  • y (numpy array) – y-position (preferentially arcsec)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • k – only evaluate the k-th lens model
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
Returns:

magnification

potential(x, y, kwargs, k=None)[source]

lensing potential

Parameters:
  • x (numpy array) – x-position (preferentially arcsec)
  • y (numpy array) – y-position (preferentially arcsec)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • k – only evaluate the k-th lens model
Returns:

lensing potential in units of arcsec^2

ray_shooting(x, y, kwargs, k=None)[source]

maps image to source position (inverse deflection)

Parameters:
  • x (numpy array) – x-position (preferentially arcsec)
  • y (numpy array) – y-position (preferentially arcsec)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • k – only evaluate the k-th lens model
Returns:

source plane positions corresponding to (x, y) in the image plane

set_dynamic()[source]

deletes cache for static setting and makes sure the observed convention in the position of lensing profiles in the multi-plane setting is enabled. Dynamic is the default setting of this class enabling an accurate computation of lensing quantities with different parameters in the lensing profiles.

Returns:None
set_static(kwargs)[source]

set this instance to a static lens model. This can improve the speed in evaluating lensing quantities at different positions but must not be used with different lens model parameters!

Parameters:kwargs – lens model keyword argument list
Returns:kwargs_updated (in case of image position convention in multiplane lensing this is changed)

lenstronomy.LensModel.lens_model_extensions module

class lenstronomy.LensModel.lens_model_extensions.LensModelExtensions(lensModel)[source]

Bases: object

class with extension routines not part of the LensModel core routines

critical_curve_caustics(kwargs_lens, compute_window=5, grid_scale=0.01)[source]
Parameters:
  • kwargs_lens – lens model kwargs
  • compute_window – window size in arcsec where the critical curve is computed
  • grid_scale – numerical grid spacing of the computation of the critical curves
Returns:

lists of ra and dec arrays corresponding to different disconnected critical curves and their caustic counterparts

critical_curve_tiling(kwargs_lens, compute_window=5, start_scale=0.5, max_order=10)[source]
Parameters:
  • kwargs_lens – lens model keyword argument list
  • compute_window – total window in the image plane where to search for critical curves
  • start_scale – float, angular scale on which to start the tiling from (if there are two distinct curves in a region, it might only find one.
  • max_order – int, maximum order in the tiling to compute critical curve triangles
Returns:

list of positions representing coordinates of the critical curve (in RA and DEC)

curved_arc_estimate(x, y, kwargs_lens, smoothing=None, smoothing_3rd=0.001, tan_diff=False)[source]

performs the estimation of the curved arc description at a particular position of an arbitrary lens profile

Parameters:
  • x – float, x-position where the estimate is provided
  • y – float, y-position where the estimate is provided
  • kwargs_lens – lens model keyword arguments
  • smoothing – (optional) finite differential of second derivative (radial and tangential stretches)
  • smoothing_3rd – differential scale for third derivative to estimate the tangential curvature
  • tan_diff – boolean, if True, also returns the relative tangential stretch differential in tangential direction
Returns:

keyword argument list corresponding to a CURVED_ARC profile at (x, y) given the initial lens model

hessian_eigenvectors(x, y, kwargs_lens, diff=None)[source]

computes magnification eigenvectors at position (x, y)

Parameters:
  • x – x-position
  • y – y-position
  • kwargs_lens – lens model keyword arguments
Returns:

radial stretch, tangential stretch

magnification_finite(x_pos, y_pos, kwargs_lens, source_sigma=0.003, window_size=0.1, grid_number=100, polar_grid=False, aspect_ratio=0.5)[source]

returns the magnification of an extended source with Gaussian light profile :param x_pos: x-axis positons of point sources :param y_pos: y-axis position of point sources :param kwargs_lens: lens model kwargs :param source_sigma: Gaussian sigma in arc sec in source :param window_size: size of window to compute the finite flux :param grid_number: number of grid cells per axis in the window to numerically compute the flux :return: numerically computed brightness of the sources

magnification_finite_adaptive(x_image, y_image, source_x, source_y, kwargs_lens, source_fwhm_parsec, z_source, cosmo=None, grid_resolution=None, grid_radius_arcsec=None, axis_ratio=0.5, tol=0.001, step_size=0.05, use_largest_eigenvalue=True, source_light_model='SINGLE_GAUSSIAN', dx=None, dy=None, size_scale=None, amp_scale=None, fixed_aperture_size=False)[source]

This method computes image magnifications with a finite-size background source assuming a Gaussian or a double Gaussian source light profile. It can be much faster that magnification_finite for lens models with many deflectors and a compact source. This is because most pixels in a rectangular window around a lensed image of a compact source do not map onto the source, and therefore don’t contribute to the integrated flux in the image plane.

Rather than ray tracing through a rectangular grid, this routine accelerates the computation of image magnifications with finite-size sources by ray tracing through an elliptical region oriented such that tracks the surface brightness of the lensed image. The aperture size is initially quite small, and increases in size until the flux inside of it (and hence the magnification) converges. The orientation of the elliptical aperture is computed from the magnification tensor evaluated at the image coordinate.

If for whatever reason you prefer a circular aperture to the elliptical approximation using the hessian eigenvectors, you can just set axis_ratio = 1.

To use the eigenvalues of the hessian matrix to estimate the optimum axis ratio, set axis_ratio = 0.

The default settings for the grid resolution and ray tracing window size work well for sources with fwhm between 0.5 - 100 pc.

Parameters:
  • x_image – a list or array of x coordinates [units arcsec]
  • y_image – a list or array of y coordinates [units arcsec]
  • kwargs_lens – keyword arguments for the lens model
  • source_fwhm_parsec – the size of the background source [units parsec]
  • z_source – the source redshift
  • cosmo – (optional) an instance of astropy.cosmology; if not specified, a default cosmology will be used
  • grid_resolution – the grid resolution in units arcsec/pixel; if not specified, an appropriate value will be estimated from the source size
  • grid_radius_arcsec – (optional) the size of the ray tracing region in arcsec; if not specified, an appropriate value will be estimated from the source size
  • axis_ratio – the axis ratio of the ellipse used for ray tracing; if axis_ratio = 0, then the eigenvalues the hessian matrix will be used to estimate an appropriate axis ratio. Be warned: if the image is highly magnified it will tend to curve out of the resulting ellipse
  • tol – tolerance for convergence in the magnification
  • step_size – sets the increment for the successively larger ray tracing windows
  • use_largest_eigenvalue – bool; if True, then the major axis of the ray tracing ellipse region will be aligned with the eigenvector corresponding to the largest eigenvalue of the hessian matrix
  • source_light_model – the model for backgourn source light; currently implemented are ‘SINGLE_GAUSSIAN’ and ‘DOUBLE_GAUSSIAN’.
  • dx – used with source model ‘DOUBLE_GAUSSIAN’, the offset of the second source light profile from the first [arcsec]
  • dy – used with source model ‘DOUBLE_GAUSSIAN’, the offset of the second source light profile from the first [arcsec]
  • size_scale – used with source model ‘DOUBLE_GAUSSIAN’, the size of the second source light profile relative to the first
  • amp_scale – used with source model ‘DOUBLE_GAUSSIAN’, the peak brightness of the second source light profile relative to the first
  • fixed_aperture_size – bool, if True the flux is computed inside a fixed aperture size with radius grid_radius_arcsec
Returns:

an array of image magnifications

radial_tangential_differentials(x, y, kwargs_lens, center_x=0, center_y=0, smoothing_3rd=0.001, smoothing_2nd=None)[source]

computes the differentials in stretches and directions

Parameters:
  • x – x-position
  • y – y-position
  • kwargs_lens – lens model keyword arguments
  • center_x – x-coord of center towards which the rotation direction is defined
  • center_y – x-coord of center towards which the rotation direction is defined
  • smoothing_3rd – finite differential length of third order in units of angle
  • smoothing_2nd – float or None, finite average differential scale of Hessian
Returns:

radial_tangential_stretch(x, y, kwargs_lens, diff=None, ra_0=0, dec_0=0, coordinate_frame_definitions=False)[source]

computes the radial and tangential stretches at a given position

Parameters:
  • x – x-position
  • y – y-position
  • kwargs_lens – lens model keyword arguments
  • diff – float or None, finite average differential scale
Returns:

radial stretch, tangential stretch

tangential_average(x, y, kwargs_lens, dr, smoothing=None, num_average=9)[source]

computes average tangential stretch around position (x, y) within dr in radial direction

Parameters:
  • x – x-position (float)
  • y – y-position (float)
  • kwargs_lens – lens model keyword argument list
  • dr – averaging scale in radial direction
  • smoothing – smoothing scale of derivative
  • num_average – integer, number of points averaged over within dr in the radial direction
Returns:

zoom_source(x_pos, y_pos, kwargs_lens, source_sigma=0.003, window_size=0.1, grid_number=100, shape='GAUSSIAN')[source]

computes the surface brightness on an image with a zoomed window

Parameters:
  • x_pos – angular coordinate of center of image
  • y_pos – angular coordinate of center of image
  • kwargs_lens – lens model parameter list
  • source_sigma – source size (in angular units)
  • window_size – window size in angular units
  • grid_number – number of grid points per axis
  • shape – string, shape of source, supports ‘GAUSSIAN’ and ‘TORUS
Returns:

2d numpy array

lenstronomy.LensModel.lens_param module

class lenstronomy.LensModel.lens_param.LensParam(lens_model_list, kwargs_fixed, kwargs_lower=None, kwargs_upper=None, num_images=0, solver_type='NONE', num_shapelet_lens=0)[source]

Bases: object

class to handle the lens model parameter

getParams(args, i)[source]
num_param()[source]
Returns:
setParams(kwargs_list)[source]
Parameters:kwargs
Returns:

lenstronomy.LensModel.multi_plane module

class lenstronomy.LensModel.multi_plane.MultiPlane(z_source, lens_model_list, lens_redshift_list, cosmo=None, numerical_alpha_class=None, observed_convention_index=None, ignore_observed_positions=False, z_source_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100)[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.

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

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

travel time in unit of days

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

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]

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

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
  • theta_y – angle in y-direction on the image
  • kwargs_lens
  • check_convention – flag to check the image position convention (leave this alone)
Returns:

angles in the source plane

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

ray-tracing through parts of the coin, 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! This can lead to duplications in the computation of deflection angles.
  • check_convention – flag to check the image position convention (leave this alone)
  • 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

set_dynamic()[source]
Returns:
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
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

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
class lenstronomy.LensModel.multi_plane.PhysicalLocation[source]

Bases: object

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

class lenstronomy.LensModel.multi_plane.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

lenstronomy.LensModel.multi_plane_base module

class lenstronomy.LensModel.multi_plane_base.MultiPlaneBase(lens_model_list, lens_redshift_list, z_source_convention, cosmo=None, numerical_alpha_class=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100)[source]

Bases: lenstronomy.LensModel.profile_list_base.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.

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]

ray_shooting_partial(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 coin, 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

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

lenstronomy.LensModel.profile_integrals module

class lenstronomy.LensModel.profile_integrals.ProfileIntegrals(profile_class)[source]

Bases: object

class to perform integrals of spherical profiles to compute: - projected densities - enclosed densities - projected enclosed densities

density_2d(r, kwargs_profile, lens_param=False)[source]

computes the projected density along the line-of-sight :param r: radius (arcsec) :param kwargs_profile: keyword argument list with lens model parameters :param lens_param: boolean, if True uses the lens model parameterization in computing the 3d density convention and the return is the convergence :return: 2d projected density at projected radius r

mass_enclosed_2d(r, kwargs_profile)[source]

computes the mass enclosed the projected line-of-sight :param r: radius (arcsec) :param kwargs_profile: keyword argument list with lens model parameters :return: projected mass enclosed radius r

mass_enclosed_3d(r, kwargs_profile)[source]

computes the mass enclosed within a sphere of radius r :param r: radius (arcsec) :param kwargs_profile: keyword argument list with lens model parameters :return: 3d mass enclosed of r

lenstronomy.LensModel.profile_list_base module

class lenstronomy.LensModel.profile_list_base.ProfileListBase(lens_model_list, numerical_alpha_class=None, lens_redshift_list=None, z_source_convention=None)[source]

Bases: object

class that manages the list of lens model class instances. This class is applicable for single plane and multi plane lensing

set_dynamic()[source]

frees cache set by static model (if exists) and re-computes all lensing quantities each time a definition is called assuming different parameters are executed. This is the default mode if not specified as set_static()

Returns:None
set_static(kwargs_list)[source]
Parameters:kwargs_list – list of keyword arguments for each profile
Returns:kwargs_list

lenstronomy.LensModel.single_plane module

class lenstronomy.LensModel.single_plane.SinglePlane(lens_model_list, numerical_alpha_class=None, lens_redshift_list=None, z_source_convention=None)[source]

Bases: lenstronomy.LensModel.profile_list_base.ProfileListBase

class to handle an arbitrary list of lens models in a single lensing plane

alpha(x, y, kwargs, k=None)[source]

deflection angles :param x: x-position (preferentially arcsec) :type x: numpy array :param y: y-position (preferentially arcsec) :type y: numpy array :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes :param k: only evaluate the k-th lens model :return: deflection angles in units of arcsec

density(r, kwargs, bool_list=None)[source]

3d mass density at radius r The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – radius (in angular units)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • bool_list – list of bools that are part of the output
Returns:

mass density at radius r (in angular units, modulo epsilon_crit)

fermat_potential(x_image, y_image, kwargs_lens, x_source=None, y_source=None, k=None)[source]

fermat potential (negative sign means earlier arrival time)

Parameters:
  • x_image – image position
  • y_image – image position
  • x_source – source position
  • y_source – source position
  • kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes
Returns:

fermat potential in arcsec**2 without geometry term (second part of Eqn 1 in Suyu et al. 2013) as a list

hessian(x, y, kwargs, k=None)[source]

hessian matrix :param x: x-position (preferentially arcsec) :type x: numpy array :param y: y-position (preferentially arcsec) :type y: numpy array :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes :param k: only evaluate the k-th lens model :return: f_xx, f_xy, f_yx, f_yy components

mass_2d(r, kwargs, bool_list=None)[source]

computes the mass enclosed a projected (2d) radius r

Parameters:
  • r – radius (in angular units)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • bool_list – list of bools that are part of the output
Returns:

projected mass (in angular units, modulo epsilon_crit)

mass_3d(r, kwargs, bool_list=None)[source]

computes the mass within a 3d sphere of radius r

if you want to have physical units of kg, you need to multiply by this factor: const.arcsec ** 2 * self._cosmo.dd * self._cosmo.ds / self._cosmo.dds * const.Mpc * const.c ** 2 / (4 * np.pi * const.G) grav_pot = -const.G * mass_dim / (r * const.arcsec * self._cosmo.dd * const.Mpc)

Parameters:
  • r – radius (in angular units)
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes
  • bool_list – list of bools that are part of the output
Returns:

mass (in angular units, modulo epsilon_crit)

potential(x, y, kwargs, k=None)[source]

lensing potential :param x: x-position (preferentially arcsec) :type x: numpy array :param y: y-position (preferentially arcsec) :type y: numpy array :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes :param k: only evaluate the k-th lens model :return: lensing potential in units of arcsec^2

ray_shooting(x, y, kwargs, k=None)[source]

maps image to source position (inverse deflection) :param x: x-position (preferentially arcsec) :type x: numpy array :param y: y-position (preferentially arcsec) :type y: numpy array :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes :param k: only evaluate the k-th lens model :return: source plane positions corresponding to (x, y) in the image plane

Module contents