lenstronomy.ImSim.MultiBand package

Submodules

lenstronomy.ImSim.MultiBand.joint_linear module

class JointLinear(multi_band_list, kwargs_model, compute_bool=None, likelihood_mask_list=None)[source]

Bases: MultiLinear

Class to model multiple exposures in the same band and makes a constraint fit to all bands simultaneously with joint constraints on the surface brightness of the model.

This model setting require the same surface brightness models to be called in all available images/bands

__init__(multi_band_list, kwargs_model, compute_bool=None, likelihood_mask_list=None)[source]
Parameters:
  • multi_band_list – list of imaging band configurations [[kwargs_data, kwargs_psf, kwargs_numerics],[…], …]

  • kwargs_model – model option keyword arguments

  • likelihood_mask_list – list of likelihood masks (booleans with size of the individual images)

  • compute_bool – (optional), bool list to indicate which band to be included in the modeling

  • linear_solver – bool, if True (default) fixes the linear amplitude parameters ‘amp’ (avoid sampling) such that they get overwritten by the linear solver solution.

image_linear_solve(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, inv_bool=False)[source]

Computes the image (lens and source surface brightness with a given lens model). The linear parameters are computed with a weighted linear least square optimization (i.e. flux normalization of the brightness profiles)

Parameters:
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • kwargs_ps – keyword arguments corresponding to “other” parameters, such as external shear and point source image positions

  • inv_bool – if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix.

Returns:

1d array of surface brightness pixels of the optimal solution of the linear parameters to match the data

linear_response_matrix(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None)[source]

Computes the linear response matrix (m x n), with n being the data size and m being the coefficients.

Parameters:
  • kwargs_lens

  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

Returns:

property data_response

Returns the 1d array of the data element that is fitted for (including masking)

Returns:

1d numpy array

error_response(kwargs_lens, kwargs_ps, kwargs_special=None)[source]

Returns the 1d array of the error estimate corresponding to the data response.

Returns:

1d numpy array of response, 2d array of additonal errors (e.g. point source uncertainties)

likelihood_data_given_model(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, check_positive_flux=False)[source]

Computes the likelihood of the data given a model This is specified with the non-linear parameters and a linear inversion and prior marginalisation.

Parameters:
  • kwargs_lens

  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

  • check_positive_flux – bool, if True, checks whether the linear inversion resulted in non-negative flux components and applies a punishment in the likelihood if so.

Returns:

log likelihood (natural logarithm) (sum of the log likelihoods of the individual images)

update_linear_kwargs(param, model_band, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)[source]
Parameters:
  • param

  • model_band

  • kwargs_lens

  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

Returns:

lenstronomy.ImSim.MultiBand.multi_data_base module

class MultiDataBase(image_model_list, compute_bool=None)[source]

Bases: object

Base class with definitions that are shared among all variations of modelling multiple data sets.

__init__(image_model_list, compute_bool=None)[source]
Parameters:
  • image_model_list – list of ImageModel instances (supporting linear inversions)

  • compute_bool – list of booleans for each imaging band indicating whether to model it or not.

property num_bands
property num_response_list

List of number of data elements that are used in the minimization.

Returns:

list of integers

reset_point_source_cache(cache=True)[source]

Deletes all the cache in the point source class and saves it from then on.

Returns:

property num_data_evaluate
num_param_linear(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)[source]
Returns:

number of linear coefficients to be solved for in the linear inversion

reduced_residuals(model_list, error_map_list=None)[source]
Parameters:
  • model_list – list of models

  • error_map_list – list of error maps

Returns:

lenstronomy.ImSim.MultiBand.multi_linear module

class MultiLinear(multi_band_list, kwargs_model, likelihood_mask_list=None, compute_bool=None, kwargs_pixelbased=None, linear_solver=True)[source]

Bases: MultiDataBase

Class to simulate/reconstruct images in multi-band option. This class calls functions of image_model.py with different bands with joint non-linear parameters and decoupled linear parameters.

the class supports keyword arguments ‘index_lens_model_list’, ‘index_source_light_model_list’, ‘index_lens_light_model_list’, ‘index_point_source_model_list’, ‘index_optical_depth_model_list’ in kwargs_model These arguments should be lists of length the number of imaging bands available and each entry in the list is a list of integers specifying the model components being evaluated for the specific band.

