lenstronomy.LensModel.QuadOptimizer package¶
Submodules¶
lenstronomy.LensModel.QuadOptimizer.multi_plane_fast module¶
- class lenstronomy.LensModel.QuadOptimizer.multi_plane_fast.MultiplaneFast(x_image, y_image, z_lens, z_source, lens_model_list, redshift_list, astropy_instance, param_class, foreground_rays, tol_source=1e-05, numerical_alpha_class=None)[source]¶
Bases:
object
This class accelerates ray tracing computations in multi plane lensing for quadruple image lenses by only computing the deflection from objects in front of the main deflector at z_lens one time. The first ray tracing computation through the foreground is saved and re-used, but it will always have the same shape as the initial x_image, y_image arrays.
- chi_square(args_lens, *args, **kwargs)[source]¶
- Parameters
args_lens – array of lens model parameters being optimized, computed from kwargs_lens in a specified param_class, see documentation in QuadOptimizer.param_manager
- Returns
total chi^2 penalty (source chi^2 + param chi^2), where param chi^2 is computed by the specified param_class
- logL(args_lens, *args, **kwargs)[source]¶
- Parameters
args_lens – array of lens model parameters being optimized, computed from kwargs_lens in a specified param_class, see documentation in QuadOptimizer.param_manager
- Returns
the log likelihood corresponding to the given chi^2
- ray_shooting_fast(args_lens)[source]¶
Performs a ray tracing computation through observed coordinates on the sky (self._x_image, self._y_image) to the source plane, returning the final coordinates of each ray on the source plane
- Parameters
args_lens – An array of parameters being optimized. The array is computed from a set of key word arguments by an instance of ParamClass (see documentation in QuadOptimizer.param_manager)
- Returns
the xy coordinate of each ray traced back to the source plane
- source_plane_chi_square(args_lens, *args, **kwargs)[source]¶
- Parameters
args_lens – array of lens model parameters being optimized, computed from kwargs_lens in a specified param_class, see documentation in QuadOptimizer.param_manager
- Returns
chi2 penalty for the source position (all images must map to the same source coordinate)
lenstronomy.LensModel.QuadOptimizer.optimizer module¶
- class lenstronomy.LensModel.QuadOptimizer.optimizer.Optimizer(x_image, y_image, lens_model_list, redshift_list, z_lens, z_source, parameter_class, astropy_instance=None, numerical_alpha_class=None, particle_swarm=True, re_optimize=False, re_optimize_scale=1.0, pso_convergence_mean=50000, foreground_rays=None, tol_source=1e-05, tol_simplex_func=0.001, simplex_n_iterations=400)[source]¶
Bases:
object
class which executes the optimization routines. Currently implemented as a particle swarm optimization followed by a downhill simplex routine.
Particle swarm optimizer is modified from the CosmoHammer particle swarm routine with different convergence criteria implemented.
- optimize(n_particles=50, n_iterations=250, verbose=False, threadCount=1)[source]¶
- Parameters
n_particles – number of PSO particles, will be ignored if self._particle_swarm is False
n_iterations – number of PSO iterations, will be ignored if self._particle_swarm is False
verbose – whether to print stuff
pool – instance of Pool with a map method for multiprocessing
- Returns
keyword arguments that map (x_image, y_image) to the same source coordinate (source_x, source_y)
lenstronomy.LensModel.QuadOptimizer.param_manager module¶
- class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFixedShear(kwargs_lens_init, shear_strength)[source]¶
Bases:
lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawParamManager
This class implements a fit of EPL + external shear with every parameter except the power law slope AND the shear strength allowed to vary. The user should specify shear_strengh in the args_param_class keyword when creating the Optimizer class
- class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFixedShearMultipole(kwargs_lens_init, shear_strength)[source]¶
Bases:
lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFixedShear
This class implements a fit of EPL + external shear + a multipole term with every parameter except the power law slope, shear strength, and multipole moment free to vary. The mass centroid and orientation of the multipole term are fixed to that of the EPL profile
- args_to_kwargs(args)[source]¶
- Parameters
args – array of lens model parameters
- Returns
dictionary of lens model parameters with fixed shear = shear_strength
- property to_vary_index¶
The number of lens models being varied in this routine. This is set to 3 because the first three lens models are EPL, SHEAR, and MULTIPOLE, and their parameters are being optimized.
The kwargs_list is split at to to_vary_index with indicies < to_vary_index accessed in this class, and lens models with indicies > to_vary_index kept fixed.
Note that this requires a specific ordering of lens_model_list :return:
- class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFreeShear(kwargs_lens_init)[source]¶
Bases:
lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawParamManager
This class implements a fit of EPL + external shear with every parameter except the power law slope allowed to vary
- class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFreeShearMultipole(kwargs_lens_init)[source]¶
Bases:
lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawParamManager
This class implements a fit of EPL + external shear + a multipole term with every parameter except the power law slope and multipole moment free to vary. The mass centroid and orientation of the multipole term are fixed to that of the EPL profile
- property to_vary_index¶
The number of lens models being varied in this routine. This is set to 3 because the first three lens models are EPL, SHEAR, and MULTIPOLE, and their parameters are being optimized.
The kwargs_list is split at to to_vary_index with indicies < to_vary_index accessed in this class, and lens models with indicies > to_vary_index kept fixed.
Note that this requires a specific ordering of lens_model_list :return:
- class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawParamManager(kwargs_lens_init)[source]¶
Bases:
object
Base class for handling the translation between key word arguments and parameter arrays for EPL mass models. This class is intended for use in modeling galaxy-scale lenses
- bounds(re_optimize, scale=1.0)[source]¶
Sets the low/high parameter bounds for the particle swarm optimization
NOTE: The low/high values specified here are intended for galaxy-scale lenses. If you want to use this for a different size system you should create a new ParamClass with different settings
- Parameters
re_optimize – keep a narrow window around each parameter
scale – scales the size of the uncertainty window
- Returns
- static kwargs_to_args(kwargs)[source]¶
- Parameters
kwargs – keyword arguments corresponding to the lens model parameters being optimized
- Returns
array of lens model parameters
- property to_vary_index¶
The number of lens models being varied in this routine. This is set to 2 because the first three lens models are EPL and SHEAR, and their parameters are being optimized.
The kwargs_list is split at to to_vary_index with indicies < to_vary_index accessed in this class, and lens models with indicies > to_vary_index kept fixed.
Note that this requires a specific ordering of lens_model_list :return: