jaxtronomy.LensModel package

Subpackages

Submodules

jaxtronomy.LensModel.lens_model module

class LensModel(lens_model_list, z_lens=None, z_source=None, lens_redshift_list=None, cosmo=None, multi_plane=False, observed_convention_index=None, z_source_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, profile_kwargs_list=None, decouple_multi_plane=False, kwargs_multiplane_model=None, distance_ratio_sampling=False, cosmology_sampling=False, cosmology_model='FlatLambdaCDM')[source]

Bases: object

Class to handle an arbitrary list of lens models.

This is the main lenstronomy LensModel API for all other modules.

__init__(lens_model_list, z_lens=None, z_source=None, lens_redshift_list=None, cosmo=None, multi_plane=False, observed_convention_index=None, z_source_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, profile_kwargs_list=None, decouple_multi_plane=False, kwargs_multiplane_model=None, distance_ratio_sampling=False, cosmology_sampling=False, cosmology_model='FlatLambdaCDM')[source]
Parameters:
  • lens_model_list – list of strings with lens model names

  • z_lens – redshift of the deflector (only considered when operating in single plane mode). Is only needed for specific functions that require a cosmology.

  • z_source – redshift of the source: Needed in multi_plane option only, not required for the core functionalities in the single plane mode.

  • lens_redshift_list – list of deflector redshift (corresponding to the lens model list), only applicable in multi_plane mode.

  • cosmo – instance of the astropy cosmology class. If not specified, uses the default cosmology.

  • multi_plane – bool, if True, uses multi-plane mode. Default is False.

  • 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

  • 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_interp – boolean (only employed in multi-plane mode), interpolates astropy.cosmology distances for faster calls when accessing several lensing planes

  • 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.

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

  • cosmology_sampling – bool, if True, will use sampled cosmology to update T_ij value in multi-lens plane computation. Not supported in JAXtronomy.

  • cosmology_model – str, name of the cosmology model to be used. Default is ‘FlatLambdaCDM’.

info()[source]

Shows what models are being initialized and what parameters are being requested for. Should be used outside of JIT.

Returns:

None

check_parameters(kwargs_list)[source]

Checks whether parameter list is consistent with the parameters required by the model. Should be used outside of JIT.

Parameters:

kwargs_list – keyword argument list as parameterised models

Returns:

None or raise ValueError with error message of what parameter is not supported.

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 (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

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

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

arrival_time(x_image, y_image, kwargs_lens, kappa_ext=0, x_source=None, y_source=None)[source]

Arrival time of images relative to a straight line without lensing. Negative values correspond to images arriving earlier, and positive signs correspond to images arriving later.

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

  • x_source – source position (optional), otherwise computed with ray-tracing

  • y_source – source position (optional), otherwise computed with ray-tracing

Returns:

arrival time of image positions in units of days

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 (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

lensing potential in units of arcsec^2

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 (None, int, or tuple of ints) – 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

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 (None, int, or tuple of ints) – 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 (None, int, or tuple of ints) – 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

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 (None, int, or tuple of ints) – 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)

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 (None, int, or tuple of ints) – 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

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

magnification.

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 (None, int, or tuple of ints) – 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

flexion(x, y, kwargs, k=None, diff=0.0001, hessian_diff=False)[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 (None, int, or tuple of ints) – 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

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)

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

property ddt_scaling

Ratio of time-delay distance between the source redshift and the time-delay distance to the z_source_convention.

Returns:

update_cosmology(cosmo=None)[source]

Returns an error if the user tries to update cosmology.

jaxtronomy.LensModel.profile_list_base module

class ProfileListBase(lens_model_list, profile_kwargs_list=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

__init__(lens_model_list, profile_kwargs_list=None, lens_redshift_list=None, z_source_convention=None)[source]
Parameters:
  • lens_model_list – list of strings with lens model names

  • 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.

set_static(kwargs_list)[source]
Parameters:

kwargs_list – list of keyword arguments for each profile

Returns:

kwargs_list

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

model_info()[source]

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

Returns:

None

check_parameters(kwargs_list)[source]

Checks whether the parameter list is consistent with the parameters required by the lens (mass) model.

Parameters:

kwargs_list – keyword argument list as parameterised models

Returns:

None or raise ValueError with error message of what parameter is not supported.

jaxtronomy.LensModel.single_plane module

class SinglePlane(lens_model_list, profile_kwargs_list=None, lens_redshift_list=None, z_source_convention=None, alpha_scaling=1)[source]

Bases: ProfileListBase

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

__init__(lens_model_list, profile_kwargs_list=None, lens_redshift_list=None, z_source_convention=None, alpha_scaling=1)[source]
Parameters:
  • lens_model_list – list of strings with lens model names

  • 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.

  • alpha_scaling – scaling factor of deflection angle relative to z_source_convention

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 (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

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

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

  • k (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

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

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 (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

lensing potential in units of arcsec^2

alpha(x, y, kwargs, k=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 (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

deflection angles in units of arcsec

hessian(x, y, kwargs, k=None)[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 (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

f_xx, f_xy, f_yx, f_yy components

change_redshift_scaling(alpha_scaling)[source]
Parameters:

alpha_scaling – scaling parameter of the reduced deflection angle relative to z_source_convention

Returns:

None

property alpha_scaling

Deflector scaling factor.

Returns:

alpha_scaling

mass_3d(r, kwargs, k=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 * jnp.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

  • k (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

mass (in angular units, modulo epsilon_crit)

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

Computes the mass enclosed a projected (2d) radius r.

The mass definition is such that:

\[\alpha = mass_2d / r / \pi\]

with alpha is the deflection angle

Parameters:
  • r – radius (in angular units)

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

  • k (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

projected mass (in angular units, modulo epsilon_crit)

density(r, kwargs, k=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

  • k (None, int, or tuple of ints) – only evaluate the k-th lens model

Returns:

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

Module contents