jaxtronomy.LensModel.Solver package

Submodules

jaxtronomy.LensModel.Solver.lens_equation_solver module

class LensEquationSolver(lensModel)[source]

Bases: object

Class to solve for image positions given lens model and source position.

__init__(lensModel)[source]

This class must contain the following definitions (with same syntax as the standard LensModel() class: def ray_shooting() def hessian() def magnification()

Parameters:

lensModel – instance of a class according to jaxtronomy.LensModel.lens_model

image_position_from_source(sourcePos_x, sourcePos_y, kwargs_lens, solver='lenstronomy', **kwargs)[source]

Solves the lens equation, i.e. finds the image positions in the lens plane that are mapped to a given source position.

Parameters:
  • sourcePos_x – source position in units of angle

  • sourcePos_y – source position in units of angle

  • kwargs_lens – lens model parameters as keyword arguments

  • solver – which solver to use, can be ‘lenstronomy’ (default) or ‘analytical’

  • kwargs – Any additional kwargs are passed to the chosen solver, see the documentation of image_position_lenstronomy, image_position_analytical and image_position_stochastic

Returns:

(exact) angular position of (multiple) images ra_pos, dec_pos in units of angle

image_position_lenstronomy(sourcePos_x, sourcePos_y, kwargs_lens, min_distance=0.1, search_window=10, precision_limit=1e-10, num_iter_max=100, arrival_time_sort=True, initial_guess_cut=True, verbose=False, x_center=0, y_center=0, num_random=0, magnification_limit=None)[source]

Finds image position given source position and lens model. The solver first samples does a grid search in the lens plane, and the grid points that are closest to the supplied source position are fed to a specialized gradient-based root finder that finds the exact solutions. Works with all lens models.

Parameters:
  • sourcePos_x – source position in units of angle

  • sourcePos_y – source position in units of angle

  • kwargs_lens – lens model parameters as keyword arguments

  • min_distance – minimum separation to consider for two images in units of angle

  • search_window – window size to be considered by the solver. Will not find image position outside this window

  • precision_limit – required precision in the lens equation solver (in units of angle in the source plane).

  • num_iter_max – maximum iteration of lens-source mapping conducted by solver to match the required precision

  • arrival_time_sort – bool, if True, sorts image position in arrival time (first arrival photon first listed)

  • initial_guess_cut – bool, if True, cuts initial local minima selected by the grid search based on distance criteria from the source position

  • verbose – bool, if True, prints some useful information for the user

  • x_center – float, center of the window to search for point sources

  • y_center – float, center of the window to search for point sources

  • num_random – int, number of random positions within the search window to be added to be starting positions for the gradient decent solver

  • magnification_limit – None or float, if set will only return image positions that have an abs(magnification) larger than this number

Returns:

(exact) angular position of (multiple) images ra_pos, dec_pos in units of angle

Raises:

AttributeError, KeyError

candidate_solutions(sourcePos_x, sourcePos_y, kwargs_lens, min_distance, search_window=10, x_center=0, y_center=0)[source]

Finds pixels in the image plane possibly hosting a solution of the lens equation, for the given source position and lens model.

Parameters:
  • sourcePos_x – source position in units of angle

  • sourcePos_y – source position in units of angle

  • kwargs_lens – lens model parameters as keyword arguments

  • min_distance – minimum separation to consider for two images in units of angle

  • search_window – window size to be considered by the solver. Will not find image position outside this window

  • verbose – bool, if True, prints some useful information for the user

  • x_center – float, center of the window to search for point sources

  • y_center – float, center of the window to search for point sources

Returns:

(approximate) angular position of (multiple) images ra_pos, dec_pos in units of angles, related ray-traced source displacements and pixel width

Raises:

AttributeError, KeyError

image_position_analytical(x, y, kwargs_lens, arrival_time_sort=True, magnification_limit=None, **kwargs_solver)[source]

Solves the lens equation. Only supports EPL-like (plus shear) models. Uses a specialized recipe that solves a one-dimensional lens equation that is easier and more reliable to solve than the usual two-dimensional lens equation.

Parameters:
  • x – source position in units of angle, an array of positions is also supported.

  • y – source position in units of angle, an array of positions is also supported.

  • kwargs_lens – lens model parameters as keyword arguments

  • arrival_time_sort – bool, if True, sorts image position in arrival time (first arrival photon first listed)

  • magnification_limit – None or float, if set will only return image positions that have an abs(magnification) larger than this number

  • kwargs_solver – additional kwargs to be supplied to the solver. Particularly relevant are Nmeas and Nmeas_extra

Returns:

(exact) angular position of (multiple) images ra_pos, dec_pos in units of angle Note: in contrast to the other solvers, generally the (heavily demagnified) central image will also be included, so setting a proper magnification_limit is more important. To get similar behaviour, a limit of 1e-1 is acceptable

find_bright_image(sourcePos_x, sourcePos_y, kwargs_lens, numImages=4, min_distance=0.01, search_window=5, precision_limit=1e-10, num_iter_max=100, arrival_time_sort=True, x_center=0, y_center=0, num_random=0, magnification_limit=None, initial_guess_cut=False, verbose=False)[source]
Parameters:
  • sourcePos_x – source position in units of angle

  • sourcePos_y – source position in units of angle

  • kwargs_lens – lens model parameters as keyword arguments

  • min_distance – minimum separation to consider for two images in units of angle

  • search_window – window size to be considered by the solver. Will not find image position outside this window

  • precision_limit – required precision in the lens equation solver (in units of angle in the source plane).

  • num_iter_max – maximum iteration of lens-source mapping conducted by solver to match the required precision

  • arrival_time_sort – bool, if True, sorts image position in arrival time (first arrival photon first listed)

  • initial_guess_cut – bool, if True, cuts initial local minima selected by the grid search based on distance criteria from the source position

  • verbose – bool, if True, prints some useful information for the user

  • x_center – float, center of the window to search for point sources

  • y_center – float, center of the window to search for point sources

  • num_random – int, number of random positions within the search window to be added to be starting positions for the gradient decent solver

  • non_linear – bool, if True applies a non-linear solver not dependent on Hessian computation

  • magnification_limit – None or float, if set will only return image positions that have an abs(magnification) larger than this number

Returns:

(exact) angular position of (multiple) images ra_pos, dec_pos in units of angle

sort_arrival_times(x_mins, y_mins, kwargs_lens)[source]

Sort arrival times (fermat potential) of image positions in increasing order of light travel time.

Parameters:
  • x_mins – ra position of images

  • y_mins – dec position of images

  • kwargs_lens – keyword arguments of lens model

Returns:

sorted lists of x_mins and y_mins

Module contents