lenstronomy.LensModel.Util package

Submodules

lenstronomy.LensModel.Util.decouple_multi_plane_util module

setup_lens_model(lens_model, kwargs_lens, index_lens_split, use_jax=False)[source]

A method to split a lens model into a piece to vary or optimize, and fixed lens model whose deflection field will be interpolated. Note that this method currently only supports splitting the lens system at one particular redshift.

Parameters:
  • lens_model – an instance of LensModel

  • kwargs_lens – keyword arguments for the lens model

  • index_lens_split – a list of indexes corresponding to the deflectors that will be left free to vary; every other deflector is assumed to remain static be absorbed into a net deflection field

  • use_jax – bool or list of bools to specify which profiles use JAXstronomy

Returns:

an instance of LensModel corresponding to the fixed (static) deflectors, an instance of LensModel corresponding to free deflectors, keyword arguments for each lens model, source redshift, the redshift where the splitting occurs, and the background cosmology

setup_grids(grid_size, grid_resolution, coordinate_center_x=0.0, coordinate_center_y=0.0)[source]

Creates grids for use in the decoupled multiplane model.

Parameters:
  • grid_size – The size (diameter of inscribed circle) of the grid

  • grid_resolution – pixel scale (units arcsec / pixel)

  • coordinate_center_x – center of the coordinate grid in arcsec

  • coordinate_center_y – center of the coordinate grid in arcsec

Returns:

1d arrays of coordinates, tuple of 1d arrays of points defining the grid, number of pixels per axis

coordinates_and_deflections(lens_model_fixed, lens_model_free, kwargs_lens_fixed, kwargs_lens_free, x_coordinate_arcsec, y_coordinate_arcsec, z_split, z_source, cosmo_bkg)[source]

Computes the lensed coordinates and deflection angles for the static lens model.

Parameters:
  • lens_model_fixed – an instance of LensModel that is static

  • lens_model_free – an instance of LensModel that is free to vary. NOTE: this should be a good guess of the “correct” lens model, as it will be used to estimate the coupling between the main deflector and deflectors between the main lens plane and the source plane

  • kwargs_lens_fixed – keyword arguments for the fixed lens model

  • kwargs_lens_free – keyword arguments for the free lens model

  • x_coordinate_arcsec – coordinates on which to perform the interpolation; should be either a single coordinate, an array of coordiantes, or a list (or array) or coordinates corresponding to multiple images (see documentation in class_setup)

  • y_coordinate_arcsec – coordinates on which to perform the interpolation; should be either a single coordinate, an array of coordiantes, or a list (or array) or coordinates corresponding to multiple images (see documentation in class_setup)

  • z_split – the redshift where the free lens model lives

  • z_source – the source redshift

  • cosmo_bkg – background cosmology

Returns:

comoving coordinates of light rays at z_split, foreground deflection angles, background deflections

decoupled_multiplane_class_setup(lens_model_free, x, y, alpha_x_foreground, alpha_y_foreground, alpha_beta_subx, alpha_beta_suby, z_split, coordinate_type='POINT', interp_points=None, x_image=None, y_image=None, method='linear', bounds_error=False, fill_value=None)[source]

This funciton creates the keyword arguments for a LensModel instance that is the decoupled multi-plane approxiamtion for the specified lens model.

Parameters:
  • lens_model_free – the lens model with parameters free to vary

  • x – comoving coordinate at z_split

  • y – comoving coordinate at z_split

  • alpha_x_foreground – ray angles at z_split (not including lens_model_free contribution)

  • alpha_y_foreground – ray angles at z_split (not including lens_model_free contribution)

  • alpha_beta_subx – deflection field from halos at redshift > z_split given the initial guess for the keyword arguments in lens_model_free

  • alpha_beta_suby – deflection field from halos at redshift > z_split given the initial guess for the keyword arguments in lens_model_free

  • z_split – redshift at which the lens model is decoupled from the line of sight

  • coordinate_type – specifies the type of interpolation to use. Options are POINT, GRID, or MULTIPLE_IMAGES. POINT specifies a single point at which to compute the interpolation GRID specifies the interpolation on a regular grid MULTIPLE_IMAGES does interpolation on an array using the NEAREST method.

  • lens_model_free

  • x – transverse comoving distance in x direction of the light rays at the main deflector

  • y – transverse comoving distance in y direction of the light rays at the main deflector

  • alpha_x_foreground – deflection angles from halos at redshift z<=z_split

  • alpha_y_foreground – deflection angles from halos at redshift z<=z_split

  • alpha_beta_subx – deflection angles from halos at redshift z > z_lens

  • alpha_beta_suby – deflection angles from halos at redshift z > z_lens

  • z_split – the redshift where foreground and background halos are split

  • coordinate_type – a string specifying the type of coordinate of x. Options are GRID, POINT, and MULTIPLE_IMAGES

  • interp_points – optional keyword argument passed to GRID method that specifies the interpolation grid

  • x_image – optional keyword argument passed to multiple images argument that specifies the image coordinates

  • y_image – optional keyword argument passed to multiple images argument that specifies the image coordinates

  • method – the interpolation method used by RegularGridInterpolator if coordinate_type==’GRID’

  • bounds_error – passed to RegularGridInterpolater, see documentation there

  • fill_value – passed to RegularGridInterpolator, see documentation there

Returns:

keyword arguments that can be passed into a LensModel class to create a decoupled-multiplane lens model

setup_raytracing_lensmodels(x_image, y_image, lens_model, kwargs_lens, index_lens_split, grid_size, grid_resolution)[source]

This function sets up the lens model used for high-resolution ray tracing with the decoupled multi-plane approximation.

Parameters:
  • x_image – list of x-coordinates of lensed image

  • y_image – list of y-coordinates of lensed image

  • lens_model – an instance of LensModel

  • kwargs_lens – keyword arguments for the lens model

  • index_lens_split – list of integers specifying the lens models to be split from the line-of-sight population (see documentation in the DecoupledMultiplane class)

  • grid_size – the size of the ray-tracing grid in arcsec

  • grid_resolution – the resolution of the ray tracing grid in arcsec/pixel

Returns:

a list of DecoupledMultiPlane lens models and corresponding keyword arguments

lenstronomy.LensModel.Util.epl_util module

min_approx(x1, x2, x3, y1, y2, y3)[source]

Get the x-value of the minimum of the parabola through the points (x1,y1), …

Parameters:
  • x1 – x-coordinate point 1

  • x2 – x-coordinate point 2

  • x3 – x-coordinate point 3

  • y1 – y-coordinate point 1

  • y2 – y-coordinate point 2

  • y3 – y-coordinate point 3

Returns:

x-location of the minimum

rotmat(th)[source]

Calculates the rotation matrix :param th: angle :return: rotation matrix.

cdot(a, b)[source]

Calculates some complex dot-product that simplifies the math :param a: complex number :param b: complex number :return: dot-product.

ps(x, p)[source]

A regularized power-law that gets rid of singularities, abs(x)**p*sign(x) :param x: x :param p: p :return:

cart_to_pol(x, y)[source]

Convert from cartesian to polar :param x: x-coordinate :param y: y-coordinate :return: tuple of (r, theta)

pol_to_cart(r, th)[source]

Convert from polar to cartesian :param r: r-coordinate :param th: theta- coordinate :return: tuple of (x,y)

pol_to_ell(r, theta, q)[source]

Converts from polar to elliptical coordinates.

ell_to_pol(rell, theta, q)[source]

Converts from elliptical to polar coordinates.

geomlinspace(a, b, N)[source]

Constructs a geomspace from a to b, with a linspace prepended to it from 0 to a, with the same spacing as the geomspace would have at a.

solvequadeq(a, b, c)[source]

Solves a quadratic equation.

Care is taken for the numerics, see also https://en.wikipedia.org/wiki/Loss_of_significance :param a: a :param b: b :param c: c :return: tuple of two solutions

brentq_nojit(f, xa, xb, xtol=2e-14, rtol=np.float64(3.552713678800501e-15), maxiter=100, args=())[source]

A numba-compatible implementation of brentq (largely copied from scipy.optimize.brentq).

Unfortunately, the scipy verison is not compatible with numba, hence this reimplementation :( :param f: function to optimize :param xa: left bound :param xb: right bound :param xtol: x-coord root tolerance :param rtol: x-coord relative tolerance :param maxiter: maximum num of iterations :param args: additional arguments to pass to function in the form f(x, args) :return:

brentq_inline(f, xa, xb, xtol=2e-14, rtol=np.float64(3.552713678800501e-15), maxiter=100, args=())

A numba-compatible implementation of brentq (largely copied from scipy.optimize.brentq).

Unfortunately, the scipy verison is not compatible with numba, hence this reimplementation :( :param f: function to optimize :param xa: left bound :param xb: right bound :param xtol: x-coord root tolerance :param rtol: x-coord relative tolerance :param maxiter: maximum num of iterations :param args: additional arguments to pass to function in the form f(x, args) :return:

Module contents