lenstronomy.Analysis package¶
Submodules¶
lenstronomy.Analysis.image_reconstruction module¶
- class MultiBandImageReconstruction(multi_band_list, kwargs_model, kwargs_params, multi_band_type='multi-linear', kwargs_likelihood=None, verbose=True)[source]¶
Bases:
objectThis class manages the output/results of a fitting process and can conveniently access image reconstruction properties in multi-band fitting. In particular, the fitting result does not come with linear inversion parameters (which may or may not be joint or different for multiple bands) and this class performs the linear inversion for the surface brightness amplitudes and stores them for each individual band to be accessible by the user.
This class is the backbone of the ModelPlot routine that provides the interface of this class with plotting and illustration routines.
- __init__(multi_band_list, kwargs_model, kwargs_params, multi_band_type='multi-linear', kwargs_likelihood=None, verbose=True)[source]¶
- Parameters:
multi_band_list – list of imaging data configuration [[kwargs_data, kwargs_psf, kwargs_numerics], […]]
kwargs_model – model keyword argument list
kwargs_params – keyword arguments of the model parameters, same as output of FittingSequence() ‘kwargs_result’
multi_band_type – string, option when having multiple imaging data sets modelled simultaneously. Options are: - ‘multi-linear’: linear amplitudes are inferred on single data set - ‘linear-joint’: linear amplitudes ae jointly inferred - ‘single-band’: single band
kwargs_likelihood – likelihood keyword arguments as supported by the Likelihood() class
verbose – if True (default), computes and prints the total log-likelihood. This option can be deactivated for speedup purposes (does not run linear inversion again), and reduces the number of prints.
- band_setup(band_index=0)[source]¶
ImageModel() instance and keyword arguments of the model components to execute all the options of the ImSim core modules.
- Parameters:
band_index – integer (>=0) of imaging band in order of multi_band_list input to this class
- Returns:
ImageModel() instance and keyword arguments of the model
- class ModelBand(multi_band_list, kwargs_model, model, error_map, cov_param, param, kwargs_params, image_likelihood_mask_list=None, band_index=0, verbose=True, linear_solver=True)[source]¶
Bases:
objectClass to plot a single band given the full modeling results This class has its specific role when the linear inference is performed on the joint band level and/or when only a subset of model components get used for this specific band in the modeling.
- __init__(multi_band_list, kwargs_model, model, error_map, cov_param, param, kwargs_params, image_likelihood_mask_list=None, band_index=0, verbose=True, linear_solver=True)[source]¶
- Parameters:
multi_band_list – list of imaging data configuration [[kwargs_data, kwargs_psf, kwargs_numerics], […]]
kwargs_model – model keyword argument list for the full multi-band modeling
model – 2d numpy array of modeled image for the specified band
error_map – 2d numpy array of size of the image, additional error in the pixels coming from PSF uncertainties
cov_param – covariance matrix of the linear inversion
param – 1d numpy array of the linear coefficients of this imaging band
kwargs_params – keyword argument of keyword argument lists of the different model components selected for the imaging band, NOT including linear amplitudes (not required as being overwritten by the param list)
image_likelihood_mask_list – list of 2d numpy arrays of likelihood masks (for all bands)
band_index – integer of the band to be considered in this class
verbose – if True (default), prints the reduced chi2 value for the current band.
linear_solver – bool, if True (default) fixes the linear amplitude parameters ‘amp’ (avoid sampling) such that they get overwritten by the linear solver solution.
- property model¶
- Returns:
model, 2d numpy array
- property norm_residuals¶
- Returns:
normalized residuals, 2d numpy array
- property image_model_class¶
ImageModel() class instance of the single band with only the model components applied to this band.
- Returns:
SingleBandMultiModel() instance, which inherits the ImageModel instance
- property kwargs_model¶
- Returns:
keyword argument of keyword argument lists of the different model components selected for the imaging band, including linear amplitudes. These format matches the image_model_class() return
- point_source_residuals(aperture_radius)[source]¶
Computes integrated residuals within circular apertures around point sources. This routine can assess the accuracy of point source flux measurements.
- Parameters:
aperture_radius – radius of the aperture considering the residuals around the point sources
- Returns:
list of integrated flux residuals (data - model) within the apertures around the point sources
lenstronomy.Analysis.kinematics_api module¶
lenstronomy.Analysis.lens_profile module¶
- class LensProfileAnalysis(lens_model)[source]¶
Bases:
objectClass with analysis routines to compute derived properties of the lens model.
- effective_einstein_radius_grid(kwargs_lens, center_x=None, center_y=None, model_bool_list=None, grid_num=200, grid_spacing=0.05, get_precision=False, verbose=True)[source]¶
Computes the radius with mean convergence=1 on a grid.
- Parameters:
kwargs_lens – list of lens model keyword arguments
center_x – position of the center (if not set, is attempting to find it from the parameters kwargs_lens)
center_y – position of the center (if not set, is attempting to find it from the parameters kwargs_lens)
model_bool_list – list of booleans indicating the addition (=True) of a model component in computing the Einstein radius
grid_num – integer, number of grid points to numerically evaluate the convergence and estimate the Einstein radius
grid_spacing – spacing in angular units of the grid
get_precision – If True, return the precision of estimated Einstein radius
verbose (bool) – if True, indicates warning when Einstein radius can not be computed
- Returns:
estimate of the Einstein radius
- effective_einstein_radius(kwargs_lens, r_min=0.001, r_max=10.0, num_points=30, spherical_model=False)[source]¶
Numerical estimate of the Einstein radius with integral approximation of radial convergence profile.
- Parameters:
kwargs_lens – list of lens model keyword arguments
r_min – minimum radius of the convergence integrand
r_max – maximum radius of the convergence integrand (should be larger than Einstein radius)
num_points – number of radial points in log spacing
spherical_model – if True, assumes the model is spherical and only calculates the convergence along one axis (for speed improvements)
- Returns:
estimate of the Einstein radius
- static effective_einstein_radius_from_radial_profile(r_array, kappa_r)[source]¶
Numerical estimate of the Einstein radius with integral approximation of radial convergence profile.
- Parameters:
r_array – radius at which convergence is measured
kappa_r – convergence array measured at r_array
- Returns:
estimate of the Einstein radius
- local_lensing_effect(kwargs_lens, ra_pos=0, dec_pos=0, model_list_bool=None)[source]¶
Computes deflection, shear and convergence at (ra_pos,dec_pos) for those part of the lens model not included in the main deflector.
- Parameters:
kwargs_lens – lens model keyword argument list
ra_pos – RA position where to compute the external effect
dec_pos – DEC position where to compute the external effect
model_list_bool – boolean list indicating which models effect to be added to the estimate
- Returns:
alpha_x, alpha_y, kappa, shear1, shear2
- profile_slope(kwargs_lens, radius, center_x=None, center_y=None, model_list_bool=None, num_points=10, alpha_differentials=True)[source]¶
Computes the logarithmic power-law slope of a profile. ATTENTION: this is not an observable!
- Parameters:
kwargs_lens – lens model keyword argument list
radius – radius from the center where to compute the logarithmic slope (angular units
center_x – center of profile from where to compute the slope
center_y – center of profile from where to compute the slope
model_list_bool – bool list, indicate which part of the model to consider
num_points – number of estimates around the Einstein radius
alpha_differentials (bool) – if True, uses the deflection angle differentials, else the convergence differentials
- Returns:
logarithmic power-law slope
- mst_invariant_differential(kwargs_lens, radius, center_x=None, center_y=None, model_list_bool=None, num_points=10)[source]¶
Average of the radial stretch differential in radial direction, divided by the radial stretch factor.
\[\xi = \frac{\partial \lambda_{\rm rad}}{\partial r} \frac{1}{\lambda_{\rm rad}}\]This quantity is invariant under the MST. The specific definition is provided by Birrer 2021. Equivalent (proportional) definitions are provided by e.g. Kochanek 2020, Sonnenfeld 2018.
- Parameters:
kwargs_lens – lens model keyword argument list
radius – radius from the center where to compute the MST invariant differential
center_x – center position
center_y – center position
model_list_bool – indicate which part of the model to consider
num_points – number of estimates around the radius
- Returns:
xi
- radial_lens_profile(r_list, kwargs_lens, center_x=None, center_y=None, model_bool_list=None, num_azimuthal_points=20)[source]¶
- Parameters:
r_list – list of radii to compute the spherically averaged lens light profile
center_x – center of the profile
center_y – center of the profile
kwargs_lens – lens parameter keyword argument list
model_bool_list – bool list or None, indicating which profiles to sum over
num_azimuthal_points (int) – number of points equally spaced azimuthally to create an average
- Returns:
flux amplitudes at r_list radii azimuthally averaged
- multi_gaussian_lens(kwargs_lens, center_x=None, center_y=None, model_bool_list=None, n_comp=20)[source]¶
Multi-gaussian lens model in convergence space.
- Parameters:
kwargs_lens
n_comp
- Returns:
- mass_fraction_within_radius(kwargs_lens, center_x, center_y, theta_E, num_pix=100)[source]¶
Computes the mean convergence of all the different lens model components within a spherical aperture.
- Parameters:
kwargs_lens – lens model keyword argument list
center_x – center of the aperture
center_y – center of the aperture
theta_E – radius of aperture
- Returns:
list of average convergences for all the model components
- convergence_peak(kwargs_lens, model_bool_list=None, grid_num=200, grid_spacing=0.01, center_x_init=0, center_y_init=0)[source]¶
Computes the maximal convergence position on a grid and returns its coordinate.
- Parameters:
kwargs_lens – lens model keyword argument list
model_bool_list – bool list (optional) to include certain models or not
- Returns:
center_x, center_y
- m_delta_crit(kwargs_lens, z_lens, z_source, cosmo, delta_crit=200)[source]¶
Calculates the mass enclosed an average of delta_crit above the critical background density.
- Parameters:
kwargs_lens – list of lens model dictionary
z_lens – redshift of the deflector
z_source – redshift of the source (for lens model conventions)
cosmo – ~astropy.cosmology instance
delta_crit – relative overdensity relative to the critical density of the universe
- Returns:
m(<delta_crit) [M_sol], r(delta_crit) [arcsec]
lenstronomy.Analysis.light2mass module¶
- light2mass_interpol(lens_light_model_list, kwargs_lens_light, lens_light_profile_kwargs_list=None, num_pix=100, delta_pix=0.05, subgrid_res=5, center_x=0, center_y=0)[source]¶
Takes a lens light model and turns it numerically in a lens model (with all lensmodel quantities computed on a grid). Then provides an interpolated grid for the quantities.
- Parameters:
lens_light_model_list – list of strings indicating the type of lens light models
kwargs_lens_light – lens light keyword argument list
lens_light_profile_kwargs_list – list of dicts, keyword arguments used to initialize lens light profile classes in the same order of the lens_light_model_list. If any of the profile_kwargs are None, then that profile will be initialized using default settings.
num_pix – number of pixels per axis for the return interpolation
delta_pix – interpolation/pixel size
center_x – center of the grid
center_y – center of the grid
subgrid_res – subgrid for the numerical integrals
- Returns:
keyword arguments for ‘INTERPOL’ lens model
lenstronomy.Analysis.light_profile module¶
- class LightProfileAnalysis(light_model)[source]¶
Bases:
objectClass with analysis routines to compute derived properties of the lens model.
- ellipticity(kwargs_light, grid_spacing, grid_num, center_x=None, center_y=None, model_bool_list=None, num_iterative=10, iterative=False)[source]¶
Make sure that the window covers all the light, otherwise the moments may give a too low answers.
- Parameters:
kwargs_light – keyword argument list of profiles
center_x – center of profile, if None takes it from the first profile in kwargs_light
center_y – center of profile, if None takes it from the first profile in kwargs_light
model_bool_list – list of booleans to select subsets of the profile
grid_spacing – grid spacing over which the moments are computed
grid_num – grid size over which the moments are computed
iterative (boolean) – if True iteratively adopts an eccentric mask to overcome edge effects
num_iterative (int) – number of iterative changes in ellipticity
- Returns:
eccentricities e1, e2
- half_light_radius(kwargs_light, grid_spacing, grid_num, center_x=None, center_y=None, model_bool_list=None)[source]¶
Computes numerically the half-light-radius of the deflector light and the total photon flux.
- Parameters:
kwargs_light – keyword argument list of profiles
center_x – center of profile, if None takes it from the first profile in kwargs_light
center_y – center of profile, if None takes it from the first profile in kwargs_light
model_bool_list – list of booleans to select subsets of the profile
grid_spacing – grid spacing over which the moments are computed
grid_num – grid size over which the moments are computed
- Returns:
half-light radius
- radial_light_profile(r_list, kwargs_light, center_x=None, center_y=None, model_bool_list=None)[source]¶
- Parameters:
r_list – list of radii to compute the spherically averaged lens light profile
center_x – center of the profile
center_y – center of the profile
kwargs_light – lens light parameter keyword argument list
model_bool_list – bool list or None, indicating which profiles to sum over
- Returns:
flux amplitudes at r_list radii spherically averaged
- multi_gaussian_decomposition(kwargs_light, model_bool_list=None, n_comp=20, center_x=None, center_y=None, r_h=None, grid_spacing=0.02, grid_num=200)[source]¶
Multi-gaussian decomposition of the lens light profile (in 1-dimension)
- Parameters:
kwargs_light – keyword argument list of profiles
center_x – center of profile, if None takes it from the first profile in kwargs_light
center_y – center of profile, if None takes it from the first profile in kwargs_light
model_bool_list – list of booleans to select subsets of the profile
grid_spacing – grid spacing over which the moments are computed for the half-light radius
grid_num – grid size over which the moments are computed
n_comp – maximum number of Gaussian’s in the MGE
r_h – float, half light radius to be used for MGE (optional, otherwise using a numerical grid)
- Returns:
amplitudes, sigmas, center_x, center_y
- multi_gaussian_decomposition_ellipse(kwargs_light, model_bool_list=None, center_x=None, center_y=None, grid_num=100, grid_spacing=0.05, n_comp=20)[source]¶
MGE with ellipticity estimate. Attention: numerical grid settings for ellipticity estimate and radial MGE may not necessarily be the same!
- Parameters:
kwargs_light – keyword argument list of profiles
center_x – center of profile, if None takes it from the first profile in kwargs_light
center_y – center of profile, if None takes it from the first profile in kwargs_light
model_bool_list – list of booleans to select subsets of the profile
grid_spacing – grid spacing over which the moments are computed
grid_num – grid size over which the moments are computed
n_comp – maximum number of Gaussians in the MGE
- Returns:
keyword arguments of the elliptical multi Gaussian profile in lenstronomy conventions
lenstronomy.Analysis.multi_patch_reconstruction module¶
- class MultiPatchReconstruction(multi_band_list, kwargs_model, kwargs_params, multi_band_type='joint-linear', kwargs_likelihood=None, kwargs_pixel_grid=None, verbose=True)[source]¶
Bases:
MultiBandImageReconstructionThis class illustrates the model of disconnected multi-patch modeling with ‘joint-linear’ option in one single array.
- __init__(multi_band_list, kwargs_model, kwargs_params, multi_band_type='joint-linear', kwargs_likelihood=None, kwargs_pixel_grid=None, verbose=True)[source]¶
- Parameters:
multi_band_list – list of imaging data configuration [[kwargs_data, kwargs_psf, kwargs_numerics], […]]
kwargs_model – model keyword argument list
kwargs_params – keyword arguments of the model parameters, same as output of FittingSequence() ‘kwargs_result’
multi_band_type – string, option when having multiple imaging data sets modelled simultaneously. Options are: - ‘multi-linear’: linear amplitudes are inferred on single data set - ‘linear-joint’: linear amplitudes ae jointly inferred - ‘single-band’: single band
kwargs_likelihood – likelihood keyword arguments as supported by the Likelihood() class
kwargs_pixel_grid – keyword argument of PixelGrid() class. This is optional and overwrites a minimal grid Attention for consistent pixel grid definitions!
verbose – if True (default), computes and prints the total log-likelihood. This can de-activated for speedup purposes (does not run linear inversion again), and reduces the number of prints.
- property pixel_grid_joint¶
- Returns:
PixelGrid() class instance covering the entire window of the sky including all individual patches
- image_joint()[source]¶
Patch together the individual patches of data and models.
- Returns:
image_joint, model_joint, norm_residuals_joint
- lens_model_joint()[source]¶
Patch together the individual patches of the lens model (can be discontinues)
- Returns:
2d numpy arrays of kappa_joint, magnification_joint, alpha_x_joint, alpha_y_joint
- source(num_pix, delta_pix, center=None)[source]¶
Source in the same coordinate system as the image.
- Parameters:
num_pix – number of pixels per axes
delta_pix – pixel size
center – list with two entries [center_x, center_y] (optional)
- Returns:
2d surface brightness grid of the reconstructed source and PixelGrid() instance of source grid