lenstronomy.LensModel package¶
Subpackages¶
- lenstronomy.LensModel.LightConeSim package
- lenstronomy.LensModel.LineOfSight package
- lenstronomy.LensModel.MultiPlane package
- Submodules
- lenstronomy.LensModel.MultiPlane.multi_plane module
MultiPlane
MultiPlane.__init__()
MultiPlane.update_source_redshift()
MultiPlane.multi_plane_base
MultiPlane.z_source
MultiPlane.z_source_convention
MultiPlane.z_lens_convention
MultiPlane.T_ij_start
MultiPlane.T_ij_stop
MultiPlane.observed2flat_convention()
MultiPlane.ray_shooting()
MultiPlane.ray_shooting_partial()
MultiPlane.ray_shooting_partial_comoving()
MultiPlane.transverse_distance_start_stop()
MultiPlane.arrival_time()
MultiPlane.geo_shapiro_delay()
MultiPlane.alpha()
MultiPlane.hessian()
MultiPlane.hessian_z1z2()
MultiPlane.co_moving2angle_z1_z2()
MultiPlane.co_moving2angle_source()
MultiPlane.set_static()
MultiPlane.set_dynamic()
PhysicalLocation
LensedLocation
- lenstronomy.LensModel.MultiPlane.multi_plane_base module
MultiPlaneBase
MultiPlaneBase.__init__()
MultiPlaneBase.z_source_convention
MultiPlaneBase.sorted_redshift_index
MultiPlaneBase.T_z_list
MultiPlaneBase.T_ij_list
MultiPlaneBase.ray_shooting_partial_comoving()
MultiPlaneBase.ray_shooting_partial()
MultiPlaneBase.transverse_distance_start_stop()
MultiPlaneBase.geo_shapiro_delay()
- Module contents
- lenstronomy.LensModel.Profiles package
- Submodules
- lenstronomy.LensModel.Profiles.arc_perturbations module
- lenstronomy.LensModel.Profiles.base_profile module
- lenstronomy.LensModel.Profiles.chameleon module
Chameleon
DoubleChameleon
DoubleChameleon.param_names
DoubleChameleon.lower_limit_default
DoubleChameleon.upper_limit_default
DoubleChameleon.__init__()
DoubleChameleon.function()
DoubleChameleon.derivatives()
DoubleChameleon.hessian()
DoubleChameleon.density_lens()
DoubleChameleon.mass_3d_lens()
DoubleChameleon.set_static()
DoubleChameleon.set_dynamic()
TripleChameleon
TripleChameleon.param_names
TripleChameleon.lower_limit_default
TripleChameleon.upper_limit_default
TripleChameleon.__init__()
TripleChameleon.function()
TripleChameleon.derivatives()
TripleChameleon.hessian()
TripleChameleon.density_lens()
TripleChameleon.mass_3d_lens()
TripleChameleon.set_static()
TripleChameleon.set_dynamic()
DoubleChameleonPointMass
- lenstronomy.LensModel.Profiles.cnfw module
- lenstronomy.LensModel.Profiles.cnfw_ellipse module
- lenstronomy.LensModel.Profiles.const_mag module
- lenstronomy.LensModel.Profiles.constant_shift module
- lenstronomy.LensModel.Profiles.convergence module
- lenstronomy.LensModel.Profiles.coreBurkert module
CoreBurkert
CoreBurkert.param_names
CoreBurkert.lower_limit_default
CoreBurkert.upper_limit_default
CoreBurkert.function()
CoreBurkert.derivatives()
CoreBurkert.hessian()
CoreBurkert.mass_2d()
CoreBurkert.coreBurkAlpha()
CoreBurkert.density()
CoreBurkert.density_2d()
CoreBurkert.mass_3d()
CoreBurkert.cBurkPot()
CoreBurkert.cBurkGamma()
- lenstronomy.LensModel.Profiles.cored_density module
CoredDensity
CoredDensity.param_names
CoredDensity.lower_limit_default
CoredDensity.upper_limit_default
CoredDensity.function()
CoredDensity.derivatives()
CoredDensity.hessian()
CoredDensity.alpha_r()
CoredDensity.d_alpha_dr()
CoredDensity.kappa_r()
CoredDensity.density()
CoredDensity.density_lens()
CoredDensity.density_2d()
CoredDensity.mass_2d()
CoredDensity.mass_3d()
CoredDensity.mass_3d_lens()
- lenstronomy.LensModel.Profiles.cored_density_2 module
CoredDensity2
CoredDensity2.model_name
CoredDensity2.param_names
CoredDensity2.lower_limit_default
CoredDensity2.upper_limit_default
CoredDensity2.function()
CoredDensity2.derivatives()
CoredDensity2.hessian()
CoredDensity2.alpha_r()
CoredDensity2.d_alpha_dr()
CoredDensity2.kappa_r()
CoredDensity2.density()
CoredDensity2.density_lens()
CoredDensity2.density_2d()
CoredDensity2.mass_2d()
CoredDensity2.mass_3d()
CoredDensity2.mass_3d_lens()
- lenstronomy.LensModel.Profiles.cored_density_exp module
CoredDensityExp
CoredDensityExp.param_names
CoredDensityExp.lower_limit_default
CoredDensityExp.upper_limit_default
CoredDensityExp.rhotilde()
CoredDensityExp.function()
CoredDensityExp.alpha_radial()
CoredDensityExp.derivatives()
CoredDensityExp.hessian()
CoredDensityExp.density()
CoredDensityExp.density_lens()
CoredDensityExp.kappa_r()
CoredDensityExp.density_2d()
CoredDensityExp.mass_3d()
CoredDensityExp.mass_3d_lens()
CoredDensityExp.mass_2d()
- lenstronomy.LensModel.Profiles.cored_density_mst module
- lenstronomy.LensModel.Profiles.cored_steep_ellipsoid module
- lenstronomy.LensModel.Profiles.curved_arc_const module
- lenstronomy.LensModel.Profiles.curved_arc_sis_mst module
- lenstronomy.LensModel.Profiles.curved_arc_spp module
- lenstronomy.LensModel.Profiles.curved_arc_spt module
- lenstronomy.LensModel.Profiles.curved_arc_tan_diff module
- lenstronomy.LensModel.Profiles.dipole module
- lenstronomy.LensModel.Profiles.elliptical_density_slice module
- lenstronomy.LensModel.Profiles.epl module
- lenstronomy.LensModel.Profiles.epl_numba module
- lenstronomy.LensModel.Profiles.flexion module
- lenstronomy.LensModel.Profiles.flexionfg module
- lenstronomy.LensModel.Profiles.gauss_decomposition module
GaussianEllipseKappaSet
GaussianEllipseKappaSet.param_names
GaussianEllipseKappaSet.lower_limit_default
GaussianEllipseKappaSet.upper_limit_default
GaussianEllipseKappaSet.__init__()
GaussianEllipseKappaSet.function()
GaussianEllipseKappaSet.derivatives()
GaussianEllipseKappaSet.hessian()
GaussianEllipseKappaSet.density_2d()
GaussDecompositionAbstract
GaussDecompositionAbstract.__init__()
GaussDecompositionAbstract.gauss_decompose()
GaussDecompositionAbstract.get_scale()
GaussDecompositionAbstract.get_kappa_1d()
GaussDecompositionAbstract.function()
GaussDecompositionAbstract.derivatives()
GaussDecompositionAbstract.hessian()
GaussDecompositionAbstract.density_2d()
SersicEllipseGaussDec
NFWEllipseGaussDec
GaussDecompositionAbstract3D
CTNFWGaussDec
- lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa module
GaussianEllipseKappa
GaussianEllipseKappa.param_names
GaussianEllipseKappa.lower_limit_default
GaussianEllipseKappa.upper_limit_default
GaussianEllipseKappa.__init__()
GaussianEllipseKappa.function()
GaussianEllipseKappa.derivatives()
GaussianEllipseKappa.hessian()
GaussianEllipseKappa.density_2d()
GaussianEllipseKappa.sgn()
GaussianEllipseKappa.sigma_function()
GaussianEllipseKappa.w_f_approx()
- lenstronomy.LensModel.Profiles.gaussian_ellipse_potential module
GaussianEllipsePotential
GaussianEllipsePotential.param_names
GaussianEllipsePotential.lower_limit_default
GaussianEllipsePotential.upper_limit_default
GaussianEllipsePotential.__init__()
GaussianEllipsePotential.function()
GaussianEllipsePotential.derivatives()
GaussianEllipsePotential.hessian()
GaussianEllipsePotential.density()
GaussianEllipsePotential.density_2d()
GaussianEllipsePotential.mass_2d()
GaussianEllipsePotential.mass_3d()
GaussianEllipsePotential.mass_3d_lens()
GaussianEllipsePotential.mass_2d_lens()
- lenstronomy.LensModel.Profiles.gaussian_kappa module
GaussianKappa
GaussianKappa.param_names
GaussianKappa.lower_limit_default
GaussianKappa.upper_limit_default
GaussianKappa.__init__()
GaussianKappa.function()
GaussianKappa.derivatives()
GaussianKappa.hessian()
GaussianKappa.density()
GaussianKappa.density_2d()
GaussianKappa.mass_2d()
GaussianKappa.mass_2d_lens()
GaussianKappa.alpha_abs()
GaussianKappa.d_alpha_dr()
GaussianKappa.mass_3d()
GaussianKappa.mass_3d_lens()
- lenstronomy.LensModel.Profiles.gaussian_potential module
- lenstronomy.LensModel.Profiles.general_nfw module
- lenstronomy.LensModel.Profiles.hernquist module
Hernquist
Hernquist.param_names
Hernquist.lower_limit_default
Hernquist.upper_limit_default
Hernquist.density()
Hernquist.density_lens()
Hernquist.density_2d()
Hernquist.mass_3d()
Hernquist.mass_3d_lens()
Hernquist.mass_2d()
Hernquist.mass_2d_lens()
Hernquist.mass_tot()
Hernquist.function()
Hernquist.derivatives()
Hernquist.hessian()
Hernquist.rho2sigma()
Hernquist.sigma2rho()
Hernquist.grav_pot()
- lenstronomy.LensModel.Profiles.hernquist_ellipse module
Hernquist_Ellipse
Hernquist_Ellipse.param_names
Hernquist_Ellipse.lower_limit_default
Hernquist_Ellipse.upper_limit_default
Hernquist_Ellipse.__init__()
Hernquist_Ellipse.function()
Hernquist_Ellipse.derivatives()
Hernquist_Ellipse.hessian()
Hernquist_Ellipse.density()
Hernquist_Ellipse.density_lens()
Hernquist_Ellipse.density_2d()
Hernquist_Ellipse.mass_2d_lens()
Hernquist_Ellipse.mass_2d()
Hernquist_Ellipse.mass_3d()
Hernquist_Ellipse.mass_3d_lens()
- lenstronomy.LensModel.Profiles.hernquist_ellipse_cse module
- lenstronomy.LensModel.Profiles.hessian module
- lenstronomy.LensModel.Profiles.interpol module
Interpol
Interpol.param_names
Interpol.lower_limit_default
Interpol.upper_limit_default
Interpol.__init__()
Interpol.function()
Interpol.derivatives()
Interpol.hessian()
Interpol.f_interp()
Interpol.f_x_interp()
Interpol.f_y_interp()
Interpol.f_xx_interp()
Interpol.f_xy_interp()
Interpol.f_yy_interp()
Interpol.do_interp()
InterpolScaled
- lenstronomy.LensModel.Profiles.multi_gaussian_kappa module
MultiGaussianKappa
MultiGaussianKappa.param_names
MultiGaussianKappa.lower_limit_default
MultiGaussianKappa.upper_limit_default
MultiGaussianKappa.__init__()
MultiGaussianKappa.function()
MultiGaussianKappa.derivatives()
MultiGaussianKappa.hessian()
MultiGaussianKappa.density()
MultiGaussianKappa.density_2d()
MultiGaussianKappa.mass_3d_lens()
MultiGaussianKappaEllipse
MultiGaussianKappaEllipse.param_names
MultiGaussianKappaEllipse.lower_limit_default
MultiGaussianKappaEllipse.upper_limit_default
MultiGaussianKappaEllipse.__init__()
MultiGaussianKappaEllipse.function()
MultiGaussianKappaEllipse.derivatives()
MultiGaussianKappaEllipse.hessian()
MultiGaussianKappaEllipse.density()
MultiGaussianKappaEllipse.density_2d()
MultiGaussianKappaEllipse.mass_3d_lens()
- lenstronomy.LensModel.Profiles.multipole module
- lenstronomy.LensModel.Profiles.nfw module
NFW
NFW.profile_name
NFW.param_names
NFW.lower_limit_default
NFW.upper_limit_default
NFW.__init__()
NFW.function()
NFW.derivatives()
NFW.hessian()
NFW.density()
NFW.density_lens()
NFW.density_2d()
NFW.mass_3d()
NFW.mass_3d_lens()
NFW.mass_2d()
NFW.mass_2d_lens()
NFW.nfw_potential()
NFW.nfw_alpha()
NFW.nfw_gamma()
NFW.F_()
NFW.g_()
NFW.h_()
NFW.alpha2rho0()
NFW.rho02alpha()
- lenstronomy.LensModel.Profiles.nfw_ellipse module
- lenstronomy.LensModel.Profiles.nfw_ellipse_cse module
- lenstronomy.LensModel.Profiles.nfw_mass_concentration module
- lenstronomy.LensModel.Profiles.nfw_vir_trunc module
- lenstronomy.LensModel.Profiles.nie module
- lenstronomy.LensModel.Profiles.nie_potential module
- lenstronomy.LensModel.Profiles.numerical_deflections module
- lenstronomy.LensModel.Profiles.p_jaffe module
PJaffe
PJaffe.param_names
PJaffe.lower_limit_default
PJaffe.upper_limit_default
PJaffe.__init__()
PJaffe.density()
PJaffe.density_2d()
PJaffe.mass_3d()
PJaffe.mass_3d_lens()
PJaffe.mass_2d()
PJaffe.mass_tot()
PJaffe.grav_pot()
PJaffe.function()
PJaffe.derivatives()
PJaffe.hessian()
PJaffe.rho2sigma()
PJaffe.sigma2rho()
- lenstronomy.LensModel.Profiles.p_jaffe_ellipse module
- lenstronomy.LensModel.Profiles.pemd module
- lenstronomy.LensModel.Profiles.point_mass module
- lenstronomy.LensModel.Profiles.sersic module
- lenstronomy.LensModel.Profiles.sersic_ellipse_kappa module
- lenstronomy.LensModel.Profiles.sersic_ellipse_potential module
- lenstronomy.LensModel.Profiles.sersic_utils module
- lenstronomy.LensModel.Profiles.shapelet_pot_cartesian module
- lenstronomy.LensModel.Profiles.shapelet_pot_polar module
- lenstronomy.LensModel.Profiles.shear module
- lenstronomy.LensModel.Profiles.sie module
- lenstronomy.LensModel.Profiles.sis module
- lenstronomy.LensModel.Profiles.sis_truncate module
- lenstronomy.LensModel.Profiles.spemd module
- lenstronomy.LensModel.Profiles.spep module
- lenstronomy.LensModel.Profiles.splcore module
- lenstronomy.LensModel.Profiles.spp module
- lenstronomy.LensModel.Profiles.tnfw module
TNFW
TNFW.profile_name
TNFW.param_names
TNFW.lower_limit_default
TNFW.upper_limit_default
TNFW.__init__()
TNFW.function()
TNFW.F()
TNFW.derivatives()
TNFW.hessian()
TNFW.density()
TNFW.density_2d()
TNFW.mass_3d()
TNFW.nfw_potential()
TNFW.nfw_alpha()
TNFW.nfw_gamma()
TNFW.mass_2d()
TNFW.alpha2rho0()
TNFW.rho02alpha()
- lenstronomy.LensModel.Profiles.tnfw_ellipse module
- lenstronomy.LensModel.Profiles.uldm module
- Module contents
- lenstronomy.LensModel.QuadOptimizer package
- Submodules
- lenstronomy.LensModel.QuadOptimizer.multi_plane_fast module
- lenstronomy.LensModel.QuadOptimizer.optimizer module
- lenstronomy.LensModel.QuadOptimizer.param_manager module
- Module contents
- lenstronomy.LensModel.Solver package
- Submodules
- lenstronomy.LensModel.Solver.lens_equation_solver module
LensEquationSolver
LensEquationSolver.__init__()
LensEquationSolver.image_position_stochastic()
LensEquationSolver.candidate_solutions()
LensEquationSolver.image_position_analytical()
LensEquationSolver.image_position_from_source()
LensEquationSolver.image_position_lenstronomy()
LensEquationSolver.findBrightImage()
LensEquationSolver.sort_arrival_times()
- lenstronomy.LensModel.Solver.solver module
- lenstronomy.LensModel.Solver.solver2point module
- lenstronomy.LensModel.Solver.solver4point module
- Module contents
- lenstronomy.LensModel.Util package
Submodules¶
lenstronomy.LensModel.convergence_integrals module¶
- potential_from_kappa_grid(kappa, grid_spacing)[source]¶
Lensing potential \(\psi ({\vec {\theta }})\) on the convergence grid \(\kappa\).
\[\psi ({\vec {\theta }})={\frac {1}{\pi }}\int d^{2}\theta ^{\prime } \kappa ({\vec {\theta }}^{\prime })\ln |{\vec {\theta }}-{\vec {\theta }}^{\prime }|\]The computation is performed as a convolution of the Green’s function with the convergence map using FFT.
- Parameters:
kappa – 2d grid of convergence values
grid_spacing – scale of an individual pixel (per axis) of grid
- Returns:
lensing potential in a 2d grid at positions x_grid, y_grid
- potential_from_kappa_grid_adaptive(kappa_high_res, grid_spacing, low_res_factor, high_res_kernel_size)[source]¶
Lensing potential on the convergence grid the computation is performed as a convolution of the Green’s function with the convergence map using FFT.
- Parameters:
kappa_high_res – 2d grid of convergence values
grid_spacing – scale of an individual pixel (per axis) of grid
low_res_factor – lower resolution factor of larger scale kernel.
high_res_kernel_size – int, size of high resolution kernel in units of degraded pixels
- Returns:
lensing potential in a 2d grid at positions x_grid, y_grid
- deflection_from_kappa_grid(kappa, grid_spacing)[source]¶
Deflection angle \(\vec {\alpha }}\) from a convergence grid \(\kappa\).
\[{\vec {\alpha }}({\vec {\theta }})={\frac {1}{\pi }} \int d^{2}\theta ^{\prime }{\frac {({\vec {\theta }}-{\vec {\theta }}^{\prime }) \kappa ({\vec {\theta }}^{\prime })}{|{\vec {\theta }}-{\vec {\theta }}^{\prime }|^{2}}}\]The computation is performed as a convolution of the Green’s function with the convergence map using FFT.
- Parameters:
kappa – convergence values for each pixel (2-d array)
grid_spacing – scale of an individual pixel (per axis) of grid
- Returns:
numerical deflection angles in x- and y- direction over the convergence grid points
- deflection_from_kappa_grid_adaptive(kappa_high_res, grid_spacing, low_res_factor, high_res_kernel_size)[source]¶
Deflection angles on the convergence grid with adaptive FFT the computation is performed as a convolution of the Green’s function with the convergence map using FFT The grid is returned in the lower resolution grid.
- Parameters:
kappa_high_res – convergence values for each pixel (2-d array)
grid_spacing – pixel size of high resolution grid
low_res_factor – lower resolution factor of larger scale kernel.
high_res_kernel_size – int, size of high resolution kernel in units of degraded pixels
- Returns:
numerical deflection angles in x- and y- direction
- potential_kernel(num_pix, delta_pix)[source]¶
Numerical gridded integration kernel for convergence to lensing kernel with given pixel size.
- Parameters:
num_pix – integer; number of pixels of kernel per axis
delta_pix – pixel size (per dimension in units of angle)
- Returns:
kernel for lensing potential
- deflection_kernel(num_pix, delta_pix)[source]¶
Numerical gridded integration kernel for convergence to deflection angle with given pixel size.
- Parameters:
num_pix – integer; number of pixels of kernel per axis, should be odd number to have a defined center
delta_pix – pixel size (per dimension in units of angle)
- Returns:
kernel for x-direction and kernel of y-direction deflection angles
lenstronomy.LensModel.lens_model module¶
- class LensModel(lens_model_list, z_lens=None, z_source=None, lens_redshift_list=None, cosmo=None, multi_plane=False, numerical_alpha_class=None, observed_convention_index=None, z_source_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, kwargs_interp=None, kwargs_synthesis=None, distance_ratio_sampling=False)[source]¶
Bases:
object
Class to handle an arbitrary list of lens models.
This is the main lenstronomy LensModel API for all other modules.
- __init__(lens_model_list, z_lens=None, z_source=None, lens_redshift_list=None, cosmo=None, multi_plane=False, numerical_alpha_class=None, observed_convention_index=None, z_source_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, kwargs_interp=None, kwargs_synthesis=None, distance_ratio_sampling=False)[source]¶
- Parameters:
lens_model_list – list of strings with lens model names
z_lens – redshift of the deflector (only considered when operating in single plane mode). Is only needed for specific functions that require a cosmology.
z_source – redshift of the source: Needed in multi_plane option only, not required for the core functionalities in the single plane mode.
lens_redshift_list – list of deflector redshift (corresponding to the lens model list), only applicable in multi_plane mode.
cosmo – instance of the astropy cosmology class. If not specified, uses the default cosmology.
multi_plane – bool, if True, uses multi-plane mode. Default is False.
numerical_alpha_class – an instance of a custom class for use in TabulatedDeflections() lens model (see documentation in Profiles/numerical_deflections)
kwargs_interp – interpolation keyword arguments specifying the numerics. See description in the Interpolate() class. Only applicable for ‘INTERPOL’ and ‘INTERPOL_SCALED’ models.
observed_convention_index – a list of indices, corresponding to the lens_model_list element with same index, where the ‘center_x’ and ‘center_y’ kwargs correspond to observed (lensed) positions, not physical positions. The code will compute the physical locations when performing computations
z_source_convention – float, redshift of a source to define the reduced deflection angles of the lens models. If None, ‘z_source’ is used.
cosmo_interp – boolean (only employed in multi-plane mode), interpolates astropy.cosmology distances for faster calls when accessing several lensing planes
z_interp_stop – (only in multi-plane with cosmo_interp=True); maximum redshift for distance interpolation This number should be higher or equal the maximum of the source redshift and/or the z_source_convention
num_z_interp – (only in multi-plane with cosmo_interp=True); number of redshift bins for interpolating
distances :param distance_ratio_sampling: bool, if True, will use sampled distance ratios to update T_ij value in multi-lens plane computation.
- ray_shooting(x, y, kwargs, k=None)[source]¶
Maps image to source position (inverse deflection)
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
- Returns:
source plane positions corresponding to (x, y) in the image plane
- fermat_potential(x_image, y_image, kwargs_lens, x_source=None, y_source=None)[source]¶
Fermat potential (negative sign means earlier arrival time) for Multi-plane lensing, it computes the effective Fermat potential (derived from the arrival time and subtracted off the time-delay distance for the given cosmology). The units are given in arcsecond square.
- Parameters:
x_image – image position
y_image – image position
x_source – source position
y_source – source position
kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes
- Returns:
fermat potential in arcsec**2 without geometry term (second part of Eqn 1 in Suyu et al. 2013) as a list
- arrival_time(x_image, y_image, kwargs_lens, kappa_ext=0, x_source=None, y_source=None)[source]¶
Arrival time of images relative to a straight line without lensing. Negative values correspond to images arriving earlier, and positive signs correspond to images arriving later.
- Parameters:
x_image – image position
y_image – image position
kwargs_lens – lens model parameter keyword argument list
kappa_ext – external convergence contribution not accounted in the lens model that leads to the same observables in position and relative fluxes but rescales the time delays
x_source – source position (optional), otherwise computed with ray-tracing
y_source – source position (optional), otherwise computed with ray-tracing
- Returns:
arrival time of image positions in units of days
- potential(x, y, kwargs, k=None)[source]¶
Lensing potential.
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
- Returns:
lensing potential in units of arcsec^2
- alpha(x, y, kwargs, k=None, diff=None)[source]¶
Deflection angles.
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
diff – None or float. If set, computes the deflection as a finite numerical differential of the lensing potential. This differential is only applicable in the single lensing plane where the form of the lensing potential is analytically known
- Returns:
deflection angles in units of arcsec
- hessian(x, y, kwargs, k=None, diff=None, diff_method='square')[source]¶
Hessian matrix.
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
- Returns:
f_xx, f_xy, f_yx, f_yy components
- kappa(x, y, kwargs, k=None, diff=None, diff_method='square')[source]¶
Lensing convergence k = 1/2 laplacian(phi)
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
- Returns:
lensing convergence
- curl(x, y, kwargs, k=None, diff=None, diff_method='square')[source]¶
curl computation F_xy - F_yx
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
- Returns:
curl at position (x, y)
- gamma(x, y, kwargs, k=None, diff=None, diff_method='square')[source]¶
shear computation g1 = 1/2(d^2phi/dx^2 - d^2phi/dy^2) g2 = d^2phi/dxdy
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
- Returns:
gamma1, gamma2
- magnification(x, y, kwargs, k=None, diff=None, diff_method='square')[source]¶
magnification.
mag = 1/det(A) A = 1 - d^2phi/d_ij
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
diff – float, scale over which the finite numerical differential is computed. If None, then using the exact (if available) differentials.
diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a cross or a square of points around (x, y)
- Returns:
magnification
- flexion(x, y, kwargs, k=None, diff=1e-06, hessian_diff=True)[source]¶
Third derivatives (flexion)
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – int or None, if set, only evaluates the differential from one model component
diff – numerical differential length of Flexion
hessian_diff – boolean, if true also computes the numerical differential length of Hessian (optional)
- Returns:
f_xxx, f_xxy, f_xyy, f_yyy
- set_static(kwargs)[source]¶
Set this instance to a static lens model. This can improve the speed in evaluating lensing quantities at different positions but must not be used with different lens model parameters!
- Parameters:
kwargs – lens model keyword argument list
- Returns:
kwargs_updated (in case of image position convention in multiplane lensing this is changed)
- set_dynamic()[source]¶
Deletes cache for static setting and makes sure the observed convention in the position of lensing profiles in the multi-plane setting is enabled. Dynamic is the default setting of this class enabling an accurate computation of lensing quantities with different parameters in the lensing profiles.
- Returns:
None
- hessian_z1z2(z1, z2, theta_x, theta_y, kwargs_lens, diff=1e-08)[source]¶
Computes Hessian matrix when Observed at z1 with rays going to z2 with z1 < z2 for multi_plane.
- Parameters:
z1 – Observer redshift
z2 – source redshift
theta_x – angular position and direction of the ray
theta_y – angular position and direction of the ray
kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes
diff – numerical differential step (float)
- Returns:
f_xx, f_xy, f_yx, f_yy
lenstronomy.LensModel.lens_model_extensions module¶
- class LensModelExtensions(lensModel)[source]¶
Bases:
object
Class with extension routines not part of the LensModel core routines.
- __init__(lensModel)[source]¶
- Parameters:
lensModel – instance of the LensModel() class, or with same functionalities. In particular, the following definitions are required to execute all functionalities presented in this class: def ray_shooting() def magnification() def kappa() def alpha() def hessian()
- magnification_finite_adaptive(x_image, y_image, kwargs_lens, source_model, kwargs_source, grid_resolution, grid_radius_arcsec, axis_ratio=0.5, tol=0.001, step_size=0.05, use_largest_eigenvalue=True, fixed_aperture_size=False)[source]¶
This method computes image magnifications with a finite-size background source.
This new updates allows for more flexibility in the source light model by requiring the user to specify the source light mode, grid size and grid resolution before calling the function.
The functions auto_raytrracing_grid_size and auto_raytracing_grid_resolution give good estimates for appropriate parameter choices for grid_radius_arcsec and grid_resolution. It can be much faster that magnification_finite for lens models with many deflectors and a compact source. This is because most pixels in a rectangular window around a lensed image of a compact source do not map onto the source, and therefore don’t contribute to the integrated flux in the image plane.
Rather than ray tracing through a rectangular grid, this routine accelerates the computation of image magnifications with finite-size sources by ray tracing through an elliptical region oriented such that tracks the surface brightness of the lensed image. The aperture size is initially quite small, and increases in size until the flux inside of it (and hence the magnification) converges. The orientation of the elliptical aperture is computed from the magnification tensor evaluated at the image coordinate.
If for whatever reason you prefer a circular aperture to the elliptical approximation using the hessian eigenvectors, you can just set axis_ratio = 1.
To use the eigenvalues of the hessian matrix to estimate the optimum axis ratio, set axis_ratio = 0.
The default settings for the grid resolution and ray tracing window size work well for sources with fwhm between 0.5 - 100 pc.
- Parameters:
x_image – a list or array of x coordinates [units arcsec]
y_image – a list or array of y coordinates [units arcsec]
kwargs_lens – keyword arguments for the lens model
source_model – instance of LightModel for the source
grid_resolution – the grid resolution in units arcsec/pixel; if not specified, an appropriate value will be estimated from the source size
grid_radius_arcsec – the size of the ray tracing region in arcsec; if not specified, an appropriate value will be estimated from the source size
axis_ratio – the axis ratio of the ellipse used for ray tracing; if axis_ratio = 0, then the eigenvalues the hessian matrix will be used to estimate an appropriate axis ratio. Be warned: if the image is highly magnified it will tend to curve out of the resulting ellipse
tol – tolerance for convergence in the magnification
step_size – sets the increment for the successively larger ray tracing windows
use_largest_eigenvalue – bool; if True, then the major axis of the ray tracing ellipse region will be aligned with the eigenvector corresponding to the largest eigenvalue of the hessian matrix
fixed_aperture_size – bool, if True the flux is computed inside a fixed aperture size with radius grid_radius_arcsec
- Kwargs_source:
keyword arguments for the light profile of the source (list of dictionary)
- Returns:
an array of image magnifications
- magnification_finite(x_pos, y_pos, kwargs_lens, source_sigma=0.003, window_size=0.1, grid_number=100, polar_grid=False, aspect_ratio=0.5)[source]¶
Returns the magnification of an extended source with Gaussian light profile.
- Parameters:
x_pos – x-axis positons of point sources
y_pos – y-axis position of point sources
kwargs_lens – lens model kwargs
source_sigma – Gaussian sigma in arc sec in source
window_size – size of window to compute the finite flux
grid_number – number of grid cells per axis in the window to numerically compute the flux
- Returns:
numerically computed brightness of the sources
- zoom_source(x_pos, y_pos, kwargs_lens, source_sigma=0.003, window_size=0.1, grid_number=100, shape='GAUSSIAN')[source]¶
Computes the surface brightness on an image with a zoomed window.
- Parameters:
x_pos – angular coordinate of center of image
y_pos – angular coordinate of center of image
kwargs_lens – lens model parameter list
source_sigma – source size (in angular units)
window_size – window size in angular units
grid_number – number of grid points per axis
shape – string, shape of source, supports ‘GAUSSIAN’ and ‘TORUS
- Returns:
2d numpy array
- critical_curve_tiling(kwargs_lens, compute_window=5, start_scale=0.5, max_order=10, center_x=0, center_y=0)[source]¶
- Parameters:
kwargs_lens – lens model keyword argument list
compute_window – total window in the image plane where to search for critical curves
start_scale – float, angular scale on which to start the tiling from (if there are two distinct curves in a region, it might only find one.
max_order – int, maximum order in the tiling to compute critical curve triangles
center_x – float, center of the window to compute critical curves and caustics
center_y – float, center of the window to compute critical curves and caustics
- Returns:
list of positions representing coordinates of the critical curve (in RA and DEC)
- caustic_area(kwargs_lens, kwargs_caustic_num, index_vertices=0)[source]¶
Computes the area inside a connected caustic curve.
- Parameters:
kwargs_lens – lens model keyword argument list
kwargs_caustic_num – keyword arguments for the numerical calculation of the caustics, as input of self.critical_curve_caustics()
index_vertices – integer, index of connected vortex from the output of self.critical_curve_caustics() of disconnected curves.
- Returns:
area within the caustic curve selected
- critical_curve_caustics(kwargs_lens, compute_window=5, grid_scale=0.01, center_x=0, center_y=0)[source]¶
- Parameters:
kwargs_lens – lens model kwargs
compute_window – window size in arcsec where the critical curve is computed
grid_scale – numerical grid spacing of the computation of the critical curves
center_x – float, center of the window to compute critical curves and caustics
center_y – float, center of the window to compute critical curves and caustics
- Returns:
lists of ra and dec arrays corresponding to different disconnected critical curves and their caustic counterparts
- hessian_eigenvectors(x, y, kwargs_lens, diff=None)[source]¶
Computes magnification eigenvectors at position (x, y)
- Parameters:
x – x-position
y – y-position
kwargs_lens – lens model keyword arguments
- Returns:
radial stretch, tangential stretch
- radial_tangential_stretch(x, y, kwargs_lens, diff=None, ra_0=0, dec_0=0, coordinate_frame_definitions=False)[source]¶
Computes the radial and tangential stretches at a given position.
- Parameters:
x – x-position
y – y-position
kwargs_lens – lens model keyword arguments
diff – float or None, finite average differential scale
- Returns:
radial stretch, tangential stretch
- radial_tangential_differentials(x, y, kwargs_lens, center_x=0, center_y=0, smoothing_3rd=0.001, smoothing_2nd=None)[source]¶
Computes the differentials in stretches and directions.
- Parameters:
x – x-position
y – y-position
kwargs_lens – lens model keyword arguments
center_x – x-coord of center towards which the rotation direction is defined
center_y – x-coord of center towards which the rotation direction is defined
smoothing_3rd – finite differential length of third order in units of angle
smoothing_2nd – float or None, finite average differential scale of Hessian
- Returns:
- curved_arc_estimate(x, y, kwargs_lens, smoothing=None, smoothing_3rd=0.001, tan_diff=False)[source]¶
Performs the estimation of the curved arc description at a particular position of an arbitrary lens profile.
- Parameters:
x – float, x-position where the estimate is provided
y – float, y-position where the estimate is provided
kwargs_lens – lens model keyword arguments
smoothing – (optional) finite differential of second derivative (radial and tangential stretches)
smoothing_3rd – differential scale for third derivative to estimate the tangential curvature
tan_diff – boolean, if True, also returns the relative tangential stretch differential in tangential direction
- Returns:
keyword argument list corresponding to a CURVED_ARC profile at (x, y) given the initial lens model
- tangential_average(x, y, kwargs_lens, dr, smoothing=None, num_average=9)[source]¶
Computes average tangential stretch around position (x, y) within dr in radial direction.
- Parameters:
x – x-position (float)
y – y-position (float)
kwargs_lens – lens model keyword argument list
dr – averaging scale in radial direction
smoothing – smoothing scale of derivative
num_average – integer, number of points averaged over within dr in the radial direction
- Returns:
- curved_arc_finite_area(x, y, kwargs_lens, dr)[source]¶
Computes an estimated curved arc over a finite extent mimicking the appearance of a finite source with radius dr.
- Parameters:
x – x-position (float)
y – y-position (float)
kwargs_lens – lens model keyword argument list
dr – radius of finite source
- Returns:
keyword arguments of curved arc
lenstronomy.LensModel.lens_param module¶
- class LensParam(lens_model_list, kwargs_fixed, kwargs_lower=None, kwargs_upper=None, kwargs_logsampling=None, num_images=0, solver_type='NONE', num_shapelet_lens=0)[source]¶
Bases:
object
Class to handle the lens model parameter.
- __init__(lens_model_list, kwargs_fixed, kwargs_lower=None, kwargs_upper=None, kwargs_logsampling=None, num_images=0, solver_type='NONE', num_shapelet_lens=0)[source]¶
- Parameters:
lens_model_list – list of strings of lens model names
kwargs_fixed – list of keyword arguments for model parameters to be held fixed
kwargs_lower – list of keyword arguments of the lower bounds of the model parameters
kwargs_upper – list of keyword arguments of the upper bounds of the model parameters
kwargs_logsampling – list of keyword arguments of parameters to be sampled in log10 space
num_images – number of images to be constrained by a non-linear solver (only relevant when shapelet potential functions are used)
solver_type – string, type of non-linear solver (only relevant in this class when ‘SHAPELETS’ is the solver type)
num_shapelet_lens – integer, number of shapelets in the lensing potential (only relevant when ‘SHAPELET’ lens model is used)
- get_params(args, i)[source]¶
- Parameters:
args – tuple of individual floats of sampling argument
i – integer, index at the beginning of the tuple for read out to keyword argument convention
- Returns:
kwargs_list, index at the end of read out of this model component
lenstronomy.LensModel.profile_integrals module¶
- class ProfileIntegrals(profile_class)[source]¶
Bases:
object
class to perform integrals of spherical profiles to compute: - projected densities - enclosed densities - projected enclosed densities
- mass_enclosed_3d(r, kwargs_profile, lens_param=False)[source]¶
Computes the mass enclosed within a sphere of radius r.
- Parameters:
r – radius (arcsec)
kwargs_profile – keyword argument list with lens model parameters
lens_param – boolean, if True uses the lens model parameterization in computing the 3d density convention and the return is the convergence
- Returns:
3d mass enclosed of r
- density_2d(r, kwargs_profile, lens_param=False)[source]¶
Computes the projected density along the line-of-sight.
- Parameters:
r – radius (arcsec)
kwargs_profile – keyword argument list with lens model parameters
lens_param – boolean, if True uses the lens model parameterization in computing the 3d density convention and the return is the convergence
- Returns:
2d projected density at projected radius r
lenstronomy.LensModel.profile_list_base module¶
- class ProfileListBase(lens_model_list, numerical_alpha_class=None, lens_redshift_list=None, z_source_convention=None, kwargs_interp=None, kwargs_synthesis=None)[source]¶
Bases:
object
Class that manages the list of lens model class instances.
This class is applicable for single plane and multi plane lensing
- __init__(lens_model_list, numerical_alpha_class=None, lens_redshift_list=None, z_source_convention=None, kwargs_interp=None, kwargs_synthesis=None)[source]¶
- Parameters:
lens_model_list – list of strings with lens model names
numerical_alpha_class – an instance of a custom class for use in NumericalAlpha() lens model deflection angles as a lens model. See the documentation in Profiles.numerical_deflections
kwargs_interp – interpolation keyword arguments specifying the numerics. See description in the Interpolate() class. Only applicable for ‘INTERPOL’ and ‘INTERPOL_SCALED’ models.
kwargs_synthesis – keyword arguments for the ‘SYNTHESIS’ lens model, if applicable
lenstronomy.LensModel.single_plane module¶
- class SinglePlane(lens_model_list, numerical_alpha_class=None, lens_redshift_list=None, z_source_convention=None, kwargs_interp=None, kwargs_synthesis=None)[source]¶
Bases:
ProfileListBase
Class to handle an arbitrary list of lens models in a single lensing plane.
- ray_shooting(x, y, kwargs, k=None)[source]¶
Maps image to source position (inverse deflection).
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
- Returns:
source plane positions corresponding to (x, y) in the image plane
- fermat_potential(x_image, y_image, kwargs_lens, x_source=None, y_source=None, k=None)[source]¶
Fermat potential (negative sign means earlier arrival time)
- Parameters:
x_image – image position
y_image – image position
x_source – source position
y_source – source position
kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes
k –
- Returns:
fermat potential in arcsec**2 without geometry term (second part of Eqn 1 in Suyu et al. 2013) as a list
- potential(x, y, kwargs, k=None)[source]¶
Lensing potential.
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
- Returns:
lensing potential in units of arcsec^2
- alpha(x, y, kwargs, k=None)[source]¶
Deflection angles.
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
- Returns:
deflectionangles in units of arcsec
- hessian(x, y, kwargs, k=None)[source]¶
Hessian matrix.
- Parameters:
x (numpy array) – x-position (preferentially arcsec)
y (numpy array) – y-position (preferentially arcsec)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
k – only evaluate the k-th lens model
- Returns:
f_xx, f_xy, f_yx, f_yy components
- mass_3d(r, kwargs, bool_list=None)[source]¶
Computes the mass within a 3d sphere of radius r.
if you want to have physical units of kg, you need to multiply by this factor: const.arcsec ** 2 * self._cosmo.dd * self._cosmo.ds / self._cosmo.dds * const.Mpc * const.c ** 2 / (4 * np.pi * const.G) grav_pot = -const.G * mass_dim / (r * const.arcsec * self._cosmo.dd * const.Mpc)
- Parameters:
r – radius (in angular units)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
bool_list – list of bools that are part of the output
- Returns:
mass (in angular units, modulo epsilon_crit)
- mass_2d(r, kwargs, bool_list=None)[source]¶
Computes the mass enclosed a projected (2d) radius r.
The mass definition is such that:
\[\alpha = mass_2d / r / \pi\]with alpha is the deflection angle
- Parameters:
r – radius (in angular units)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
bool_list – list of bools that are part of the output
- Returns:
projected mass (in angular units, modulo epsilon_crit)
- density(r, kwargs, bool_list=None)[source]¶
3d mass density at radius r The integral in the LOS projection of this quantity results in the convergence quantity.
- Parameters:
r – radius (in angular units)
kwargs – list of keyword arguments of lens model parameters matching the lens model classes
bool_list – list of bools that are part of the output
- Returns:
mass density at radius r (in angular units, modulo epsilon_crit)