lenstronomy.Sampling.Likelihoods package

Submodules

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: object

Manages 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

num_param_linear(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None, kwargs_tracer_source=None)[source]
Returns:

number of linear parameters solved for during the image reconstruction process

reset_point_source_cache(cache=True)[source]
Parameters:

cache – boolean

Returns:

None

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=False, check_matched_source_position=False, source_position_tolerance=0.001, source_position_sigma=0.001, force_no_add_image=False, restrict_image_number=False, max_num_images=None)[source]

Bases: object

Likelihood 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=False, check_matched_source_position=False, source_position_tolerance=0.001, 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)

  • check_matched_source_position – bool, if True, checks whether multiple images are a solution of the same source

  • source_position_tolerance – tolerance level (in arc seconds in the source plane) of the different images

  • source_position_sigma – r.m.s. value corresponding to a 1-sigma Gaussian likelihood accepted by the model precision in matching the source position

  • 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 of the first point source model.

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: object

Class 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]

logL(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None, kwargs_tracer_source=None)[source]
Parameters:

kwargs_lens – lens model parameter list

Returns:

log likelihood of lens center

lenstronomy.Sampling.Likelihoods.time_delay_likelihood module

class TimeDelayLikelihood(time_delays_measured, time_delays_uncertainties, lens_model_class, point_source_class)[source]

Bases: object

Class 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)[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

logL(kwargs_lens, kwargs_ps, kwargs_cosmo)[source]

Routine to compute the log likelihood of the time delay distance :param kwargs_lens: lens model kwargs list :param kwargs_ps: point source kwargs list :param kwargs_cosmo: cosmology and other kwargs :return: log likelihood of the model given the time delay data.

property num_data
Returns:

number of time delay measurements

Module contents