lenstronomy.LensModel.Profiles package

Submodules

lenstronomy.LensModel.Profiles.arc_perturbations module

class ArcPerturbations[source]

Bases: LensProfileBase

Uses radial and tangential fourier modes within a specific range in both directions to perturb a lensing potential.

param_names = ['coeff', 'd_r', 'd_phi', 'center_x', 'center_y']
__init__()[source]
function(x, y, coeff, d_r, d_phi, center_x, center_y)[source]
Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • coeff – float, amplitude of basis

  • d_r – period of radial sinusoidal in units of angle

  • d_phi – period of tangential sinusoidal in radian

  • center_x – center of rotation for tangential basis

  • center_y – center of rotation for tangential basis

Returns:

derivatives(x, y, coeff, d_r, d_phi, center_x, center_y)[source]
Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • coeff – float, amplitude of basis

  • d_r – period of radial sinusoidal in units of angle

  • d_phi – period of tangential sinusoidal in radian

  • center_x – center of rotation for tangential basis

  • center_y – center of rotation for tangential basis

Returns:

f_x, f_y

hessian(x, y, coeff, d_r, d_phi, center_x, center_y)[source]
Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • coeff – float, amplitude of basis

  • d_r – period of radial sinusoidal in units of angle

  • d_phi – period of tangential sinusoidal in radian

  • center_x – center of rotation for tangential basis

  • center_y – center of rotation for tangential basis

Returns:

f_xx, f_yy, f_xy

lenstronomy.LensModel.Profiles.base_profile module

class LensProfileBase(*args, **kwargs)[source]

Bases: object

This class acts as the base class of all lens model functions and indicates raise statements and default outputs if these functions are not defined in the specific lens model class.

To implement a new lens model profile you should: 1. make a new python file in this folder 2. create a class inheriting this class; YourModel(LensProfileBase) 3. write new definitions following the same input and output conventions as this base class - function(x, y, <other parameters>) - derivatives(x, y, <other parameters>) - hessian(x, y, <other parameters>) 4. set the variables for sampling the new profile

param_names = [“param1”, “param2”, …] lower_limit_default = {“param1”: value, “param2: value, …} upper_limit_default = {“param1”: value, “param2: value, …}

  1. give the new profile a meaningful name and add it in the LensModel.profile_list_base class

  2. write test functions in the test/test_LensModel/test_Profiles folder with a new file with test_<profile name>.py

  3. add a test to check whether the numerical derivatives of the lensing potential and deflection angles result in

    the corresponding quantities in test/test_LensModel/test_numerical_lens_differentials.py

With that, you should be good to go and import and use it for any purpose. Further definitions in the class are optional and only used for certain applications (such as kinematics)

__init__(*args, **kwargs)[source]
function(*args, **kwargs)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

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

Deflection angles.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

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

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

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

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity. (optional definition)

\[\kappa(x, y) = \int_{-\infty}^{\infty} \rho(x, y, z) dz\]
Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

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

Mass enclosed within a 3D sphere or radius r given a lens parameterization with angular units. The input parameter are identical as for the derivatives definition. (optional definition)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

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

Two-dimensional enclosed mass at radius r (optional definition)

\[M_{2d}(R) = \int_{0}^{R} \rho_{2d}(r) 2\pi r dr\]

with \(\rho_{2d}(r)\) is the density_2d_lens() definition

The mass definition is such that:

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

with alpha is the deflection angle

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

set_static(**kwargs)[source]

Pre-computes certain computations that do only relate to the lens model parameters and not to the specific position where to evaluate the lens model.

Parameters:

kwargs – lens model parameters

Returns:

no return, for certain lens model some private self variables are initiated

set_dynamic()[source]
Returns:

no return, deletes pre-computed variables for certain lens models

lenstronomy.LensModel.Profiles.blank_plane module

class BlankPlane(*args, **kwargs)[source]

Bases: LensProfileBase

Class for a blank lens plane.

This is needed to create a blank plane that has a source without any lensing effect, when distance ratios are sampled in multi-lens-plane and multi-source plane case.

param_names = []
lower_limit_default = {}
upper_limit_default = {}
function(x, y)[source]
derivatives(x, y)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • alpha_x – shift in x-direction (angle)

  • alpha_y – shift in y-direction (angle)

Returns:

deflection in x- and y-direction

hessian(x, y)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • alpha_x – shift in x-direction (angle)

  • alpha_y – shift in y-direction (angle)

Returns:

hessian elements f_xx, f_xy, f_yx, f_yy

lenstronomy.LensModel.Profiles.bpl module

class BPL[source]

Bases: LensProfileBase

Broken Power Law (BPL) mass profile.

The 3D density follows Du et al. (2020):

\[\begin{split}\rho(r) = \begin{cases} \rho_c\,(r/r_c)^{-\alpha_c} & r \le r_c \\ \rho_c\,(r/r_c)^{-\alpha} & r \ge r_c \end{cases}\end{split}\]

Assuming a homoeoidal (elliptically symmetric) projected mass distribution, the convergence can be written as:

\[\kappa(R) = \kappa_1(R) + \kappa_2(R),\]

with a elliptical power-law term

\[\kappa_1(R) = \frac{3-\alpha}{2}\left(\frac{b}{R}\right)^{\alpha-1},\]

and a core/break correction (kappa_2) that is non-zero only for (Rle r_c) (Du et al. 2020).

The elliptical radius is defined in the lenstronomy convention as

\[R \equiv R_{\rm el} = \sqrt{q x^2 + y^2/q},\]

where (q) is the minor/major axis ratio and ((x, y)) are coordinates in the major-axis-aligned frame.

The analytic deflection and shear expressions are implemented in BPLMajorAxis using the complex BK75 formalism and the special series (S_0) and (S_2) defined in Du et al. (2020). The lensing potential is evaluated via 1D numerical quadrature.

param_names = ['b', 'a', 'a_c', 'r_c', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'a': 1, 'a_c': 0, 'b': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'r_c': 0}
upper_limit_default = {'a': 3, 'a_c': 3, 'b': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'r_c': 100}
__init__()[source]

Initialize the BPL profile.

param_conv(b, a, a_c, r_c, e1, e2)[source]

Converts parameters as defined in this class to the parameters used in the BPLMajorAxis() class.

Parameters:
  • b – lens strength parameter as defined in the profile class

  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • r_c – break radius (r_c)

  • e1 – eccentricity modulus

  • e2 – eccentricity modulus

Returns:

b, a, a_c, r_c, q, phi_G

set_static(b, a, a_c, r_c, e1, e2, center_x=0, center_y=0)[source]

Cache converted parameters for repeated calls.

Parameters:
  • b – lens strength parameter

  • a – outer 3D slope (alpha)

  • a_c – inner 3D slope (alpha_c)

  • r_c – break radius (r_c)

  • e1 – eccentricity modulus

  • e2 – eccentricity modulus

  • center_x – profile center

  • center_y – profile center

Returns:

self variables set

set_dynamic()[source]

Disable static-parameter caching.

Returns:

None

function(x, y, b, a, a_c, r_c, e1, e2, center_x=0, center_y=0, target_precision=None, maxiter=None, **kwargs)[source]

Returns the lensing potential.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • b – lens strength parameter

  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • r_c – break radius (r_c)

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

  • target_precision – convergence threshold for internal S0/S2 series evaluation

  • maxiter – maximum iteration cap for internal S0/S2 series evaluation

Returns:

lensing potential

derivatives(x, y, b, a, a_c, r_c, e1, e2, center_x=0, center_y=0, target_precision=None, maxiter=None, **kwargs)[source]

Returns the deflection angles.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • b – lens strength parameter

  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • r_c – break radius (r_c)

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

  • target_precision – convergence threshold for internal S0 series evaluation

  • maxiter – maximum iteration cap for internal S0 series evaluation

Returns:

alpha_x, alpha_y

hessian(x, y, b, a, a_c, r_c, e1, e2, center_x=0, center_y=0, target_precision=None, maxiter=None, **kwargs)[source]

Hessian matrix of the lensing potential.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • b – lens strength parameter

  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • r_c – break radius (r_c)

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

  • target_precision – convergence threshold for internal S2 series evaluation

  • maxiter – maximum iteration cap for internal S2 series evaluation

Returns:

f_xx, f_xy, f_yx, f_yy

static Beta_func(a)[source]

Beta function coefficient (B(alpha)) defined in Du et al. (2020, Eq. 5).

Parameters:

a – outer slope (alpha)

Returns:

(B(alpha)=mathrm{B}(1/2,(alpha-1)/2))

rho_c_from_b(b, a, r_c)[source]

Compute (rho_c) from (b, a, r_c) using Du et al. (2020, Eq. 8), in lens units.

The normalization is defined such that (b^{alpha-1} = B(alpha),2/(3-alpha),rho_c,r_c^{alpha}).

Parameters:
  • b – lens strength parameter

  • a – outer slope (alpha)

  • r_c – break radius (r_c)

Returns:

central density (rho_c) (in internal lensing units)

mass_3d_lens(r, b, a, a_c, r_c, e1=None, e2=None)[source]

3D enclosed mass (M(<r)) for the BPL density profile.

Parameters:
  • r – 3D radius (can be scalar or array)

  • b – lens strength parameter

  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • r_c – break radius (r_c)

  • e1 – eccentricity component (not used)

  • e2 – eccentricity component (not used)

Returns:

enclosed 3D mass (M(<r))

class BPLMajorAxis(target_precision=1e-05, maxiter=4000)[source]

Bases: LensProfileBase

This class contains the function and the derivatives of the elliptical BPL profile.

In the major-axis-aligned frame, the complex conjugate deflection field for an elliptically symmetric surface density can be written (Bourassa & Kantowski 1975; Du et al. 2020)

\[\alpha^*(z)=\frac{2}{z}\int_0^{R_{\rm el}}\frac{\kappa(R)\,R\,dR}{\sqrt{1-\zeta^2 R^2}},\quad \zeta^2=(1/q-q)/z^2,\]

where (z=x+i y) and (R_{rm el}=sqrt{q x^2+y^2/q}). Substituting the BPL convergence yields closed-form expressions for the deflection and shear (Du et al. 2020, Eq. 18-26). The inner correction terms are evaluated via the series (S_0) (deflection) and (S_2) (shear), using Aitken-accelerated recursion for numerical stability.

param_names = ['b', 'a', 'a_c', 'r_c', 'center_x', 'center_y']
DEFAULT_TARGET_PRECISION = 1e-05
DEFAULT_MAXITER = 4000
__init__(target_precision=1e-05, maxiter=4000)[source]

Create a major-axis-aligned BPL evaluator.

Parameters:
  • target_precision – default convergence threshold passed to S0/S2 when not overridden per call

  • maxiter – default maximum iteration count passed to S0/S2 when not overridden per call

Returns:

self

function(x, y, b, a, a_c, r_c, q, target_precision=None, maxiter=None, **kwargs)[source]

Returns the lensing potential (computed via 1D numerical quadrature).

Parameters:
  • x – x-coordinate in image plane relative to center (major axis frame)

  • y – y-coordinate in image plane relative to center (major axis frame)

  • b – lens strength parameter

  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • r_c – break radius (r_c)

  • q – axis ratio (minor/major)

  • target_precision – convergence threshold for internal series (passed through)

  • maxiter – maximum iteration cap for internal series (passed through)

Returns:

lensing potential

derivatives(x, y, b, a, a_c, r_c, q, target_precision=None, maxiter=None)[source]

Returns the deflection angles.

The deflection is evaluated as (alpha^*=alpha_1^*+alpha_2^*) following Du et al. (2020, Eq. 18-22), where (alpha_1) is the EPL (Elliptical Power Law) term and (alpha_2) is the inner correction involving the series (S_0).

Parameters:
  • x – x-coordinate in image plane relative to center (major axis frame)

  • y – y-coordinate in image plane relative to center (major axis frame)

  • b – lens strength parameter

  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • r_c – break radius (r_c)

  • q – axis ratio (minor/major)

  • target_precision – convergence threshold for S0 recursion

  • maxiter – maximum iteration cap for S0 recursion

Returns:

alpha_x, alpha_y

hessian(x, y, b, a, a_c, r_c, q, target_precision=None, maxiter=None)[source]

Hessian matrix of the lensing potential.

This routine returns second derivatives computed from convergence and shear. The shear uses the EPL term and the inner correction term involving the series (S_2) (Du et al. 2020, Eq. 23-26).

Parameters:
  • x – x-coordinate in image plane relative to center (major axis frame)

  • y – y-coordinate in image plane relative to center (major axis frame)

  • b – lens strength parameter

  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • r_c – break radius (r_c)

  • q – axis ratio (minor/major)

  • target_precision – convergence threshold for S2 recursion

  • maxiter – maximum iteration cap for S2 recursion

Returns:

f_xx, f_xy, f_yx, f_yy

static Beta_func(a)[source]

Beta function coefficient (B(alpha)) defined in Du et al. (2020, Eq. 5).

Parameters:

a – outer slope (alpha)

Returns:

(B(alpha)=mathrm{B}(1/2,(alpha-1)/2))

F(a, z)[source]

Helper function F(a, z) used in the analytic expressions (Du et al. 2020, Eq. 21).

This is a special case of the generalized hypergeometric function ({}_3F_2), rewritten in terms of ({}_2F_1).

Parameters:
  • a – scalar parameter (typically ((3-alpha)/2) or ((3-alpha_c)/2))

  • z – complex argument (typically (C=r_c^2zeta^2))

Returns:

F(a, z)

exhyp2f1(a, b, c, z)[source]

Evaluate a numerically-stable form of ({}_2F_1) for specific parameter combinations.

When (c-a-b approx 1/2), apply a square-root transformation to improve convergence near branch cuts.

Parameters:
  • a – ({}_2F_1) parameter a

  • b – ({}_2F_1) parameter b

  • c – ({}_2F_1) parameter c

  • z – complex argument

Returns:

({}_2F_1(a,b;c;z)) evaluated stably

S0(a, a_c, C, R_el, r_c, target_precision, maxiter)[source]

Series S0 used in the deflection correction term (Du et al. 2020, Eq. 22).

Internally, this uses Aitken-accelerated recursion implemented in s0arr().

Parameters:
  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • C – complex coefficient (C=r_c^2zeta^2)

  • R_el – elliptical radius (R_{rm el})

  • r_c – break radius (r_c)

  • target_precision – convergence threshold for the recursion

  • maxiter – maximum iteration cap for the recursion

Returns:

complex series value S0 (same broadcast shape as inputs)

S2(a, a_c, C, R_el, r_c, target_precision, maxiter)[source]

Series S2 used in the shear correction term (Du et al. 2020, Eq. 26).

Internally, this uses Aitken-accelerated recursion implemented in s2arr().

Parameters:
  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • C – complex coefficient (C=r_c^2zeta^2)

  • R_el – elliptical radius (R_{rm el})

  • r_c – break radius (r_c)

  • target_precision – convergence threshold for the recursion

  • maxiter – maximum iteration cap for the recursion

Returns:

complex series value S2 (same broadcast shape as inputs)

s0arr(alpha, alphac, zel2, c, target_precision, maxiter=None)[source]

Vectorized evaluator for the S0 series recursion.

Parameters:
  • alpha – outer slope (alpha)

  • alphac – inner slope (alpha_c)

  • zel2 – (tilde z^2 = 1 - (R_{rm el}/r_c)^2) (array-like)

  • c – complex coefficient (C=r_c^2zeta^2) (array-like)

  • target_precision – convergence threshold

  • maxiter – maximum iteration cap (or None to use default)

Returns:

complex array of S0 values

s2arr(alpha, alphac, zel2, c, target_precision, maxiter=None)[source]

Vectorized evaluator for the S2 series recursion.

Parameters:
  • alpha – outer slope (alpha)

  • alphac – inner slope (alpha_c)

  • zel2 – (tilde z^2 = 1 - (R_{rm el}/r_c)^2) (array-like)

  • c – complex coefficient (C=r_c^2zeta^2) (array-like)

  • target_precision – convergence threshold

  • maxiter – maximum iteration cap (or None to use default)

Returns:

complex array of S2 values

kappa2func(b, a, a_c, r_c, R_el)[source]

Core/break correction to the convergence (kappa_2(R)) (Du et al. 2020, Eq. 14).

Parameters:
  • b – lens strength parameter

  • a – outer slope (alpha)

  • a_c – inner slope (alpha_c)

  • r_c – break radius (r_c)

  • R_el – elliptical radius (R_{rm el})

Returns:

(kappa_2) (same shape as R_el)

zel(R_el, r_c)[source]

Compute (tilde z = sqrt{1 - (R_{rm el}/r_c)^2}) used in Du et al. (2020).

Parameters:
  • R_el – elliptical radius (R_{rm el})

  • r_c – break radius (r_c)

Returns:

(tilde z) (same shape as R_el), with 0 for R_el >= r_c

kappa_mean(R, alpha, alpha_c, b, r_c)[source]

Mean convergence (barkappa(R)) inside projected radius R.

Parameters:
  • R – projected radius (scalar)

  • alpha – outer slope (alpha)

  • alpha_c – inner slope (alpha_c)

  • b – lens strength parameter

  • r_c – break radius (r_c)

Returns:

mean convergence (barkappa(R))

phi_r(xi, alpha, alpha_c, b, r_c)[source]

Radial integrand kappa_mean(xi) * xi used in the potential quadrature.

Parameters:
  • xi – projected radius xi

  • alpha – outer slope (alpha)

  • alpha_c – inner slope (alpha_c)

  • b – lens strength parameter

  • r_c – break radius (r_c)

Returns:

kappa_mean(xi) * xi

integrand_psi(u, x, y, alpha, alpha_c, b, r_c, q)[source]

Integrand for the 1D potential quadrature.

Parameters:
  • u – integration variable in (0, 1)

  • x – x-coordinate in major-axis frame

  • y – y-coordinate in major-axis frame

  • alpha – outer slope (alpha)

  • alpha_c – inner slope (alpha_c)

  • b – lens strength parameter

  • r_c – break radius (r_c)

  • q – axis ratio (minor/major)

Returns:

integrand value for the potential (psi)

lenstronomy.LensModel.Profiles.chameleon module

class Chameleon(static=False)[source]

Bases: LensProfileBase

Class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile.

