lenstronomy.LensModel.Solver package — lenstronomy 1.9.1 documentation

# lenstronomy.LensModel.Solver package

## Submodules

## lenstronomy.LensModel.Solver.lens_equation_solver module

class lenstronomy.LensModel.Solver.lens_equation_solver.LensEquationSolver(lensModel)

  Bases: `object`

  class to solve for image positions given lens model and source position

  candidate_solutions(sourcePos_x, sourcePos_y, kwargs_lens, min_distance=0.1, search_window=10, verbose=False, x_center=0, y_center=0)

    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

  findBrightImage(sourcePos_x, sourcePos_y, kwargs_lens, numImages=4, min_distance=0.01, search_window=5, precision_limit=1e-10, num_iter_max=10, arrival_time_sort=True, x_center=0, y_center=0, num_random=0, non_linear=False, magnification_limit=None, initial_guess_cut=True, verbose=False)
    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

  image_position_analytical(x, y, kwargs_lens, arrival_time_sort=True, magnification_limit=None, **kwargs_solver)
    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

      - Nmeas – resolution with which to sample the angular grid, higher means more reliable lens equation solving. For solving many positions at once, you may want to set this higher.

      - Nmeas_extra – resolution with which to additionally sample the angular grid at the low-shear end, higher means more reliable lens equation solving. For solving many positions at once, you may want to set this higher.

    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 a proper magnification_limit is more important. To get similar behaviour, a limit of 1e-1 is acceptable

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

    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), ‘analytical’ or ‘stochastic’.

      - 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, non_linear=False, magnification_limit=None)

    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

      - 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

    Raises

      AttributeError, KeyError

  image_position_stochastic(source_x, source_y, kwargs_lens, search_window=10, precision_limit=1e-10, arrival_time_sort=True, x_center=0, y_center=0, num_random=1000)

    Solves the lens equation stochastic with the scipy minimization routine on the quadratic distance between the backwards ray-shooted proposed image position and the source position. Credits to Giulia Pagano

    Parameters

      - source_x – source position

      - source_y – source position

      - kwargs_lens – lens model list of keyword arguments

      - search_window – angular size of search window

      - precision_limit – limit required on the precision in the source plane

      - arrival_time_sort – bool, if True sorts according to arrival time

      - x_center – center of search window

      - y_center – center of search window

      - num_random – number of random starting points of the non-linear solver in the search window

    Returns

      x_image, y_image

  sort_arrival_times(x_mins, y_mins, kwargs_lens)

    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

## lenstronomy.LensModel.Solver.solver module

class lenstronomy.LensModel.Solver.solver.Solver(solver_type, lensModel, num_images)

  Bases: `object`

  joint solve class to manage with type of solver to be executed and checks whether the requirements are fulfilled.

  add_fixed_lens(kwargs_fixed_lens, kwargs_lens_init)

    returns kwargs that are kept fixed during run, depending on options

    Parameters

      - kwargs_fixed_lens – keyword argument list of fixed parameters (indicated by fitting argument of the user)

      - kwargs_lens_init – Initial values of the full lens model keyword arguments

    Returns

      updated kwargs_fixed_lens, added fixed parameters being added (and replaced later on) by the non-linear solver.

  check_solver(image_x, image_y, kwargs_lens)

    returns the precision of the solver to match the image position

    Parameters

      - kwargs_lens – full lens model (including solved parameters)

      - image_x – point source in image

      - image_y – point source in image

    Returns

      precision of Euclidean distances between the different rays arriving at the image positions

  constraint_lensmodel(x_pos, y_pos, kwargs_list, xtol=1.49012e-12)
    Parameters

      - x_pos –

      - y_pos –

      - kwargs_list –

    Returns

  update_solver(kwargs_lens, x_pos, y_pos)
    Parameters

      - kwargs_lens –

      - x_pos –

      - y_pos –

    Returns

## lenstronomy.LensModel.Solver.solver2point module

class lenstronomy.LensModel.Solver.solver2point.Solver2Point(lensModel, solver_type='CENTER', decoupling=True)

  Bases: `object`

  class to solve a constraint lens model with two point source positions

  options are: ‘CENTER’: solves for ‘center_x’, ‘center_y’ parameters of the first lens model ‘ELLIPSE’: solves for ‘e1’, ‘e2’ of the first lens (can also be shear) ‘SHAPELETS’: solves for shapelet coefficients c01, c10 ‘THETA_E_PHI: solves for Einstein radius of first lens model and shear angle of second model

  add_fixed_lens(kwargs_fixed_lens_list, kwargs_lens_init)
    Parameters

      - kwargs_fixed_lens_list –

      - kwargs_lens_init –

    Returns

  constraint_lensmodel(x_pos, y_pos, kwargs_list, xtol=1.49012e-12)

    constrains lens model parameters by demanding the solution to match the image positions to a single source position

    Parameters

      - x_pos – list of image positions (x-axis)

      - y_pos – list of image position (y-axis)

      - kwargs_list – list of lens model kwargs

      - xtol – tolerance level of solution when to stop the non-linear solver

    Returns

      updated lens model that satisfies the lens equation for the point sources

  solve(x_pos, y_pos, init, kwargs_list, a, xtol=1.49012e-12)

## lenstronomy.LensModel.Solver.solver4point module

class lenstronomy.LensModel.Solver.solver4point.Solver4Point(lensModel, solver_type='PROFILE')

  Bases: `object`

  class to make the constraints for the solver

  add_fixed_lens(kwargs_fixed_lens_list, kwargs_lens_init)
    Parameters

      - kwargs_fixed_lens_list –

      - kwargs_lens_init –

    Returns

  constraint_lensmodel(x_pos, y_pos, kwargs_list, xtol=1.49012e-12)
    Parameters

      - x_pos – list of image positions (x-axis)

      - y_pos – list of image position (y-axis)

      - init – initial parameters

      - kwargs_list – list of lens model kwargs

    Returns

      updated lens model that satisfies the lens equation for the point sources

  solve(x_pos, y_pos, init, kwargs_list, a, xtol=1.49012e-10)

## Module contents