E.g. there are two bands and you want to different light profiles being modeled. - you define two different light profiles lens_light_model_list = [‘SERSIC’, ‘SERSIC’] - set index_lens_light_model_list = [[0], [1]] - (optional) for now all the parameters between the two light profiles are independent in the model. You have the possibility to join a subset of model parameters (e.g. joint centroid). See the Param() class for documentation.

__init__(multi_band_list, kwargs_model, likelihood_mask_list=None, compute_bool=None, kwargs_pixelbased=None, linear_solver=True)[source]
Parameters:
  • multi_band_list – list of imaging band configurations [[kwargs_data, kwargs_psf, kwargs_numerics],[…], …]

  • kwargs_model – model option keyword arguments

  • likelihood_mask_list – list of likelihood masks (booleans with size of the individual images)

  • compute_bool – (optional), bool list to indicate which band to be included in the modeling

  • linear_solver – bool, if True (default) fixes the linear amplitude parameters ‘amp’ (avoid sampling) such that they get overwritten by the linear solver solution.

image_linear_solve(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, inv_bool=False)[source]

Computes the image (lens and source surface brightness with a given lens model). The linear parameters are computed with a weighted linear least square optimization (i.e. flux normalization of the brightness profiles)

Parameters:
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • kwargs_ps – keyword arguments corresponding to “other” parameters, such as external shear and point source image positions

  • inv_bool – if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix.

Returns:

1d array of surface brightness pixels of the optimal solution of the linear parameters to match the data

likelihood_data_given_model(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, check_positive_flux=False)[source]

Computes the likelihood of the data given a model This is specified with the non-linear parameters and a linear inversion and prior marginalisation.

Parameters:
  • kwargs_lens

  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

  • check_positive_flux – bool, if True, checks whether the linear inversion resulted in non-negative flux components and applies a punishment in the likelihood if so.

Returns:

log likelihood (natural logarithm) (sum of the log likelihoods of the individual images)

update_linear_kwargs(param, model_band, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)[source]

Links linear parameters to kwargs arguments.

Parameters:
  • param (list of array) – linear parameter vector corresponding to the response matrix

  • model_band – for which band the model parameters need to be retrieved

  • kwargs_lens

  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

Returns:

updated list of kwargs with linear parameter values for specific band

lenstronomy.ImSim.MultiBand.single_band_multi_model module

class SingleBandMultiModel(multi_band_list, kwargs_model, likelihood_mask_list=None, band_index=0, kwargs_pixelbased=None, linear_solver=True)[source]

Bases: ImageLinearFit

Class to simulate/reconstruct images in multi-band option. This class calls functions of image_model.py with different bands with decoupled linear parameters and the option to pass/select different light models for the different bands.

the class supports keyword arguments ‘index_lens_model_list’, ‘index_source_light_model_list’, ‘index_lens_light_model_list’, ‘index_point_source_model_list’, ‘index_optical_depth_model_list’ in kwargs_model These arguments should be lists of length the number of imaging bands available and each entry in the list is a list of integers specifying the model components being evaluated for the specific band.

E.g. there are two bands, and you want to different light profiles being modeled. - you define two different light profiles lens_light_model_list = [‘SERSIC’, ‘SERSIC’] - set index_lens_light_model_list = [[0], [1]] - (optional) for now all the parameters between the two light profiles are independent in the model. You have the possibility to join a subset of model parameters (e.g. joint centroid). See the Param() class for documentation.