param_names = ['alpha_1', 'w_c', 'w_t', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'alpha_1': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.8, 'e2': -0.8, 'w_c': 0, 'w_t': 0}
upper_limit_default = {'alpha_1': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.8, 'e2': 0.8, 'w_c': 100, 'w_t': 100}
__init__(static=False)[source]
function(x, y, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – ra-coordinate

  • y – dec-coordinate

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • w_c – see Suyu+2014

  • w_t – see Suyu+2014

  • e1 – ellipticity parameter

  • e2 – ellipticity parameter

  • center_x – ra center

  • center_y – dec center

Returns:

lensing potential

derivatives(x, y, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – ra-coordinate

  • y – dec-coordinate

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • w_c – see Suyu+2014

  • w_t – see Suyu+2014

  • e1 – ellipticity parameter

  • e2 – ellipticity parameter

  • center_x – ra center

  • center_y – dec center

Returns:

deflection angles (RA, DEC)

hessian(x, y, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – ra-coordinate

  • y – dec-coordinate

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • w_c – see Suyu+2014

  • w_t – see Suyu+2014

  • e1 – ellipticity parameter

  • e2 – ellipticity parameter

  • center_x – ra center

  • center_y – dec center

Returns:

second derivatives of the lensing potential (Hessian: f_xx, f_xy, f_yx, f_yy)

density_lens(r, alpha_1, w_c, w_t, e1=0, e2=0, center_x=0, center_y=0)[source]

Spherical average density as a function of 3d radius.

Parameters:
  • r – 3d radius

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • w_c – see Suyu+2014

  • w_t – see Suyu+2014

  • e1 – ellipticity parameter

  • e2 – ellipticity parameter

  • center_x – ra center

  • center_y – dec center

Returns:

matter density at 3d radius r

mass_3d_lens(r, alpha_1, w_c, w_t, e1=0, e2=0, center_x=0, center_y=0)[source]

Mass enclosed 3d radius.

Parameters:
  • r – 3d radius

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • w_c – see Suyu+2014

  • w_t – see Suyu+2014

  • e1 – ellipticity parameter

  • e2 – ellipticity parameter

  • center_x – ra center

  • center_y – dec center

Returns:

mass enclosed 3d radius r

param_convert(alpha_1, w_c, w_t, e1, e2)[source]

Convert the parameter alpha_1 (deflection angle one arcsecond from the center) into the “Einstein radius” scale parameter of the two NIE profiles.

Parameters:
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • w_c – see Suyu+2014

  • w_t – see Suyu+2014

  • e1 – eccentricity modulus

  • e2 – eccentricity modulus

Returns:

set_static(alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • alpha_1

  • w_c

  • w_t

  • e1

  • e2

  • center_x

  • center_y

Returns:

set_dynamic()[source]
Returns:

class DoubleChameleon[source]

Bases: LensProfileBase

Class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile.

param_names = ['alpha_1', 'ratio', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'center_x', 'center_y']
lower_limit_default = {'alpha_1': 0, 'center_x': -100, 'center_y': -100, 'e11': -0.8, 'e12': -0.8, 'e21': -0.8, 'e22': -0.8, 'ratio': 0, 'w_c1': 0, 'w_c2': 0, 'w_t1': 0, 'w_t2': 0}
upper_limit_default = {'alpha_1': 100, 'center_x': 100, 'center_y': 100, 'e11': 0.8, 'e12': 0.8, 'e21': 0.8, 'e22': 0.8, 'ratio': 100, 'w_c1': 100, 'w_c2': 100, 'w_t1': 100, 'w_t2': 100}
__init__()[source]
function(x, y, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
Parameters:
  • x – ra-coordinate

  • y – dec-coordinate

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • w_c1 – Suyu+2014 for first profile

  • w_t1 – Suyu+2014 for first profile

  • e11 – ellipticity parameter for first profile

  • e21 – ellipticity parameter for first profile

  • w_c2 – Suyu+2014 for second profile

  • w_t2 – Suyu+2014 for second profile

  • e12 – ellipticity parameter for second profile

  • e22 – ellipticity parameter for second profile

  • center_x – ra center

  • center_y – dec center

Returns:

lensing potential

derivatives(x, y, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
Parameters:
  • x – ra-coordinate

  • y – dec-coordinate

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • w_c1 – Suyu+2014 for first profile

  • w_t1 – Suyu+2014 for first profile

  • e11 – ellipticity parameter for first profile

  • e21 – ellipticity parameter for first profile

  • w_c2 – Suyu+2014 for second profile

  • w_t2 – Suyu+2014 for second profile

  • e12 – ellipticity parameter for second profile

  • e22 – ellipticity parameter for second profile^V

  • center_x – ra center

  • center_y – dec center

Returns:

deflection angles (RA, DEC)

hessian(x, y, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
Parameters:
  • x – ra-coordinate

  • y – dec-coordinate

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • w_c1 – Suyu+2014 for first profile

  • w_t1 – Suyu+2014 for first profile

  • e11 – ellipticity parameter for first profile

  • e21 – ellipticity parameter for first profile

  • w_c2 – Suyu+2014 for second profile

  • w_t2 – Suyu+2014 for second profile

  • e12 – ellipticity parameter for second profile

  • e22 – ellipticity parameter for second profile

  • center_x – ra center

  • center_y – dec center

Returns:

second derivatives of the lensing potential (Hessian: f_xx, f_yy, f_xy)

density_lens(r, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
Parameters:
  • r – 3d radius

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • w_c1 – Suyu+2014 for first profile

  • w_t1 – Suyu+2014 for first profile

  • e11 – ellipticity parameter for first profile

  • e21 – ellipticity parameter for first profile

  • w_c2 – Suyu+2014 for second profile

  • w_t2 – Suyu+2014 for second profile

  • e12 – ellipticity parameter for second profile

  • e22 – ellipticity parameter for second profile

  • center_x – ra center

  • center_y – dec center

Returns:

3d density at radius r

mass_3d_lens(r, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
Parameters:
  • r – 3d radius

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • w_c1 – Suyu+2014 for first profile

  • w_t1 – Suyu+2014 for first profile

  • e11 – ellipticity parameter for first profile

  • e21 – ellipticity parameter for first profile

  • w_c2 – Suyu+2014 for second profile

  • w_t2 – Suyu+2014 for second profile

  • e12 – ellipticity parameter for second profile

  • e22 – ellipticity parameter for second profile

  • center_x – ra center

  • center_y – dec center

Returns:

mass enclosed 3d radius

set_static(alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]

Pre-computes certain computations that do only relate to the lens model parameters and not to the specific position where to evaluate the lens model.

Parameters:

kwargs – lens model parameters

Returns:

no return, for certain lens model some private self variables are initiated

set_dynamic()[source]
Returns:

no return, deletes pre-computed variables for certain lens models

class TripleChameleon[source]

Bases: LensProfileBase

Class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile.

param_names = ['alpha_1', 'ratio12', 'ratio13', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'w_c3', 'w_t3', 'e13', 'e23', 'center_x', 'center_y']
lower_limit_default = {'alpha_1': 0, 'center_x': -100, 'center_y': -100, 'e11': -0.8, 'e12': -0.8, 'e13': -0.8, 'e21': -0.8, 'e22': -0.8, 'e23': -0.8, 'ratio12': 0, 'ratio13': 0, 'w_c1': 0, 'w_c2': 0, 'w_c3': 0, 'w_t1': 0, 'w_t2': 0, 'w_t3': 0}
upper_limit_default = {'alpha_1': 100, 'center_x': 100, 'center_y': 100, 'e11': 0.8, 'e12': 0.8, 'e13': 0.8, 'e21': 0.8, 'e22': 0.8, 'e23': 0.8, 'ratio12': 100, 'ratio13': 100, 'w_c1': 100, 'w_c2': 100, 'w_c3': 100, 'w_t1': 100, 'w_t2': 100, 'w_t3': 100}
__init__()[source]
function(x, y, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
Parameters:
  • alpha_1

  • ratio12 – ratio of first to second amplitude

  • ratio13 – ratio of first to third amplitude

  • w_c1

  • w_t1

  • e11

  • e21

  • w_c2

  • w_t2

  • e12

  • e22

  • center_x

  • center_y

Returns:

derivatives(x, y, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
Parameters:
  • alpha_1

  • ratio12 – ratio of first to second amplitude

  • ratio13 – ratio of first to third amplidute

  • w_c1

  • w_t1

  • e11

  • e21

  • w_c2

  • w_t2

  • e12

  • e22

  • center_x

  • center_y

Returns:

hessian(x, y, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
Parameters:
  • alpha_1

  • ratio12 – ratio of first to second amplitude

  • ratio13 – ratio of first to third amplidute

  • w_c1

  • w_t1

  • e11

  • e21

  • w_c2

  • w_t2

  • e12

  • e22

  • center_x

  • center_y

Returns:

density_lens(r, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
Parameters:
  • r – 3d radius

  • alpha_1

  • ratio12 – ratio of first to second amplitude

  • ratio13 – ratio of first to third amplitude

  • w_c1

  • w_t1

  • e11

  • e21

  • w_c2

  • w_t2

  • e12

  • e22

  • center_x

  • center_y

Returns:

density at radius r (spherical average)

mass_3d_lens(r, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
Parameters:
  • r – 3d radius

  • alpha_1

  • ratio12 – ratio of first to second amplitude

  • ratio13 – ratio of first to third amplitude

  • w_c1

  • w_t1

  • e11

  • e21

  • w_c2

  • w_t2

  • e12

  • e22

  • center_x

  • center_y

Returns:

mass enclosed 3d radius

set_static(alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]

Pre-computes certain computations that do only relate to the lens model parameters and not to the specific position where to evaluate the lens model.

Parameters:

kwargs – lens model parameters

Returns:

no return, for certain lens model some private self variables are initiated

set_dynamic()[source]
Returns:

no return, deletes pre-computed variables for certain lens models

class DoubleChameleonPointMass[source]

Bases: LensProfileBase

Class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile.

param_names = ['alpha_1', 'ratio_chameleon', 'ratio_pointmass', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'center_x', 'center_y']
lower_limit_default = {'alpha_1': 0, 'center_x': -100, 'center_y': -100, 'e11': -0.8, 'e12': -0.8, 'e21': -0.8, 'e22': -0.8, 'ratio_chameleon': 0, 'ratio_pointmass': 0, 'w_c1': 0, 'w_c2': 0, 'w_t1': 0, 'w_t2': 0}
upper_limit_default = {'alpha_1': 100, 'center_x': 100, 'center_y': 100, 'e11': 0.8, 'e12': 0.8, 'e21': 0.8, 'e22': 0.8, 'ratio_chameleon': 100, 'ratio_pointmass': 100, 'w_c1': 100, 'w_c2': 100, 'w_t1': 100, 'w_t2': 100}
__init__()[source]
function(x, y, alpha_1, ratio_pointmass, ratio_chameleon, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]

#TODO chose better parameterization for combining point mass and Chameleon profiles

Parameters:
  • x – ra-coordinate

  • y – dec-coordinate

  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • ratio_pointmass – ratio of point source Einstein radius to combined Chameleon deflection angle at r=1

  • ratio_chameleon – ratio in deflection angles at r=1 for the two Chameleon profiles

  • w_c1 – Suyu+2014 for first profile

  • w_t1 – Suyu+2014 for first profile

  • e11 – ellipticity parameter for first profile

  • e21 – ellipticity parameter for first profile

  • w_c2 – Suyu+2014 for second profile

  • w_t2 – Suyu+2014 for second profile

  • e12 – ellipticity parameter for second profile

  • e22 – ellipticity parameter for second profile

  • center_x – ra center

  • center_y – dec center

Returns:

lensing potential

derivatives(x, y, alpha_1, ratio_pointmass, ratio_chameleon, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
Parameters:
  • x

  • y

  • alpha_1

  • ratio_pointmass – ratio of point source Einstein radius to combined Chameleon deflection angle at r=1

  • ratio_chameleon – ratio in deflection angles at r=1 for the two Chameleon profiles

  • w_c1 – Suyu+2014 for first profile

  • w_t1 – Suyu+2014 for first profile

  • e11 – ellipticity parameter for first profile

  • e21 – ellipticity parameter for first profile

  • w_c2 – Suyu+2014 for second profile

  • w_t2 – Suyu+2014 for second profile

  • e12 – ellipticity parameter for second profile

  • e22 – ellipticity parameter for second profile

  • center_x – ra center

  • center_y – dec center

Returns:

hessian(x, y, alpha_1, ratio_pointmass, ratio_chameleon, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
Parameters:
  • x

  • y

  • alpha_1

  • ratio_pointmass – ratio of point source Einstein radius to combined Chameleon deflection angle at r=1

  • ratio_chameleon – ratio in deflection angles at r=1 for the two Chameleon profiles

  • w_c1 – Suyu+2014 for first profile

  • w_t1 – Suyu+2014 for first profile

  • e11 – ellipticity parameter for first profile

  • e21 – ellipticity parameter for first profile

  • w_c2 – Suyu+2014 for second profile

  • w_t2 – Suyu+2014 for second profile

  • e12 – ellipticity parameter for second profile

  • e22 – ellipticity parameter for second profile

  • center_x – ra center

  • center_y – dec center

Returns:

lenstronomy.LensModel.Profiles.cnfw module

class CNFW[source]

Bases: LensProfileBase

this class computes the lensing quantities of a cored NFW profile: rho = rho0 * (r + r_core)^-1 * (r + rs)^-2 alpha_Rs is the normalization equivalent to the deflection angle at rs in the absence of a core

model_name = 'CNFW'
param_names = ['Rs', 'alpha_Rs', 'r_core', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'r_core': 0}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'r_core': 100}
__init__()[source]
function(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]
Parameters:
  • x – angular position

  • y – angular position

  • Rs – angular turn over point

  • alpha_Rs – deflection at Rs (in the absence of a core

  • r_core – core radius

  • center_x – center of halo

  • center_y – center of halo

Returns:

derivatives(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]

Deflection angles.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

hessian(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy.

density(R, Rs, rho0, r_core)[source]

Three dimensional truncated NFW profile.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (central core density)

Returns:

rho(R) density

density_lens(R, Rs, alpha_Rs, r_core)[source]

Computes the density at 3d radius r given lens model parameterization.

The integral in the LOS projection of this quantity results in the convergence quantity.

density_2d(x, y, Rs, rho0, r_core, center_x=0, center_y=0)[source]

Projected two dimenstional NFW profile (kappa*Sigma_crit)

Parameters:
  • x (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

Returns:

Epsilon(R) projected density at radius R

mass_3d(R, Rs, rho0, r_core)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • R

  • Rs

  • rho0

  • r_core

Returns:

mass_3d_lens(R, Rs, alpha_Rs, r_core)[source]

Mass enclosed a 3d sphere or radius r given a lens parameterization with angular units.

Returns:

alpha_r(R, Rs, rho0, r_core)[source]

Deflection angel of NFW profile along the radial direction.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

Returns:

Epsilon(R) projected density at radius R

cnfw_gamma(R, Rs, rho0, r_core, ax_x, ax_y)[source]

Shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate ‘axis’.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

Returns:

Epsilon(R) projected density at radius R

mass_2d(R, Rs, rho0, r_core)[source]

Analytic solution of the projection integral (convergence)

lenstronomy.LensModel.Profiles.cnfw_ellipse_potential module

class CNFWEllipsePotential[source]

Bases: LensProfileBase

This class contains functions concerning the CNFW profile with ellipticity in the potential.

relation are: R_200 = c * Rs

param_names = ['Rs', 'alpha_Rs', 'r_core', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'r_core': 0}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'r_core': 100}
__init__()[source]
function(x, y, Rs, alpha_Rs, r_core, e1, e2, center_x=0, center_y=0)[source]

Returns double integral of NFW profile.

derivatives(x, y, Rs, alpha_Rs, r_core, e1, e2, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function (integral of NFW)

hessian(x, y, Rs, alpha_Rs, r_core, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy.

mass_3d_lens(R, Rs, alpha_Rs, r_core, e1=0, e2=0)[source]

Mass enclosed a 3d sphere or radius r given a lens parameterization with angular units.

Returns:

density_lens(R, Rs, alpha_Rs, r_core, e1=0, e2=0)[source]

Computes the density at 3d radius r given lens model parameterization.

The integral in the LOS projection of this quantity results in the convergence quantity.

lenstronomy.LensModel.Profiles.const_mag module

class ConstMag(*args, **kwargs)[source]

Bases: LensProfileBase

This class implements the macromodel potential of Diego et al.

ConstMag assumes constant radial and tangential magnification components.

The lensing potential is given by:

\[\psi(\theta_x, \theta_y) = \frac{\kappa}{2}(\theta_x^2 + \theta_y^2) + \frac{\gamma_1}{2}(\theta_x^2 - \theta_y^2) - \gamma_2(\theta_x \theta_y)\]

where: \(\theta_x\) and \(\theta_y\) are angular coordinates in the image plane, \(\gamma_1\) and \(\gamma_2\) are the horizontal and vertical components of shear, respectively, and \(\kappa\) is the convergence.

\(\kappa\) and \(\gamma\) depend on the parity. A negative parity means the image becomes inverted compared to the source.

For positive parity (\(\text{parity} = +1\)):

\[\gamma = \frac{1}{2} \left(\frac{1}{\mu_t} - \frac{1}{\mu_r}\right) \kappa = 1 - \gamma - \frac{1}{\mu_r}\]

For negative parity (\(\text{parity} = -1\)):

\[\gamma = \frac{1}{2} \left(\frac{1}{\mu_t} + \frac{1}{\mu_r}\right) \kappa = 1 - \gamma + \frac{1}{\mu_r}\]

where \(mu_r\) and \(mu_t\) are the radial and tangental components of magnification, respectively.

The shear components are calculated as:

\[\gamma_1 = \gamma\cos{2\phi_G} \gamma_2 = -\gamma\sin{2\phi_G}\]

where \(\phi_G\) is the shear orientation angle relative to the x-axis.

For a detailed derivation see <https://www.aanda.org/articles/aa/pdf/2019/07/aa35490-19.pdf>` _ Convergence and shear are computed according to Diego2018 <arXiv:1706.10281v2>

param_names = ['center_x', 'center_y', 'mu_r', 'mu_t', 'parity', 'phi_G']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'mu_r': 1, 'mu_t': 1000, 'parity': -1, 'phi_G': 0.0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'mu_r': 1, 'mu_t': 1000, 'parity': 1, 'phi_G': 3.141592653589793}
function(x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coord (in angles)

  • y – y-coord (in angles)

  • mu_r – radial magnification

  • mu_t – tangential magnification

  • parity – parity side of the macromodel. Either +1 (positive parity) or -1 (negative parity)

  • phi_G – shear orientation angle (relative to the x-axis)

Returns:

lensing potential

derivatives(x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coord (in angles)

  • y – y-coord (in angles)

  • mu_r – radial magnification

  • mu_t – tangential magnification

  • parity – parity of the side of the macromodel. Either +1 (positive parity) or -1 (negative parity)

  • phi_G – shear orientation angle (relative to the x-axis)

Returns:

deflection angle (in angles)

hessian(x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coord (in angles)

  • y – y-coord (in angles)

  • mu_r – radial magnification

  • mu_t – tangential magnification

  • parity – parity of the side of the macromodel. Either +1 (positive parity) or -1 (negative parity)

  • phi_G – shear orientation angle (relative to the x-axis)

Returns:

hessian matrix (in angles)

lenstronomy.LensModel.Profiles.constant_shift module

class Shift(*args, **kwargs)[source]

Bases: LensProfileBase

Lens model with a constant shift of the deflection field.

param_names = ['alpha_x', 'alpha_y']
lower_limit_default = {'alpha_x': -1000, 'alpha_y': -1000}
upper_limit_default = {'alpha_x': 1000, 'alpha_y': 1000}
function(x, y, alpha_x, alpha_y)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • alpha_x – shift in x-direction (angle)

  • alpha_y – shift in y-direction (angle)

Returns:

lensing potential

derivatives(x, y, alpha_x, alpha_y)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • alpha_x – shift in x-direction (angle)

  • alpha_y – shift in y-direction (angle)

Returns:

deflection in x- and y-direction

hessian(x, y, alpha_x, alpha_y)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • alpha_x – shift in x-direction (angle)

  • alpha_y – shift in y-direction (angle)

Returns:

hessian elements f_xx, f_xy, f_yx, f_yy

lenstronomy.LensModel.Profiles.convergence module

class Convergence(*args, **kwargs)[source]

Bases: LensProfileBase

A single mass sheet (external convergence)

model_name = 'CONVERGENCE'
param_names = ['kappa', 'ra_0', 'dec_0']
lower_limit_default = {'dec_0': -100, 'kappa': -10, 'ra_0': -100}
upper_limit_default = {'dec_0': 100, 'kappa': 10, 'ra_0': 100}
function(x, y, kappa, ra_0=0, dec_0=0)[source]

Lensing potential.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • kappa – (external) convergence

Returns:

lensing potential

derivatives(x, y, kappa, ra_0=0, dec_0=0)[source]

Deflection angle.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • kappa – (external) convergence

Returns:

deflection angles (first order derivatives)

hessian(x, y, kappa, ra_0=0, dec_0=0)[source]

Hessian matrix.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • kappa – external convergence

  • ra_0 – zero point of polynomial expansion (no deflection added)

  • dec_0 – zero point of polynomial expansion (no deflection added)

Returns:

second order derivatives f_xx, f_xy, f_yx, f_yy

lenstronomy.LensModel.Profiles.coreBurkert module

class CoreBurkert(*args, **kwargs)[source]

Bases: LensProfileBase

Lensing properties of a modified Burkert profile with variable core size normalized by rho0, the central core density.

param_names = ['Rs', 'alpha_Rs', 'r_core', 'center_x', 'center_y']
lower_limit_default = {'Rs': 1, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'r_core': 0.5}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 100, 'center_x': 100, 'center_y': 100, 'r_core': 50}
function(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]
Parameters:
  • x – angular position

  • y – angular position

  • Rs – angular turn over point

  • alpha_Rs – deflection angle at Rs

  • center_x – center of halo

  • center_y – center of halo

Returns:

derivatives(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]

Deflection angles :param x: x coordinate :param y: y coordinate :param Rs: scale radius :param alpha_Rs: deflection angle at Rs :param r_core: core radius :param center_x:

Parameters:

center_y

Returns:

hessian(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]
Parameters:
  • x – x coordinate

  • y – y coordinate

  • Rs – scale radius

  • alpha_Rs – deflection angle at Rs

  • r_core – core radius

  • center_x

  • center_y

Returns:

mass_2d(R, Rs, rho0, r_core)[source]

Analytic solution of the projection integral (convergence)

Parameters:
  • R – projected distance

  • Rs – scale radius

  • rho0 – central core density

  • r_core – core radius

coreBurkAlpha(R, Rs, rho0, r_core, ax_x, ax_y)[source]

Deflection angle.

Parameters:
  • R

  • Rs

  • rho0

  • r_core

  • ax_x

  • ax_y

Returns:

density(R, Rs, rho0, r_core)[source]

Three dimensional cored Burkert profile.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – characteristic density

Returns:

rho(R) density

density_2d(x, y, Rs, rho0, r_core, center_x=0, center_y=0)[source]

Projected two dimenstional core Burkert profile (kappa*Sigma_crit)

Parameters:
  • x – x coordinate

  • y – y coordinate

  • Rs – scale radius

  • rho0 – central core density

  • r_core – core radius

mass_3d(R, Rs, rho0, r_core)[source]
Parameters:
  • R – projected distance

  • Rs – scale radius

  • rho0 – central core density

  • r_core – core radius

cBurkPot(R, Rs, rho0, r_core)[source]
Parameters:
  • R – projected distance

  • Rs – scale radius

  • rho0 – central core density

  • r_core – core radius

cBurkGamma(R, Rs, rho0, r_core, ax_x, ax_y)[source]
Parameters:
  • R – projected distance

  • Rs – scale radius

  • rho0 – central core density

  • r_core – core radius

  • ax_x – x coordinate

  • ax_y – y coordinate

Returns:

lenstronomy.LensModel.Profiles.cored_density module

class CoredDensity(*args, **kwargs)[source]

Bases: LensProfileBase

class for a uniform cored density dropping steep in the outskirts This profile is e.g. featured in Blum et al. 2020 https://arxiv.org/abs/2001.07182v1

..math::

rho_c(r) = frac{2}{pi} Sigma_{c} R_c^3 left(R_c^2 + r^2 right)^{-2}

with the convergence profile as

..math::

kappa_c(theta) = left(1 + frac{theta^2}{theta_c^2} right)^{-3/2}.

An approximate mass-sheet degeneracy can then be written as

..math::

kappa_{lambda_c}(theta) = lambda_c kappa(theta) + (1-lambda_c) kappa_c(theta).

param_names = ['sigma0', 'r_core', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'r_core': 0, 'sigma0': -1}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'r_core': 100, 'sigma0': 10}
function(x, y, sigma0, r_core, center_x=0, center_y=0)[source]

Potential of cored density profile.

Parameters:
  • x – x-coordinate in angular units

  • y – y-coordinate in angular units

  • sigma0 – convergence in the core

  • r_core – core radius

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

lensing potential at (x, y)

derivatives(x, y, sigma0, r_core, center_x=0, center_y=0)[source]

Deflection angle of cored density profile.

Parameters:
  • x – x-coordinate in angular units

  • y – y-coordinate in angular units

  • sigma0 – convergence in the core

  • r_core – core radius

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

alpha_x, alpha_y at (x, y)

hessian(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in angular units

  • y – y-coordinate in angular units

  • sigma0 – convergence in the core

  • r_core – core radius

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

Hessian df/dxdx, df/dxdy, df/dydx, df/dydy at position (x, y)

static alpha_r(r, sigma0, r_core)[source]

Radial deflection angle of the cored density profile.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

deflection angle

static d_alpha_dr(r, sigma0, r_core)[source]

Radial derivatives of the radial deflection angle.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

dalpha/dr

static kappa_r(r, sigma0, r_core)[source]

Convergence of the cored density profile. This routine is also for testing.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

convergence at r

static density(r, sigma0, r_core)[source]

Rho(r) = 2/pi * Sigma_crit R_c**3 * (R_c**2 + r**2)**(-2)

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

density at radius r

density_lens(r, sigma0, r_core)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

desnity at radius r

density_2d(x, y, sigma0, r_core, center_x=0, center_y=0)[source]

Projected density at projected radius r.

Parameters:
  • x – x-coordinate in angular units

  • y – y-coordinate in angular units

  • sigma0 – convergence in the core

  • r_core – core radius

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

projected density

mass_2d(r, sigma0, r_core)[source]

Mass enclosed in cylinder of radius r.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

mass enclosed in cylinder of radius r

static mass_3d(r, sigma0, r_core)[source]

Mass enclosed 3d radius.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

mass enclosed 3d radius

mass_3d_lens(r, sigma0, r_core)[source]

Mass enclosed a 3d sphere or radius r given a lens parameterization with angular units For this profile those are identical.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

mass enclosed 3d radius

lenstronomy.LensModel.Profiles.cored_density_2 module

class CoredDensity2(*args, **kwargs)[source]

Bases: LensProfileBase

Class for a uniform cored density dropping steep in the outskirts credits for suggesting this profile goes to Kfir Blum.

\[\rho(r) = 2/\pi * \Sigma_{\rm crit} R_c^2 * (R_c^2 + r^2)^{-3/2}\]

This profile drops like an NFW profile as math:rho(r)^{-3}.

model_name = 'CORED_DENSITY_2'
param_names = ['sigma0', 'r_core', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'r_core': 0, 'sigma0': -1}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'r_core': 100, 'sigma0': 10}
function(x, y, sigma0, r_core, center_x=0, center_y=0)[source]

Potential of cored density profile.

Parameters:
  • x – x-coordinate in angular units

  • y – y-coordinate in angular units

  • sigma0 – convergence in the core

  • r_core – core radius

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

lensing potential at (x, y)

derivatives(x, y, sigma0, r_core, center_x=0, center_y=0)[source]

Deflection angle of cored density profile.

Parameters:
  • x – x-coordinate in angular units

  • y – y-coordinate in angular units

  • sigma0 – convergence in the core

  • r_core – core radius

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

alpha_x, alpha_y at (x, y)

hessian(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in angular units

  • y – y-coordinate in angular units

  • sigma0 – convergence in the core

  • r_core – core radius

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

Hessian df/dxdx, df/dxdy, df/dydx, df/dydy at position (x, y)

static alpha_r(r, sigma0, r_core)[source]

Radial deflection angle of the cored density profile.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

deflection angle

static d_alpha_dr(r, sigma0, r_core)[source]

Radial derivatives of the radial deflection angle.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

dalpha/dr

static kappa_r(r, sigma0, r_core)[source]

Convergence of the cored density profile. This routine is also for testing.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

convergence at r

static density(r, sigma0, r_core)[source]

Rho(r) = 2/pi * Sigma_crit R_c**3 * (R_c**2 + r**2)**(-3/2)

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

density at radius r

density_lens(r, sigma0, r_core)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

density at radius r

density_2d(x, y, sigma0, r_core, center_x=0, center_y=0)[source]

Projected density at projected radius r.

Parameters:
  • x – x-coordinate in angular units

  • y – y-coordinate in angular units

  • sigma0 – convergence in the core

  • r_core – core radius

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

projected density

static mass_2d(r, sigma0, r_core)[source]

Mass enclosed in cylinder of radius r.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

mass enclosed in cylinder of radius r

static mass_3d(r, sigma0, r_core)[source]

Mass enclosed 3d radius.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

mass enclosed 3d radius

mass_3d_lens(r, sigma0, r_core)[source]

Mass enclosed a 3d sphere or radius r given a lens parameterization with angular units For this profile those are identical.

Parameters:
  • r – radius (angular scale)

  • sigma0 – convergence in the core

  • r_core – core radius

Returns:

mass enclosed 3d radius

lenstronomy.LensModel.Profiles.cored_density_exp module

class CoredDensityExp(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains functions concerning an exponential cored density profile, namely.

..math::

rho(r) = rho_0 exp(- (theta / theta_c)^2)

param_names = ['kappa_0', 'theta_c', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'kappa_0': 0, 'theta_c': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'kappa_0': 10, 'theta_c': 100}
static rhotilde(kappa_0, theta_c)[source]

Computes the central density in angular units :param kappa_0: central convergence of profile :param theta_c: core radius (in arcsec) :return: central density in 1/arcsec.

function(x, y, kappa_0, theta_c, center_x=0, center_y=0)[source]
Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

lensing potential (in arcsec^2)

static alpha_radial(r, kappa_0, theta_c)[source]

Returns the radial part of the deflection angle :param r: angular position (normally in units of arc seconds) :param kappa_0: central convergence of profile :param theta_c: core radius (in arcsec) :return: radial deflection angle.

derivatives(x, y, kappa_0, theta_c, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function (lensing potential), which are the deflection angles.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

deflection angle in x, deflection angle in y

hessian(x, y, kappa_0, theta_c, center_x=0, center_y=0)[source]
Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

density(R, kappa_0, theta_c)[source]

Three dimensional density profile in angular units (rho0_physical = rho0_angular Sigma_crit / D_lens)

Parameters:
  • R – projected angular position (normally in units of arc seconds)

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

Returns:

rho(R) density

density_lens(r, kappa_0, theta_c)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – angular position (normally in units of arc seconds)

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

Returns:

density rho(r)

static kappa_r(R, kappa_0, theta_c)[source]

Convergence of the cored density profile. This routine is also for testing.

Parameters:
  • R – radius (angular scale)

  • kappa_0 – convergence in the core

  • theta_c – core radius

Returns:

convergence at r

density_2d(x, y, kappa_0, theta_c, center_x=0, center_y=0)[source]

Projected two dimensional ULDM profile (convergence * Sigma_crit), but given our units convention for rho0, it is basically the convergence.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

Returns:

Epsilon(R) projected density at radius R

static mass_3d(R, kappa_0, theta_c)[source]

Mass enclosed a 3d sphere or radius r :param kappa_0: central convergence of profile :param theta_c: core radius (in arcsec) :param R: radius in arcseconds :return: mass of soliton in angular units.

mass_3d_lens(r, kappa_0, theta_c)[source]

Mass enclosed a 3d sphere or radius r :param kappa_0: central convergence of profile :param theta_c: core radius (in arcsec) :return: mass.

mass_2d(R, kappa_0, theta_c)[source]

Mass enclosed a 2d sphere of radius r returns.

\[M_{2D} = 2 \pi \int_0^r dr' r' \int dz \rho(\sqrt(r'^2 + z^2))\]
Parameters:
  • kappa_0 – central convergence of soliton

  • theta_c – core radius (in arcsec)

Returns:

M_2D (ULDM only)

lenstronomy.LensModel.Profiles.cored_density_mst module

class CoredDensityMST(profile_type='CORED_DENSITY')[source]

Bases: LensProfileBase

Approximate mass-sheet transform of a density core.

This routine takes the parameters of the density core and subtracts a mass-sheet that approximates the cored profile in it’s center to counter-act (in approximation) this model. This allows for better sampling of the mass-sheet transformed quantities that do not have strong covariances. The subtraction of the mass-sheet is done such that the sampler returns the real central convergence of the original model (but be careful, the output of quantities like the Einstein angle of the main deflector are still the not-scaled one). Attention!!! The interpretation of the result is that the mass sheet as ‘CONVERGENCE’ that is present needs to be subtracted in post- processing.

param_names = ['lambda_approx', 'r_core', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'lambda_approx': -1, 'r_core': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'lambda_approx': 10, 'r_core': 100}
__init__(profile_type='CORED_DENSITY')[source]
function(x, y, lambda_approx, r_core, center_x=0, center_y=0)[source]

Lensing potential of approximate mass-sheet correction.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • lambda_approx – approximate mass sheet transform

  • r_core – core radius of the cored density profile

  • center_x – x-center of the profile

  • center_y – y-center of the profile

Returns:

lensing potential correction

derivatives(x, y, lambda_approx, r_core, center_x=0, center_y=0)[source]

Deflection angles of approximate mass-sheet correction.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • lambda_approx – approximate mass sheet transform

  • r_core – core radius of the cored density profile

  • center_x – x-center of the profile

  • center_y – y-center of the profile

Returns:

alpha_x, alpha_y

hessian(x, y, lambda_approx, r_core, center_x=0, center_y=0)[source]

Hessian terms of approximate mass-sheet correction.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • lambda_approx – approximate mass sheet transform

  • r_core – core radius of the cored density profile

  • center_x – x-center of the profile

  • center_y – y-center of the profile

Returns:

df/dxx, df/dxy, df/dyx, df/dyy

lenstronomy.LensModel.Profiles.cored_steep_ellipsoid module

class CSE(axis='product_avg')[source]

Bases: LensProfileBase

Cored steep ellipsoid (CSE) :param axis: ‘major’ or ‘product_avg’ ; whether to evaluate corresponding to r= major axis or r= sqrt(ab) source: Keeton and Kochanek (1998) Oguri 2021: https://arxiv.org/pdf/2106.11464.pdf

\[\kappa(u;s) = \frac{A}{2(s^2 + \xi^2)^{3/2}}\]

with

\[\xi(x, y) = \sqrt{x^2 + \frac{y^2}{q^2}}\]
param_names = ['a', 's', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'a': -1000, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 's': 0}
upper_limit_default = {'a': 1000, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 's': 10000}
__init__(axis='product_avg')[source]
function(x, y, a, s, e1, e2, center_x, center_y)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a – lensing strength

  • s – core radius

  • e1 – eccentricity

  • e2 – eccentricity

  • center_x – center of profile

  • center_y – center of profile

Returns:

lensing potential

derivatives(x, y, a, s, e1, e2, center_x, center_y)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a – lensing strength

  • s – core radius

  • e1 – eccentricity

  • e2 – eccentricity

  • center_x – center of profile

  • center_y – center of profile

Returns:

deflection in x- and y-direction

hessian(x, y, a, s, e1, e2, center_x, center_y)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a – lensing strength

  • s – core radius

  • e1 – eccentricity

  • e2 – eccentricity

  • center_x – center of profile

  • center_y – center of profile

Returns:

hessian elements f_xx, f_xy, f_yx, f_yy

class CSEMajorAxis(*args, **kwargs)[source]

Bases: LensProfileBase

Cored steep ellipsoid (CSE) along the major axis source: Keeton and Kochanek (1998) Oguri 2021: https://arxiv.org/pdf/2106.11464.pdf

\[\kappa(u;s) = \frac{A}{2(s^2 + \xi^2)^{3/2}}\]

with

\[\xi(x, y) = \sqrt{x^2 + \frac{y^2}{q^2}}\]
param_names = ['a', 's', 'q', 'center_x', 'center_y']
lower_limit_default = {'a': -1000, 'center_x': -100, 'center_y': -100, 'q': 0.001, 's': 0}
upper_limit_default = {'a': 1000, 'center_x': 100, 'center_y': 100, 'q': 0.99999, 's': 10000}
function(x, y, a, s, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a – lensing strength

  • s – core radius

  • q – axis ratio

Returns:

lensing potential

derivatives(x, y, a, s, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a – lensing strength

  • s – core radius

  • q – axis ratio

Returns:

deflection in x- and y-direction

hessian(x, y, a, s, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a – lensing strength

  • s – core radius

  • q – axis ratio

Returns:

hessian elements f_xx, f_xy, f_yx, f_yy

class CSEMajorAxisSet[source]

Bases: LensProfileBase

A set of CSE profiles along a joint center and axis.

__init__()[source]
function(x, y, a_list, s_list, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a_list – list of lensing strength

  • s_list – list of core radius

  • q – axis ratio

Returns:

lensing potential

derivatives(x, y, a_list, s_list, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a_list – list of lensing strength

  • s_list – list of core radius

  • q – axis ratio

Returns:

deflection in x- and y-direction

hessian(x, y, a_list, s_list, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a_list – list of lensing strength

  • s_list – list of core radius

  • q – axis ratio

Returns:

hessian elements f_xx, f_xy, f_yx, f_yy

class CSEProductAvg[source]

Bases: LensProfileBase

Cored steep ellipsoid (CSE) evaluated at the product-averaged radius sqrt(ab), such that mass is not changed when increasing ellipticity.

Same as CSEMajorAxis but evaluated at r=sqrt(q)*r_original

Keeton and Kochanek (1998) Oguri 2021: https://arxiv.org/pdf/2106.11464.pdf

\[\kappa(u;s) = \frac{A}{2(s^2 + \xi^2)^{3/2}}\]

with

\[\xi(x, y) = \sqrt{qx^2 + \frac{y^2}{q}}\]
param_names = ['a', 's', 'q', 'center_x', 'center_y']
lower_limit_default = {'a': -1000, 'center_x': -100, 'center_y': -100, 'q': 0.001, 's': 0}
upper_limit_default = {'a': 1000, 'center_x': 100, 'center_y': 100, 'q': 0.99999, 's': 10000}
__init__()[source]
function(x, y, a, s, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a – lensing strength

  • s – core radius

  • q – axis ratio

Returns:

lensing potential

derivatives(x, y, a, s, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a – lensing strength

  • s – core radius

  • q – axis ratio

Returns:

deflection in x- and y-direction

hessian(x, y, a, s, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a – lensing strength

  • s – core radius

  • q – axis ratio

Returns:

hessian elements f_xx, f_xy, f_yx, f_yy

class CSEProductAvgSet[source]

Bases: LensProfileBase

A set of CSE profiles along a joint center and axis.

__init__()[source]
function(x, y, a_list, s_list, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a_list – list of lensing strength

  • s_list – list of core radius

  • q – axis ratio

Returns:

lensing potential

derivatives(x, y, a_list, s_list, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a_list – list of lensing strength

  • s_list – list of core radius

  • q – axis ratio

Returns:

deflection in x- and y-direction

hessian(x, y, a_list, s_list, q)[source]
Parameters:
  • x – coordinate in image plane (angle)

  • y – coordinate in image plane (angle)

  • a_list – list of lensing strength

  • s_list – list of core radius

  • q – axis ratio

Returns:

hessian elements f_xx, f_xy, f_yx, f_yy

lenstronomy.LensModel.Profiles.curved_arc_const module

class CurvedArcConstMST[source]

Bases: LensProfileBase

Lens model that describes a section of a highly magnified deflector region. The parameterization is chosen to describe local observables efficient.

Observables are: - curvature radius (basically bending relative to the center of the profile) - radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) - tangential stretch (plus sign). Infinity means at critical curve - direction of curvature - position of arc

Requirements: - Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) - Must best reflect the observables in lensing - minimal covariances between the parameters, intuitive parameterization.

param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'radial_stretch': -5, 'tangential_stretch': -100}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'radial_stretch': 5, 'tangential_stretch': 100}
__init__()[source]
function(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]

ATTENTION: there may not be a global lensing potential!

Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

hessian(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

class CurvedArcConst(*args, **kwargs)[source]

Bases: LensProfileBase

Curved arc lensing with orientation of curvature perpendicular to the x-axis with unity radial stretch.

param_names = ['tangential_stretch', 'curvature', 'direction', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'tangential_stretch': -100}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'tangential_stretch': 100}
function(x, y, tangential_stretch, curvature, direction, center_x, center_y)[source]

ATTENTION: there may not be a global lensing potential!

Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

derivatives(x, y, tangential_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

hessian(x, y, tangential_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

lenstronomy.LensModel.Profiles.curved_arc_sis_mst module

class CurvedArcSISMST[source]

Bases: LensProfileBase

Lens model that describes a section of a highly magnified deflector region. The parameterization is chosen to describe local observables efficient.

Observables are: - curvature radius (basically bending relative to the center of the profile) - radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) - tangential stretch (plus sign). Infinity means at critical curve - direction of curvature - position of arc

Requirements: - Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) - Must best reflect the observables in lensing - minimal covariances between the parameters, intuitive parameterization.

param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'radial_stretch': -5, 'tangential_stretch': -100}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'radial_stretch': 5, 'tangential_stretch': 100}
__init__()[source]
static stretch2sis_mst(tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

parameters in terms of a spherical SIS + MST resulting in the same observables

static sis_mst2stretch(theta_E, kappa_ext, center_x_sis, center_y_sis, center_x, center_y)[source]

Turn Singular power-law lens model into stretch parameterization at position (center_x, center_y) This is the inverse function of stretch2spp()

Parameters:
  • theta_E – Einstein radius of SIS profile

  • kappa_ext – external convergence (MST factor 1 - kappa_ext)

  • center_x_sis – center of SPP model

  • center_y_sis – center of SPP model

  • center_x – center of curved model definition

  • center_y – center of curved model definition

Returns:

tangential_stretch, radial_stretch, curvature, direction

Returns:

function(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]

ATTENTION: there may not be a global lensing potential!

Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

hessian(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

lenstronomy.LensModel.Profiles.curved_arc_spp module

class CurvedArcSPP[source]

Bases: LensProfileBase

Lens model that describes a section of a highly magnified deflector region. The parameterization is chosen to describe local observables efficient.

Observables are: - curvature radius (basically bending relative to the center of the profile) - radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) - tangential stretch (plus sign). Infinity means at critical curve - direction of curvature - position of arc

Requirements: - Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) - Must best reflect the observables in lensing - minimal covariances between the parameters, intuitive parameterization.

param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'radial_stretch': -5, 'tangential_stretch': -100}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'radial_stretch': 5, 'tangential_stretch': 100}
__init__()[source]
static stretch2spp(tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

parameters in terms of a spherical power-law profile resulting in the same observables

static spp2stretch(theta_E, gamma, center_x_spp, center_y_spp, center_x, center_y)[source]

Turn Singular power-law lens model into stretch parameterization at position (center_x, center_y) This is the inverse function of stretch2spp()

Parameters:
  • theta_E – Einstein radius of SPP model

  • gamma – power-law slope

  • center_x_spp – center of SPP model

  • center_y_spp – center of SPP model

  • center_x – center of curved model definition

  • center_y – center of curved model definition

Returns:

tangential_stretch, radial_stretch, curvature, direction

function(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]

ATTENTION: there may not be a global lensing potential!

Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

hessian(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

center_deflector(curvature, direction, center_x, center_y)[source]
Parameters:
  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

center_spp_x, center_spp_y

lenstronomy.LensModel.Profiles.curved_arc_spt module

class CurvedArcSPT[source]

Bases: LensProfileBase

Curved arc model based on SIS+MST with an additional non-linear shear distortions applied on the source coordinates around the center.

This profile is effectively a Source Position Transform of a curved arc and a shear distortion.

param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'gamma1', 'gamma2', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'gamma1': -0.5, 'gamma2': -0.5, 'radial_stretch': -5, 'tangential_stretch': -100}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'gamma1': 0.5, 'gamma2': 0.5, 'radial_stretch': 5, 'tangential_stretch': 100}
__init__()[source]
function(x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, gamma2, center_x, center_y)[source]

ATTENTION: there may not be a global lensing potential!

Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • gamma1 – non-linear reduced shear distortion in the source plane

  • gamma2 – non-linear reduced shear distortion in the source plane

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, gamma2, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • gamma1 – non-linear reduced shear distortion in the source plane

  • gamma2 – non-linear reduced shear distortion in the source plane

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

hessian(x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, gamma2, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • gamma1 – non-linear reduced shear distortion in the source plane

  • gamma2 – non-linear reduced shear distortion in the source plane

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

lenstronomy.LensModel.Profiles.curved_arc_tan_diff module

class CurvedArcTanDiff[source]

Bases: LensProfileBase

Curved arc model with an additional non-zero tangential stretch differential in tangential direction component.

Observables are: - curvature radius (basically bending relative to the center of the profile) - radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) - tangential stretch (plus sign). Infinity means at critical curve - direction of curvature - position of arc

Requirements: - Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) - Must best reflect the observables in lensing - minimal covariances between the parameters, intuitive parameterization.

param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'dtan_dtan', 'direction', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'dtan_dtan': -10, 'radial_stretch': -5, 'tangential_stretch': -100}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'dtan_dtan': 10, 'radial_stretch': 5, 'tangential_stretch': 100}
__init__()[source]
static stretch2sie_mst(tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y)[source]
Parameters:
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • dtan_dtan – d(tangential_stretch) / d(tangential direction) / tangential stretch

  • direction – float, angle in radian

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

parameters in terms of a spherical SIS + MST resulting in the same observables

function(x, y, tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y)[source]

ATTENTION: there may not be a global lensing potential!

Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • dtan_dtan – d(tangential_stretch) / d(tangential direction) / tangential stretch

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

derivatives(x, y, tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • dtan_dtan – d(tangential_stretch) / d(tangential direction) / tangential stretch

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

hessian(x, y, tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y)[source]
Parameters:
  • x

  • y

  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • radial_stretch – float, stretch of intrinsic source in radial direction

  • curvature – 1/curvature radius

  • direction – float, angle in radian

  • dtan_dtan – d(tangential_stretch) / d(tangential direction) / tangential stretch

  • center_x – center of source in image plane

  • center_y – center of source in image plane

Returns:

lenstronomy.LensModel.Profiles.dipole module

class Dipole(*args, **kwargs)[source]

Bases: LensProfileBase

Class for dipole response of two massive bodies (experimental)

param_names = ['com_x', 'com_y', 'phi_dipole', 'coupling']
lower_limit_default = {'com_x': -100, 'com_y': -100, 'coupling': -10, 'phi_dipole': -10}
upper_limit_default = {'com_x': 100, 'com_y': 100, 'coupling': 10, 'phi_dipole': 10}
function(x, y, com_x, com_y, phi_dipole, coupling)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, com_x, com_y, phi_dipole, coupling)[source]

Deflection angles.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

hessian(x, y, com_x, com_y, phi_dipole, coupling)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

class DipoleUtil[source]

Bases: object

Pre-calculation of dipole properties.

static com(center1_x, center1_y, center2_x, center2_y, Fm)[source]
Returns:

center of mass

static mass_ratio(theta_E, theta_E_sub)[source]

Computes mass ration of the two clumps with given Einstein radius and power law slope (clump1/sub-clump) :param theta_E:

Parameters:

theta_E_sub

Returns:

static angle(center1_x, center1_y, center2_x, center2_y)[source]

Compute the rotation angle of the dipole :return:

lenstronomy.LensModel.Profiles.elliptical_density_slice module

class ElliSLICE(*args, **kwargs)[source]

Bases: LensProfileBase

This class computes the lensing quantities for an elliptical slice of constant density. Based on Schramm 1994 https://ui.adsabs.harvard.edu/abs/1994A%26A…284…44S/abstract

Computes the lensing quantities of an elliptical slice with semi major axis ‘a’ and semi minor axis ‘b’, centered on ‘center_x’ and ‘center_y’, oriented with an angle ‘psi’ in radian, and with constant surface mass density ‘sigma_0’. In other words, this lens model is characterized by the surface mass density :

..math::

kappa(x,y) = left{ begin{array}{ll} sigma_0 & mbox{if } frac{x_{rot}^2}{a^2} + frac{y_{rot}^2}{b^2} leq 1 0 & mbox{else} end{array} right}.

with

..math::

x_{rot} = x_c cos psi + y_c sin psi y_{rot} = - x_c sin psi + y_c cos psi x_c = x - center_x y_c = y - center_y

param_names = ['a', 'b', 'psi', 'sigma_0', 'center_x', 'center_y']
lower_limit_default = {'a': 0.0, 'b': 0.0, 'center_x': -100.0, 'center_y': -100.0, 'psi': -1.5707963267948966}
upper_limit_default = {'a': 100.0, 'b': 100.0, 'center_x': 100.0, 'center_y': 100.0, 'psi': 1.5707963267948966}
function(x, y, a, b, psi, sigma_0, center_x=0.0, center_y=0.0)[source]

Lensing potential.

Parameters:
  • a – float, semi-major axis, must be positive

  • b – float, semi-minor axis, must be positive

  • psi – float, orientation in radian

  • sigma_0 – float, surface mass density, must be positive

  • center_x – float, center on the x axis

  • center_y – float, center on the y axis

derivatives(x, y, a, b, psi, sigma_0, center_x=0.0, center_y=0.0)[source]

Lensing deflection angle.

Parameters:
  • a – float, semi-major axis, must be positive

  • b – float, semi-minor axis, must be positive

  • psi – float, orientation in radian

  • sigma_0 – float, surface mass density, must be positive

  • center_x – float, center on the x axis

  • center_y – float, center on the y axis

hessian(x, y, a, b, psi, sigma_0, center_x=0.0, center_y=0.0)[source]

Lensing second derivatives.

Parameters:
  • a – float, semi-major axis, must be positive

  • b – float, semi-minor axis, must be positive

  • psi – float, orientation in radian

  • sigma_0 – float, surface mass density, must be positive

  • center_x – float, center on the x axis

  • center_y – float, center on the y axis

static sign(z)[source]

Sign function.

Parameters:

z – complex

alpha_in(x, y, kwargs_slice)[source]

Deflection angle for (x,y) inside the elliptical slice.

Parameters:

kwargs_slice – dict, dictionary with the slice definition (a,b,psi,sigma_0)

alpha_ext(x, y, kwargs_slice)[source]

Deflection angle for (x,y) outside the elliptical slice.

Parameters:

kwargs_slice – dict, dictionary with the slice definition (a,b,psi,sigma_0)

static pot_in(x, y, kwargs_slice)[source]

Lensing potential for (x,y) inside the elliptical slice.

Parameters:

kwargs_slice – dict, dictionary with the slice definition (a,b,psi,sigma_0)

pot_ext(x, y, kwargs_slice)[source]

Lensing potential for (x,y) outside the elliptical slice.

Parameters:

kwargs_slice – dict, dictionary with the slice definition (a,b,psi,sigma_0)

lenstronomy.LensModel.Profiles.epl module

class EPL[source]

Bases: LensProfileBase

Elliptical Power Law mass profile.

\[\kappa(x, y) = \frac{3-\gamma}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q}} \right)^{\gamma-1}\]

with \(\theta_{E}\) is the (circularized) Einstein radius, \(\gamma\) is the negative power-law slope of the 3D mass distributions, \(q\) is the minor/major axis ratio, and \(x\) and \(y\) are defined in a coordinate system aligned with the major and minor axis of the lens.

In terms of eccentricities, this profile is defined as

\[\kappa(r) = \frac{3-\gamma}{2} \left(\frac{\theta'_{E}}{r \sqrt{1 - e*\cos(2*\phi)}} \right)^{\gamma-1}\]

with \(\epsilon\) is the ellipticity defined as

\[\epsilon = \frac{1-q^2}{1+q^2}\]

And an Einstein radius \(\theta'_{\rm E}\) related to the definition used is

\[\left(\frac{\theta'_{\rm E}}{\theta_{\rm E}}\right)^{2} = \frac{2q}{1+q^2}.\]

The mathematical form of the calculation is presented by Tessore & Metcalf (2015), https://arxiv.org/abs/1507.01819. The current implementation is using hyperbolic functions. The paper presents an iterative calculation scheme, converging in few iterations to high precision and accuracy.

A (faster) implementation of the same model using numba is accessible as ‘EPL_NUMBA’ with the iterative calculation scheme. An alternative implementation of the same model using a fortran code FASTELL is implemented as ‘PEMD’ profile.

param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
__init__()[source]
param_conv(theta_E, gamma, e1, e2)[source]

Converts parameters as defined in this class to the parameters used in the EPLMajorAxis() class.

Parameters:
  • theta_E – Einstein radius as defined in the profile class

  • gamma – negative power-law slope

  • e1 – eccentricity modulus

  • e2 – eccentricity modulus

Returns:

b, t, q, phi_G

set_static(theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

self variables set

set_dynamic()[source]
Returns:

function(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

lensing potential

derivatives(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

alpha_x, alpha_y

hessian(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

f_xx, f_xy, f_yx, f_yy

mass_3d_lens(r, theta_E, gamma, e1=None, e2=None)[source]

Computes the spherical power-law mass enclosed (with SPP routine)

Parameters:
  • r – radius within the mass is computed

  • theta_E – Einstein radius

  • gamma – power-law slope

  • e1 – eccentricity component (not used)

  • e2 – eccentricity component (not used)

Returns:

mass enclosed a 3D radius r.

density_lens(r, theta_E, gamma, e1=None, e2=None)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – radius within the mass is computed

  • theta_E – Einstein radius

  • gamma – power-law slope

  • e1 – eccentricity component (not used)

  • e2 – eccentricity component (not used)

Returns:

mass enclosed a 3D radius r

class EPLMajorAxis[source]

Bases: LensProfileBase

This class contains the function and the derivatives of the elliptical power law.

\[\kappa = (2-t)/2 * \left[\frac{b}{\sqrt{q^2 x^2 + y^2}}\right]^t\]

where with \(t = \gamma - 1\) (from EPL class) being the projected power-law slope of the convergence profile, critical radius b, axis ratio q.

Tessore & Metcalf (2015), https://arxiv.org/abs/1507.01819

param_names = ['b', 't', 'q', 'center_x', 'center_y']
__init__()[source]
function(x, y, b, t, q)[source]

Returns the lensing potential.

Parameters:
  • x – x-coordinate in image plane relative to center (major axis)

  • y – y-coordinate in image plane relative to center (minor axis)

  • b – critical radius

  • t – projected power-law slope

  • q – axis ratio

Returns:

lensing potential

derivatives(x, y, b, t, q)[source]

Returns the deflection angles.

Parameters:
  • x – x-coordinate in image plane relative to center (major axis)

  • y – y-coordinate in image plane relative to center (minor axis)

  • b – critical radius

  • t – projected power-law slope

  • q – axis ratio

Returns:

f_x, f_y

hessian(x, y, b, t, q)[source]

Hessian matrix of the lensing potential.

Parameters:
  • x – x-coordinate in image plane relative to center (major axis)

  • y – y-coordinate in image plane relative to center (minor axis)

  • b – critical radius

  • t – projected power-law slope

  • q – axis ratio

Returns:

f_xx, f_yy, f_xy

class EPLQPhi[source]

Bases: LensProfileBase

Class to model a EPL sampling over q and phi instead of e1 and e2.

param_names = ['theta_E', 'gamma', 'q', 'phi', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'gamma': 1.5, 'phi': -3.141592653589793, 'q': 0, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'gamma': 2.5, 'phi': 3.141592653589793, 'q': 1, 'theta_E': 100}
__init__()[source]
function(x, y, theta_E, gamma, q, phi, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • q – axis ratio

  • phi – position angle

  • center_x – profile center

  • center_y – profile center

Returns:

lensing potential

derivatives(x, y, theta_E, gamma, q, phi, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • q – axis ratio

  • phi – position angle

  • center_x – profile center

  • center_y – profile center

Returns:

alpha_x, alpha_y

hessian(x, y, theta_E, gamma, q, phi, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • q – axis ratio

  • phi – position angle

  • center_x – profile center

  • center_y – profile center

Returns:

f_xx, f_xy, f_yx, f_yy

mass_3d_lens(r, theta_E, gamma, q=None, phi=None)[source]

Computes the spherical power-law mass enclosed (with SPP routine).

Parameters:
  • r – radius within the mass is computed

  • theta_E – Einstein radius

  • gamma – power-law slope

  • q – axis ratio (not used)

  • phi – position angle (not used)

Returns:

mass enclosed a 3D radius r.

density_lens(r, theta_E, gamma, q=None, phi=None)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – radius within the mass is computed

  • theta_E – Einstein radius

  • gamma – power-law slope

  • q – axis ratio (not used)

  • phi – position angle (not used)

Returns:

mass enclosed a 3D radius r

lenstronomy.LensModel.Profiles.epl_boxydisky module

class EPL_BOXYDISKY_ELL[source]

Bases: LensProfileBase

“ EPL (Elliptical Power Law) mass profile combined with an elliptical multipole with m=4, so that it’s either purely boxy or disky with EPL’s axis and multipole’s axis aligned (exact for general axis ratio q).

Read the documentation of lenstronomy.LensModel.Profiles.epl and lenstronomy.LensModel.Profiles.multipole for details.

Parameters:
  • theta_E – Einstein radius

  • gamma – negative power-law slope of the 3D mass distributions

  • e1 – eccentricity. For details, read lenstronomy.Util.param_util.phi_q2_ellipticity document.

  • e2 – eccentricity. For details, read lenstronomy.Util.param_util.phi_q2_ellipticity document.

  • center_x – center of distortion

  • center_y – center of distortion

  • a4_a – Strength of the deviation of multipole order 4 of the elliptical isodensity contours, which is translated into the multipole strength from the MULTIPOLE_ELL class through a rescaling by theta_E. Profile is disky when a4_a>0 and boxy when a4_a<0.

param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y', 'a4_a']
lower_limit_default = {'a4_a': -0.1, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'a4_a': 0.1, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
__init__()[source]
function(x, y, theta_E, gamma, e1, e2, a4_a, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • a4_a – multipole strength. The profile becomes disky when a4_a>0 and boxy when a4_a<0

  • center_x – profile center

  • center_y – profile center

Returns:

lensing potential

derivatives(x, y, theta_E, gamma, e1, e2, a4_a, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • a4_a – multipole strength. The profile becomes disky when a4_a>0 and boxy when a4_a<0

  • center_x – profile center

  • center_y – profile center

Returns:

alpha_x, alpha_y

hessian(x, y, theta_E, gamma, e1, e2, a4_a, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • a4_a – multipole strength. The profile becomes disky when a4_a>0 and boxy when a4_a<0

  • center_x – profile center

  • center_y – profile center

Returns:

f_xx, f_xy, f_yx, f_yy

class EPL_BOXYDISKY[source]

Bases: LensProfileBase

“ EPL (Elliptical Power Law) mass profile combined with a circular multipole with m=4, so that it’s either purely boxy or disky with EPL’s axis and multipole’s axis aligned (exact for axis ratio q=1 only).

Reference to the implementation: https://ui.adsabs.harvard.edu/abs/2022A%26A…659A.127V/abstract

Read the documentation of lenstronomy.LensModel.Profiles.epl and lenstronomy.LensModel.Profiles.multipole for details.

Parameters:
  • theta_E – Einstein radius

  • gamma – negative power-law slope of the 3D mass distributions

  • e1 – eccentricity. For details, read lenstronomy.Util.param_util.phi_q2_ellipticity document.

  • e2 – eccentricity. For details, read lenstronomy.Util.param_util.phi_q2_ellipticity document.

  • center_x – center of distortion

  • center_y – center of distortion

  • a4_a – Strength of the deviation of multipole order 4 of the elliptical isodensity contours, which is translated into the multipole strength from the MULTIPOLE class through a rescaling by theta_E / sqrt(q). Profile is disky when a4_a>0 and boxy when a4_a<0.

param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y', 'a4_a']
lower_limit_default = {'a4_a': -0.1, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'a4_a': 0.1, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
__init__()[source]
function(x, y, theta_E, gamma, e1, e2, a4_a, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • a4_a – multipole strength. The profile becomes disky when a4_a>0 and boxy when a4_a<0

  • center_x – profile center

  • center_y – profile center

Returns:

lensing potential

derivatives(x, y, theta_E, gamma, e1, e2, a4_a, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • a4_a – multipole strength. The profile becomes disky when a4_a>0 and boxy when a4_a<0

  • center_x – profile center

  • center_y – profile center

Returns:

alpha_x, alpha_y

hessian(x, y, theta_E, gamma, e1, e2, a4_a, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • a4_a – multipole strength. The profile becomes disky when a4_a>0 and boxy when a4_a<0

  • center_x – profile center

  • center_y – profile center

Returns:

f_xx, f_xy, f_yx, f_yy

lenstronomy.LensModel.Profiles.epl_multipole_m1m3m4 module

class EPL_MULTIPOLE_M1M3M4[source]

Bases: LensProfileBase

EPL (Elliptical Power Law) mass profile combined with three circular multipole terms of order m=1, m=3 and m=4 (exact for axis ratio =1).

Reference to the implementation: https://ui.adsabs.harvard.edu/abs/2022A%26A…659A.127V/abstract

See also documentation of EPL_BOXYDIKSY CLASS, lenstronomy.LensModel.Profiles.epl and lenstronomy.LensModel.Profiles.multipole for details. For an example of using all three circular multipoles together, see e.g. https://ui.adsabs.harvard.edu/abs/2024arXiv241012987L/abstract

Parameters:
  • theta_E – Einstein radius

  • gamma – negative power-law slope of the 3D mass distributions

  • e1 – eccentricity. For details, read lenstronomy.Util.param_util.phi_q2_ellipticity document.

  • e2 – eccentricity. For details, read lenstronomy.Util.param_util.phi_q2_ellipticity document.

  • a1_a – amplitude of the m=1 mutipole perturbation

  • delta_phi_m1 – orientation of the m=1 multipole perturbation relative to EPL

  • center_x – center of distortion

  • center_y – center of distortion

  • a3_a – Strength of the deviation from elliptical isodensity contours caused by the multipole term of order 3 translated into the multipole strength from the MULTIPOLE class through a rescaling by theta_E / sqrt(q). The rescaling preserves the shape of the isodensity contours such that a3_a produces the same shape regardless of theta_E or q.

  • delta_phi_m3 – angle of the m=3 multipole profile relative to the position angle of the EPL profile

  • a4_a – Strength of the deviation from elliptical isodensity contours caused by the multipole term of order 3 translated into the multipole strength from the MULTIPOLE class through a rescaling by theta_E / sqrt(q). Profile is disky when a4_a>0 and boxy when a4_a<0 for phi_m_a4a=0.0.

  • delta_phi_m4 – angle of the m=4 multipole profile relative to the position angle of the EPL profile

param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y', 'a1_a', 'delta_phi_m1', 'a3_a', 'delta_phi_m3', 'a4_a', 'delta_phi_m4']
lower_limit_default = {'a1_a': -0.2, 'a3_a': -0.2, 'a4_a': -0.2, 'center_x': -100, 'center_y': -100, 'delta_phi_m1': -3.141592653589793, 'delta_phi_m3': -0.5235987755982988, 'delta_phi_m4': -0.39269908169872414, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'a1_a': 0.2, 'a3_a': 0.2, 'a4_a': 0.2, 'center_x': 100, 'center_y': 100, 'delta_phi_m1': 3.141592653589793, 'delta_phi_m3': 0.5235987755982988, 'delta_phi_m4': 0.39269908169872414, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
__init__()[source]
function(x, y, theta_E, gamma, e1, e2, a1_a, delta_phi_m1, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the gravitational potential in units of theta_E^2.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a1_a – amplitude of the m=1 mutipole perturbation

  • delta_phi_m1 – orientation of the m=1 multipole perturbation relative to EPL

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

lensing potential.

derivatives(x, y, theta_E, gamma, e1, e2, a1_a, delta_phi_m1, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the derivatives of the potential (deflection angles)in units of theta_E.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a1_a – amplitude of the m=1 mutipole perturbation

  • delta_phi_m1 – orientation of the m=1 multipole perturbation relative to EPL

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

alpha_x, alpha_y.

hessian(x, y, theta_E, gamma, e1, e2, a1_a, delta_phi_m1, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the components of the hessian matrix (second derivatives of the potential)

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a1_a – amplitude of the m=1 mutipole perturbation

  • delta_phi_m1 – orientation of the m=1 multipole perturbation relative to EPL

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

f_xx, f_xy, f_yx, f_yy.

class EPL_MULTIPOLE_M1M3M4_ELL[source]

Bases: LensProfileBase

EPL (Elliptical Power Law) mass profile combined with three elliptical multipole terms of order m=1, m=3 and m=4 (exact for general axis ratio q).

See also documentation of EPL_BOXYDIKSY CLASS, lenstronomy.LensModel.Profiles.epl and lenstronomy.LensModel.Profiles.multipole for details.

param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y', 'a1_a', 'delta_phi_m1', 'a3_a', 'delta_phi_m3', 'a4_a', 'delta_phi_m4']
lower_limit_default = {'a1_a': -0.2, 'a3_a': -0.2, 'a4_a': -0.2, 'center_x': -100, 'center_y': -100, 'delta_phi_m1': -3.141592653589793, 'delta_phi_m3': -0.5235987755982988, 'delta_phi_m4': -0.39269908169872414, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'a1_a': 0.2, 'a3_a': 0.2, 'a4_a': 0.2, 'center_x': 100, 'center_y': 100, 'delta_phi_m1': 3.141592653589793, 'delta_phi_m3': 0.5235987755982988, 'delta_phi_m4': 0.39269908169872414, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
__init__()[source]
function(x, y, theta_E, gamma, e1, e2, a1_a, delta_phi_m1, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the gravitational potential in units of theta_E^2.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a1_a – amplitude of the m=1 mutipole perturbation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m1 – orientation of the m=1 multipole perturbation relative to EPL

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

lensing potential.

derivatives(x, y, theta_E, gamma, e1, e2, a1_a, delta_phi_m1, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the derivatives of the potential (deflection angles)in units of theta_E.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a1_a – amplitude of the m=1 mutipole perturbationfrom pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m1 – orientation of the m=1 multipole perturbation relative to EPL

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

alpha_x, alpha_y.

hessian(x, y, theta_E, gamma, e1, e2, a1_a, delta_phi_m1, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the components of the hessian matrix (second derivatives of the potential)

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a1_a – amplitude of the m=1 mutipole perturbation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m1 – orientation of the m=1 multipole perturbation relative to EPL

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

f_xx, f_xy, f_yx, f_yy.

lenstronomy.LensModel.Profiles.epl_multipole_m3m4 module

class EPL_MULTIPOLE_M3M4[source]

Bases: LensProfileBase

EPL (Elliptical Power Law) mass profile combined with two circular multipole terms of order m=3 and m=4 (exact for axis ratio =1).

Reference to the implementation: https://ui.adsabs.harvard.edu/abs/2022A%26A…659A.127V/abstract

See also documentation of EPL_BOXYDIKSY CLASS, lenstronomy.LensModel.Profiles.epl and lenstronomy.LensModel.Profiles.multipole for details.

param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y', 'a3_a', 'delta_phi_m3', 'a4_a', 'delta_phi_m4']
lower_limit_default = {'a3_a': -0.2, 'a4_a': -0.2, 'center_x': -100, 'center_y': -100, 'delta_phi_m3': -0.5235987755982988, 'delta_phi_m4': -0.39269908169872414, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'a3_a': 0.2, 'a4_a': 0.2, 'center_x': 100, 'center_y': 100, 'delta_phi_m3': 0.5235987755982988, 'delta_phi_m4': 0.39269908169872414, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
__init__()[source]
function(x, y, theta_E, gamma, e1, e2, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the gravitational potential in units of theta_E^2.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

lensing potential.

derivatives(x, y, theta_E, gamma, e1, e2, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the derivatives of the potential (deflection angles)in units of theta_E.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

alpha_x, alpha_y.

hessian(x, y, theta_E, gamma, e1, e2, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the components of the hessian matrix (second derivatives of the potential)

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE profile by a scaling theta_E / sqrt(q)

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

f_xx, f_xy, f_yx, f_yy.

class EPL_MULTIPOLE_M3M4_ELL[source]

Bases: LensProfileBase

EPL (Elliptical Power Law) mass profile combined with two elliptical multipole terms of order m=3 and m=4 (exact for general axis ratio q).

See also documentation of EPL_BOXYDIKSY CLASS, lenstronomy.LensModel.Profiles.epl and lenstronomy.LensModel.Profiles.multipole for details.

param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y', 'a3_a', 'delta_phi_m3', 'a4_a', 'delta_phi_m4']
lower_limit_default = {'a3_a': -0.2, 'a4_a': -0.2, 'center_x': -100, 'center_y': -100, 'delta_phi_m3': -0.5235987755982988, 'delta_phi_m4': -0.39269908169872414, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'a3_a': 0.2, 'a4_a': 0.2, 'center_x': 100, 'center_y': 100, 'delta_phi_m3': 0.5235987755982988, 'delta_phi_m4': 0.39269908169872414, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
__init__()[source]
function(x, y, theta_E, gamma, e1, e2, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the gravitational potential in units of theta_E^2.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

lensing potential.

derivatives(x, y, theta_E, gamma, e1, e2, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the derivatives of the potential (deflection angles)in units of theta_E.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

alpha_x, alpha_y.

hessian(x, y, theta_E, gamma, e1, e2, a3_a, delta_phi_m3, a4_a, delta_phi_m4, center_x=0, center_y=0)[source]

Computes the components of the hessian matrix (second derivatives of the potential)

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – log-slope of EPL mass profile

  • e1 – ellipticity of EPL profile (along 1st axis)

  • e2 – ellipticity of EPL profile (along 2nd axis)

  • a3_a – amplitude of the m=3 multiple deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m3 – orientation of the m=3 profile relative to the position angle of the EPL profile

  • a4_a – amplitude of the m=4 multipole deviation from pure elliptical shape related to the physical amplitude of the MULTIPOLE_ELL profile by a scaling theta_E

  • delta_phi_m4 – orientation of the m=4 profile relative to the position angle of the EPL profile

  • center_x – center of the profile

  • center_y – center of the profile

Returns:

f_xx, f_xy, f_yx, f_yy.

lenstronomy.LensModel.Profiles.epl_numba module

class EPL_numba[source]

Bases: LensProfileBase

” Elliptical Power Law mass profile - computation accelerated with numba

\[\kappa(x, y) = \frac{3-\gamma}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q}} \right)^{\gamma-1}\]

with \(\theta_{E}\) is the (circularized) Einstein radius, \(\gamma\) is the negative power-law slope of the 3D mass distributions, \(q\) is the minor/major axis ratio, and \(x\) and \(y\) are defined in a coordinate system aligned with the major and minor axis of the lens.

In terms of eccentricities, this profile is defined as

\[\kappa(r) = \frac{3-\gamma}{2} \left(\frac{\theta'_{E}}{r \sqrt{1 − e*\cos(2*\phi)}} \right)^{\gamma-1}\]

with \(\epsilon\) is the ellipticity defined as

\[\epsilon = \frac{1-q^2}{1+q^2}\]

And an Einstein radius \(\theta'_{\rm E}\) related to the definition used is

\[\left(\frac{\theta'_{\rm E}}{\theta_{\rm E}}\right)^{2} = \frac{2q}{1+q^2}.\]

The mathematical form of the calculation is presented by Tessore & Metcalf (2015), https://arxiv.org/abs/1507.01819. The current implementation is using hyperbolic functions. The paper presents an iterative calculation scheme, converging in few iterations to high precision and accuracy.

A (slower) implementation of the same model using hyperbolic functions without the iterative calculation is accessible as ‘EPL’ not requiring numba.

param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
__init__()[source]
static function(x, y, theta_E, gamma, e1, e2, center_x=0.0, center_y=0.0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

lensing potential

static derivatives(x, y, theta_E, gamma, e1, e2, center_x=0.0, center_y=0.0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

deflection angles alpha_x, alpha_y

static hessian(x, y, theta_E, gamma, e1, e2, center_x=0.0, center_y=0.0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

Hessian components f_xx, f_yy, f_xy

lenstronomy.LensModel.Profiles.flexion module

class Flexion(*args, **kwargs)[source]

Bases: LensProfileBase

Class for flexion.

param_names = ['g1', 'g2', 'g3', 'g4', 'ra_0', 'dec_0']
lower_limit_default = {'dec_0': -100, 'g1': -0.1, 'g2': -0.1, 'g3': -0.1, 'g4': -0.1, 'ra_0': -100}
upper_limit_default = {'dec_0': 100, 'g1': 0.1, 'g2': 0.1, 'g3': 0.1, 'g4': 0.1, 'ra_0': 100}
function(x, y, g1, g2, g3, g4, ra_0=0, dec_0=0)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, g1, g2, g3, g4, ra_0=0, dec_0=0)[source]

Deflection angles.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

hessian(x, y, g1, g2, g3, g4, ra_0=0, dec_0=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

lenstronomy.LensModel.Profiles.flexionfg module

class Flexionfg[source]

Bases: LensProfileBase

Flexion consist of basis F flexion and G flexion (F1,F2,G1,G2), see formulas 2.54, 2.55 in Massimo Meneghetti 2017 - “Introduction to Gravitational Lensing”.

The flexion is a third order derivative of the lensing potential, i.e. the deflection angle. The flexion is a measure of the lensing shear gradient, i.e. the change of the shear field with respect to the position on the sky.

The second order lensing effects can be expressed in terms of the third derivatives of the lensing potential, which can be written in terms of the flexion F and G.

\[\beta_i\simeq\sum_{j} A_{ij}\theta_j+\frac{1}{2}\sum_{j}\sum_{k}D_{ijk}\theta_j\theta_k\]

Which is the second order lensing effects expressed in terms of the third derivatives of the lensing potential (Formula 3.60 in Meneghetti 2021).

These in turn can be expressed in terms of the flexion F and G.

\[D_{111}=-2\gamma_{11}-\gamma_{22}=\frac{1}{2}(3F_1+G_1) D_{211}=D_{131}=D_{112}-\gamma_{21}=-\frac{1}{2}(F_2+G_2) D_{122}=D_{212}=D_{221}=-\gamma_{22}=-\frac{1}{2}(F_1-G_1) D_{222}=2\gamma_{12}-\gamma_{21}=-\frac{1}{2}(3F_2-G_2)\]

(Formula 3.98 in Meneghetti 2017).

Then we find that the two components of vec{beta} are:

\[\beta_1=A_{11}\theta_1+A_{12}\theta_2+\frac{1}{2}D_{111}\theta_1^2+D_{121}\theta_1\theta_2+\frac{1}{2}D_{122}\theta_2^2 \beta_2=A_{21}\theta_1+A_{22}\theta_2+\frac{1}{2}D_{211}\theta_1^2+D_{212}\theta_1\theta_2+\frac{1}{2}D_{222}\theta_2^2\]

(Formula 3.99 in Meneghetti 2021).

Now we can express the flexion in terms of ra_0, and dec_0, which are the zero-points of the polynomial expansion. Instead of using absolute coordinates theta_1, and theta_2, we define the relative angular positions:

\[x = \theta_1 - ra_0 y = \theta_2 - dec_0\]
param_names = ['F1', 'F2', 'G1', 'G2', 'ra_0', 'dec_0']
lower_limit_default = {'F1': -0.1, 'F2': -0.1, 'G1': -0.1, 'G2': -0.1, 'dec_0': -100, 'ra_0': -100}
upper_limit_default = {'F1': 0.1, 'F2': 0.1, 'G1': 0.1, 'G2': 0.1, 'dec_0': 100, 'ra_0': 100}
__init__()[source]
function(x, y, F1, F2, G1, G2, ra_0=0, dec_0=0)[source]

Lensing potential.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • F1 – F1 flexion, derivative of kappa in x direction

  • F2 – F2 flexion, derivative of kappa in y direction

  • G1 – G1 flexion

  • G2 – G2 flexion

  • ra_0 – center x-coordinate

  • dec_0 – center y-coordinate

Returns:

lensing potential

derivatives(x, y, F1, F2, G1, G2, ra_0=0, dec_0=0)[source]

Deflection angle.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • F1 – F1 flexion, derivative of kappa in x direction

  • F2 – F2 flexion, derivative of kappa in y direction

  • G1 – G1 flexion

  • G2 – G2 flexion

  • ra_0 – center x-coordinate

  • dec_0 – center x-coordinate

Returns:

deflection angle.

hessian(x, y, F1, F2, G1, G2, ra_0=0, dec_0=0)[source]

Hessian matrix.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • F1 – F1 flexion, derivative of kappa in x direction

  • F2 – F2 flexion, derivative of kappa in y direction

  • G1 – G1 flexion

  • G2 – G2 flexion

  • ra_0 – center x-coordinate

  • dec_0 – center y-coordinate

Returns:

second order derivatives f_xx, f_yy, f_xy

static transform_fg(F1, F2, G1, G2)[source]

Basis transform from (F1,F2,G1,G2) to (g1,g2,g3,g4).

Parameters:
  • F1 – F1 flexion, derivative of kappa in x direction

  • F2 – F2 flexion, derivative of kappa in y direction

  • G1 – G1 flexion

  • G2 – G2 flexion

Returns:

g1,g2,g3,g4 (phi_xxx, phi_xxy, phi_xyy, phi_yyy)

lenstronomy.LensModel.Profiles.gauss_decomposition module

This module contains the class to compute lensing properties of any elliptical profile using Shajib (2019)’s Gauss decomposition.

class SersicEllipseGaussDec(n_sigma=15, sigma_start_mult=0.02, sigma_end_mult=15.0, precision=10, use_scipy_wofz=True, min_ellipticity=1e-05)[source]

Bases: GaussDecompositionAbstract

This class computes the lensing properties of an elliptical Sersic profile using the Shajib (2019)’s Gauss decomposition method.

param_names = ['k_eff', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'R_sersic': 0.0, 'center_x': -100.0, 'center_y': -100.0, 'e1': -0.5, 'e2': -0.5, 'k_eff': 0.0, 'n_sersic': 0.5}
upper_limit_default = {'R_sersic': 100.0, 'center_x': 100.0, 'center_y': 100.0, 'e1': 0.5, 'e2': 0.5, 'k_eff': 100.0, 'n_sersic': 8.0}
get_kappa_1d(y, **kwargs)[source]

Compute the spherical Sersic profile at y.

Parameters:
  • y (float) – y coordinate

  • kwargs – Keyword arguments

Keyword Arguments:
  • n_sersic (float) – Sersic index

  • R_sersic (float) – Sersic scale radius

  • k_eff (float) – Sersic convergence at R_sersic

Returns:

Sersic function at y

Return type:

type(y)

get_scale(**kwargs)[source]

Identify the scale size from the keyword arguments.

Parameters:

kwargs – Keyword arguments

Keyword Arguments:
  • n_sersic (float) – Sersic index

  • R_sersic (float) – Sersic scale radius

  • k_eff (float) – Sersic convergence at R_sersic

Returns:

Sersic radius

Return type:

float

class NFWEllipseGaussDec(n_sigma=20, sigma_start_mult=0.0001, sigma_end_mult=250.0, precision=10, use_scipy_wofz=True, min_ellipticity=1e-05)[source]

Bases: GaussDecompositionAbstract

This class computes the lensing properties of an elliptical, projected NFW profile using Shajib (2019)’s Gauss decomposition method.

param_names = ['Rs', 'alpha_Rs', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5}
__init__(n_sigma=20, sigma_start_mult=0.0001, sigma_end_mult=250.0, precision=10, use_scipy_wofz=True, min_ellipticity=1e-05)[source]

Set up settings for the Gaussian decomposition. For more details about the decomposition parameters, see Shajib (2019).

Parameters:
  • n_sigma (int) – Number of Gaussian components

  • sigma_start_mult (float) – Lower range of logarithmically spaced sigmas

  • sigma_end_mult (float) – Upper range of logarithmically spaced sigmas

  • precision (int) – Numerical precision of Gaussian decomposition

  • use_scipy_wofz (bool) – To be passed to class GaussianEllipseKappa. If True, Gaussian lensing will use scipy.special.wofz function. Set False for lower precision, but faster speed.

  • min_ellipticity (float) – To be passed to class GaussianEllipseKappa. Minimum ellipticity for Gaussian elliptical lensing calculation. For lower ellipticity than min_ellipticity the equations for the spherical case will be used.

get_kappa_1d(y, **kwargs)[source]

Compute the spherical projected NFW profile at y.

Parameters:
  • y (float) – y coordinate

  • kwargs – Keyword arguments

Keyword Arguments:
  • alpha_Rs (float) – Deflection angle at Rs

  • R_s (float) – NFW scale radius

Returns:

projected NFW profile at y

Return type:

type(y)

get_scale(**kwargs)[source]

Identify the scale size from the keyword arguments.

Parameters:

kwargs – Keyword arguments

Keyword Arguments:
  • alpha_Rs (float) – Deflection angle at Rs

  • R_s (float) – NFW scale radius

Returns:

NFW scale radius

Return type:

float

class GeneralizedNFWEllipseGaussDec(n_sigma=20, sigma_start_mult=0.0001, sigma_end_mult=250.0, precision=10, use_scipy_wofz=False, min_ellipticity=1e-05)[source]

Bases: GaussDecompositionAbstract

This class computes the lensing properties of an elliptical, projected gNFW profile using Shajib (2019)’s Gauss decomposition method.

param_names = ['Rs', 'alpha_Rs', 'e1', 'e2', 'center_x', 'center_y', 'gamma_in']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma_in': 0.0}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma_in': 2.5}
__init__(n_sigma=20, sigma_start_mult=0.0001, sigma_end_mult=250.0, precision=10, use_scipy_wofz=False, min_ellipticity=1e-05)[source]

Set up settings for the Gaussian decomposition. For more details about the decomposition parameters, see Shajib (2019).

Parameters:
  • n_sigma (int) – Number of Gaussian components

  • sigma_start_mult (float) – Lower range of logarithmically spaced sigmas

  • sigma_end_mult (float) – Upper range of logarithmically spaced sigmas

  • precision (int) – Numerical precision of Gaussian decomposition

  • use_scipy_wofz (bool) – To be passed to class GaussianEllipseKappa. If True, Gaussian lensing will use scipy.special.wofz function. Set False for lower precision, but faster speed.

  • min_ellipticity (float) – To be passed to class GaussianEllipseKappa. Minimum ellipticity for Gaussian elliptical lensing calculation. For lower ellipticity than min_ellipticity the equations for the spherical case will be used.

get_kappa_1d(y, **kwargs)[source]

Compute the spherical projected gNFW profile at y. See Keeton (2001, page 11).

Parameters:
  • y (float) – y coordinate

  • **kwargs – Keyword arguments

Keyword Arguments:
  • alpha_Rs (float) – Deflection angle at Rs

  • R_s (float) – gNFW scale radius

Returns:

projected NFW profile at y

Return type:

type(y)

get_scale(**kwargs)[source]

Identify the scale size from the keyword arguments.

Parameters:

**kwargs – Keyword arguments

Keyword Arguments:
  • alpha_Rs (float) – Deflection angle at Rs

  • R_s (float) – NFW scale radius

Returns:

NFW scale radius

Return type:

float

lenstronomy.LensModel.Profiles.gaussian module

class Gaussian[source]

Bases: LensProfileBase

This class contains functions to evaluate a Gaussian convergence and calculates its derivative and hessian matrix.

param_names = ['amp', 'sigma', 'center_x', 'center_y']
lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'sigma': 0}
upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'sigma': 100}
__init__()[source]
function(x, y, amp, sigma, center_x=0, center_y=0)[source]

Returns potential for a Gaussian convergence.

Parameters:
  • x – x position

  • y – y position

  • amp – 2d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

  • center_x – x position of the center of the lens

  • center_y – y position of the center of the lens

derivatives(x, y, amp, sigma, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

Parameters:
  • x – x position

  • y – y position

  • amp – 2d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

  • center_x – x position of the center of the lens

  • center_y – y position of the center of the lens

hessian(x, y, amp, sigma, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

Parameters:
  • x – x position

  • y – y position

  • amp – 2d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

  • center_x – x position of the center of the lens

  • center_y – y position of the center of the lens

density(r, amp, sigma)[source]

3d mass density as a function of radius r.

Parameters:
  • r – radius

  • amp – 3d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

density_lens(r, amp, sigma)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity. (optional definition)

\[\kappa(x, y) = \int_{-\infty}^{\infty} \rho(x, y, z) dz\]
Parameters:
  • r – radial distance from the center (in 3D)

  • amp – 2d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

Returns:

density

density_2d(x, y, amp, sigma, center_x=0, center_y=0)[source]

Projected 2d density at position (x,y)

Parameters:
  • x – x position

  • y – y position

  • amp – 3d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

  • center_x – x position of the center of the lens

  • center_y – y position of the center of the lens

mass_2d(R, amp, sigma)[source]

Mass enclosed in a circle of radius R when projected into 2d.

Parameters:
  • R – projected radius

  • amp – 3d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

mass_2d_lens(R, amp, sigma)[source]

Mass enclosed in a circle of radius R when projected into 2d.

Parameters:
  • R – projected radius

  • amp – 2d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

alpha_abs(R, amp, sigma)[source]

Absolute value of the deflection.

Parameters:
  • R – radius projected into 2d

  • amp – 2d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

Returns:

d_alpha_dr(R, amp, sigma_x, sigma_y)[source]

Derivative of deflection angle w.r.t r.

Parameters:
  • R – radius projected into 2d

  • amp – 2d amplitude of Gaussian

  • sigma_x – standard deviation of Gaussian in x direction

  • sigma_y – standard deviation of Gaussian in y direction

mass_3d(R, amp, sigma)[source]

Mass enclosed within a 3D sphere of projected radius R given a lens parameterization with angular units. The input parameter amp is the 3d amplitude.

Parameters:
  • R – radius projected into 2d

  • amp – 3d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

mass_3d_lens(R, amp, sigma)[source]

Mass enclosed within a 3D sphere of projected radius R given a lens parameterization with angular units. The input parameters are identical as for the derivatives definition. (optional definition)

Parameters:
  • R – radius projected into 2d

  • amp – 2d amplitude of Gaussian

  • sigma – standard deviation of Gaussian

lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa module

This module defines class GaussianEllipseKappa to compute the lensing properties of an elliptical Gaussian profile with ellipticity in the convergence using the formulae from Shajib (2019).

class GaussianEllipseKappa(use_scipy_wofz=True, min_ellipticity=1e-05)[source]

Bases: LensProfileBase

This class contains functions to evaluate the derivative and hessian matrix of the deflection potential for an elliptical Gaussian convergence.

The formulae are from Shajib (2019).

param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma': 0}
upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma': 100}
__init__(use_scipy_wofz=True, min_ellipticity=1e-05)[source]

Setup which method to use the Faddeeva function and the ellipticity limit for spherical approximation.

Parameters:
  • use_scipy_wofz (bool) – If True, use scipy.special.wofz.

  • min_ellipticity (float) – Minimum allowed ellipticity. For q > 1 - min_ellipticity, values for spherical case will be returned.

function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]

Compute the potential function for elliptical Gaussian convergence.

Parameters:
  • x (float or numpy.array) – x coordinate

  • y (float or numpy.array) – y coordinate

  • amp (float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • sigma (float) – Standard deviation of Gaussian

  • e1 (float) – Ellipticity parameter 1

  • e2 (float) – Ellipticity parameter 2

  • center_x (float) – x coordinate of centroid

  • center_y (float) – y coordianate of centroid

Returns:

Potential for elliptical Gaussian convergence

Return type:

float, or numpy.array with shape equal to x.shape

derivatives(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]

Compute the derivatives of function angles \(\partial f/\partial x\), \(\partial f/\partial y\) at \(x,\ y\).

Parameters:
  • x (float or numpy.array) – x coordinate

  • y (float or numpy.array) – y coordinate

  • amp (float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • sigma (float) – Standard deviation of Gaussian

  • e1 (float) – Ellipticity parameter 1

  • e2 (float) – Ellipticity parameter 2

  • center_x (float) – x coordinate of centroid

  • center_y (float) – y coordianate of centroid

Returns:

Deflection angle \(\partial f/\partial x\), \(\partial f/\partial y\) for elliptical Gaussian convergence.

Return type:

tuple (float, float) or (numpy.array, numpy.array) with each numpy.array’s shape equal to x.shape.

hessian(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]

Compute Hessian matrix of function \(\partial^2f/\partial x^2\), \(\partial^2 f/\partial y^2\), \(\partial^2/\partial x\partial y\).

Parameters:
  • x (float or numpy.array) – x coordinate

  • y (float or numpy.array) – y coordinate

  • amp (float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • sigma (float) – Standard deviation of Gaussian

  • e1 (float) – Ellipticity parameter 1

  • e2 (float) – Ellipticity parameter 2

  • center_x (float) – x coordinate of centroid

  • center_y (float) – y coordianate of centroid

Returns:

Hessian \(A/(2 \pi \sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\) for elliptical Gaussian convergence.

Return type:

tuple (float, float, float) , or (numpy.array, numpy.array, numpy.array) with each numpy.array’s shape equal to x.shape.

density_2d(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]

Compute the density of elliptical Gaussian \(A/(2 \pi \sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\).

Parameters:
  • x (float or numpy.array) – x coordinate.

  • y (float or numpy.array) – y coordinate.

  • amp (float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • sigma (float) – Standard deviation of Gaussian.

  • e1 (float) – Ellipticity parameter 1.

  • e2 (float) – Ellipticity parameter 2.

  • center_x (float) – x coordinate of centroid.

  • center_y (float) – y coordianate of centroid.

Returns:

Density \(\kappa\) for elliptical Gaussian convergence.

Return type:

float, or numpy.array with shape = x.shape.

static sgn(z)[source]

Compute the sign function \(\mathrm{sgn}(z)\) factor for deflection as sugggested by Bray (1984). For current implementation, returning 1 is sufficient.

Parameters:

z (complex) – Complex variable \(z = x + \mathrm{i}y\)

Returns:

\(\mathrm{sgn}(z)\)

Return type:

float

sigma_function(x, y, q)[source]

Compute the function \(\varsigma (z; q)\) from equation (4.12) of Shajib (2019).

Parameters:
  • x (float or numpy.array) – Real part of complex variable, \(x = \mathrm{Re}(z)\)

  • y (float or numpy.array) – Imaginary part of complex variable, \(y = \mathrm{Im}(z)\)

  • q (float) – Axis ratio

Returns:

real and imaginary part of \(\varsigma(z; q)\) function

Return type:

tuple (type(x), type(x))

static w_f_approx(z)[source]

Compute the Faddeeva function \(w_{\mathrm F}(z)\) using the approximation given in Zaghloul (2017).

Parameters:

z (complex or numpy.array(dtype=complex)) – complex number

Returns:

\(w_\mathrm{F}(z)\)

Return type:

complex

lenstronomy.LensModel.Profiles.gaussian_ellipse_potential module

class GaussianEllipsePotential[source]

Bases: LensProfileBase

This class contains functions to evaluate a Gaussian convergence and calculates its derivative and hessian matrix with ellipticity in the potential.

The calculation follows Glenn van de Ven et al. 2009.

param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma': 0}
upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma': 100}
__init__()[source]
function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]

Returns Gaussian.

derivatives(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

hessian(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

density(r, amp, sigma, e1, e2)[source]
Parameters:
  • r

  • amp

  • sigma

Returns:

density_2d(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x

  • y

  • amp

  • sigma

  • e1

  • e2

  • center_x

  • center_y

Returns:

mass_2d(R, amp, sigma, e1, e2)[source]
Parameters:
  • R

  • amp

  • sigma

  • e1

  • e2

Returns:

mass_3d(R, amp, sigma, e1, e2)[source]
Parameters:
  • R

  • amp

  • sigma

  • e1

  • e2

Returns:

mass_3d_lens(R, amp, sigma, e1, e2)[source]
Parameters:
  • R

  • amp

  • sigma

  • e1

  • e2

Returns:

mass_2d_lens(R, amp, sigma, e1, e2)[source]
Parameters:
  • R

  • amp

  • sigma

  • e1

  • e2

Returns:

lenstronomy.LensModel.Profiles.gaussian_potential module

class GaussianPotential(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains functions to evaluate a Gaussian potential and calculates its derivative and hessian matrix.

param_names = ['amp', 'sigma_x', 'sigma_y', 'center_x', 'center_y']
lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'sigma_x': 0, 'sigma_y': 0}
upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'sigma_x': 100, 'sigma_y': 100}
function(x, y, amp, sigma_x, sigma_y, center_x=0, center_y=0)[source]

Returns Gaussian.

derivatives(x, y, amp, sigma_x, sigma_y, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

hessian(x, y, amp, sigma_x, sigma_y, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

lenstronomy.LensModel.Profiles.gnfw module

class GNFW(trapezoidal_integration=False, integration_steps=1000)[source]

Bases: LensProfileBase

This class computes the lensing quantities of a generalized NFW profile:

\[\rho(r) = \frac{\rho_{\rm s}} { (r/r_{\rm s}})^{\gamma_{\rm in}} * (1 + r/r_{\rm s})^{3 - {\gamma_{\rm in}}}\]

This class uses the normalization parameter kappa_s defined as:

\[kappas_{\rm s} = \frac{\rho_{\rm s} r_{\rm s}}{\Sigma_{\rm crit}}\]

Some expressions are obtained from Keeton 2001 https://ui.adsabs.harvard.edu/abs/2001astro.ph..2341K/abstract. See and cite the references therein.

model_name = 'GNFW'
param_names = ['Rs', 'alpha_Rs', 'gamma_in', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'gamma_in': 0.0}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10.0, 'center_x': 100, 'center_y': 100, 'gamma_in': 3.0}
__init__(trapezoidal_integration=False, integration_steps=1000)[source]
Parameters:
  • trapezoidal_integrate – bool, if True, the numerical integral is performed with the trapezoidal rule, otherwise with ~scipy.integrate.quad

  • integration_steps – number of steps in the trapezoidal integral

function(x, y, Rs, alpha_Rs, gamma_in, center_x=0, center_y=0)[source]

Potential of gNFW profile.

Parameters:
  • x (float/numpy array) – angular position

  • y (float/numpy array) – angular position

  • Rs (float) – angular turn over point

  • alpha_Rs (float) – deflection (angular units) at projected Rs

  • gamma_in (float) – inner slope

  • center_x (float) – center of halo

  • center_y (float) – center of halo

Returns:

potential at radius r

Return type:

float

derivatives(x, y, Rs, alpha_Rs, gamma_in, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

Parameters:
  • x (float/numpy array) – angular position

  • y (float/numpy array) – angular position

  • Rs (float) – angular turn over point

  • alpha_Rs (float) – deflection (angular units) at projected Rs

  • gamma_in (float) – inner slope

  • center_x (float) – center of halo

  • center_y (float) – center of halo

Returns:

deflection angle in x, deflection angle in y

Return type:

float, float

hessian(x, y, Rs, alpha_Rs, gamma_in, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy.

Parameters:
  • x (float/numpy array) – angular position

  • y (float/numpy array) – angular position

  • Rs (float) – angular turn over point

  • alpha_Rs (float) – deflection (angular units) at projected Rs

  • gamma_in (float) – inner slope

  • center_x (float) – center of halo

  • center_y (float) – center of halo

Returns:

f_xx, f_xy, f_xy, f_yy

Return type:

float, float, float, float

density(R, Rs, rho0, gamma_in)[source]

Three dimensional generalized NFW profile.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization

  • gamma_in (float) – inner slope

Returns:

rho(R) density

Return type:

float

density_lens(R, Rs, alpha_Rs, gamma_in)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • alpha_Rs (float) – deflection at Rs

  • gamma_in (float) – inner slope

Returns:

density at radius R

Return type:

float

density_2d(x, y, Rs, rho0, gamma_in, center_x=0, center_y=0)[source]

Projected two dimenstional NFW profile (kappa*Sigma_crit)

Parameters:
  • x (float/numpy array) – x-coordinate

  • y (float/numpy array) – y-coordinate

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

  • gamma_in (float) – inner slope

  • center_x (float) – center of halo

  • center_y (float) – center of halo

Returns:

Epsilon(R) projected density at radius R

mass_3d(R, Rs, rho0, gamma_in)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

  • gamma_in (float) – inner slope

Returns:

mass enclosed a 3d sphere or radius r

Return type:

float

mass_3d_lens(R, Rs, alpha_Rs, gamma_in)[source]

Mass enclosed a 3d sphere or radius r given a lens parameterization with angular units.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • alpha_Rs (float) – deflection at Rs

  • gamma_in (float) – inner slope

Returns:

mass enclosed a 3d sphere or radius r

Return type:

float

alpha(R, Rs, alpha_Rs, gamma_in)[source]

Deflection angel of gNFW profile along the radial direction.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • alpha_Rs (float) – deflection at Rs

  • gamma_in (float) – inner slope

Returns:

deflection angel at radius R

Return type:

float

kappa(R, Rs, alpha_Rs, gamma_in)[source]

Convergence of gNFW profile along the radial direction.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • alpha_Rs (float) – deflection at Rs

  • gamma_in (float) – inner slope

Returns:

convergence at radius R

Return type:

float

kappa_s_to_alpha_Rs(kappa_s, Rs, gamma_in)[source]

Convert the convergence at Rs to the density normalization.

Parameters:
  • kappa_s (float) – convergence at Rs

  • Rs (float) – scale radius

  • gamma_in (float) – inner slope

Returns:

rho0

Return type:

float

alpha_Rs_to_kappa_s(Rs, alpha_Rs, gamma_in)[source]

Convert the deflection at Rs to the convergence at Rs.

Parameters:
  • Rs (float) – scale radius

  • alpha_Rs (float) – deflection at Rs

  • gamma_in (float) – inner slope

Returns:

kappa_s

Return type:

float

rho02alpha(rho0, Rs, gamma_in)[source]

Convenience function to compute alpha_Rs from rho0.

Parameters:
  • rho0 (float) – density normalization (characteristic density)

  • Rs (float) – scale radius

  • gamma_in (float) – inner slope

Returns:

alpha_Rs

Return type:

float

alpha2rho0(alpha_Rs, Rs, gamma_in)[source]

Convenience function to compute rho0 from alpha_Rs.

Parameters:
  • alpha_Rs (float) – deflection at Rs

  • Rs (float) – scale radius

  • gamma_in (float) – inner slope

Returns:

rho0

Return type:

float

static rho0_to_kappa_s(rho0, Rs)[source]

Convenience function to compute rho0 from alpha_Rs.

Parameters:
  • rho0 (float) – density normalization (characteristic density)

  • Rs (float) – scale radius

  • gamma_in (float) – inner slope

Returns:

kappa_s

Return type:

float

static kappa_s_to_rho0(kappa_s, Rs)[source]

Convenience function to compute rho0 from kappa_s. The returned rho_0 is normalized with $Sigma_{rm crit}$.

Parameters:
  • kappa_s (float) – convergence at Rs

  • Rs (float) – scale radius

  • gamma_in (float) – inner slope

Returns:

rho0

Return type:

float

get_alpha_Rs_for_kappa_s_1(Rs, gamma_in)[source]

Compute the deflection at Rs.

Parameters:
  • Rs (float) – scale radius

  • gamma_in (float) – inner slope

Returns:

alpha_Rs for kappa_s = 1

Return type:

float

lenstronomy.LensModel.Profiles.greenboschnfw module

class GreenBoschNFW(r_min: float = 5e-05, r_max_factor: float = 10.0, num_bins: int = 400, **kwargs_numerics)[source]

Bases: LensProfileBase

This class computes the lensing quantities of a tidally evolved NFW profile:

\[\rho(r,t) = \frac{ f_{te} \rho_{0} } { ( 1 + (\frac{r}{r_s}\frac{c_s - r_{te}}{c_s * r_{te}} )^{\delta}) (\frac{r}{r_s}) (1 + \frac{r}{r_s})^2 }\]

This class uses the dimensionless NFW normalization parameter “rho0ang” defined as:

\[\rho0ang = \frac{ D_{l} \rho_{0,phys} }{ \Sigma_{crit} } ([Mpc] * [M_{solar}/Mpc^3 ] / [M_{solar}/Mpc^2] * [pi/180/3600 radians/arcsecond]), where D_{l} is the angular diameter distance to the lens in Mpc\]

The density profile is defined in Green/Bosch 2019, see: https://ui.adsabs.harvard.edu/abs/2019MNRAS.490.2091G/abstract

model_name = 'GreenBoschNFW'
param_names = ['f_b', 'c_s', 'Rs', 'rho0ang', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0.02, 'c_s': 0.02, 'center_x': -10000.0, 'center_y': -10000.0, 'f_b': 1e-05, 'rho0ang': 0.0}
upper_limit_default = {'Rs': 1000.0, 'c_s': 1000.0, 'center_x': 10000.0, 'center_y': 10000.0, 'f_b': 1.0, 'rho0ang': 1e+25}
__init__(r_min: float = 5e-05, r_max_factor: float = 10.0, num_bins: int = 400, **kwargs_numerics)[source]

Initialization of the GreenBoschNFW class object.

Parameters:
  • r_min (Float) – Minimum 2D radius of integration from subhalo center [arcseconds]

  • r_max_factor (Float) – Maximum 2D radius of integration from subhalo center in units of scale radius [arcseconds/Rs]

  • num_bins (Integer) – Number of log-spaced radial bins to integrate

function(x, y, f_b, c_s, Rs, rho0ang, center_x, center_y)[source]

Lensing potential of the GreenBoschNFW profile.

Parameters:
  • x (Float) – Angular position [arcseconds]

  • y (Float) – Angular position [arcseconds]

  • f_b (Float) – Instantaneous bound mass fraction relative to infall mass (M_bound / M_infall)

  • c_s (Float) – Infall NFW concentration (R_virial / R_scale)

  • Rs (Float) – Infall NFW scale radius [arcseconds]

  • rho0ang (Float) – Dimensionless NFW normalization

  • center_x (Float) – Position of halo center [arcseconds]

  • center_y (Float) – Position of halo center [arcseconds]

Returns:

Lensing potential enclosing radius r

Return type:

Float

derivatives(x, y, f_b, c_s, Rs, rho0ang, center_x, center_y)[source]

Returns first derivatives of the lensing potential, df/dx and df/dy.

Parameters:
  • x (Float) – Angular position [arcseconds]

  • y (Float) – Angular position [arcseconds]

  • f_b (Float) – Instantaneous bound mass fraction relative to infall mass (M_bound / M_infall)

  • c_s (Float) – Infall NFW concentration (R_virial / R_scale)

  • Rs (Float) – Infall NFW scale radius [arcseconds]

  • rho0ang (Float) – Dimensionless NFW normalization

  • center_x (Float) – Position of halo center [arcseconds]

  • center_y (Float) – Position of halo center [arcseconds]

Returns:

f_x, f_y at interpolated positions (x, y)

hessian(x, y, f_b, c_s, Rs, rho0ang, center_x, center_y)[source]

Returns Hessian matrix/second derivates of the lensing potential, d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

Parameters:
  • x (Float) – Angular position [arcseconds]

  • y (Float) – Angular position [arcseconds]

  • f_b (Float) – Instantaneous bound mass fraction relative to infall mass (M_bound / M_infall)

  • c_s (Float) – Infall NFW concentration (R_virial / R_scale)

  • Rs (Float) – Infall NFW scale radius [arcseconds]

  • rho0ang (Float) – Dimensionless NFW normalization

  • center_x (Float) – Position of halo center [arcseconds]

  • center_y (Float) – Position of halo center [arcseconds]

Returns:

f_xx, f_xy, f_yx, f_yy at interpolated positions (x, y)

set_dynamic()[source]
Returns:

no return, deletes the pre-computed kappa(r) and rbin, for every instance of this class (subhalo)

rho_3d_lens(r, f_b, c_s, Rs, rho0ang)[source]

Returns the 3D density profile of the subhalo.

Parameters:
  • r (Float) – 3D radius from the halo center

  • f_b (Float) – Instantaneous bound mass fraction relative to infall mass (M_bound / M_infall)

  • c_s (Float) – Infall NFW concentration (R_virial / R_scale)

  • Rs (Float) – Infall NFW scale radius [arcseconds]

  • rho0ang (Float) – Dimensionless NFW normalization

  • center_x – Position of halo center [arcseconds]

Returns:

Density rho(r)

rbin_kappa_r(f_b, c_s, Rs, rho0ang)[source]

Returns the radial bins and the 2D radial convergence kappa(r), where r is in arcseconds.

Parameters:
  • f_b (Float) – Instantaneous bound mass fraction relative to infall mass (M_bound / M_infall)

  • c_s (Float) – Infall NFW concentration (R_virial / R_scale)

  • Rs (Float) – Infall NFW scale radius [arcseconds]

  • rho0ang (Float) – Dimensionless NFW normalization

  • center_x – Position of halo center [arcseconds]

Returns:

Radial convergence kappa(r)

lenstronomy.LensModel.Profiles.hernquist module

class Hernquist(*args, **kwargs)[source]

Bases: LensProfileBase

Class to compute the Hernquist 1990 model (https://articles.adsabs.harvard.edu/pdf/1990ApJ…356..359H) This model in 3D is:

\[\rho(r) = \frac{\rho_0}{(r/R_s) (1 + r/R_s)^3}\]

where \(\rho_0\) is a characteristic density and \(R_s\) is a scale length.

In lensing terms, the normalization parameter ‘sigma0’ is defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0

Examples for converting angular to physical mass units

>>> from lenstronomy.Cosmo.lens_cosmo import LensCosmo
>>> from astropy.cosmology import FlatLambdaCDM
>>> cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05)
>>> lens_cosmo = LensCosmo(z_lens=0.5, z_source=1.5, cosmo=cosmo)

Here we compute the angular scale of Rs on the sky (in arc seconds) and the deflection the normalization sigma0 from the total stellar mass in M_sol and Rs in [Mpc]:

>>> sigma0, rs_angle = lens_cosmo.hernquist_phys2angular(mass=10**11, rs=0.02)

And here we perform the inverse calculation given Rs_angle and alpha_Rs to return the physical halo properties.

>>> m_tot, rs = lens_cosmo.hernquist_angular2phys(sigma0=sigma0 rs_angle=rs_angle)

The lens model calculation uses angular units as arguments! So to execute a deflection angle calculation one uses

>>> from lenstronomy.LensModel.Profiles.hernquist import Hernquist
>>> hernquist = Hernquist()
>>> alpha_x, alpha_y = hernquist.derivatives(x=1, y=1, Rs=rs_angle, sigma0=sigma0, center_x=0, center_y=0)
param_names = ['sigma0', 'Rs', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'center_x': -100, 'center_y': -100, 'sigma0': 0}
upper_limit_default = {'Rs': 100, 'center_x': 100, 'center_y': 100, 'sigma0': 100}
static density(r, rho0, Rs)[source]

Computes the 3-d density.

Parameters:
  • r – 3-d radius

  • rho0 – density normalization

  • Rs – Hernquist radius

Returns:

density at radius r

density_lens(r, sigma0, Rs)[source]

Density as a function of 3d radius in lensing parameters This function converts the lensing definition sigma0 into the 3d density.

Parameters:
  • r – 3d radius

  • sigma0 – rho0 * Rs (units of projected density)

  • Rs – Hernquist radius

Returns:

enclosed mass in 3d

density_2d(x, y, rho0, Rs, center_x=0, center_y=0)[source]

Projected density along the line of sight at coordinate (x, y)

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • rho0 – density normalization

  • Rs – Hernquist radius

  • center_x – x-center of the profile

  • center_y – y-center of the profile

Returns:

projected density

static mass_3d(r, rho0, Rs)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – 3-d radius within the mass is integrated (same distance units as density definition)

  • rho0 – density normalization

  • Rs – Hernquist radius

Returns:

enclosed mass

mass_3d_lens(r, sigma0, Rs)[source]

Mass enclosed a 3d sphere or radius r for lens parameterisation This function converts the lensing definition sigma0 into the 3d density.

Parameters:
  • r – radius

  • sigma0 – rho0 * Rs (units of projected density)

  • Rs – Hernquist radius

Returns:

enclosed mass in 3d

mass_2d(r, rho0, Rs)[source]

Mass enclosed projected 2d sphere of radius r.

Parameters:
  • r – projected radius

  • rho0 – density normalization

  • Rs – Hernquist radius

Returns:

mass enclosed 2d projected radius

mass_2d_lens(r, sigma0, Rs)[source]

Mass enclosed projected 2d sphere of radius r Same as mass_2d but with input normalization in units of projected density.

Parameters:
  • r – projected radius

  • sigma0 – rho0 * Rs (units of projected density)

  • Rs – Hernquist radius

Returns:

mass enclosed 2d projected radius

static mass_tot(rho0, Rs)[source]

Total mass within the profile.

Parameters:
  • rho0 – density normalization

  • Rs – Hernquist radius

Returns:

total mass within profile

function(x, y, sigma0, Rs, center_x=0, center_y=0)[source]

Lensing potential, which is given by:

\[\phi = \sigma_0 R_s^2 \left[ \log \left( \frac{X^2}{4} \right) + 2 F(X) \right]\]

where \(F(X)\) is a function of \(X = r/R_s\). See equation 47 and 50 in https://arxiv.org/abs/astro-ph/0102341v2

Parameters:
  • x – x-coordinate position (units of angle)

  • y – y-coordinate position (units of angle)

  • sigma0 – normalization parameter defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0

  • Rs – Hernquist radius in units of angle

  • center_x – x-center of the profile (units of angle)

  • center_y – y-center of the profile (units of angle)

Returns:

lensing potential at (x,y)

derivatives(x, y, sigma0, Rs, center_x=0, center_y=0)[source]

Calculates derivatives of the lensing potential (function).

Parameters:
  • x – x-coordinate position (units of angle)

  • y – y-coordinate position (units of angle)

  • sigma0 – normalization parameter defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0

  • Rs – Hernquist radius in units of angle

  • center_x – x-center of the profile (units of angle)

  • center_y – y-center of the profile (units of angle)

Returns:

derivative of function (deflection angles in x- and y-direction)

hessian(x, y, sigma0, Rs, center_x=0, center_y=0)[source]

Hessian terms of the lensing potential (function).

Parameters:
  • x – x-coordinate position (units of angle)

  • y – y-coordinate position (units of angle)

  • sigma0 – normalization parameter defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0

  • Rs – Hernquist radius in units of angle

  • center_x – x-center of the profile (units of angle)

  • center_y – y-center of the profile (units of angle)

Returns:

df/dxdx, df/dxdy, df/dydx, df/dydy

static rho2sigma(rho0, Rs)[source]

Converts 3d density into 2d projected density parameter.

Parameters:
  • rho0 – 3d density normalization of Hernquist model

  • Rs – Hernquist radius

Returns:

sigma0 defined quantity in projected units

static sigma2rho(sigma0, Rs)[source]

Converts projected density parameter (in units of deflection) into 3d density parameter.

Parameters:
  • sigma0 – density defined quantity in projected units

  • Rs – Hernquist radius

Returns:

rho0 the 3d density normalization of Hernquist model

grav_pot(x, y, rho0, Rs, center_x=0, center_y=0)[source]

#TODO decide whether these functions are needed or not

gravitational potential (modulo 4 pi G and rho0 in appropriate units) :param x: x-coordinate position (units of angle) :param y: y-coordinate position (units of angle) :param rho0: density normalization parameter of Hernquist profile :param Rs: Hernquist radius in units of angle :param center_x: x-center of the profile (units of angle) :param center_y: y-center of the profile (units of angle) :return: gravitational potential at projected radius

lenstronomy.LensModel.Profiles.hernquist_ellipse_cse module

class HernquistEllipseCSE[source]

Bases: HernquistEllipsePotential

This class contains functions for the elliptical Hernquist profile.

Ellipticity is defined in the convergence. Approximation with CSE profile introduced by Oguri 2021: https://arxiv.org/pdf/2106.11464.pdf

param_names = ['sigma0', 'Rs', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma0': 0}
upper_limit_default = {'Rs': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma0': 100}
__init__()[source]
function(x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0)[source]

Returns double integral of NFW profile.

derivatives(x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function (integral of NFW)

hessian(x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

lenstronomy.LensModel.Profiles.hernquist_ellipse_potential module

class HernquistEllipsePotential[source]

Bases: LensProfileBase

This class implements the elliptical version of the Hernquist potential for gravitational lensing.

The Hernquist profile, presented in Hernquist (1990), https://ui.adsabs.harvard.edu/abs/1990ApJ…356..359H/abstract, is a spherically symmetric density profile.

This profile is defined by the density function:

\[\rho(R) = \frac{\rho_0}{\left( \frac{R}{R_s} \right) \left( 1 + \frac{R}{R_s} \right)^3}\]

where \(\rho_0\) is the density normalization (rho0), and \(R_s\) is the Hernquist radius (Rs). Here, we will use \(\sigma_0 = \rho_0 \times R_s\) as a parameter (sigma0) as it is more convenient to tune.

In this implementation, the profile is generalized to include elliptical symmetry in the lensing potential rather than in the mass distribution. The potential ellipticity is parameterized by (e1, e2), and the profile is defined by \(\sigma_0\) (sigma0), \(R_s\) (Rs), and a positional center (center_x, center_y).

The ellipticity, \(e\), is defined as

\[e = \sqrt{e_1^2 + e_2^2} = \equic \frac{1 - q^2}{1 + q^2}\]

where \(e_1\) and \(e_2\) are e1 and e2 respectively.

param_names = ['sigma0', 'Rs', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma0': 0}
upper_limit_default = {'Rs': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma0': 100}
__init__()[source]
function(x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0)[source]

Returns double integral of NFW profile.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • sigma0\(\rho_0 \times R_s\) (units of projected density)

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

lensing potential

derivatives(x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0)[source]

Returns \(\frac{df}{dx}\) and \(\frac{df}{dy}\) of the function (integral of NFW).

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • sigma0\(\rho_0 \times R_s\) (units of projected density)

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

gradient of the potential

hessian(x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function.

\[\frac{d^2f}{dx^2}, \frac{d^2}{dxdy}, \frac{d^2}{dydx}, \frac{d^f}{dy^2}\]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • sigma0\(\rho_0 \times R_s\) (units of projected density)

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

tuple of second derivatives

density(r, rho0, Rs, e1=0, e2=0)[source]

Computes the 3D density.

Parameters:
  • r – 3D radius

  • rho0 – density normalization

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

Returns:

density at radius r

density_lens(r, sigma0, Rs, e1=0, e2=0)[source]

Returns the density as a function of 3D radius in lensing parameters.

This function converts the lensing definition sigma0 into the 3D density.

Parameters:
  • r – 3D radius

  • sigma0\(\rho_0 \times R_s\) (units of projected density)

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

Returns:

enclosed mass in 3D

density_2d(x, y, rho0, Rs, e1=0, e2=0, center_x=0, center_y=0)[source]

Projected density along the line of sight at coordinate (x, y).

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • rho0 – density normalization

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – x-center of the profile

  • center_y – y-center of the profile

Returns:

projected density

mass_2d_lens(r, sigma0, Rs, e1=0, e2=0)[source]

Mass enclosed projected 2D sphere of radius r. Same as mass_2d but with input normalization in units of projected density.

Parameters:
  • r – projected radius

  • sigma0\(\rho_0 \times R_s\) (units of projected density)

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

Returns:

mass enclosed 2D projected radius

mass_2d(r, rho0, Rs, e1=0, e2=0)[source]

Mass enclosed projected 2D sphere of radius r.

Parameters:
  • r – projected radius

  • rho0 – density normalization

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

Returns:

mass enclosed 2D projected radius

mass_3d(r, rho0, Rs, e1=0, e2=0)[source]

Mass enclosed a 3D sphere or radius r.

Parameters:
  • r – 3D radius within the mass is integrated (same distance units as density definition)

  • rho0 – density normalization

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

Returns:

enclosed mass

mass_3d_lens(r, sigma0, Rs, e1=0, e2=0)[source]

Mass enclosed a 3D sphere or radius r in lensing parameterization.

Parameters:
  • r – 3D radius within the mass is integrated (same distance units as density definition)

  • sigma0\(\rho_0 \times R_s\) (units of projected density)

  • Rs – Hernquist radius

  • e1 – eccentricity component

  • e2 – eccentricity component

Returns:

enclosed mass

lenstronomy.LensModel.Profiles.hessian module

class Hessian(*args, **kwargs)[source]

Bases: LensProfileBase

Class for constant Hessian distortion (second order) The input is in the same convention as the LensModel.hessian() output.

param_names = ['f_xx', 'f_yy', 'f_xy', 'f_yx', 'ra_0', 'dec_0']
lower_limit_default = {'dec_0': -100, 'f_xx': -100, 'f_xy': -100, 'f_yx': -100, 'f_yy': -100, 'ra_0': -100}
upper_limit_default = {'dec_0': 100, 'f_xx': 100, 'f_xy': 100, 'f_yx': 100, 'f_yy': 100, 'ra_0': 100}
function(x, y, f_xx, f_yy, f_xy, f_yx, ra_0=0, dec_0=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • f_xx – dalpha_x/dx

  • f_yy – dalpha_y/dy

  • f_xy – dalpha_x/dy

  • f_yx – dalpha_y/dx

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

lensing potential

derivatives(x, y, f_xx, f_yy, f_xy, f_yx, ra_0=0, dec_0=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • f_xx – dalpha_x/dx

  • f_yy – dalpha_y/dy

  • f_xy – dalpha_x/dy

  • f_yx – dalpha_y/dx

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

deflection angles

hessian(x, y, f_xx, f_yy, f_xy, f_yx, ra_0=0, dec_0=0)[source]

Hessian. Attention: If f_xy != f_yx then this function is not accurate!

Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • f_xx – dalpha_x/dx

  • f_yy – dalpha_y/dy

  • f_xy – dalpha_x/dy

  • f_yx – dalpha_y/dx

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

f_xx, f_yy, f_xy

lenstronomy.LensModel.Profiles.interpol module

class Interpol(grid=False, min_grid_number=100, kwargs_spline=None)[source]

Bases: LensProfileBase

Class which uses an interpolation of a lens model and its first and second order derivatives.

See also the tests in lenstronomy.test.test_LensModel.test_Profiles.test_interpol.py for example use cases as checks against known analytic models.

The deflection angle is in the same convention as the one in the LensModel module, meaning that: source position = image position - deflection angle

param_names = ['grid_interp_x', 'grid_interp_y', 'f_', 'f_x', 'f_y', 'f_xx', 'f_yy', 'f_xy']
lower_limit_default = {}
upper_limit_default = {}
__init__(grid=False, min_grid_number=100, kwargs_spline=None)[source]
Parameters:
  • grid – bool, if True, computes the calculation on a grid

  • min_grid_number – minimum numbers of positions to compute the interpolation on a grid, otherwise in a loop

  • kwargs_spline – keyword arguments for the scipy.interpolate.RectBivariateSpline() interpolation (optional) if =None, a default linear interpolation is chosen.

function(x, y, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
Parameters:
  • x – x-coordinate (angular position), float or numpy array

  • y – y-coordinate (angular position), float or numpy array

  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

Returns:

potential at interpolated positions (x, y)

derivatives(x, y, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]

Returns df/dx and df/dy of the function.

Parameters:
  • x – x-coordinate (angular position), float or numpy array

  • y – y-coordinate (angular position), float or numpy array

  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

Returns:

f_x, f_y at interpolated positions (x, y)

hessian(x, y, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

Parameters:
  • x – x-coordinate (angular position), float or numpy array

  • y – y-coordinate (angular position), float or numpy array

  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

Returns:

f_xx, f_xy, f_yx, f_yy at interpolated positions (x, y)

f_interp(x, y, x_grid=None, y_grid=None, f_=None, grid=False)[source]
f_x_interp(x, y, x_grid=None, y_grid=None, f_x=None, grid=False)[source]
f_y_interp(x, y, x_grid=None, y_grid=None, f_y=None, grid=False)[source]
f_xx_interp(x, y, x_grid=None, y_grid=None, f_xx=None, grid=False)[source]
f_xy_interp(x, y, x_grid=None, y_grid=None, f_xy=None, grid=False)[source]
f_yy_interp(x, y, x_grid=None, y_grid=None, f_yy=None, grid=False)[source]
do_interp(x_grid, y_grid, f_, f_x, f_y, f_xx=None, f_yy=None, f_xy=None)[source]
class InterpolScaled(grid=True, min_grid_number=100, kwargs_spline=None)[source]

Bases: LensProfileBase

Class for handling an interpolated lensing map and has the freedom to scale its lensing effect.

Applications are e.g. mass to light ratio.

param_names = ['scale_factor', 'grid_interp_x', 'grid_interp_y', 'f_', 'f_x', 'f_y', 'f_xx', 'f_yy', 'f_xy']
lower_limit_default = {'scale_factor': 0}
upper_limit_default = {'scale_factor': 100}
__init__(grid=True, min_grid_number=100, kwargs_spline=None)[source]
Parameters:
  • grid – bool, if True, computes the calculation on a grid

  • min_grid_number – minimum numbers of positions to compute the interpolation on a grid

  • kwargs_spline – keyword arguments for the scipy.interpolate.RectBivariateSpline() interpolation (optional) if =None, a default linear interpolation is chosen.

function(x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
Parameters:
  • x – x-coordinate (angular position), float or numpy array

  • y – y-coordinate (angular position), float or numpy array

  • scale_factor – float, overall scaling of the lens model relative to the input interpolation grid

  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

Returns:

potential at interpolated positions (x, y)

derivatives(x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
Parameters:
  • x – x-coordinate (angular position), float or numpy array

  • y – y-coordinate (angular position), float or numpy array

  • scale_factor – float, overall scaling of the lens model relative to the input interpolation grid

  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

Returns:

deflection angles in x- and y-direction at position (x, y)

hessian(x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
Parameters:
  • x – x-coordinate (angular position), float or numpy array

  • y – y-coordinate (angular position), float or numpy array

  • scale_factor – float, overall scaling of the lens model relative to the input interpolation grid

  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

Returns:

second derivatives of the lensing potential f_xx, f_yy, f_xy at position (x, y)

lenstronomy.LensModel.Profiles.multi_gaussian module

class MultiGaussian[source]

Bases: LensProfileBase

This class implements a sum of multiple circular Gaussian profiles for use in gravitational lensing.

Each component in the sum is a circular Gaussian potential profile defined by its amplitude (amp) and standard deviation (sigma). The Gaussian profiles are centered at (center_x, center_y) and are scaled by an optional global factor (scale_factor).

This model can approximate more complex smooth mass distributions by combining multiple Gaussians with different widths and amplitudes.

param_names = ['amp', 'sigma', 'center_x', 'center_y', 'scale_factor']
lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'scale_factor': 0, 'sigma': 0}
upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'scale_factor': 10000, 'sigma': 100}
__init__()[source]
function(x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1)[source]

Returns the summed Gaussian potential evaluated at coordinates (x, y).

Each component is a circular 2D Gaussian profile centered at (center_x, center_y), with its own amplitude and width (sigma). The total potential is the sum of all such Gaussian components. A scale factor is optional.

Parameters:
  • x – x-coordinate(s) of the evaluation grid (array-like)

  • y – y-coordinate(s) of the evaluation grid (array-like)

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each Gaussian component

  • center_x – x-coordinate of the shared center (default is 0)

  • center_y – y-coordinate of the shared center (default is 0)

  • scale_factor – global factor applied to each amplitude

Returns:

total potential evaluated at (x, y)

derivatives(x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1)[source]

Returns the gradient in both angular directions of the summed Gaussian potential evaluated at (x, y).

\[\frac{df}{dx}, \frac{df}{dy}\]
Parameters:
  • x – x-coordinate(s) where the gradient is evaluated

  • y – y-coordinate(s) where the gradient is evaluated

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • center_x – x-coordinate of the shared center (default is 0)

  • center_y – y-coordinate of the shared center (default is 0)

  • scale_factor – global factor applied to each amplitude

Returns:

\(\frac{df}{dx}, \frac{df}{dy}\) of the same shape as x and y

hessian(x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1)[source]

Returns the second derivatives of the summed Gaussian potential evaluated at (x, y).

Parameters:
  • x – x-coordinate(s) where the gradient is evaluated

  • y – y-coordinate(s) where the gradient is evaluated

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • center_x – x-coordinate of the shared center (default is 0)

  • center_y – y-coordinate of the shared center (default is 0)

  • scale_factor – global factor applied to each amplitude

Returns:

\(\frac{df}{dx}, \frac{df}{dy}\) of the same shape as x and y

density(r, amp, sigma, scale_factor=1)[source]

Returns the 3D density profile evaluated at radius r for a sum of Gaussian components.

Parameters:
  • r – radial coordinate to evaluate the density

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • scale_factor – global factor applied to each amplitude

Returns:

total 3D density evaluated at r

density_2d(x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1)[source]

Returns the 2D density evaluated at (x, y).

Parameters:
  • x – x-coordinate(s) where the gradient is evaluated

  • y – y-coordinate(s) where the gradient is evaluated

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • center_x – x-coordinate of the shared center (default is 0)

  • center_y – y-coordinate of the shared center (default is 0)

  • scale_factor – global factor applied to each amplitude

Returns:

total 2D surface density

mass_3d_lens(R, amp, sigma, scale_factor=1)[source]

Returns the enclosed 3D mass within radius r.

Parameters:
  • R – radial coordinate to evaluate the density

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • scale_factor – global factor applied to each amplitude

Returns:

total 3D mass evaluated within r

class MultiGaussianEllipsePotential[source]

Bases: LensProfileBase

Implementation of a sum of elliptical Gaussian lensing potentials.

Each component is a 2D elliptical Gaussian described by an amplitude and width, with ellipticity defined in the potential via parameters e1 and e2, which are constant across all components. The Gaussians are centered at a common position (center_x, center_y) and scaled globally using scale_factor.

param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y', 'scale_factor']
lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'scale_factor': 0, 'sigma': 0}
upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'scale_factor': 10000, 'sigma': 100}
__init__()[source]
function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]

Compute the total lensing potential by summing elliptical Gaussian components.

Parameters:
  • x – x-coordinate(s) where the gradient is evaluated

  • y – y-coordinate(s) where the gradient is evaluated

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • center_x – x-coordinate of the shared center (default is 0)

  • center_y – y-coordinate of the shared center (default is 0)

  • scale_factor – global factor applied to each amplitude

Returns:

potential

derivatives(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]

Compute the gradient in both angular directions of the total lensing potential.

Parameters:
  • x – x-coordinate(s) where the gradient is evaluated

  • y – y-coordinate(s) where the gradient is evaluated

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • center_x – x-coordinate of the shared center (default is 0)

  • center_y – y-coordinate of the shared center (default is 0)

  • scale_factor – global factor applied to each amplitude

Returns:

gradient of potential

hessian(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]

Compute the hessian of the total lensing potential.

Parameters:
  • x – x-coordinate(s) where the gradient is evaluated

  • y – y-coordinate(s) where the gradient is evaluated

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • center_x – x-coordinate of the shared center (default is 0)

  • center_y – y-coordinate of the shared center (default is 0)

  • scale_factor – global factor applied to each amplitude

Returns:

hessian of potential

density(r, amp, sigma, e1, e2, scale_factor=1)[source]

Compute the 3D density at radial distance r by summing elliptical Gaussians.

Parameters:
  • r – radial coordinate to evaluate the density

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • scale_factor – global factor applied to each amplitude

Returns:

total 3D density evaluated at r

density_2d(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]

Returns the 2D density evaluated at (x, y).

Parameters:
  • x – x-coordinate(s) where the gradient is evaluated

  • y – y-coordinate(s) where the gradient is evaluated

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • center_x – x-coordinate of the shared center (default is 0)

  • center_y – y-coordinate of the shared center (default is 0)

  • scale_factor – global factor applied to each amplitude

Returns:

total 2D surface density

mass_3d_lens(R, amp, sigma, e1, e2, scale_factor=1)[source]

Returns the enclosed 3D mass within radius r.

Parameters:
  • R – radial coordinate to evaluate the density

  • amp – amplitudes for each Gaussian component

  • sigma – standard deviations for each component

  • scale_factor – global factor applied to each amplitude

Returns:

total 3D mass evaluated within r

lenstronomy.LensModel.Profiles.multi_gaussian_ellipse_kappa module

This module contains the class to compute lensing properties of a multi-Gaussian convergence profile with the ellipticity defined in the convergence.

class MultiGaussianEllipseKappa(use_scipy_wofz=True, min_ellipticity=1e-05)[source]

Bases: LensProfileBase

This class computes the lensing properties of a set of concentric elliptical Gaussian convergences.

param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y', 'scale_factor']
lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'scale_factor': 0, 'sigma': 0}
upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'scale_factor': 10000, 'sigma': 100}
__init__(use_scipy_wofz=True, min_ellipticity=1e-05)[source]
Parameters:
  • use_scipy_wofz (bool) – To initiate class GaussianEllipseKappa. If True, Gaussian lensing will use scipy.special.wofz function. Set False for lower precision, but faster speed.

  • min_ellipticity (float) – To be passed to class GaussianEllipseKappa. Minimum ellipticity for Gaussian elliptical lensing calculation. For lower ellipticity than min_ellipticity the equations for the spherical case will be used.

function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]

Compute the potential function for a set of concentric elliptical Gaussian convergence profiles.

Parameters:
  • x (float or numpy.array) – x coordinate

  • y (float or numpy.array) – y coordinate

  • amp (numpy.array with dtype=float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • sigma (numpy.array with dtype=float) – Standard deviation of Gaussian

  • e1 (float) – Ellipticity parameter 1

  • e2 (float) – Ellipticity parameter 2

  • center_x (float) – x coordinate of centroid

  • center_y (float) – y coordianate of centroid

  • scale_factor (float) – Scaling factor for amplitude

Returns:

Potential for elliptical Gaussian convergence

Return type:

float, or numpy.array with shape = x.shape

derivatives(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]

Compute the derivatives of function angles \(\partial f/\partial x\), \(\partial f/\partial y\) at \(x,\ y\) for a set of concentric elliptic Gaussian convergence profiles.

Parameters:
  • x (float or numpy.array) – x coordinate

  • y (float or numpy.array) – y coordinate

  • amp (numpy.array with dtype=float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • sigma (numpy.array with dtype=float) – Standard deviation of Gaussian

  • e1 (float) – Ellipticity parameter 1

  • e2 (float) – Ellipticity parameter 2

  • center_x (float) – x coordinate of centroid

  • center_y (float) – y coordianate of centroid

  • scale_factor (float) – Scaling factor for amplitude

Returns:

Deflection angle \(\partial f/\partial x\), \(\partial f/\partial y\) for elliptical Gaussian convergence

Return type:

tuple (float, float) or (numpy.array, numpy.array) with each numpy array’s shape equal to x.shape

hessian(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]

Compute Hessian matrix of function \(\partial^2f/\partial x^2\), \(\partial^2 f/\partial y^2\), \(\partial^2 f/\partial x\partial y\) for a set of concentric elliptic Gaussian convergence profiles.

Parameters:
  • x (float or numpy.array) – x coordinate

  • y (float or numpy.array) – y coordinate

  • amp (numpy.array with dtype=float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • sigma (numpy.array with dtype=float) – Standard deviation of Gaussian

  • e1 (float) – Ellipticity parameter 1

  • e2 (float) – Ellipticity parameter 2

  • center_x (float) – x coordinate of centroid

  • center_y (float) – y coordianate of centroid

  • scale_factor – Scaling factor for amplitude scale_factor: float

Returns:

Hessian \(\partial^2f/\partial x^2\), \(\partial^2/\partial x\partial y\), \(\partial^2/\partial y\partial x\), \(\partial^2 f/\partial y^2\) for elliptical Gaussian convergence.

Return type:

tuple (float, float, float) , or (numpy.array, numpy.array, numpy.array) with each numpy array’s shape equal to x.shape

density_2d(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]

Compute the density of a set of concentric elliptical Gaussian convergence profiles \(\sum A/(2\pi \sigma^2) \exp(-( x^2+y^2/q^2)/2\sigma^2)\).

Parameters:
  • x (float or numpy.array) – x coordinate

  • y (float or numpy.array) – y coordinate

  • amp (numpy.array with dtype=float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • sigma (numpy.array with dtype=float) – Standard deviation of Gaussian

  • e1 (float) – Ellipticity parameter 1

  • e2 (float) – Ellipticity parameter 2

  • center_x (float) – x coordinate of centroid

  • center_y (float) – y coordianate of centroid

  • scale_factor (float) – Scaling factor for amplitude

Returns:

Density \(\kappa\) for elliptical Gaussian convergence

Return type:

float, or numpy.array with shape equal to x.shape

lenstronomy.LensModel.Profiles.multipole module

class Multipole(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains a CIRCULAR multipole contribution (for 1 component with m>=2) This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf, Equation B12 Only the q=1 case (ie., circular symmetry) makes this definition consistent with interpretation of multipoles as a deformation of the isophotes with an order m symmetry (eg., disky/boxy in the m=4 case).

m : int, multipole order, m>=1 a_m : float, multipole strength phi_m : float, multipole orientation in radian

param_names = ['m', 'a_m', 'phi_m', 'center_x', 'center_y', 'r_E']
lower_limit_default = {'a_m': 0, 'center_x': -100, 'center_y': -100, 'm': 1, 'phi_m': -3.141592653589793, 'r_E': 0}
upper_limit_default = {'a_m': 100, 'center_x': 100, 'center_y': 100, 'm': 100, 'phi_m': 3.141592653589793, 'r_E': 100}
function(x, y, m, a_m, phi_m, center_x=0, center_y=0, r_E=1)[source]

Lensing potential of multipole contribution (for 1 component with m>=1) This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf

Parameters:
  • x – x-coordinate to evaluate function

  • y – y-coordinate to evaluate function

  • m – int, multipole order, m>=1

  • a_m – float, multipole strength

  • phi_m – float, multipole orientation in radian

  • center_x – x-position

  • center_y – y-position

  • r_E – float, normalizing radius (only used for the m=1, Einstein radius by default)

Returns:

lensing potential

derivatives(x, y, m, a_m, phi_m, center_x=0, center_y=0, r_E=1)[source]

Deflection of a multipole contribution (for 1 component with m>=1) This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf Equation B12

Parameters:
  • x – x-coordinate to evaluate function

  • y – y-coordinate to evaluate function

  • m – int, multipole order, m>=1

  • a_m – float, multipole strength

  • phi_m – float, multipole orientation in radian

  • center_x – x-position

  • center_y – y-position

  • r_E – float, normalizing radius (only used for the m=1, Einstein radius by default)

Returns:

deflection angles alpha_x, alpha_y

hessian(x, y, m, a_m, phi_m, center_x=0, center_y=0, r_E=1)[source]

Hessian of a multipole contribution (for 1 component with m>=1) This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf

Parameters:
  • x – x-coordinate to evaluate function

  • y – y-coordinate to evaluate function

  • m – int, multipole order, m>=1

  • a_m – float, multipole strength

  • phi_m – float, multipole orientation in radian

  • center_x – x-position

  • center_y – y-position

  • r_E – float, normalizing radius (not used for Hessian)

Returns:

f_xx, f_xy, f_yx, f_yy

class EllipticalMultipole(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains a multipole contribution that encode deviations from the elliptical isodensity contours of a SIE with any axis ratio q.

This uses the definitions from Paugnat & Gilman (2025): “Elliptical multipoles for gravitational lenses”

m : int, multipole order, (m=1, m=3 or m=4) a_m : float, multipole strength phi_m : float, multipole orientation in radian q : axis ratio of the reference ellipses

param_names = ['m', 'a_m', 'phi_m', 'q', 'center_x', 'center_y', 'r_E']
lower_limit_default = {'a_m': 0, 'center_x': -100, 'center_y': -100, 'm': 1, 'phi_m': -3.141592653589793, 'q': 0.001, 'r_E': 0}
upper_limit_default = {'a_m': 100, 'center_x': 100, 'center_y': 100, 'm': 100, 'phi_m': 3.141592653589793, 'q': 1, 'r_E': 100}
function(x, y, m, a_m, phi_m, q, center_x=0, center_y=0, r_E=1)[source]

Lensing potential of multipole contribution (for 1 component with m=1, m=3 or m=4)

Parameters:
  • x – x-coordinate to evaluate function

  • y – y-coordinate to evaluate function

  • m – int, multipole order (m=1, m=3 or m=4)

  • a_m – float, multipole strength

  • phi_m – float, multipole orientation in radian

  • center_x – x-position

  • center_y – y-position

  • r_E – float, normalizing radius (only used for odd m, Einstein radius by default)

Returns:

lensing potential

derivatives(x, y, m, a_m, phi_m, q, center_x=0, center_y=0, r_E=1)[source]

Deflection of a multipole contribution (for 1 component with m=1, m=3 or m=4)

Parameters:
  • x – x-coordinate to evaluate function

  • y – y-coordinate to evaluate function

  • m – int, multipole order (m=1, m=3 or m=4)

  • a_m – float, multipole strength

  • phi_m – float, multipole orientation in radian

  • center_x – x-position

  • center_y – y-position

  • r_E – float, normalizing radius (only used for odd m, Einstein radius by default)

Returns:

deflection angles alpha_x, alpha_y

hessian(x, y, m, a_m, phi_m, q, center_x=0, center_y=0, r_E=1)[source]

Hessian of a multipole contribution (for 1 component with m=1, m=3 or m=4)

Parameters:
  • x – x-coordinate to evaluate function

  • y – y-coordinate to evaluate function

  • m – int, multipole order (m=1, m=3 or m=4)

  • a_m – float, multipole strength

  • phi_m – float, multipole orientation in radian

  • center_x – x-position

  • center_y – y-position

  • r_E – float, normalizing radius (not used for Hessian)

Returns:

f_xx, f_xy, f_yx, f_yy

lenstronomy.LensModel.Profiles.nfw module

class NFW(interpol=False, num_interp_X=1000, max_interp_X=10)[source]

Bases: LensProfileBase

Class to compute the functions concerning the Navarro-Frenk-White (NFW) 1997 profile (https://arxiv.org/abs/astro-ph/9611107). This model in 3D is:

\[\rho(r) = \frac{\rho_0}{(r/R_s) (1 + r/R_s)^2}\]

where \(\rho_0\) is the density normalization and \(R_s\) is the scale radius.

The Virial radius in terms of \(R_s\) is \(R_{200} = c * R_s\), where \(c\) is the concentration. The definition of ‘\(R_s\)’ is in angular (arc second) units and the normalization is put in with regard to a deflection angle at ‘\(R_s\)’ - ‘\(\alpha_{R_s}\)’. \(\alpha_{R_s}\) and \(\rho_0\) are related by:

\[\alpha_{R_s} = 4 R_s^2 \rho_0(1 + \ln(1/2))\]

To convert a physical mass and concentration definition into those lensing quantities for a specific redshift configuration and cosmological model, you can find routines in lenstronomy.Cosmo.lens_cosmo.py

Examples for converting angular to physical mass units

>>> from lenstronomy.Cosmo.lens_cosmo import LensCosmo
>>> from astropy.cosmology import FlatLambdaCDM
>>> cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05)
>>> lens_cosmo = LensCosmo(z_lens=0.5, z_source=1.5, cosmo=cosmo)

Here we compute the angular scale of Rs on the sky (in arc seconds) and the deflection angle at Rs (in arc seconds):

>>> Rs_angle, alpha_Rs = lens_cosmo.nfw_physical2angle(M=10**13, c=6)

And here we perform the inverse calculation given Rs_angle and alpha_Rs to return the physical halo properties.

>>> rho0, Rs, c, r200, M200 = lens_cosmo.nfw_angle2physical(Rs_angle=Rs_angle, alpha_Rs=alpha_Rs)

The lens model calculation uses angular units as arguments! So to execute a deflection angle calculation one uses

>>> from lenstronomy.LensModel.Profiles.nfw import NFW
>>> nfw = NFW()
>>> alpha_x, alpha_y = nfw.derivatives(x=1, y=1, Rs=Rs_angle, alpha_Rs=alpha_Rs, center_x=0, center_y=0)
profile_name = 'NFW'
param_names = ['Rs', 'alpha_Rs', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100}
__init__(interpol=False, num_interp_X=1000, max_interp_X=10)[source]
Parameters:
  • interpol – bool, if True, interpolates the functions F(), g() and h()

  • num_interp_X – int (only considered if interpol=True), number of interpolation elements in units of r/r_s

  • max_interp_X – float (only considered if interpol=True), maximum r/r_s value to be interpolated (returning zeros outside)

function(x, y, Rs, alpha_Rs, center_x=0, center_y=0)[source]

Lensing potential of the NFW profile, which is given by:

\[\phi = 2 \rho_0 R_s^3 \left[ \ln^2 \left( \frac{X}{2} \right) - \operatorname{arctanh}^2(\sqrt{1-X^2}) \right]\]

where \(X = r/R_s\). See equation 54 in https://arxiv.org/abs/astro-ph/0102341v2.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

lensing potential

derivatives(x, y, Rs, alpha_Rs, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function (integral of NFW), which are the deflection angles.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

deflection angle in x, deflection angle in y

hessian(x, y, Rs, alpha_Rs, center_x=0, center_y=0)[source]
Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

static density(R, Rs, rho0)[source]

Three-dimensional density of the NFW profile at radius R.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

Returns:

rho(R) density

density_lens(r, Rs, alpha_Rs)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – 3d radios

  • Rs – turn-over radius of NFW profile

  • alpha_Rs – deflection at Rs

Returns:

density rho(r)

density_2d(x, y, Rs, rho0, center_x=0, center_y=0)[source]

Projected two-dimensional NFW profile (kappa)

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

  • center_x – x-centroid position

  • center_y – y-centroid position

Returns:

Epsilon(R) projected density at radius R

mass_3d(r, Rs, rho0)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – 3d radius

  • Rs – scale radius

  • rho0 – density normalization (characteristic density)

Returns:

M(<r)

mass_3d_lens(r, Rs, alpha_Rs)[source]

Mass enclosed a 3d sphere or radius r. This function takes as input the lensing parameterization.

Parameters:
  • r – 3d radius

  • Rs – scale radius

  • alpha_Rs – deflection (angular units) at projected Rs

Returns:

M(<r)

mass_2d(R, Rs, rho0)[source]

Mass enclosed a 2d cylinder or projected radius R.

Parameters:
  • R – projected radius

  • Rs – scale radius

  • rho0 – density normalization (characteristic density)

Returns:

mass in cylinder.

mass_2d_lens(R, Rs, alpha_Rs)[source]
Parameters:
  • R – projected radius

  • Rs – scale radius

  • alpha_Rs – deflection (angular units) at projected Rs

Returns:

mass enclosed 2d cylinder <R

nfw_potential(R, Rs, rho0)[source]

Lensing potential of NFW profile (Sigma_crit D_OL**2)

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

Returns:

Epsilon(R) projected density at radius R

nfw_alpha(R, Rs, rho0, ax_x, ax_y)[source]

Deflection angle of NFW profile (times Sigma_crit D_OL) along the projection to coordinate ‘axis’.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

  • ax_x (same as R) – projection to either x- or y-axis

  • ax_y (same as R) – projection to either x- or y-axis

Returns:

Epsilon(R) projected density at radius R

nfw_gamma(R, Rs, rho0, ax_x, ax_y)[source]

Shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate ‘axis’.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

  • ax_x (same as R) – projection to either x- or y-axis

  • ax_y (same as R) – projection to either x- or y-axis

Returns:

Epsilon(R) projected density at radius R

F_(X)[source]

Computes h()

Parameters:

X

Returns:

g_(X)[source]

Computes h()

Parameters:

X (float >0) – R/Rs

Returns:

h_(X)[source]

Computes h()

Parameters:

X (float >0) – R/Rs

Returns:

h(X)

static alpha2rho0(alpha_Rs, Rs)[source]

Convert angle at Rs into rho0.

Parameters:
  • alpha_Rs – deflection angle at RS

  • Rs – scale radius

Returns:

density normalization (characteristic density)

static rho02alpha(rho0, Rs)[source]

Convert rho0 to angle at Rs.

Parameters:
  • rho0 – density normalization (characteristic density)

  • Rs – scale radius

Returns:

deflection angle at RS

lenstronomy.LensModel.Profiles.nfw_core_truncated module

class TNFWC(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains an pseudo NFW profile with a core radius and a truncation radius. The density in 3D is given by.

\[\rho(r) = \frac{\rho_0 r_s^3}{\left(r^2+r_c^2\right)^{1/2} \left(r_s^2+r^2\right)} \left(\frac{r_t^2}{r^2+r_t^2}\right)\]

When the core radius goes to zero and the truncation radius approaches infinity this profile reduces to an NFW profile with the squared term inside the parentheses.

TODO: add the gravitational potential for this profile TODO: add analytic solution for 3D mass

profile_name = 'TNFWC'
param_names = ['Rs', 'alpha_Rs', 'center_x', 'center_y', 'r_trunc', 'r_core']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'r_core': 1e-05, 'r_trunc': 0.001}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'r_core': 1000.0, 'r_trunc': 1000.0}
derivatives(x, y, Rs, alpha_Rs, r_core, r_trunc, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function which are the deflection angles.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

deflection angle in x, deflection angle in y

hessian(x, y, Rs, alpha_Rs, r_core, r_trunc, center_x=0, center_y=0)[source]
Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

static density(R, Rs, rho0, r_core, r_trunc)[source]

3D density profile.

Parameters:
  • R – radius of interest

  • rho0 – central density normalization

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

Returns:

rho(R) density

density_lens(r, Rs, alpha_Rs, r_core, r_trunc)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – 3d radios

  • Rs – scale radius

  • alpha_Rs – deflection at Rs

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

Returns:

density rho(r)

density_2d(x, y, Rs, rho0, r_core, r_trunc, center_x=0, center_y=0)[source]

2D (projected) density profile.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • rho0 – density normalization at Rs

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

  • center_x – profile center (same units as x)

  • center_y – profile center (same units as x)

Returns:

Epsilon(R) projected density at radius R

mass_3d(r, Rs, rho0, r_core, r_trunc)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – 3d radius

  • Rs – scale radius

  • rho0 – density normalization

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

Returns:

M(<r)

mass_3d_lens(r, Rs, alpha_Rs, r_core, r_trunc)[source]

Mass enclosed a 3d sphere or radius r. This function takes as input the lensing parameterization.

Parameters:
  • r – 3d radius

  • Rs – scale radius

  • alpha_Rs – deflection angle at Rs

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

Returns:

M(<r)

mass_2d(R, Rs, rho0, r_core, r_trunc)[source]

Mass enclosed a 2d cylinder or projected radius R.

Parameters:
  • R – 3d radius

  • Rs – scale radius

  • rho0 – central density normalization

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

Returns:

mass in cylinder

nfw_alpha(R, Rs, rho0, r_core, r_trunc, ax_x, ax_y)[source]

Deflection angle of the profile (times Sigma_crit D_OL) along the projection to coordinate ‘axis’.

Parameters:
  • R – 3d radius

  • Rs – scale radius

  • rho0 – central density normalization

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

  • ax_x – x coordinate relative to center

  • ax_y – y coordinate relative to center

Returns:

Epsilon(R) projected density at radius R

nfw_gamma(R, Rs, rho0, r_core, r_trunc, ax_x, ax_y)[source]

Shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate ‘axis’.

Parameters:
  • R – 3d radius

  • Rs – scale radius

  • rho0 – central density normalization

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

  • ax_x – x coordinate relative to center

  • ax_y – y coordinate relative to center

Returns:

Epsilon(R) projected density at radius R

alpha2rho0(alpha_Rs, Rs, r_core, r_trunc)[source]

Convert angle at Rs into rho0.

Parameters:
  • alpha_Rs – deflection angle at RS

  • Rs – scale radius

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

Returns:

density normalization

rho02alpha(rho0, Rs, r_core, r_trunc)[source]

Convert rho0 to angle at Rs.

Parameters:
  • rho0 – density normalization

  • Rs – scale radius

  • r_core – core radius [arcsec]

  • r_trunc – truncation radius [arcsec]

Returns:

deflection angle at RS

lenstronomy.LensModel.Profiles.nfw_ellipse_cse module

class NFW_ELLIPSE_CSE(high_accuracy=True)[source]

Bases: LensProfileBase

this class contains functions concerning the NFW profile with an ellipticity defined in the convergence parameterization of alpha_Rs and Rs is the same as for the spherical NFW profile Approximation with CSE profile introduced by Oguri 2021: https://arxiv.org/pdf/2106.11464.pdf Match to NFW using CSEs is approximate: kappa matches to ~1-2%

relation are: R_200 = c * Rs

profile_name = 'NFW_ELLIPSE_CSE'
param_names = ['Rs', 'alpha_Rs', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5}
__init__(high_accuracy=True)[source]
Parameters:

high_accuracy (boolean) – if True uses a more accurate larger set of CSE profiles (see Oguri 2021)

function(x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0)[source]

Returns elliptically distorted NFW lensing potential.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

lensing potential

derivatives(x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function, calculated as an elliptically distorted deflection angle of the spherical NFW profile.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

deflection in x-direction, deflection in y-direction

hessian(x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy the calculation is performed as a numerical differential from the deflection field. Analytical relations are possible.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

mass_3d_lens(r, Rs, alpha_Rs, e1=1, e2=0)[source]
Parameters:
  • r – radius (in angular units)

  • Rs

  • alpha_Rs

  • e1

  • e2

Returns:

lenstronomy.LensModel.Profiles.nfw_ellipse_potential module

class NFWEllipsePotential(interpol=False, num_interp_X=1000, max_interp_X=10)[source]

Bases: LensProfileBase

This class contains functions concerning the NFW profile with an ellipticity defined in the potential parameterization of alpha_Rs and Rs is the same as for the spherical NFW profile.

from Glose & Kneib: https://cds.cern.ch/record/529584/files/0112138.pdf

relation are: R_200 = c * Rs

profile_name = 'NFW_ELLIPSE_POTENTIAL'
param_names = ['Rs', 'alpha_Rs', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5}
__init__(interpol=False, num_interp_X=1000, max_interp_X=10)[source]
Parameters:
  • interpol – bool, if True, interpolates the functions F(), g() and h()

  • num_interp_X – int (only considered if interpol=True), number of interpolation elements in units of r/r_s

  • max_interp_X – float (only considered if interpol=True), maximum r/r_s value to be interpolated (returning zeros outside)

function(x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0)[source]

Returns elliptically distorted NFW lensing potential.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

lensing potential

derivatives(x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function, calculated as an elliptically distorted deflection angle of the spherical NFW profile.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

deflection in x-direction, deflection in y-direction

hessian(x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy the calculation is performed as a numerical differential from the deflection field. Analytical relations are possible.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

mass_3d_lens(r, Rs, alpha_Rs, e1=1, e2=0)[source]
Parameters:
  • r – radius (in angular units)

  • Rs

  • alpha_Rs

  • e1

  • e2

Returns:

density_lens(r, Rs, alpha_Rs, e1=1, e2=0)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – 3d radios

  • Rs – turn-over radius of NFW profile

  • alpha_Rs – deflection at Rs

Returns:

density rho(r)

lenstronomy.LensModel.Profiles.nfw_mass_concentration module

This module contains a class to compute the Navarro-Frank-White function in mass/kappa space.

class NFWMC(z_lens, z_source, cosmo=None, static=False)[source]

Bases: LensProfileBase

this class contains functions parameterises the NFW profile with log10 M200 and the concentration rs/r200 relation are: R_200 = c * Rs

ATTENTION: the parameterization is cosmology and redshift dependent! The cosmology to connect mass and deflection relations is fixed to default H0=70km/s Omega_m=0.3 flat LCDM. It is recommended to keep a given cosmology definition in the lens modeling as the observable reduced deflection angles are sensitive in this parameterization. If you do not want to impose a mass-concentration relation, it is recommended to use the default NFW lensing profile parameterized in reduced deflection angles.

param_names = ['logM', 'concentration', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'concentration': 0.01, 'logM': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'concentration': 1000, 'logM': 16}
__init__(z_lens, z_source, cosmo=None, static=False)[source]
Parameters:
  • z_lens – redshift of lens

  • z_source – redshift of source

  • cosmo – astropy cosmology instance

  • static – boolean, if True, only operates with fixed parameter values

set_static(logM, concentration, *args, **kwargs)[source]
Parameters:
  • logM – log10(M200)

  • concentration – halo concentration c = r_200 / r_s

Returns:

set_dynamic()[source]
Returns:

function(x, y, logM, concentration, center_x=0, center_y=0)[source]
Parameters:
  • x – angular position

  • y – angular position

  • Rs – angular turn over point

  • alpha_Rs – deflection at Rs

  • center_x – center of halo

  • center_y – center of halo

Returns:

derivatives(x, y, logM, concentration, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function (integral of NFW)

hessian(x, y, logM, concentration, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

lenstronomy.LensModel.Profiles.nfw_mass_concentration_ellipse module

This module contains a class to compute the elliptical Navarro-Frank-White function in mass/kappa space.

class NFWMCEllipsePotential(z_lens, z_source, cosmo=None, static=False)[source]

Bases: NFWMC

This class contains functions parameterises the NFW profile with log10 M200 and the concentration rs/r200 relation are: R_200 = c * Rs.

ATTENTION: the parameterization is cosmology and redshift dependent! The cosmology to connect mass and deflection relations is fixed to default H0=70km/s Omega_m=0.3 flat LCDM. It is recommended to keep a given cosmology definition in the lens modeling as the observable reduced deflection angles are sensitive in this parameterization. If you do not want to impose a mass-concentration relation, it is recommended to use the default NFW lensing profile parameterized in reduced deflection angles.

param_names = ['logM', 'concentration', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'concentration': 0.01, 'e1': -0.5, 'e2': -0.5, 'logM': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'concentration': 1000, 'e1': 0.5, 'e2': 0.5, 'logM': 16}
__init__(z_lens, z_source, cosmo=None, static=False)[source]
Parameters:
  • z_lens – redshift of lens

  • z_source – redshift of source

  • cosmo – astropy cosmology instance

  • static – boolean, if True, only operates with fixed parameter values

function(x, y, logM, concentration, e1, e2, center_x=0, center_y=0)[source]

Compute the lensing potential of the NFW profile with ellipticity.

Parameters:
  • x – angular position

  • y – angular position

  • Rs – angular turn over point

  • alpha_Rs – deflection at Rs

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo

  • center_y – center of halo

Returns:

derivatives(x, y, logM, concentration, e1, e2, center_x=0, center_y=0)[source]

Return df/dx and df/dy of the function (integral of NFW).

Parameters:
  • x – angular position

  • y – angular position

  • Rs – angular turn over point

  • alpha_Rs – deflection at Rs

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo

  • center_y – center of halo

Returns:

hessian(x, y, logM, concentration, e1, e2, center_x=0, center_y=0)[source]

Return Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

Parameters:
  • x – angular position

  • y – angular position

  • Rs – angular turn over point

  • alpha_Rs – deflection at Rs

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo

  • center_y – center of halo

Returns:

lenstronomy.LensModel.Profiles.nfw_vir_trunc module

class NFWVirTrunc(z_lens, z_source, cosmo=None)[source]

Bases: LensProfileBase

this class contains functions concerning the NFW profile that is sharply truncated at the virial radius https://arxiv.org/pdf/astro-ph/0304034.pdf

relation are: R_200 = c * Rs

__init__(z_lens, z_source, cosmo=None)[source]
Parameters:
  • z_lens – redshift of lens

  • z_source – redshift of source

  • cosmo – astropy cosmology instance

kappa(theta, logM, c)[source]

Projected surface brightness.

Parameters:
  • theta – radial angle from the center of the profile

  • logM – log_10 halo mass in physical units of M_sun

  • c – concentration of the halo; r_200 = c * r_s

Returns:

convergence at theta

lenstronomy.LensModel.Profiles.nie module

class NIE[source]

Bases: LensProfileBase

Non-singular isothermal ellipsoid (NIE)

\[\kappa = \theta_E/2 \left[s^2_{scale} + qx^2 + y^2/q]−1/2\]
param_names = ['theta_E', 'e1', 'e2', 's_scale', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 's_scale': 0, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 's_scale': 100, 'theta_E': 10}
__init__()[source]
function(x, y, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale

  • center_x – profile center

  • center_y – profile center

Returns:

lensing potential

derivatives(x, y, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale

  • center_x – profile center

  • center_y – profile center

Returns:

alpha_x, alpha_y

hessian(x, y, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale

  • center_x – profile center

  • center_y – profile center

Returns:

f_xx, f_xy, f_yx, f_yy

density_lens(r, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]

3d mass density at 3d radius r. This function assumes spherical symmetry/ignoring the eccentricity.

Parameters:
  • r – 3d radius

  • theta_E – Einstein radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale

  • center_x – profile center

  • center_y – profile center

Returns:

3d mass density at 3d radius r

mass_3d_lens(r, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]

Mass enclosed a 3d radius r. This function assumes spherical symmetry/ignoring the eccentricity.

Parameters:
  • r – 3d radius

  • theta_E – Einstein radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale

  • center_x – profile center

  • center_y – profile center

Returns:

3d mass density at 3d radius r

param_conv(theta_E, e1, e2, s_scale)[source]
set_static(theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
Parameters:
  • theta_E – Einstein radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale

  • center_x – profile center

  • center_y – profile center

Returns:

self variables set

set_dynamic()[source]
Returns:

class NIEMajorAxis(diff=1e-10)[source]

Bases: LensProfileBase

This class contains the function and the derivatives of the non-singular isothermal ellipse. See Keeton and Kochanek 1998, https://arxiv.org/pdf/astro-ph/9705194.pdf

\[\kappa = b * (q2(s2 + x2) + y2􏰉)^{−1/2}`\]
param_names = ['b', 's', 'q', 'center_x', 'center_y']
__init__(diff=1e-10)[source]
function(x, y, b, s, q)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, b, s, q)[source]

Returns df/dx and df/dy of the function.

hessian(x, y, b, s, q)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

static kappa(x, y, b, s, q)[source]

convergence.

Parameters:
  • x – major axis coordinate

  • y – minor axis coordinate

  • b – normalization

  • s – smoothing scale

  • q – axis ratio

Returns:

convergence

lenstronomy.LensModel.Profiles.nie_potential module

class NIE_POTENTIAL[source]

Bases: LensProfileBase

This class implements the elliptical potential of Eq.

(67) of LECTURES ON GRAVITATIONAL LENSING and Eq. (1) of Blandford & Kochanek 1987, mapped to Eq. (8) of Barnaka1998 to find the ellipticity bounds

param_names = ['center_x', 'center_y', 'theta_E', 'theta_c', 'e1', 'e2']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': 0, 'e2': 0, 'theta_E': 0, 'theta_c': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.2, 'e2': 0.2, 'theta_E': 10, 'theta_c': 10}
__init__()[source]
param_conv(theta_E, theta_c, e1, e2)[source]
set_static(theta_E, theta_c, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • theta_c – core radius

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

self variables set

set_dynamic()[source]
Returns:

function(x, y, theta_E, theta_c, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coord (in angles)

  • y – y-coord (in angles)

  • theta_E – Einstein radius (in angles)

  • theta_c – core radius (in angles)

  • e1 – eccentricity component, x direction(dimensionless)

  • e2 – eccentricity component, y direction (dimensionless)

Returns:

lensing potential

derivatives(x, y, theta_E, theta_c, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coord (in angles)

  • y – y-coord (in angles)

  • theta_E – Einstein radius (in angles)

  • theta_c – core radius (in angles)

  • e1 – eccentricity component, x direction(dimensionless)

  • e2 – eccentricity component, y direction (dimensionless)

Returns:

deflection angle (in angles)

hessian(x, y, theta_E, theta_c, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coord (in angles)

  • y – y-coord (in angles)

  • theta_E – Einstein radius (in angles)

  • theta_c – core radius (in angles)

  • e1 – eccentricity component, x direction(dimensionless)

  • e2 – eccentricity component, y direction (dimensionless)

Returns:

hessian matrix (in angles)

class NIEPotentialMajorAxis(diff=1e-10)[source]

Bases: LensProfileBase

This class implements the elliptical potential of Eq.

(67) of LECTURES ON GRAVITATIONAL LENSING and Eq. (1) of Blandford & Kochanek 1987, mapped to Eq. (8) of Barnaka1998 to find the ellipticity bounds

param_names = ['theta_E', 'theta_c', 'eps', 'center_x', 'center_y']
__init__(diff=1e-10)[source]
function(x, y, theta_E, theta_c, eps)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, theta_E, theta_c, eps)[source]

Returns df/dx and df/dy of the function.

hessian(x, y, theta_E, theta_c, eps)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

lenstronomy.LensModel.Profiles.numerical_deflections module

class TabulatedDeflections(custom_class)[source]

Bases: LensProfileBase

A user-defined class that returns deflection angles given a set of observed coordinates on the sky (x, y).

This class has similar functionality as INTERPOL, with the difference being that the interpolation for this class is done prior to class creation. When used with routines in the lenstronomy.Sampling, this class effectively acts as a fixed lens model with no keyword arguments.

profile_name = 'TABULATED_DEFLECTIONS'
param_names = []
lower_limit_default = {}
upper_limit_default = {}
__init__(custom_class)[source]
Parameters:

custom_class – a user-defined class that has a __call___ method that returns deflection angles

Code example:

>>> custom_class = CustomLensingClass()
>>> alpha_x, alpha_y = custom_class(x, y, **kwargs)

or equivalently:

>>> from lenstronomy.LensModel.lens_model import LensModel
>>> lens_model_list = ['TABULATED_DEFLECTIONS']
>>> lens_model = LensModel(lens_model_list, profile_kwargs_list=[{"custom_class": custom_class}])
>>>> alpha_x, alpha_y = lens_model.alpha(x, y, **kwargs)
function(x, y, center_x=0, center_y=0, **kwargs)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, center_x=0, center_y=0, **kwargs)[source]
Parameters:
  • x – x coordinate [arcsec]

  • y – x coordinate [arcsec]

  • center_x – deflector x center [arcsec]

  • center_y – deflector y center [arcsec]

  • kwargs – keyword arguments for the custom profile

Returns:

hessian(x, y, center_x=0, center_y=0, **kwargs)[source]

Returns the components of the hessian matrix :param x: x coordinate [arcsec] :param y: y coordinate [arcsec] :param center_x: the deflector x coordinate :param center_y: the deflector y coordinate :param kwargs: keyword arguments for the profile :return: the derivatives of the deflection angles that make up the hessian matrix.

lenstronomy.LensModel.Profiles.pemd module

class PEMD(suppress_fastell=False)[source]

Bases: LensProfileBase

Class for power law ellipse mass density profile (PEMD). This class effectively calls the class SPEMD_SMOOTH with a fixed and very small central smoothing scale to perform the numerical integral using the FASTELL code by Renan Barkana. An alternative implementation of the same model using pure python with analytical functions is probided as ‘EPL’ profile.

\[\kappa(x, y) = \frac{3-\gamma}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q}} \right)^{\gamma-1}\]

with \(\theta_{E}\) is the (circularized) Einstein radius, \(\gamma\) is the negative power-law slope of the 3D mass distributions, \(q\) is the minor/major axis ratio, and \(x\) and \(y\) are defined in a coordinate system aligned with the major and minor axis of the lens.

In terms of eccentricities, this profile is defined as

\[\kappa(r) = \frac{3-\gamma}{2} \left(\frac{\theta'_{E}}{r \sqrt{1 − e*\cos(2*\phi)}} \right)^{\gamma-1}\]

with \(\epsilon\) is the ellipticity defined as

\[\epsilon = \frac{1-q^2}{1+q^2}\]

And an Einstein radius \(\theta'_{\rm E}\) related to the definition used is

\[\left(\frac{\theta'_{\rm E}}{\theta_{\rm E}}\right)^{2} = \frac{2q}{1+q^2}.\]
param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
__init__(suppress_fastell=False)[source]
Parameters:

suppress_fastell – bool, if True, does not raise if fastell4py is not installed

function(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

lensing potential

derivatives(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

deflection angles alpha_x, alpha_y

hessian(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

Hessian components f_xx, f_xy, f_yx, f_yy

mass_3d_lens(r, theta_E, gamma, e1=None, e2=None)[source]

Computes the spherical power-law mass enclosed (with SPP routine).

Parameters:
  • r – radius within the mass is computed

  • theta_E – Einstein radius

  • gamma – power-law slope

  • e1 – eccentricity component (not used)

  • e2 – eccentricity component (not used)

Returns:

mass enclosed a 3D radius r

density_lens(r, theta_E, gamma, e1=None, e2=None)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – radius within the mass is computed

  • theta_E – Einstein radius

  • gamma – power-law slope

  • e1 – eccentricity component (not used)

  • e2 – eccentricity component (not used)

Returns:

mass enclosed a 3D radius r

lenstronomy.LensModel.Profiles.point_mass module

class PointMass[source]

Bases: LensProfileBase

Class to compute the physical deflection angle of a point mass, given as an Einstein radius.

param_names = ['theta_E', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'theta_E': 100}
__init__()[source]
function(x, y, theta_E, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coord (in angles)

  • y – y-coord (in angles)

  • theta_E – Einstein radius (in angles)

Returns:

lensing potential

derivatives(x, y, theta_E, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coord (in angles)

  • y – y-coord (in angles)

  • theta_E – Einstein radius (in angles)

Returns:

deflection angle (in angles)

hessian(x, y, theta_E, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coord (in angles)

  • y – y-coord (in angles)

  • theta_E – Einstein radius (in angles)

Returns:

hessian matrix (in angles)

mass_3d_lens(r, theta_E)[source]

Mass enclosed within a 3d sphere of radius r, however it is just the point mass (in angular units).

Parameters:
  • r (float) – radius in arcsec

  • theta_E (float) – Einstein radius in arcsec

Returns:

mass in units of M_sun

Return type:

float

lenstronomy.LensModel.Profiles.pseudo_double_powerlaw module

class PseudoDoublePowerlaw(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains a double power law profile with flexible inner and outer logarithmic slopes g and n.

\[\rho(r) = \frac{\rho_0}{r^{\gamma}} \frac{Rs^{n}}{\left(r^2 + Rs^2 \right)^{(n - \gamma)/2}}\]

For g = 1.0 and n=3, it is approximately the same as an NFW profile The original reference is [1].

TODO: implement the gravitational potential for this profile

profile_name = 'PSEUDO_DPL'
param_names = ['Rs', 'alpha_Rs', 'center_x', 'center_y', 'gamma_inner', 'gamma_outer']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'gamma_inner': 0.1, 'gamma_outer': 1.0}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'gamma_inner': 2.9, 'gamma_outer': 10.0}
derivatives(x, y, Rs, alpha_Rs, gamma_inner, gamma_outer, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function which are the deflection angles.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

deflection angle in x, deflection angle in y

hessian(x, y, Rs, alpha_Rs, gamma_inner, gamma_outer, center_x=0, center_y=0)[source]
Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

static density(R, Rs, rho0, gamma_inner, gamma_outer)[source]

Three dimensional NFW profile.

Parameters:
  • R – radius of interest

  • rho0 – central density normalization

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

Returns:

rho(R) density

density_lens(r, Rs, alpha_Rs, gamma_inner, gamma_outer)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – 3d radios

  • Rs – scale radius

  • alpha_Rs – deflection at Rs

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

Returns:

density rho(r)

density_2d(x, y, Rs, rho0, gamma_inner, gamma_outer, center_x=0, center_y=0)[source]

Projected two dimensional profile.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • rho0 – density normalization at Rs

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

  • center_x – profile center (same units as x)

  • center_y – profile center (same units as x)

Returns:

Epsilon(R) projected density at radius R

static mass_3d(r, Rs, rho0, gamma_inner, gamma_outer)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – 3d radius

  • Rs – scale radius

  • rho0 – density normalization

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

Returns:

M(<r)

mass_3d_lens(r, Rs, alpha_Rs, gamma_inner, gamma_outer)[source]

Mass enclosed a 3d sphere or radius r. This function takes as input the lensing parameterization.

Parameters:
  • r – 3d radius

  • Rs – scale radius

  • alpha_Rs – deflection angle at Rs

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

Returns:

M(<r)

mass_2d(R, Rs, rho0, gamma_inner, gamma_outer)[source]

Mass enclosed a 2d cylinder or projected radius R.

Parameters:
  • R – 3d radius

  • Rs – scale radius

  • rho0 – central density normalization

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

Returns:

mass in cylinder

alpha(R, Rs, rho0, gamma_inner, gamma_outer, ax_x, ax_y)[source]

Deflection angle of NFW profile (times Sigma_crit D_OL) along the projection to coordinate ‘axis’.

Parameters:
  • R – 3d radius

  • Rs – scale radius

  • rho0 – central density normalization

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

  • ax_x – x coordinate relative to center

  • ax_y – y coordinate relative to center

Returns:

Epsilon(R) projected density at radius R

gamma(R, Rs, rho0, gamma_inner, gamma_outer, ax_x, ax_y)[source]

Shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate ‘axis’.

Parameters:
  • R – 3d radius

  • Rs – scale radius

  • rho0 – central density normalization

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

  • ax_x – x coordinate relative to center

  • ax_y – y coordinate relative to center

Returns:

Epsilon(R) projected density at radius R

alpha2rho0(alpha_Rs, Rs, gamma_inner, gamma_outer)[source]

Convert angle at Rs into rho0.

Parameters:
  • alpha_Rs – deflection angle at RS

  • Rs – scale radius

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

Returns:

density normalization (characteristic density)

rho02alpha(rho0, Rs, gamma_inner, gamma_outer)[source]

Convert rho0 to angle at Rs.

Parameters:
  • rho0 – density normalization (characteristic density)

  • Rs – scale radius

  • gamma_inner – logarithmic profile slope interior to Rs

  • gamma_outer – logarithmic profile slope outside Rs

Returns:

deflection angle at RS

lenstronomy.LensModel.Profiles.pseudo_jaffe module

class PseudoJaffe[source]

Bases: LensProfileBase

class to compute the DUAL PSEUDO ISOTHERMAL MASS DISTRIBUTION based on Eliasdottir (2007) https://arxiv.org/pdf/0710.5636.pdf Appendix A

Module name: ‘PJAFFE’;

An alternative name is dPIED (in the elliptical scenario)

This profile is for the spherical case. For an elliptical version, use “PJAFFE_ELLIPSE” (ellipticitly in the potential) # TODO: add/revise name once ellipticity in the mass is available

The 3D density distribution is

\[\rho(r) = \frac{\rho_0}{(1+r^2/Ra^2)(1+r^2/Rs^2)}\]

with \(Rs > Ra\).

The projected density is

\[\Sigma(R) = \Sigma_0 \frac{Ra Rs}{Rs-Ra}\left(\frac{1}{\sqrt{Ra^2+R^2}} - \frac{1}{\sqrt{Rs^2+R^2}} \right)\]

with

\[\Sigma_0 = \pi \rho_0 \frac{Ra Rs}{Rs + Ra}\]

In the lensing parameterization,

\[\sigma_0 = \frac{\Sigma_0}{\Sigma_{\rm crit}}\]
param_names = ['sigma0', 'Ra', 'Rs', 'center_x', 'center_y']
lower_limit_default = {'Ra': 0, 'Rs': 0, 'center_x': -100, 'center_y': -100, 'sigma0': 0}
upper_limit_default = {'Ra': 100, 'Rs': 100, 'center_x': 100, 'center_y': 100, 'sigma0': 10}
__init__()[source]
density(r, rho0, Ra, Rs)[source]

Computes the density.

Parameters:
  • r – radial distance from the center (in 3D)

  • rho0 – density normalization (see class documentation above)

  • Ra – core radius

  • Rs – transition radius from logarithmic slope -2 to -4

Returns:

density at r

density_lens(r, sigma0, Ra, Rs)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity. (optional definition)

\[\kappa(x, y) = \int_{-\infty}^{\infty} \rho(x, y, z) dz\]
Parameters:
  • r – radial distance from the center (in 3D)

  • sigma0 – density normalization (see class documentation above)

  • Ra – core radius

  • Rs – transition radius from logarithmic slope -2 to -4

Returns:

density

density_2d(x, y, rho0, Ra, Rs, center_x=0, center_y=0)[source]

Projected density.

Parameters:
  • x – projected coordinate on the sky

  • y – projected coordinate on the sky

  • rho0 – density normalization (see class documentation above)

  • Ra – core radius

  • Rs – transition radius from logarithmic slope -2 to -4

  • center_x – center of profile

  • center_y – center of profile

Returns:

projected density

mass_3d(r, rho0, Ra, Rs)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – radial distance from the center (in 3D)

  • rho0 – density normalization (see class documentation above)

  • Ra – core radius

  • Rs – transition radius from logarithmic slope -2 to -4

Returns:

M(<r)

mass_3d_lens(r, sigma0, Ra, Rs)[source]

Mass enclosed a 3d sphere or radius r given a lens parameterization with angular units.

Parameters:
  • r – radial distance from the center (in 3D)

  • sigma0 – density normalization (see class documentation above)

  • Ra – core radius

  • Rs – transition radius from logarithmic slope -2 to -4

Returns:

M(<r) in angular units (modulo critical mass density)

mass_2d(r, rho0, Ra, Rs)[source]

Mass enclosed projected 2d sphere of radius r.

Parameters:
  • r – radial distance from the center in projection

  • rho0 – density normalization (see class documentation above)

  • Ra – core radius

  • Rs – transition radius from logarithmic slope -2 to -4

Returns:

Sigma(<r)

mass_tot(rho0, Ra, Rs)[source]

Total mass within the profile.

Parameters:
  • rho0 – density normalization (see class documentation above)

  • Ra – core radius

  • Rs – transition radius from logarithmic slope -2 to -4

Returns:

total mass

grav_pot(r, rho0, Ra, Rs)[source]

Gravitational potential (modulo 4 pi G and rho0 in appropriate units)

Parameters:
  • r – radial distance from the center (in 3D)

  • rho0 – density normalization (see class documentation above)

  • Ra – core radius

  • Rs – transition radius from logarithmic slope -2 to -4

Returns:

gravitational potential (modulo 4 pi G and rho0 in appropriate units)

function(x, y, sigma0, Ra, Rs, center_x=0, center_y=0)[source]

Lensing potential.

Parameters:
  • x – projected coordinate on the sky

  • y – projected coordinate on the sky

  • sigma0 – sigma0/sigma_crit (see class documentation above)

  • Ra – core radius (see class documentation above)

  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

  • center_x – center of profile

  • center_y – center of profile

Returns:

lensing potential

derivatives(x, y, sigma0, Ra, Rs, center_x=0, center_y=0)[source]

Deflection angles.

Parameters:
  • x – projected coordinate on the sky

  • y – projected coordinate on the sky

  • sigma0 – sigma0/sigma_crit (see class documentation above)

  • Ra – core radius (see class documentation above)

  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

  • center_x – center of profile

  • center_y – center of profile

Returns:

f_x, f_y

hessian(x, y, sigma0, Ra, Rs, center_x=0, center_y=0)[source]

Hessian of lensing potential.

Parameters:
  • x – projected coordinate on the sky

  • y – projected coordinate on the sky

  • sigma0 – sigma0/sigma_crit (see class documentation above)

  • Ra – core radius (see class documentation above)

  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

  • center_x – center of profile

  • center_y – center of profile

Returns:

f_xx, f_xy, f_yx, f_yy

rho2sigma(rho0, Ra, Rs)[source]

Converts 3d density into 2d projected density parameter, Equation A4 in Eliasdottir (2007)

Parameters:
  • rho0 – density normalization

  • Ra – core radius (see class documentation above)

  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

Returns:

projected density normalization

sigma2rho(sigma0, Ra, Rs)[source]

Inverse of rho2sigma()

Parameters:
  • sigma0 – projected density normalization

  • Ra – core radius (see class documentation above)

  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

Returns:

3D density normalization

lenstronomy.LensModel.Profiles.pseudo_jaffe_ellipse_potential module

class PseudoJaffeEllipsePotential[source]

Bases: LensProfileBase

class to compute the DUAL PSEUDO ISOTHERMAL ELLIPTICAL MASS DISTRIBUTION based on Eliasdottir (2007) https://arxiv.org/pdf/0710.5636.pdf Appendix A with the ellipticity implemented in the potential

Module name: ‘PJAFFE_ELLIPSE’;

An alternative name is dPIED.

The 3D density distribution is

\[\rho(r) = \frac{\rho_0}{(1+r^2/Ra^2)(1+r^2/Rs^2)}\]

with \(Rs > Ra\).

The projected density is

\[\Sigma(R) = \Sigma_0 \frac{Ra Rs}{Rs-Ra}\left(\frac{1}{\sqrt{Ra^2+R^2}} - \frac{1}{\sqrt{Rs^2+R^2}} \right)\]

with

\[\Sigma_0 = \pi \rho_0 \frac{Ra Rs}{Rs + Ra}\]

In the lensing parameterization,

\[\sigma_0 = \frac{\Sigma_0}{\Sigma_{\rm crit}}\]
param_names = ['sigma0', 'Ra', 'Rs', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'Ra': 0, 'Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma0': 0}
upper_limit_default = {'Ra': 100, 'Rs': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma0': 10}
__init__()[source]
function(x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0)[source]

Returns double integral of NFW profile.

derivatives(x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function (integral of NFW)

hessian(x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

mass_3d_lens(r, sigma0, Ra, Rs, e1=0, e2=0)[source]
Parameters:
  • r

  • sigma0

  • Ra

  • Rs

  • e1

  • e2

Returns:

lenstronomy.LensModel.Profiles.radial_interpolated module

class RadialInterpolate(*args, **kwargs)[source]

Bases: LensProfileBase

Radially interpolated profile with azimuthal symmetry.

param_names = ['r_bin', 'kappa_r', 'center_x', 'center_y']
lower_limit_default = {}
upper_limit_default = {}
function(x, y, r_bin=None, kappa_r=None, center_x=0, center_y=0)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:
  • x – x-coordinate (angular position), float or numpy array

  • y – y-coordinate (angular position), float or numpy array

  • r_bin (array) – radial bins for which convergence values are provided

  • kappa_r (array of same size as r_bin) – convergence values corresponding to the r_bin radii

  • center_x (float) – x-position of center of radial density profile

  • center_y (float) – y-position of center of radial density profile

Returns:

lensing potential

derivatives(x, y, r_bin=None, kappa_r=None, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

Parameters:
  • x – x-coordinate (angular position), float or numpy array

  • y – y-coordinate (angular position), float or numpy array

  • r_bin (array) – radial bins for which convergence values are provided

  • kappa_r (array of same size as r_bin) – convergence values corresponding to the r_bin radii

  • center_x (float) – x-position of center of radial density profile

  • center_y (float) – y-position of center of radial density profile

Returns:

f_x, f_y at interpolated positions (x, y)

hessian(x, y, r_bin=None, kappa_r=None, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

Parameters:
  • x – x-coordinate (angular position), float or numpy array

  • y – y-coordinate (angular position), float or numpy array

  • r_bin (array) – radial bins for which convergence values are provided

  • kappa_r (array of same size as r_bin) – convergence values corresponding to the r_bin radii

  • center_x (float) – x-position of center of radial density profile

  • center_y (float) – y-position of center of radial density profile

Returns:

f_xx, f_xy, f_yx, f_yy at interpolated positions (x, y)

alpha(r, r_bin, kappa_r)[source]

Radial deflection angle m(<r) / r / pi.

Parameters:
  • r – radius from center

  • r_bin (array) – radial bins for which convergence values are provided

  • kappa_r (array of same size as r_bin) – convergence values corresponding to the r_bin radii

Returns:

radial deflection angle

set_dynamic()[source]
Returns:

no return, deletes pre-computed variables for certain lens models

lenstronomy.LensModel.Profiles.sersic module

class Sersic(smoothing=0.0001, sersic_major_axis=False)[source]

Bases: SersicUtil, LensProfileBase

this class contains functions to evaluate a Sersic mass profile: https://arxiv.org/pdf/astro-ph/0311559.pdf

\[\kappa(R) = \kappa_{\rm eff} \exp \left( -b_n \left[(R/R_{\rm Sersic})^{\frac{1}{n}}-1\right]\right)\]

with \(b_{n}\approx 1.999n-0.327\)

Examples

Example for converting physical mass units into convergence units used in the definition of this profile.

We first define an AstroPy cosmology instance and a LensCosmo class instance with a lens and source redshift.

>>> from lenstronomy.Cosmo.lens_cosmo import LensCosmo
>>> from astropy.cosmology import FlatLambdaCDM
>>> cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05)
>>> lens_cosmo = LensCosmo(z_lens=0.5, z_source=1.5, cosmo=cosmo)

We define the half-light radius R_sersic (arc seconds on the sky) and Sersic index n_sersic

>>> R_sersic = 2
>>> n_sersic = 4

Here we compute k_eff, the convergence at the half-light radius R_sersic for a stellar mass in Msun

>>> k_eff = lens_cosmo.sersic_m_star2k_eff(m_star=10**11.5, R_sersic=R_sersic, n_sersic=n_sersic)

And here we perform the inverse calculation given k_eff to return the physical stellar mass.

>>> m_star = lens_cosmo.sersic_k_eff2m_star(k_eff=k_eff, R_sersic=R_sersic, n_sersic=n_sersic)

The lens model calculation uses angular units as arguments! So to execute a deflection angle calculation one uses

>>> from lenstronomy.LensModel.Profiles.sersic import Sersic
>>> sersic = Sersic()
>>> alpha_x, alpha_y = sersic.derivatives(x=1, y=1, k_eff=k_eff, R_sersic=R_sersic, center_x=0, center_y=0)
param_names = ['k_eff', 'R_sersic', 'n_sersic', 'center_x', 'center_y']
lower_limit_default = {'R_sersic': 0, 'center_x': -100, 'center_y': -100, 'k_eff': 0, 'n_sersic': 0.5}
upper_limit_default = {'R_sersic': 100, 'center_x': 100, 'center_y': 100, 'k_eff': 10, 'n_sersic': 8}
function(x, y, n_sersic, R_sersic, k_eff, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • n_sersic – Sersic index

  • R_sersic – half light radius

  • k_eff – convergence at half light radius

  • center_x – x-center

  • center_y – y-center

Returns:

derivatives(x, y, n_sersic, R_sersic, k_eff, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

hessian(x, y, n_sersic, R_sersic, k_eff, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

lenstronomy.LensModel.Profiles.sersic_ellipse_kappa module

class SersicEllipseKappa[source]

Bases: LensProfileBase

This class contains the function and the derivatives of an elliptical sersic profile with the ellipticity introduced in the convergence (not the potential).

This requires the use of numerical integrals (Keeton 2004)

param_names = ['k_eff', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'R_sersic': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'k_eff': 0, 'n_sersic': 0.5}
upper_limit_default = {'R_sersic': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'k_eff': 10, 'n_sersic': 8}
__init__()[source]
function(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]

Deflection angles.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

hessian(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

projected_mass(x, y, q, n_sersic, R_sersic, k_eff, u=1, power=1)[source]

lenstronomy.LensModel.Profiles.sersic_ellipse_potential module

class SersicEllipsePotential[source]

Bases: LensProfileBase

this class contains functions to evaluate a Sersic mass profile: https://arxiv.org/pdf/astro-ph/0311559.pdf

param_names = ['k_eff', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'R_sersic': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'k_eff': 0, 'n_sersic': 0.5}
upper_limit_default = {'R_sersic': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'k_eff': 10, 'n_sersic': 8}
__init__()[source]
function(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]

Returns Gaussian.

derivatives(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

hessian(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

lenstronomy.LensModel.Profiles.sersic_utils module

class SersicUtil(smoothing=0.0001, sersic_major_axis=False)[source]

Bases: object

__init__(smoothing=0.0001, sersic_major_axis=False)[source]
Parameters:
  • smoothing – smoothing scale of the innermost part of the profile (for numerical reasons)

  • sersic_major_axis – boolean; if True, defines the half-light radius of the Sersic light profile along the semi-major axis (which is the Galfit convention) if False, uses the product average of semi-major and semi-minor axis as the convention (default definition for all light profiles in lenstronomy other than the Sersic profile)

k_bn(n, Re)[source]

Returns normalisation of the sersic profile such that Re is the half light radius given n_sersic slope.

k_Re(n, k)[source]
static b_n(n)[source]

B(n) computation. This is the approximation of the exact solution to the relation, 2*incomplete_gamma_function(2n; b_n) = Gamma_function(2*n).

Parameters:

n – the sersic index

Returns:

b(n)

get_distance_from_center(x, y, e1, e2, center_x, center_y)[source]

Get the distance from the center of Sersic, accounting for orientation and axis ratio :param x:

Parameters:
  • y

  • e1 – eccentricity

  • e2 – eccentricity

  • center_x – center x of sersic

  • center_y – center y of sersic

alpha_abs(x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0)[source]
Parameters:
  • x

  • y

  • n_sersic

  • r_eff

  • k_eff

  • center_x

  • center_y

Returns:

d_alpha_dr(x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0)[source]
Parameters:
  • x

  • y

  • n_sersic

  • r_eff

  • k_eff

  • center_x

  • center_y

Returns:

density(x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0)[source]

De-projection of the Sersic profile based on Prugniel & Simien (1997) :return:

total_flux(amp, R_sersic, n_sersic, e1=0, e2=0, **kwargs)[source]

Computes analytical integral to compute total flux of the Sersic profile.

Parameters:
  • amp – amplitude parameter in Sersic function (surface brightness at R_sersic

  • R_sersic – half-light radius in semi-major axis

  • n_sersic – Sersic index

  • e1 – eccentricity

  • e2 – eccentricity

Returns:

Analytic integral of the total flux of the Sersic profile

lenstronomy.LensModel.Profiles.shapelet_pot_cartesian module

class CartShapelets(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains the function and the derivatives of the cartesian shapelets.

param_names = ['coeffs', 'beta', 'center_x', 'center_y']
lower_limit_default = {'beta': 0, 'center_x': -100, 'center_y': -100, 'coeffs': [0]}
upper_limit_default = {'beta': 100, 'center_x': 100, 'center_y': 100, 'coeffs': [100]}
function(x, y, coeffs, beta, center_x=0, center_y=0)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, coeffs, beta, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

hessian(x, y, coeffs, beta, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

H_n(n, x)[source]

Constructs the Hermite polynomial of order n at position x (dimensionless)

Parameters:
  • n – The n’the basis function.

  • x – 1-dim position (dimensionless)

Returns:

array– H_n(x).

Raises:

AttributeError, KeyError

phi_n(n, x)[source]

Constructs the 1-dim basis function (formula (1) in Refregier et al. 2001)

Parameters:
  • n – The n’the basis function.

  • x – 1-dim position (dimensionless)

Returns:

array– phi_n(x).

Raises:

AttributeError, KeyError

pre_calc(x, y, beta, n_order, center_x, center_y)[source]

Calculates the H_n(x) and H_n(y) for a given x-array and y-array :param x:

Parameters:
  • y

  • amp

  • beta

  • n_order

  • center_x

  • center_y

Returns:

list of H_n(x) and H_n(y)

lenstronomy.LensModel.Profiles.shapelet_pot_polar module

class PolarShapelets[source]

Bases: LensProfileBase

This class contains the function and the derivatives of the Singular Isothermal Sphere.

param_names = ['coeffs', 'beta', 'center_x', 'center_y']
lower_limit_default = {'beta': 0, 'center_x': -100, 'center_y': -100, 'coeffs': [0]}
upper_limit_default = {'beta': 100, 'center_x': 100, 'center_y': 100, 'coeffs': [100]}
__init__()[source]
function(x, y, coeffs, beta, center_x=0, center_y=0)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, coeffs, beta, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

hessian(x, y, coeffs, beta, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

lenstronomy.LensModel.Profiles.shear module

class Shear(*args, **kwargs)[source]

Bases: LensProfileBase

Class for external shear gamma1, gamma2 expression.

param_names = ['gamma1', 'gamma2', 'ra_0', 'dec_0']
lower_limit_default = {'dec_0': -100, 'gamma1': -0.5, 'gamma2': -0.5, 'ra_0': -100}
upper_limit_default = {'dec_0': 100, 'gamma1': 0.5, 'gamma2': 0.5, 'ra_0': 100}
function(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • gamma1 – shear component

  • gamma2 – shear component

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

lensing potential

derivatives(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • gamma1 – shear component

  • gamma2 – shear component

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

deflection angles

hessian(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • gamma1 – shear component

  • gamma2 – shear component

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

f_xx, f_xy, f_yx, f_yy

class ShearGammaPsi[source]

Bases: LensProfileBase

class to model a shear field with shear strength and direction. The translation ot the cartesian shear distortions is as follow:

\[\gamma_1 = \gamma_{ext} \cos(2 \phi_{ext}) \gamma_2 = \gamma_{ext} \sin(2 \phi_{ext})\]
param_names = ['gamma_ext', 'psi_ext', 'ra_0', 'dec_0']
lower_limit_default = {'dec_0': -100, 'gamma_ext': 0, 'psi_ext': -3.141592653589793, 'ra_0': -100}
upper_limit_default = {'dec_0': 100, 'gamma_ext': 1, 'psi_ext': 3.141592653589793, 'ra_0': 100}
__init__()[source]
static function(x, y, gamma_ext, psi_ext, ra_0=0, dec_0=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • gamma_ext – shear strength

  • psi_ext – shear angle (radian)

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

derivatives(x, y, gamma_ext, psi_ext, ra_0=0, dec_0=0)[source]

Deflection angles.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

hessian(x, y, gamma_ext, psi_ext, ra_0=0, dec_0=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

class ShearReduced[source]

Bases: LensProfileBase

Reduced shear distortions \(\gamma' = \gamma / (1-\kappa)\). This distortion keeps the magnification as unity and, thus, does not change the size of apparent objects. To keep the magnification at unity, it requires.

\[(1-\kappa)^2) - \gamma_1^2 - \gamma_2^ = 1\]

Thus, for given pair of reduced shear \((\gamma'_1, \gamma'_2)\), an additional convergence term is calculated and added to the lensing distortions.

param_names = ['gamma1', 'gamma2', 'ra_0', 'dec_0']
lower_limit_default = {'dec_0': -100, 'gamma1': -0.5, 'gamma2': -0.5, 'ra_0': -100}
upper_limit_default = {'dec_0': 100, 'gamma1': 0.5, 'gamma2': 0.5, 'ra_0': 100}
__init__()[source]
function(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • gamma1 – shear component

  • gamma2 – shear component

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

lensing potential

derivatives(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • gamma1 – shear component

  • gamma2 – shear component

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

deflection angles

hessian(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y0-coordinate (angle)

  • gamma1 – shear component

  • gamma2 – shear component

  • ra_0 – x/ra position where shear deflection is 0

  • dec_0 – y/dec position where shear deflection is 0

Returns:

f_xx, f_xy, f_yx, f_yy

lenstronomy.LensModel.Profiles.sie module

class SIE(NIE=True)[source]

Bases: LensProfileBase

Class for singular isothermal ellipsoid (SIS with ellipticity)

\[\kappa(x, y) = \frac{1}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q}} \right)\]

with \(\theta_{E}\) is the (circularized) Einstein radius, \(q\) is the minor/major axis ratio, and \(x\) and \(y\) are defined in a coordinate system aligned with the major and minor axis of the lens.

In terms of eccentricities, this profile is defined as

\[\kappa(r) = \frac{1}{2} \left(\frac{\theta'_{E}}{r \sqrt{1 − e*\cos(2*\phi)}} \right)\]

with \(\epsilon\) is the ellipticity defined as

\[\epsilon = \frac{1-q^2}{1+q^2}\]

And an Einstein radius \(\theta'_{\rm E}\) related to the definition used is

\[\left(\frac{\theta'_{\rm E}}{\theta_{\rm E}}\right)^{2} = \frac{2q}{1+q^2}.\]
param_names = ['theta_E', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'theta_E': 100}
__init__(NIE=True)[source]
Parameters:

NIE – bool, if True, is using the NIE analytic model. Otherwise it uses PEMD with gamma=2 from fastell4py

function(x, y, theta_E, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate (angular coordinates)

  • y – y-coordinate (angular coordinates)

  • theta_E – Einstein radius

  • e1 – eccentricity

  • e2 – eccentricity

  • center_x – centroid

  • center_y – centroid

Returns:

derivatives(x, y, theta_E, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate (angular coordinates)

  • y – y-coordinate (angular coordinates)

  • theta_E – Einstein radius

  • e1 – eccentricity

  • e2 – eccentricity

  • center_x – centroid

  • center_y – centroid

Returns:

hessian(x, y, theta_E, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate (angular coordinates)

  • y – y-coordinate (angular coordinates)

  • theta_E – Einstein radius

  • e1 – eccentricity

  • e2 – eccentricity

  • center_x – centroid

  • center_y – centroid

Returns:

static theta2rho(theta_E)[source]

Converts projected density parameter (in units of deflection) into 3d density parameter.

Parameters:

theta_E

Returns:

static mass_3d(r, rho0, e1=0, e2=0)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – radius in angular units

  • rho0 – density at angle=1

Returns:

mass in angular units

mass_3d_lens(r, theta_E, e1=0, e2=0)[source]

Mass enclosed a 3d sphere or radius r given a lens parameterization with angular units.

Parameters:
  • r – radius in angular units

  • theta_E – Einstein radius

Returns:

mass in angular units

mass_2d(r, rho0, e1=0, e2=0)[source]

Mass enclosed projected 2d sphere of radius r.

Parameters:
  • r

  • rho0

  • e1

  • e2

Returns:

mass_2d_lens(r, theta_E, e1=0, e2=0)[source]
Parameters:
  • r

  • theta_E

  • e1

  • e2

Returns:

grav_pot(x, y, rho0, e1=0, e2=0, center_x=0, center_y=0)[source]

Gravitational potential (modulo 4 pi G and rho0 in appropriate units)

Parameters:
  • x

  • y

  • rho0

  • e1

  • e2

  • center_x

  • center_y

Returns:

density_lens(r, theta_E, e1=0, e2=0)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – radius in angles

  • theta_E – Einstein radius

  • e1 – eccentricity component

  • e2 – eccentricity component

Returns:

density

static density(r, rho0, e1=0, e2=0)[source]

Computes the density.

Parameters:
  • r – radius in angles

  • rho0 – density at angle=1

Returns:

density at r

static density_2d(x, y, rho0, e1=0, e2=0, center_x=0, center_y=0)[source]

Projected density.

Parameters:
  • x

  • y

  • rho0

  • e1

  • e2

  • center_x

  • center_y

Returns:

lenstronomy.LensModel.Profiles.sis module

class SIS(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains the function and the derivatives of the Singular Isothermal Sphere.

\[\kappa(x, y) = \frac{1}{2} \left(\frac{\theta_{E}}{\sqrt{x^2 + y^2}} \right)\]

with \(\theta_{E}\) is the Einstein radius,

param_names = ['theta_E', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'theta_E': 100}
function(x, y, theta_E, center_x=0, center_y=0)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, theta_E, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function.

hessian(x, y, theta_E, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2.

static rho2theta(rho0)[source]

Converts 3d density into 2d projected density parameter :param rho0:

Returns:

static theta2rho(theta_E)[source]

Converts projected density parameter (in units of deflection) into 3d density parameter :param theta_E: Einstein radius :return:

static mass_3d(r, rho0)[source]

Mass enclosed a 3d sphere or radius r :param r: radius in angular units :param rho0: density at angle=1 :return: mass in angular units.

mass_3d_lens(r, theta_E)[source]

Mass enclosed a 3d sphere or radius r given a lens parameterization with angular units.

Parameters:
  • r – radius in angular units

  • theta_E – Einstein radius

Returns:

mass in angular units

static mass_2d(r, rho0)[source]

Mass enclosed projected 2d sphere of radius r :param r:

Parameters:

rho0

Returns:

mass_2d_lens(r, theta_E)[source]
Parameters:
  • r – radius

  • theta_E – Einstein radius

Returns:

mass within a radius in projection

grav_pot(x, y, rho0, center_x=0, center_y=0)[source]

Gravitational potential (modulo 4 pi G and rho0 in appropriate units) :param x:

Parameters:
  • y

  • rho0

  • center_x

  • center_y

Returns:

static density(r, rho0)[source]

Computes the density :param r: radius in angles :param rho0: density at angle=1 :return: density at r.

density_lens(r, theta_E)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in projected in units of angles (i.e. arc seconds) results in the convergence quantity.

Parameters:
  • r – 3d radius

  • theta_E – Einstein radius

Returns:

density(r)

static density_2d(x, y, rho0, center_x=0, center_y=0)[source]

Projected density :param x:

Parameters:
  • y

  • rho0

  • center_x

  • center_y

Returns:

lenstronomy.LensModel.Profiles.sis_truncate module

class SIS_truncate(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains the function and the derivatives of the truncated Singular Isothermal Sphere potential:

\[\begin{split}\psi(x, y) = \begin{cases} \theta_{E} \, r & r < r_{\text{trunc}} \\ \theta_{E} \, r_{\text{trunc}} + \frac{1}{2} \theta_{E} \left(3 - \frac{r}{r_{\text{trunc}}}\right) (r - r_{\text{trunc}}) & r_{\text{trunc}} \leq r < 2 r_{\text{trunc}} \\ \frac{3}{2} \theta_{E} \, r_{\text{trunc}} & r \geq 2 r_{\text{trunc}} \end{cases}\end{split}\]

where \(\theta_{E}\) is the Einstein radius and \(r_{\text{trunc}}\) is the truncation radius

param_names = ['theta_E', 'r_trunc', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'r_trunc': 0, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'r_trunc': 100, 'theta_E': 100}
function(x, y, theta_E, r_trunc, center_x=0, center_y=0)[source]
Parameters:
  • x (array of size (n)) – set of x-coordinates

  • y (array of size (n)) – set of y-coordinates

  • theta_E (float (in arcsec)) – Einstein radius of lens

  • r_trunc (float (in arcsec)) – truncated radius

  • center_x – profile center

  • center_y – profile center

Returns:

function

derivatives(x, y, theta_E, r_trunc, center_x=0, center_y=0)[source]

Computes the first derivatives df/dx and df/dy.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius of lens

  • r_trunc (float (in arcsec)) – truncated radius

  • center_x – profile center

  • center_y – profile center

Returns:

first derivatives (df/dx, df/dy)

hessian(x, y, theta_E, r_trunc, center_x=0, center_y=0)[source]

Computes the Hessian matrix.

Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius of lens

  • r_trunc (float (in arcsec)) – truncated radius

  • center_x – profile center

  • center_y – profile center

Returns:

Hessian matrix components (d^2f/dx^2, d^2f/dxdy, d^2f/dydx, d^2f/dy^2)

lenstronomy.LensModel.Profiles.spemd module

class SPEMD(suppress_fastell=False)[source]

Bases: LensProfileBase

Class for smooth power law ellipse mass density profile (SPEMD). This class effectively performs the FASTELL calculations by Renan Barkana. The parameters are changed and represent a spherically averaged Einstein radius an a logarithmic 3D mass profile slope.

The SPEMD mass profile is defined as follow:

\[\kappa(x, y) = \frac{3-\gamma}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q + s^2}} \right)^{\gamma-1}\]

with \(\theta_{E}\) is the (circularized) Einstein radius, \(\gamma\) is the negative power-law slope of the 3D mass distributions, \(q\) is the minor/major axis ratio, and \(x\) and \(y\) are defined in a coordinate system aligned with the major and minor axis of the lens.

the FASTELL definitions are as follows:

The parameters are position \((x1,x2)\), overall factor (\(b\)), power (gam), axis ratio (arat) which is <=1, core radius squared (\(s2\)), and the output potential (\(\phi\)). The projected mass density distribution, in units of the critical density, is

\[\kappa(x1,x2)=b_{fastell} \left[u2+s2\right]^{-gam},\]

with \(u2=\left[x1^2+x2^2/(arat^2)\right]\).

The conversion from lenstronomy definitions of this class to FASTELL are:

\[q_{fastell} \equiv q_{lenstronomy}\]
\[gam \equiv (\gamma-1)/2\]
\[b_{fastell} \equiv (3-\gamma)/2. * \left(\theta_{E}^2 / q\right)^{gam}\]
\[s2_{fastell} = s_{lenstronomy}^2 * q\]
param_names = ['theta_E', 'gamma', 'e1', 'e2', 's_scale', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 0, 's_scale': 0, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 100, 's_scale': 100, 'theta_E': 100}
__init__(suppress_fastell=False)[source]
function(x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale in the center of the profile (angle)

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

lensing potential

derivatives(x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale in the center of the profile

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

deflection angles alpha_x, alpha_y

hessian(x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale in the center of the profile

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

Hessian components f_xx, f_xy, f_yx, f_yy

param_transform(x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0)[source]

Transforms parameters in the format of fastell4py.

Parameters:
  • x – x-coordinate (angle)

  • y – y-coordinate (angle)

  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • e1 – eccentricity component

  • e2 – eccentricity component

  • s_scale – smoothing scale in the center of the profile

  • center_x – x-position of lens center

  • center_y – y-position of lens center

Returns:

x-rotated, y-rotated, q_fastell, gam, s2, q, phi_G

static convert_params(theta_E, gamma, q, s_scale)[source]

Converts parameter definitions into quantities used by the FASTELL fortran library.

Parameters:
  • theta_E – Einstein radius

  • gamma – 3D power-law slope of mass profile

  • q – axis ratio minor/major

  • s_scale – float, smoothing scale in the core

Returns:

pre-factors to SPEMP profile for FASTELL

static is_not_empty(x1, x2)[source]

Check if float or not an empty array.

Returns:

True if x1 and x2 are either floats/ints or an non-empty array, False if e.g. objects are []

Return type:

bool

lenstronomy.LensModel.Profiles.spep module

class SPEP[source]

Bases: LensProfileBase

Softened Power-Law Elliptical Potential (SPEP)

\[\psi(x, y) = \frac{2 E^2}{\eta^2} \left( \frac{p^2 + s^2}{E^2} \right)^{\eta/2}\]

where \(E\) is the normalization factor related to the Einstein radius \(\theta_{E}\), \(\gamma\) is the power law slope, \(s\) is the softening parameter, \(\eta = 3 - \gamma\) is the power-law exponent transformation, and \(p^2\) is given by

\[p^2 = x_t^2 + \frac{y_t^2}{q^2},\]

with the transformed coordinates \(x_t, y_t\) aligned with the major and minor axes of the lens, given by:

\[x_t = \cos(\phi_G) (x - x_c) + \sin(\phi_G) (y - y_c)\]
\[y_t = -\sin(\phi_G) (x - x_c) + \cos(\phi_G) (y - y_c).\]

The Einstein radius normalization \(E\) is given by

\[E = \frac{\theta_E}{\left( \frac{3 - \gamma}{2} \right)^{1/(1 - \gamma)} \sqrt{q}}.\]

Here, \(q\) is the axis ratio of the elliptical potential.

A mathematical derivation of this potential is discussed in Barkana (1998), https://iopscience.iop.org/article/10.1086/305950/fulltext/.

param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 0, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 100, 'theta_E': 100}
__init__()[source]
function(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x (array of size (n)) – set of x-coordinates

  • theta_E (float.) – Einstein radius of lens

  • gamma (<2 float) – power law slope of mass profifle

  • e1 (-1<e1<1) – eccentricity

  • e2 (-1<e1<1) – eccentricity

Returns:

function

Raises:

AttributeError, KeyError

derivatives(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

alpha_x, alpha_y

hessian(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
Parameters:
  • x – x-coordinate in image plane

  • y – y-coordinate in image plane

  • theta_E – Einstein radius

  • gamma – power law slope

  • e1 – eccentricity component

  • e2 – eccentricity component

  • center_x – profile center

  • center_y – profile center

Returns:

f_xx, f_xy, f_yx, f_yy

mass_3d_lens(r, theta_E, gamma, e1=None, e2=None)[source]

Computes the spherical power-law mass enclosed (with SPP routine)

Parameters:
  • r – radius within the mass is computed

  • theta_E – Einstein radius

  • gamma – power-law slope

  • e1 – eccentricity component (not used)

  • e2 – eccentricity component (not used)

Returns:

mass enclosed a 3D radius r

density_lens(r, theta_E, gamma, e1=None, e2=None)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – radius within the mass is computed

  • theta_E – Einstein radius

  • gamma – power-law slope

  • e1 – eccentricity component (not used)

  • e2 – eccentricity component (not used)

Returns:

mass enclosed a 3D radius r

lenstronomy.LensModel.Profiles.splcore module

class SPLCORE(*args, **kwargs)[source]

Bases: LensProfileBase

This lens profile corresponds to a spherical power law (SPL) mass distribution with logarithmic slope gamma and a 3D core radius r_core.

\[\rho\left(r, \rho_0, r_c, \gamma\right) = \rho_0 \frac{{r_c}^\gamma}{\left(r^2 + r_c^2\right)^{\frac{\gamma}{2}}}\]

The difference between this and EPL is that this model contains a core radius, is circular, and is also defined for gamma=3.

With respect to SPEMD, this model is different in that it is also defined for gamma = 3, is circular, and is defined in terms of a physical density parameter rho0, or the central density at r=0 divided by the critical density for lensing such that rho0 has units 1/arcsec.

This class is defined for all gamma > 1

param_names = ['sigma0', 'center_x', 'center_y', 'r_core', 'gamma']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'gamma': 1.000001, 'r_core': 1e-06, 'sigma0': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'gamma': 5.0, 'r_core': 100, 'sigma0': 1000000000000.0}
function(x, y, sigma0, r_core, gamma, center_x=0, center_y=0)[source]

Lensing potential (only needed for specific calculations, such as time delays)

Parameters:

kwargs – keywords of the profile

Returns:

raise as definition is not defined

derivatives(x, y, sigma0, r_core, gamma, center_x=0, center_y=0)[source]
Parameters:
  • x – projected x position at which to evaluate function [arcsec]

  • y – projected y position at which to evaluate function [arcsec]

  • sigma0 – convergence at r = 0

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

  • center_x – x coordinate center of lens model [arcsec]

  • center_y – y coordinate center of lens model [arcsec]

Returns:

deflection angle alpha in x and y directions

hessian(x, y, sigma0, r_core, gamma, center_x=0, center_y=0)[source]
Parameters:
  • x – projected x position at which to evaluate function [arcsec]

  • y – projected y position at which to evaluate function [arcsec]

  • sigma0 – convergence at r = 0

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

  • center_x – x coordinate center of lens model [arcsec]

  • center_y – y coordinate center of lens model [arcsec]

Returns:

hessian elements

alpha_(x/y) = alpha_r * cos/sin(x/y / r)

alpha(r, sigma0, r_core, gamma)[source]

Returns the deflection angle at r.

Parameters:
  • r – radius [arcsec]

  • sigma0 – convergence at r=0

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

Returns:

deflection angle at r

static density(r, rho0, r_core, gamma)[source]

Returns the 3D density at r.

Parameters:
  • r – radius [arcsec]

  • rho0 – convergence at r=0

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

Returns:

density at r

density_lens(r, sigma0, r_core, gamma)[source]

Returns the 3D density at r.

Parameters:
  • r – radius [arcsec]

  • sigma0 – convergence at r=0

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

Returns:

density at r

density_2d(x, y, rho0, r_core, gamma)[source]

Returns the convergence at radius r.

Parameters:
  • x – x position [arcsec]

  • y – y position [arcsec]

  • rho0 – convergence at r=0

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

Returns:

convergence at r

mass_3d(r, rho0, r_core, gamma)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – radius [arcsec]

  • rho0 – density at r = 0 in units [rho_0_physical / sigma_crit] (which should be equal to [arcsec]) where rho_0_physical is a physical density normalization and sigma_crit is the critical density for lensing

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

Returns:

mass inside radius r

mass_3d_lens(r, sigma0, r_core, gamma)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – radius [arcsec]

  • sigma0 – convergence at r = 0

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

Returns:

mass inside radius r

mass_2d(r, rho0, r_core, gamma)[source]

Mass enclosed projected 2d disk of radius r.

Parameters:
  • r – radius [arcsec]

  • rho0 – density at r = 0 in units [rho_0_physical / sigma_crit] (which should be equal to [1/arcsec]) where rho_0_physical is a physical density normalization and sigma_crit is the critical density for lensing

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

Returns:

projected mass inside disk of radius r

mass_2d_lens(r, sigma0, r_core, gamma)[source]

Mass enclosed projected 2d disk of radius r.

Parameters:
  • r – radius [arcsec]

  • sigma0 – convergence at r = 0 where rho_0_physical is a physical density normalization and sigma_crit is the critical density for lensing

  • r_core – core radius [arcsec]

  • gamma – logarithmic slope at r -> infinity

Returns:

projected mass inside disk of radius r

lenstronomy.LensModel.Profiles.spp module

class SPP(*args, **kwargs)[source]

Bases: LensProfileBase

Class to compute the Spherical Power-law Potential (SPP) Model.

Given by:

\[\psi(r) = \frac{2 E^2}{\eta^2} \left( \frac{r^2 + s^2}{E^2} \right)^{\frac{\eta}{2}}\]

where: \(r^2 = (x-x_{\text{center}})^2 + (y-y_{\text{center}})^2\) is squared radius from center of lens, \(s^2 = 0\) due to no softening, :math:’E’ is the characteristic scale factor related to the Einstein radius \(\theta_{E}\), given by:

\[E = \frac{\theta_E}{\left( \frac{3 - \gamma}{2} \right)^{\frac{1}{1 - \gamma}}}\]

:math:’theta_{E}` is the Einstein radius of the lens, \(\eta = -\gamma + 3\) is a parameter that depends on the power law slope \(\gamma\), \(\gamma\) is the power law slope of the mass profile.

param_names = ['theta_E', 'gamma', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'gamma': 1.5, 'theta_E': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'gamma': 2.5, 'theta_E': 100}
function(x, y, theta_E, gamma, center_x=0, center_y=0)[source]
Parameters:
  • x (array of size (n)) – set of x-coordinates

  • y (array of size (n)) – set of y-coordinates

  • theta_E (float) – Einstein radius of lens

  • gamma (<2 float) – power law slope of mass profile

  • center_x (float) – x-coordinate of the lens center

  • center_y (float) – y-coordinate of the lens center

Returns:

function value

Raises:

AttributeError, KeyError

derivatives(x, y, theta_E, gamma, center_x=0.0, center_y=0.0)[source]
Parameters:
  • x – x-coordinate position

  • y – y-coordinate position

  • theta_E – Einstein radius of lens

  • gamma – power law slope of mass profile

  • center_x – x-coordinate of the lens center

  • center_y – y-coordinate of the lens center

Returns:

f_x, f_y

hessian(x, y, theta_E, gamma, center_x=0.0, center_y=0.0)[source]
Parameters:
  • x – x-coordinate position

  • y – y-coordinate position

  • theta_E – Einstein radius of lens

  • gamma – power law slope of mass profile

  • center_x – x-coordinate of the lens center

  • center_y – y-coordinate of the lens center

Returns:

f_xx, f_xy, f_yx, f_yy

static rho2theta(rho0, gamma)[source]

Converts 3D density into 2D projected density parameter.

Parameters:
  • rho0 – 3D density parameter

  • gamma – power law slope of mass profile

Returns:

2D projected density parameter (theta_E)

static theta2rho(theta_E, gamma)[source]

Converts projected density parameter (in units of deflection) into 3d density parameter.

Parameters:
  • theta_E – 2D projected density parameter

  • gamma – power law slope of mass profile

Returns:

3D density parameter (rho0)

static mass_3d(r, rho0, gamma)[source]

Calculates the mass enclosed in a 3D sphere of radius r.

Parameters:
  • r – radius of the sphere

  • rho0 – 3D density parameter

  • gamma – power law slope of mass profile

Returns:

mass enclosed in the sphere

mass_3d_lens(r, theta_E, gamma)[source]

Calculates the mass enclosed in a 3D sphere of radius r using lens model parameters.

Parameters:
  • r – radius of the sphere

  • theta_E – 2D projected density parameter

  • gamma – power law slope of mass profile

Returns:

mass enclosed in the sphere

mass_2d(r, rho0, gamma)[source]

Calculates the mass enclosed in a projected circle of radius r.

Parameters:
  • r – radius of the projected circle

  • rho0 – 3D density parameter

  • gamma – power law slope of mass profile

Returns:

mass enclosed in the projected circle

mass_2d_lens(r, theta_E, gamma)[source]

Calculates the mass enclosed in a projected circle of radius r using lens model parameters.

Parameters:
  • r – radius of the projected circle

  • theta_E – 2D projected density parameter

  • gamma – power law slope of mass profile

Returns:

mass enclosed in the projected circle

grav_pot(x, y, rho0, gamma, center_x=0, center_y=0)[source]

Gravitational potential (modulo 4 pi G and rho0 in appropriate units)

Parameters:
  • x – x-coordinate position

  • y – y-coordinate position

  • rho0 – 3D density parameter

  • gamma – power law slope of mass profile

  • center_x – x-coordinate of the lens center

  • center_y – y-coordinate of the lens center

Returns:

gravitational potential

static density(r, rho0, gamma)[source]

Calculates the 3D density.

Parameters:
  • r – radius

  • rho0 – 3D density parameter

  • gamma – power law slope of mass profile

Returns:

3D density

density_lens(r, theta_E, gamma)[source]

Calculates the 3D density using lens model parameters.

The integral is projected in units of angles (i.e. arc seconds) results in the convergence quantity.

Parameters:
  • r – radius

  • theta_E – 2D projected density parameter

  • gamma – power law slope of mass profile

Returns:

3D density

static density_2d(x, y, rho0, gamma, center_x=0, center_y=0)[source]

Calculates the 2D projected density.

Parameters:
  • x – x-coordinate position

  • y – y-coordinate position

  • rho0 – 3D density parameter

  • gamma – power law slope of mass profile

  • center_x – x-coordinate of the center of the profile

  • center_y – y-coordinate of the center of the profile

Returns:

2D projected density

lenstronomy.LensModel.Profiles.synthesis module

class SynthesisProfile(target_lens_model, component_lens_model, kwargs_list, lin_fit_hyperparams)[source]

Bases: LensProfileBase

A general class which describes a linear sum of many simple profiles to approximate a target profile.

Example: Mimic an NFW profile with many CSE profiles. In this case, you could use LensModel([‘SYNTHESIS’], profile_kwargs_list=[kwargs_synthesis]) with kwargs_synthesis={‘target_lens_model’: ‘NFW’, ‘component_lens_model’: ‘CSE’, ‘kwargs_list’: kwargs_list, ‘lin_fit_hyperparams’:{‘lower_log_bound’:-6, ‘upper_log_bound’:3, ‘num_r_evals’:100, ‘sigma’:0.01} (default values) } where kwargs_list would be a list of input CSE kwargs (where the amplitude will be re-adjusted).

profile_name = 'SYNTHESIS'
__init__(target_lens_model, component_lens_model, kwargs_list, lin_fit_hyperparams)[source]
Parameters:
  • target_lens_model – name of target profile

  • component_lens_model – name of component profile

  • kwargs_list – list of kwargs of component profile, length of list corresponds to number of components used to fit. The normalization (must be nonzero) will be effectively overridden by the linear weights

  • lin_fit_hyperparams – kwargs indicating range of fit, number of points to evaluate fit, etc.

linear_weight_mle_fit(kwargs_target, kwargs_list)[source]
set_static(linear_weights)[source]

Sets weights to be static self values. Useful to call e.g. function many times with the same kwargs. If kwargs_target or kwargs_list change, need to rerun linear fit by using set_dynamic.

Parameters:

linear_weights – output of LinearWeightMLEFit

Returns:

self weights set

set_dynamic()[source]
Returns:

no return, deletes pre-computed variables for certain lens models

circular_centered_kwargs(kwargs)[source]
Parameters:

kwargs – kwargs to remove center and ellipticity for linear fit. These are re-added when functions are called

set_limits(kwargs_list, lin_fit_hyperparams)[source]
Parameters:
  • kwargs_list – list of kwargs of component profile

  • lin_fit_hyperparams – kwargs indicating range of fit, number of points to evaluate fit, etc. ‘lower_log_bound’: log10 innermost radius of fit ‘upper_log_bound’: log10 outermost radius of fit ‘num_r_evals’: number of locations to evaluate fit to minimize chi2, must be larger than the number of components ‘sigma’: used to evaluate chi2. default is 1%

function(x, y, **kwargs_target)[source]

Returns lensing potential.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds) :kwargs_target: kwargs of target profile to be approximated

derivatives(x, y, **kwargs_target)[source]

Returns df/dx and df/dy of the function which are the deflection angles.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds) :kwargs_target: kwargs of target profile to be approximated

hessian(x, y, **kwargs_target)[source]

Returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds) :kwargs_target: kwargs of target profile to be approximated

check_num_evals()[source]

Confirm that the number of evaluations is more than the number of components.

Still not guaranteed to prevent overfitting

lenstronomy.LensModel.Profiles.tnfw module

class TNFW[source]

Bases: LensProfileBase

This class contains functions concerning the truncated NFW profile with a truncation function (r_trunc^2)*(r^2+r_trunc^2)

density equation is:

\[\rho(r) = \frac{r_\text{trunc}^2}{r^2+r_\text{trunc}^2}\frac{\rho_0(\alpha_{R_s})}{r/R_s(1+r/R_s)^2}\]

relation are: R_200 = c * Rs

profile_name = 'TNFW'
param_names = ['Rs', 'alpha_Rs', 'r_trunc', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'r_trunc': 0}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'r_trunc': 100}
__init__()[source]
function(x, y, Rs, alpha_Rs, r_trunc, center_x=0, center_y=0)[source]
Parameters:
  • x – angular position

  • y – angular position

  • Rs – angular turn over point

  • alpha_Rs – deflection at Rs

  • r_trunc – truncation radius

  • center_x – center of halo

  • center_y – center of halo

Returns:

lensing potential

F(x)[source]

Classic NFW function in terms of arctanh and arctan.

Parameters:

x – r/Rs

Returns:

derivatives(x, y, Rs, alpha_Rs, r_trunc, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function (integral of TNFW), which are the deflection angles.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • r_trunc – truncation radius (angular units)

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

deflection angle in x, deflection angle in y

hessian(x, y, Rs, alpha_Rs, r_trunc, center_x=0, center_y=0)[source]

Returns d^2f/dx^2, d^2f/dxdy, d^2f/dydx, d^2f/dy^2 of the TNFW potential f.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • r_trunc – truncation radius (angular units)

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy

static density(r, Rs, rho0, r_trunc)[source]

Three dimensional truncated NFW profile.

Parameters:
  • r (float/numpy array) – radius of interest

  • Rs (float > 0) – scale radius

  • r_trunc (float > 0) – truncation radius (angular units)

Returns:

rho(r) density

density_2d(x, y, Rs, rho0, r_trunc, center_x=0, center_y=0)[source]

Projected two dimensional NFW profile (kappa*Sigma_crit)

Parameters:
  • R (float/numpy array) – projected radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

  • r_trunc (float > 0) – truncation radius (angular units)

Returns:

Epsilon(R) projected density at radius R

mass_3d(r, Rs, rho0, r_trunc)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – 3d radius

  • Rs – scale radius

  • rho0 – density normalization (characteristic density)

  • r_trunc – truncation radius (angular units)

Returns:

M(<r)

tnfw_potential(R, Rs, rho0, r_trunc)[source]

Lensing potential of truncated NFW profile.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

  • r_trunc (float > 0) – truncation radius (angular units)

Returns:

lensing potential

tnfw_alpha(R, Rs, rho0, r_trunc, ax_x, ax_y)[source]

Deflection angle of TNFW profile along the projection to coordinate axis.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

  • r_trunc (float > 0) – truncation radius (angular units)

  • axis (same as R) – projection to either x- or y-axis

Returns:

tnfw_gamma(R, Rs, rho0, r_trunc, ax_x, ax_y)[source]

Shear gamma of TNFW profile (times Sigma_crit) along the projection to coordinate ‘axis’.

Parameters:
  • R (float/numpy array) – radius of interest

  • Rs (float) – scale radius

  • rho0 (float) – density normalization (characteristic density)

  • r_trunc (float > 0) – truncation radius (angular units)

  • axis (same as R) – projection to either x- or y-axis

Returns:

mass_2d(R, Rs, rho0, r_trunc)[source]

Analytic solution of the projection integral (convergence)

Parameters:
  • R – projected radius

  • Rs – scale radius

  • rho0 – density normalization (characteristic density)

  • r_trunc – truncation radius (angular units)

Returns:

mass enclosed 2d projected cylinder

static alpha2rho0(alpha_Rs, Rs)[source]

Convert angle at Rs into rho0; neglects the truncation.

Parameters:
  • alpha_Rs – deflection angle at RS

  • Rs – scale radius

Returns:

density normalization (characteristic density)

static rho02alpha(rho0, Rs)[source]

Convert rho0 to angle at Rs; neglects the truncation.

Parameters:
  • rho0 – density normalization (characteristic density)

  • Rs – scale radius

Returns:

deflection angle at RS

lenstronomy.LensModel.Profiles.tnfw_ellipse_potential module

class TNFWELLIPSEPotential[source]

Bases: LensProfileBase

This class contains functions concerning the truncated NFW profile with an ellipticity defined in the potential parameterization of alpha_Rs, Rs and r_trunc is the same as for the spherical NFW profile.

from Glose & Kneib: https://cds.cern.ch/record/529584/files/0112138.pdf

relation are: R_200 = c * Rs

profile_name = 'TNFW_ELLIPSE_POTENTIAL'
param_names = ['Rs', 'alpha_Rs', 'r_trunc', 'e1', 'e2', 'center_x', 'center_y']
lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'r_trunc': 0}
upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'r_trunc': 100}
__init__()[source]
function(x, y, Rs, alpha_Rs, r_trunc, e1, e2, center_x=0, center_y=0)[source]

Returns elliptically distorted NFW lensing potential.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • r_trunc – truncation radius

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

lensing potential

derivatives(x, y, Rs, alpha_Rs, r_trunc, e1, e2, center_x=0, center_y=0)[source]

Returns df/dx and df/dy of the function, calculated as an elliptically distorted deflection angle of the spherical NFW profile.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • r_trunc – truncation radius

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

deflection in x-direction, deflection in y-direction

hessian(x, y, Rs, alpha_Rs, r_trunc, e1, e2, center_x=0, center_y=0)[source]

Returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy the calculation is performed as a numerical differential from the deflection field. Analytical relations are possible.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • Rs – turn over point in the slope of the NFW profile in angular unit

  • alpha_Rs – deflection (angular units) at projected Rs

  • r_trunc – truncation radius

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

mass_3d_lens(r, Rs, alpha_Rs, r_trunc, e1=1, e2=0)[source]
Parameters:
  • r – radius (in angular units)

  • Rs – turn-over radius of NFW profile

  • alpha_Rs – deflection at Rs

  • r_trunc – truncation radius

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

Returns:

density_lens(r, Rs, alpha_Rs, r_trunc, e1=1, e2=0)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – 3d radios

  • Rs – turn-over radius of NFW profile

  • alpha_Rs – deflection at Rs

  • r_trunc – truncation radius

  • e1 – eccentricity component in x-direction

  • e2 – eccentricity component in y-direction

Returns:

density rho(r)

lenstronomy.LensModel.Profiles.uldm module

class Uldm(*args, **kwargs)[source]

Bases: LensProfileBase

This class contains functions concerning the ULDM soliton density profile, whose good approximation is (see for example https://arxiv.org/pdf/1406.6586.pdf )

\[\rho = \rho_0 (1 + a(\theta/\theta_c)^2)^{-\beta}\]

where \(\theta_c\) is the core radius, corresponding to the radius where the density drops by half its central value, :math: beta is the slope (called just slope in the parameters of this model), :math: rho_0 = kappa_0 Sigma_c/D_lens, and :math: a is a parameter, dependent on :math: beta, chosen such that :math: theta_c indeed corresponds to the radius where the density drops by half (simple math gives :math: a = 0.5^{-1/beta} - 1 ). For an ULDM soliton profile without contributions to background potential, it turns out that :math: beta = 8, a = 0.091. We allow :math: beta to be different from 8 to model solitons which feel the influence of background potential (see 2105.10873) The profile has, as parameters:

  • kappa_0: central convergence

  • theta_c: core radius (in arcseconds)

  • slope: exponent entering the profile, default value is 8

param_names = ['kappa_0', 'theta_c', 'slope', 'center_x', 'center_y']
lower_limit_default = {'center_x': -100, 'center_y': -100, 'kappa_0': 0, 'slope': 3.5, 'theta_c': 0}
upper_limit_default = {'center_x': 100, 'center_y': 100, 'kappa_0': 1.0, 'slope': 10, 'theta_c': 100}
static rhotilde(kappa_0, theta_c, slope=8)[source]

Computes the central density in angular units.

Parameters:
  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

Returns:

central density in 1/arcsec

function(x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8)[source]
Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

lensing potential (in arcsec^2)

static alpha_radial(r, kappa_0, theta_c, slope=8)[source]

Returns the radial part of the deflection angle.

Parameters:
  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

  • r – radius where the deflection angle is computed

Returns:

radial deflection angle

derivatives(x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8)[source]

Returns df/dx and df/dy of the function (lensing potential), which are the deflection angles.

Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

deflection angle in x, deflection angle in y

hessian(x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8)[source]
Parameters:
  • x – angular position (normally in units of arc seconds)

  • y – angular position (normally in units of arc seconds)

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

  • center_x – center of halo (in angular units)

  • center_y – center of halo (in angular units)

Returns:

Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

density(R, kappa_0, theta_c, slope=8)[source]

Three dimensional ULDM profile in angular units (rho0_physical = rho0_angular Sigma_crit / D_lens)

Parameters:
  • R – radius of interest

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

Returns:

rho(R) density in angular units

density_lens(r, kappa_0, theta_c, slope=8)[source]

Computes the density at 3d radius r given lens model parameterization. The integral in the LOS projection of this quantity results in the convergence quantity.

Parameters:
  • r – 3d radius

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

Returns:

density rho(r)

static kappa_r(R, kappa_0, theta_c, slope=8)[source]

Convergence of the cored density profile. This routine is also for testing.

Parameters:
  • R – radius (angular scale)

  • kappa_0 – convergence in the core

  • theta_c – core radius

  • slope – exponent entering the profile

Returns:

convergence at r

density_2d(x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8)[source]

Projected two dimensional ULDM profile (convergence * Sigma_crit), but given our units convention for rho0, it is basically the convergence.

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

Returns:

Epsilon(R) projected density at radius R

mass_3d(R, kappa_0, theta_c, slope=8)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • R – radius in arcseconds

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

Returns:

mass of soliton in angular units

mass_3d_lens(r, kappa_0, theta_c, slope=8)[source]

Mass enclosed a 3d sphere or radius r.

Parameters:
  • r – radius over which the mass is computed

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

Returns:

mass enclosed in 3D ball

mass_2d(R, kappa_0, theta_c, slope=8)[source]

Mass enclosed a 2d sphere or radius r.

Parameters:
  • R – radius over which the mass is computed

  • kappa_0 – central convergence of profile

  • theta_c – core radius (in arcsec)

  • slope – exponent entering the profile

Returns:

mass enclosed in 2d sphere

Module contents