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.joint_linear_vary_background module

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

Bases: MultiLinear

Class to model multiple exposures and makes a joint linear fit across all bands simultaneously, with shared surface brightness constraints and a free per-band background level.

Like JointLinear, the same surface brightness models must be called in all bands. Unlike JointLinear, each band has an additional free constant background parameter appended to the end of the linear parameter vector. This is not compatible with other lenstronomy fitting methods (e.g. FittingSequence).

The returned param array has length N_model_params + N_bands, where the last N_bands entries are the best-fit background levels for each band in the order they appear in multi_band_list.

Note

The purpose of this class is to calculate the optimum flux for all bands simultaneously, assuming transparency corrections have already been applied via flux_scaling, while allowing the sky background to be different in each exposure. The joint solve yields better-constrained source fluxes than fitting each band independently, because the shared model parameters are constrained by all the data at once.

In ground-based observing, sky transparency variations can introduce a multiplicative offset between exposures. It is recommended to first fit each exposure independently using MultiLinear to measure the relative image amplitudes, and then pass these as flux_scaling in each band’s kwargs_data. This corrects for transparency offsets before the joint solve.

Usage:

from lenstronomy.ImSim.MultiBand.joint_linear_vary_background import JointLinear_VaryBG
image_model = JointLinear_VaryBG(multi_band_list, kwargs_model)
model, error_map, cov_param, param_vals = image_model.image_linear_solve(
    inv_bool=True, **kwargs_result
)
# param_vals[-N_bands:] are the best-fit background values per band
__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:

list of best-fit 2D model images (one per band), list of model error maps, covariance matrix of shape (N_params + N_bands, N_params + N_bands) or None if inv_bool is False, and 1D parameter array of length N_params + N_bands (last N_bands entries are the per-band background levels)

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 of shape (N_params + N_bands, N_pixels_total), where the last N_bands rows encode the per-band constant background: row N_params + i is all-ones for band i’s pixels and zero elsewhere.

Parameters:
  • kwargs_lens

  • kwargs_source

  • kwargs_lens_light

  • kwargs_ps

Returns:

2D numpy array of shape (N_params + N_bands, N_pixels_total)

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 – list of keyword arguments for the mass profiles

  • kwargs_source – list of keyword arguments for the source light profiles

  • kwargs_lens_light – list of keyword arguments for the lens light profiles

  • kwargs_ps – list of keyword arguments for point sources

  • 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), linear parameters

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 – integer, which band the model parameters need to be retrieved

  • kwargs_lens – list of keyword arguments for the mass profiles

  • kwargs_source – list of keyword arguments for the source light profiles

  • kwargs_lens_light – list of keyword arguments for the lens light profiles

  • kwargs_ps – list of keyword arguments for point sources

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, ImageModel

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

  • kwargs_extinction – list of keyword arguments for extinction model

  • kwargs_special – list of special keyword arguments

  • 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

  • kwargs_special – list of special keyword arguments

  • 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 – list of dicts containing point source keyword arguments

  • kwargs_lens – list of dicts containing lens model keyword arguments

  • kwargs_special – list of dicts containing “special” keywords

  • unconvolved – bool, if False, applies convolution

  • k – int or tuple, only evaluate the k-th point source model

Returns:

image of point source

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

  • kwargs_extinction – keyword arguments corresponding to dust extinction

  • kwargs_special – keyword arguments corresponding to “special” parameters

  • 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=None)[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 – list of dicts containing lens model keyword arguments

  • kwargs_source – list of dicts containing source model keyword arguments

  • kwargs_lens_light – list of dicts containing lens light model keyword arguments

  • kwargs_ps – list of dicts containing point source keyword arguments

  • kwargs_extinction – keyword arguments corresponding to dust extinction

  • kwargs_special – keyword arguments corresponding to “special” parameters

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

  • linear_solver – bool or None. If None, uses self.linear_solver by default. Allows the user to deactivate or activate linear solve if desired.

Returns:

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

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

Links linear parameters to kwargs arguments.

Parameters:
  • param – linear parameter vector corresponding to the response matrix

  • kwargs_lens – list of dicts containing lens model keyword arguments

  • kwargs_source – list of dicts containing source model keyword arguments

  • kwargs_lens_light – list of dicts containing lens light model keyword arguments

  • kwargs_ps – list of dicts containing point source keyword arguments

Returns:

updated list of kwargs with linear parameter values

num_param_linear(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None)[source]
Parameters:
  • kwargs_lens – list of dicts containing lens model keyword arguments

  • kwargs_source – list of dicts containing source model keyword arguments

  • kwargs_lens_light – list of dicts containing lens light model keyword arguments

  • kwargs_ps – list of dicts containing point source keyword arguments

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 being the data size and m being the coefficients.

Parameters:
  • kwargs_lens – list of dicts containing lens model keyword arguments

  • kwargs_source – list of dicts containing source model keyword arguments

  • kwargs_lens_light – list of dicts containing lens light model keyword arguments

  • kwargs_ps – list of dicts containing point source keyword arguments

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

  • kwargs_special – keyword arguments corresponding to “special” parameters

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.

Parameters:
  • kwargs_lens – list of dicts containing lens model keyword arguments

  • kwargs_ps – list of dicts containing point source keyword arguments

  • kwargs_special – keyword arguments corresponding to “special” parameters

Returns:

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

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 corresponding to “special” parameters

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 – list of dicts containing source model keyword arguments

  • kwargs_lens_light – list of dicts containing lens light model keyword arguments

  • kwargs_ps – list of dicts containing point source keyword arguments

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 – list of dicts containing lens model keyword arguments

  • kwargs_source – list of dicts containing source model keyword arguments

  • kwargs_lens_light – list of dicts containing lens light model keyword arguments

  • kwargs_ps – list of dicts containing point source keyword arguments

  • kwargs_extinction – list of keyword arguments of extinction model

Returns:

downselected list of kwargs corresponding to the index lists

Module contents