__init__(multi_band_list, kwargs_model, likelihood_mask_list=None, band_index=0, kwargs_pixelbased=None, linear_solver=True)[source]
Parameters:
  • multi_band_list – list of imaging band configurations [[kwargs_data, kwargs_psf, kwargs_numerics],[…], …]

  • kwargs_model – model option keyword arguments

  • likelihood_mask_list – list of likelihood masks (booleans with size of the individual images

  • band_index – integer, index of the imaging band to model

  • 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.

image(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, unconvolved=False, source_add=True, lens_light_add=True, point_source_add=True)[source]

Make an image with a realisation of linear parameter values “param”.

Parameters:
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • kwargs_ps – keyword arguments corresponding to “other” parameters, such as external shear and point source image positions

  • unconvolved – if True: returns the unconvolved light distribution (prefect seeing)

  • source_add – if True, compute source, otherwise without

  • lens_light_add – if True, compute lens light, otherwise without

  • point_source_add – if True, add point sources, otherwise without

Returns:

2d array of surface brightness pixels of the simulation

source_surface_brightness(kwargs_source, kwargs_lens=None, kwargs_extinction=None, kwargs_special=None, unconvolved=False, de_lensed=False, k=None, update_pixelbased_mapping=True)[source]

Computes the source surface brightness distribution.

Parameters:
  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • kwargs_extinction – list of keyword arguments of extinction model

  • unconvolved – if True: returns the unconvolved light distribution (prefect seeing)

  • de_lensed – if True: returns the un-lensed source surface brightness profile, otherwise the lensed.

  • k – integer, if set, will only return the model of the specific index

Returns:

2d array of surface brightness pixels

lens_surface_brightness(kwargs_lens_light, unconvolved=False, k=None)[source]

Computes the lens surface brightness distribution.

Parameters:
  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • unconvolved – if True, returns unconvolved surface brightness (perfect seeing), otherwise convolved with PSF kernel

Returns:

2d array of surface brightness pixels

point_source(kwargs_ps, kwargs_lens=None, kwargs_special=None, unconvolved=False, k=None)[source]

Computes the point source positions and paints PSF convolutions on them.

Parameters:
  • kwargs_ps

  • kwargs_lens

  • kwargs_special

  • unconvolved

  • k

Returns:

image_linear_solve(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, inv_bool=False)[source]

Computes the image (lens and source surface brightness with a given lens model).

The linear parameters are computed with a weighted linear least square optimization (i.e. flux normalization of the brightness profiles)

Parameters:
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • kwargs_ps – keyword arguments corresponding to “other” parameters, such as external shear and point source image positions

  • inv_bool – if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix.

Returns:

1d array of surface brightness pixels of the optimal solution of the linear parameters to match the data

likelihood_data_given_model(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, check_positive_flux=False, linear_solver=True)[source]

Computes the likelihood of the data given a model This is specified with the non-linear parameters and a linear inversion and prior marginalisation.

Parameters:
  • kwargs_lens

  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

  • check_positive_flux – bool, if True, checks whether the linear inversion resulted in non-negative flux components and applies a punishment in the likelihood if so.

Returns:

log likelihood (natural logarithm) (sum of the log likelihoods of the individual images)

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

number of linear coefficients to be solved for in the linear inversion

linear_response_matrix(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None)[source]

Computes the linear response matrix (m x n), with n beeing the data size and m being the coefficients.

Parameters:
  • kwargs_lens

  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

Returns:

error_map_source(kwargs_source, x_grid, y_grid, cov_param, model_index_select=True)[source]

Variance of the linear source reconstruction in the source plane coordinates, computed by the diagonal elements of the covariance matrix of the source reconstruction as a sum of the errors of the basis set.

Parameters:
  • kwargs_source – keyword arguments of source model

  • x_grid – x-axis of positions to compute error map

  • y_grid – y-axis of positions to compute error map

  • cov_param – covariance matrix of liner inversion parameters

  • model_index_select – boolean, if True, selects the model components of this band (default). If False, assumes input kwargs_source is already selected list.

Returns:

diagonal covariance errors at the positions (x_grid, y_grid)

error_response(kwargs_lens, kwargs_ps, kwargs_special)[source]

Returns the 1d array of the error estimate corresponding to the data response.

Returns:

1d numpy array of response, 2d array of additional errors (e.g. point source uncertainties)

update_linear_kwargs(param, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, model_band=None)[source]

links linear parameters to kwargs arguments ATTENTION: this function requires input dictionary lists to be already contracted to the ones applied to the specific band

Parameters:

param – linear parameter vector corresponding to the response matrix

Returns:

updated list of kwargs with linear parameter values

extinction_map(kwargs_extinction=None, kwargs_special=None)[source]

Differential extinction per pixel.

Parameters:
  • kwargs_extinction – list of keyword arguments corresponding to the optical depth models tau, such that extinction is exp(-tau)

  • kwargs_special – keyword arguments, additional parameter to the extinction

Returns:

2d array of size of the image

linear_param_from_kwargs(kwargs_source, kwargs_lens_light, kwargs_ps)[source]

Inverse function of update_linear() returning the linear amplitude list for the keyword argument list.

Parameters:
  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

Returns:

list of linear coefficients

select_kwargs(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None)[source]

Select subset of kwargs lists referenced to this imaging band.

Parameters:
  • kwargs_lens

  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

Returns:

Module contents