lenstronomy.LensModel.Solver package¶
Submodules¶
lenstronomy.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 lenstronomy.LensModel.lens_model
-
candidate_solutions
(sourcePos_x, sourcePos_y, kwargs_lens, min_distance=0.1, search_window=10, verbose=False, 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
-
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)[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
-
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 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)[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), ‘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)[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
- 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)[source]¶ 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)[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
-
lenstronomy.LensModel.Solver.solver module¶
-
class
Solver
(solver_type, lensModel, num_images)[source]¶ Bases:
object
Joint solve class to manage with type of solver to be executed and checks whether the requirements are fulfilled.
-
__init__
(solver_type, lensModel, num_images)[source]¶ Parameters: - solver_type – string, option for specific solver type see detailed instruction of the Solver4Point and Solver2Point classes
- lensModel – instance of a LensModel() class
- num_images – int, number of images to be solved for
-
add_fixed_lens
(kwargs_fixed_lens, kwargs_lens_init)[source]¶ 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)[source]¶ 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)[source]¶ Parameters: - x_pos – x-position constraints on images
- y_pos – y-position constraints on images
- kwargs_list – lens model keyword argument list
- 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, accuracy
-
lenstronomy.LensModel.Solver.solver2point module¶
-
class
Solver2Point
(lensModel, solver_type='CENTER', decoupling=True)[source]¶ 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
-
__init__
(lensModel, solver_type='CENTER', decoupling=True)[source]¶ Parameters: - lensModel – instance of LensModel class
- solver_type – string
- decoupling – bool
-
add_fixed_lens
(kwargs_fixed_lens_list, kwargs_lens_init)[source]¶ Parameters: - kwargs_fixed_lens_list –
- kwargs_lens_init –
Returns:
-
constraint_lensmodel
(x_pos, y_pos, kwargs_list, xtol=1.49012e-12)[source]¶ 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
-
lenstronomy.LensModel.Solver.solver4point module¶
-
class
Solver4Point
(lensModel, solver_type='PROFILE')[source]¶ Bases:
object
Class to make the constraints for the solver.
-
__init__
(lensModel, solver_type='PROFILE')[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
add_fixed_lens
(kwargs_fixed_lens_list, kwargs_lens_init)[source]¶ Parameters: - kwargs_fixed_lens_list –
- kwargs_lens_init –
Returns:
-
constraint_lensmodel
(x_pos, y_pos, kwargs_list, xtol=1.49012e-12)[source]¶ Parameters: - x_pos – list of image positions (x-axis)
- y_pos – list of image position (y-axis)
- xtol – numerical tolerance level
- kwargs_list – list of lens model kwargs
Returns: updated lens model that satisfies the lens equation for the point sources, accuracy
-