lenstronomy.Sampling.Likelihoods package¶
Submodules¶
lenstronomy.Sampling.Likelihoods.flux_ratio_likelihood module¶
- class FluxRatioLikelihood(lens_model_class, flux_ratios, flux_ratio_errors, flux_ratio_measurement_bool=None, num_point_sources=1, source_type='INF', window_size=0.1, grid_number=100, polar_grid=False, aspect_ratio=0.5, point_source_redshift_list=None)[source]¶
Bases:
objectLikelihood class for magnification of multiply lensed images.
- __init__(lens_model_class, flux_ratios, flux_ratio_errors, flux_ratio_measurement_bool=None, num_point_sources=1, source_type='INF', window_size=0.1, grid_number=100, polar_grid=False, aspect_ratio=0.5, point_source_redshift_list=None)[source]¶
- Parameters:
lens_model_class – LensModel class instance
flux_ratios – ratio of fluxes of the multiple images (relative to the first appearing in same order as the images)
flux_ratio_errors – errors in the flux ratios (relative to the first appearing). Alternatively a log-normal covariance matrix. Note: in the case of a covariance matrix, the errors are assumed to be log-normal, i.e. the logarithms of the flux ratios, ln(F[i]/F[0]) are assumed to have a multivariate Gaussian distribution, with the given covariance matrix.
flux_ratio_measurement_bool – list of bools of length of the point source model, indicating for which point sources there is a flux ratio measurement
num_point_sources (int>=0) – number of point sources in the point source model output
source_type – string, type of source, ‘INF’ specifies a point source, while ‘GAUSSIAN’ specifies a finite-size source modeled as a Gaussian
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
point_source_redshift_list – list of redshifts to the different sources
- logL(ra_image_list, dec_image_list, kwargs_lens, kwargs_special)[source]¶
- Parameters:
kwargs_lens – lens model keyword argument list
kwargs_special – dictionary of ‘special’ keyword parameters
- Returns:
log likelihood of the measured flux ratios given a model
- property num_data¶
- Returns:
integer, number of data points associated with the flux ratios
lenstronomy.Sampling.Likelihoods.image_likelihood module¶
- class ImageLikelihood(multi_band_list, multi_band_type, kwargs_model, bands_compute=None, image_likelihood_mask_list=None, source_marg=False, linear_prior=None, check_positive_flux=False, kwargs_pixelbased=None, linear_solver=True)[source]¶
Bases:
objectManages imaging data likelihoods.
- __init__(multi_band_list, multi_band_type, kwargs_model, bands_compute=None, image_likelihood_mask_list=None, source_marg=False, linear_prior=None, check_positive_flux=False, kwargs_pixelbased=None, linear_solver=True)[source]¶
- Parameters:
bands_compute – list of bools with same length as data objects, indicates which “band” to include in the fitting
image_likelihood_mask_list – list of boolean 2d arrays of size of images marking the pixels to be evaluated in the likelihood
source_marg – marginalization addition on the imaging likelihood based on the covariance of the inferred linear coefficients
linear_prior – float or list of floats (when multi-linear setting is chosen) indicating the range of linear amplitude priors when computing the marginalization term.
check_positive_flux – bool, option to punish models that do not have all positive linear amplitude parameters
kwargs_pixelbased – keyword arguments with various settings related to the pixel-based solver (see SLITronomy documentation)
linear_solver – bool, if True (default) fixes the linear amplitude parameters ‘amp’ (avoid sampling) such that they get overwritten by the linear solver solution.
- logL(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None, **kwargs)[source]¶
- Parameters:
kwargs_lens – lens model keyword argument list according to LensModel module
kwargs_source – source light keyword argument list according to LightModel module
kwargs_lens_light – deflector light (not lensed) keyword argument list according to LightModel module
kwargs_ps – point source keyword argument list according to PointSource module
kwargs_special – special keyword argument list as part of the Param module
kwargs_extinction – extinction parameter keyword argument list according to LightModel module
- Returns:
log likelihood of the data given the model, linear parameter inversion list
- property num_data¶
- Returns:
number of image data points
lenstronomy.Sampling.Likelihoods.kinematic_2D_likelihood module¶
- class KinLikelihood(kinematic_bin_2d_class, lens_model_class, lens_light_model_class, kwargs_data, idx_lens=0, idx_lens_light=0)[source]¶
Bases:
objectClass to compute the likelihood associated to binned 2D kinematic maps.
- __init__(kinematic_bin_2d_class, lens_model_class, lens_light_model_class, kwargs_data, idx_lens=0, idx_lens_light=0)[source]¶
- Parameters:
kinematic_data_2d_class – KinBin class instance
lens_model_class – LensModel class instance
lens_light_model_class – LightModel class instance
kwargs_data – kwargs describing image rotation
idx_lens – int, index of the LensModel mass profile to consider for kinematics
idx_lens_light – int, index of the lens LightModel profile to consider for kinematics
- calc_vrms(kwargs_lens, kwargs_lens_light, kwargs_special, verbose=False)[source]¶
Calculates binned vrms using SKiNN.
- Parameters:
kwargs_lens – lens model kwargs list
kwargs_lens_light – lens light kwargs list
kwargs_special – cosmology and other kwargs
verbose – default False; if True print statements when out of bounds return binned vrms [km/s]; if SKiNN not installed return nan
- logL(kwargs_lens, kwargs_lens_light, kwargs_special, verbose=False)[source]¶
Calculates Log likelihood from 2D kinematic likelihood.
- Parameters:
kwargs_lens – lens model kwargs list
kwargs_lens_light – lens light kwargs list
kwargs_special – cosmology and other kwargs
verbose – default False; if True print statements when out of bounds return kinematics log likelihood
- convert_to_nn_params(kwargs_lens, kwargs_lens_light, kwargs_special)[source]¶
Converts lenstronomy kwargs into input vector for SKiNN, also returns whether or not mass and light are aligned.
- Parameters:
kwargs_lens – lens model kwargs list
kwargs_lens_light – lens light kwargs list
kwargs_special – cosmology and other kwargs
- Returns:
parameters in GLEE convention to be input into NN
- rescale_distance(image, kwargs_special)[source]¶
Rescales velocity map according to distance, requires lens redshift.
- Parameters:
image – vrms image [km/s]
kwargs_special – kwargs with cosmological distances for rescaling return rescaled vrms image [km/s]
- kwargs_data2image_input(kwargs_data)[source]¶
Creates the kwargs of the image needed for 2D kinematic likelihood.
- Parameters:
kwargs_data – kwargs giving image and describing imaging data coordinate transformation
- Return kwargs:
coordinate transformation kwargs as input for KinNNImageAlign class
lenstronomy.Sampling.Likelihoods.kinematic_NN_call module¶
- class KinematicNN[source]¶
Bases:
objectClass to call the NN to emulate JAM kinematics.
- generate_map(input_p, verbose=False)[source]¶
Generate velocity map given input parameters.
- Parameters:
input_p – vector of input parameters
- Returns:
the velocity map associated with input_p
- check_bounds(input_p, same_orientation=True, verbose=False)[source]¶
Checks to see if input parameters lie in bounds used for the training set.
- Parameters:
input_p – input parameters to NN
same_orientation – default True; confirms that mass and light have same position angles
verbose – default False; if True prints statements when out of bounds
lenstronomy.Sampling.Likelihoods.position_likelihood module¶
- class PositionLikelihood(point_source_class, image_position_uncertainty=0.005, astrometric_likelihood=False, image_position_likelihood=False, ra_image_list=None, dec_image_list=None, source_position_likelihood=None, source_position_tolerance=None, source_position_sigma=0.001, force_no_add_image=False, restrict_image_number=False, max_num_images=None)[source]¶
Bases:
objectLikelihood of positions of multiply imaged point sources.
- __init__(point_source_class, image_position_uncertainty=0.005, astrometric_likelihood=False, image_position_likelihood=False, ra_image_list=None, dec_image_list=None, source_position_likelihood=None, source_position_tolerance=None, source_position_sigma=0.001, force_no_add_image=False, restrict_image_number=False, max_num_images=None)[source]¶
- Parameters:
point_source_class – Instance of PointSource() class
image_position_uncertainty – uncertainty in image position uncertainty (1-sigma Gaussian radially), this is applicable for astrometric uncertainties as well as if image positions are provided as data
astrometric_likelihood – bool, if True, evaluates the astrometric uncertainty of the predicted and modeled image positions with an offset ‘delta_x_image’ and ‘delta_y_image’
image_position_likelihood – bool, if True, evaluates the likelihood of the model predicted image position given the data/measured image positions
ra_image_list – list or RA image positions per model component
dec_image_list – list or DEC image positions per model component
source_position_likelihood – bool, if True, ray-traces image positions back to source plane and evaluates relative errors in respect ot the position_uncertainties in the image plane (image_position_uncertainty)
source_position_tolerance (None or float) – tolerance level (in arc seconds in the source plane) of the different images. If set =! None, then the backwards ray tracing is performed on the images and demand on the same position of the source is meant to match the requirements, otherwise a punishing likelihood term is introduced
source_position_sigma – r.m.s. value corresponding to a 1-sigma Gaussian likelihood accepted by the model precision in matching the source position transformed from the image plane. Used for source_position_likelihood
force_no_add_image – bool, if True, will punish additional images appearing in the frame of the modelled image(first calculate them)
restrict_image_number – bool, if True, searches for all appearing images in the frame of the data and compares with max_num_images
max_num_images – integer, maximum number of appearing images. Default is the number of images given in the Param() class
- logL(kwargs_lens, kwargs_ps, kwargs_special, verbose=False)[source]¶
- Parameters:
kwargs_lens – lens model parameter keyword argument list
kwargs_ps – point source model parameter keyword argument list
kwargs_special – special keyword arguments
verbose – bool
- Returns:
log likelihood of the optional likelihoods being computed
- check_additional_images(kwargs_ps, kwargs_lens)[source]¶
Checks whether additional images have been found and placed in kwargs_ps.
- Parameters:
kwargs_ps – point source kwargs
kwargs_lens – lens model keyword arguments
- Returns:
bool, True if more image positions are found than originally been assigned
- static astrometric_likelihood(kwargs_ps, kwargs_special, sigma)[source]¶
Evaluates the astrometric uncertainty of the model plotted point sources (only available for ‘LENSED_POSITION’ point source model) and predicted image position by the lens model including an astrometric correction term.
- Parameters:
kwargs_ps – point source model kwargs list
kwargs_special – kwargs list, should include the astrometric corrections ‘delta_x’, ‘delta_y’
sigma – 1-sigma Gaussian uncertainty in the astrometry
- Returns:
log likelihood of the astrometirc correction between predicted image positions and model placement of the point sources
- image_position_likelihood(kwargs_ps, kwargs_lens, sigma)[source]¶
Computes the likelihood of the model predicted image position relative to measured image positions with an astrometric error. This routine requires the ‘ra_image_list’ and ‘dec_image_list’ being declared in the initiation of the class.
- Parameters:
kwargs_ps – point source keyword argument list
kwargs_lens – lens model keyword argument list
sigma – 1-sigma uncertainty in the measured position of the images
- Returns:
log likelihood of the model predicted image positions given the data/measured image positions.
- source_position_likelihood(kwargs_lens, kwargs_ps, sigma, hard_bound_rms=None, verbose=False)[source]¶
Computes a likelihood/punishing factor of how well the source positions of multiple images match given the image position and a lens model. The likelihood level is computed in respect of a displacement in the image plane and transposed through the Hessian into the source plane.
- Parameters:
kwargs_lens – lens model keyword argument list
kwargs_ps – point source keyword argument list
sigma – 1-sigma Gaussian uncertainty in the image plane
hard_bound_rms – hard bound deviation between the mapping of the images back to the source plane (in source frame)
verbose – bool, if True provides print statements with useful information.
- Returns:
log likelihood of the model reproducing the correct image positions given an image position uncertainty
- property num_data¶
- Returns:
integer, number of data points associated with the class instance
lenstronomy.Sampling.Likelihoods.prior_likelihood module¶
- class PriorLikelihood(prior_lens=None, prior_source=None, prior_lens_light=None, prior_ps=None, prior_special=None, prior_extinction=None, prior_lens_kde=None, prior_source_kde=None, prior_lens_light_kde=None, prior_ps_kde=None, prior_special_kde=None, prior_extinction_kde=None, prior_lens_lognormal=None, prior_source_lognormal=None, prior_lens_light_lognormal=None, prior_ps_lognormal=None, prior_special_lognormal=None, prior_extinction_lognormal=None)[source]¶
Bases:
objectClass containing additional Gaussian priors to be folded into the likelihood.
- __init__(prior_lens=None, prior_source=None, prior_lens_light=None, prior_ps=None, prior_special=None, prior_extinction=None, prior_lens_kde=None, prior_source_kde=None, prior_lens_light_kde=None, prior_ps_kde=None, prior_special_kde=None, prior_extinction_kde=None, prior_lens_lognormal=None, prior_source_lognormal=None, prior_lens_light_lognormal=None, prior_ps_lognormal=None, prior_special_lognormal=None, prior_extinction_lognormal=None)[source]¶
- Parameters:
prior_lens – list of [index_model, param_name, mean, 1-sigma priors]
prior_source – list of [index_model, param_name, mean, 1-sigma priors]
prior_lens_light – list of [index_model, param_name, mean, 1-sigma priors]
prior_ps – list of [index_model, param_name, mean, 1-sigma priors]
prior_special – list of [param_name, mean, 1-sigma priors]
prior_extinction – list of [index_model, param_name, mean, 1-sigma priors]
prior_lens_kde – list of [index_model, param_name, samples]
prior_source_kde – list of [index_model, param_name, samples]
prior_lens_light_kde – list of [index_model, param_name, samples]
prior_ps_kde – list of [index_model, param_name, samples]
prior_special_kde – list of [param_name, samples]
prior_extinction_kde – list of [index_model, param_name, samples]
prior_lens_lognormal – list of [index_model, param_name, mean, 1-sigma priors]
prior_source_lognormal – list of [index_model, param_name, mean, 1-sigma priors]
prior_lens_light_lognormal – list of [index_model, param_name, mean, 1-sigma priors]
prior_ps_lognormal – list of [index_model, param_name, mean, 1-sigma priors]
prior_special_lognormal – list of [param_name, mean, 1-sigma priors]
prior_extinction_lognormal – list of [index_model, param_name, mean, 1-sigma priors]
lenstronomy.Sampling.Likelihoods.time_delay_likelihood module¶
- class TimeDelayLikelihood(time_delays_measured, time_delays_uncertainties, lens_model_class, point_source_class, time_delay_measurement_bool_list=None, bimodal_measurement=False)[source]¶
Bases:
objectClass to compute the likelihood of a model given a measurement of time delays.
- __init__(time_delays_measured, time_delays_uncertainties, lens_model_class, point_source_class, time_delay_measurement_bool_list=None, bimodal_measurement=False)[source]¶
- Parameters:
time_delays_measured – relative time delays (in days) in respect to the first image of the point source
time_delays_uncertainties – time-delay uncertainties in same order as time_delay_measured. Alternatively a full covariance matrix that describes the likelihood.
lens_model_class – instance of the LensModel() class
point_source_class – instance of the PointSource() class, note: the first point source type is the one the time delays are imposed on
time_delay_measurement_bool_list – list of list of bool to indicate for which point source model a measurement is available. This list must have the same length as time_delays_measured and time_delays_uncertainties. Example for two point sources, imaged 4 times each: [[True, False, True], [True, True, True]]
bimodal_measurement (bool) – if True, two sets of delays are required. Only allowed for one set of point sources
- logL(kwargs_lens, kwargs_ps, kwargs_cosmo, lambda_mst=1)[source]¶
Routine to compute the log likelihood of the time-delay distance.
- Parameters:
kwargs_lens – lens model kwargs list
kwargs_ps – point source kwargs list
kwargs_cosmo – cosmology and other kwargs
lambda_mst (float or int) – mass-sheet transform of the input lens model that is not accounted for in the lens model parameters
- Returns:
log likelihood of the model given the time delay data.
- property num_data¶
- Returns:
number of time delay measurements
lenstronomy.Sampling.Likelihoods.tracer_likelihood module¶
- class TracerLikelihood(tracer_data, kwargs_model, kwargs_imaging, tracer_likelihood_mask=None, linear_solver=True)[source]¶
Bases:
objectClass to evaluate the tracer map.
- __init__(tracer_data, kwargs_model, kwargs_imaging, tracer_likelihood_mask=None, linear_solver=True)[source]¶
- Parameters:
tracer_bands_compute – list of bools with same length as data objects, indicates which “band” to include in the fitting
tracer_likelihood_mask – boolean 2d arrays of size of images marking the pixels to be
linear_solver – boolean, if True, linear solver for surface brigthness amplitude is activated evaluated in the likelihood
- logL(kwargs_tracer_source, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None, param=None)[source]¶
- Parameters:
kwargs_lens – lens model keyword argument list according to LensModel module
kwargs_source – source light keyword argument list according to LightModel module
kwargs_lens_light – deflector light (not lensed) keyword argument list according to LightModel module
kwargs_ps – point source keyword argument list according to PointSource module
kwargs_special – special keyword argument list as part of the Param module
kwargs_extinction – extinction parameter keyword argument list according to LightModel module
- Returns:
log likelihood of the data given the model
- property num_data¶
- Returns:
number of image data points