jaxtronomy.ImSim package¶
Subpackages¶
- jaxtronomy.ImSim.MultiBand package
- Submodules
- jaxtronomy.ImSim.MultiBand.single_band_multi_model module
SingleBandMultiModelSingleBandMultiModel.__init__()SingleBandMultiModel.image()SingleBandMultiModel.source_surface_brightness()SingleBandMultiModel.lens_surface_brightness()SingleBandMultiModel.point_source()SingleBandMultiModel.image_linear_solve()SingleBandMultiModel.likelihood_data_given_model()SingleBandMultiModel.update_linear_kwargs()SingleBandMultiModel.num_param_linear()SingleBandMultiModel.linear_response_matrix()SingleBandMultiModel.error_map_source()SingleBandMultiModel.error_response()SingleBandMultiModel.linear_param_from_kwargs()SingleBandMultiModel.select_kwargs()
- Module contents
- jaxtronomy.ImSim.Numerics package
- Submodules
- jaxtronomy.ImSim.Numerics.convolution module
- jaxtronomy.ImSim.Numerics.grid module
- jaxtronomy.ImSim.Numerics.numerics module
- jaxtronomy.ImSim.Numerics.numerics_subframe module
- jaxtronomy.ImSim.Numerics.point_source_rendering module
- Module contents
Submodules¶
jaxtronomy.ImSim.de_lens module¶
- get_param_WLS(A, C_D_inv, d, inv_bool=True)[source]¶
Returns the parameter values given.
- Parameters:
A – response matrix Nd x Ns (Nd = # data points, Ns = # parameters)
C_D_inv – inverse covariance matrix of the data, Nd x Nd, diagonal form
d – data array, 1-d Nd
inv_bool – boolean, whether returning also the inverse matrix or just solve the linear system
- Returns:
1-d array of parameter values
jaxtronomy.ImSim.image_linear_solve module¶
- class ImageLinearFit(data_class, psf_class, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None, extinction_class=None, kwargs_numerics=None, likelihood_mask=None, psf_error_map_bool_list=None, kwargs_pixelbased=None)[source]¶
Bases:
ImageModelLinear version class, inherits ImageModel.
When light models use pixel-based profile types, such as ‘SLIT_STARLETS’, the WLS linear inversion is replaced by the regularized inversion performed by an external solver. The current pixel-based solver is provided by the SLITronomy plug-in.
- __init__(data_class, psf_class, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None, extinction_class=None, kwargs_numerics=None, likelihood_mask=None, psf_error_map_bool_list=None, kwargs_pixelbased=None)[source]¶
- Parameters:
data_class – ImageData() instance
psf_class – PSF() instance
lens_model_class – LensModel() instance
source_model_class – LightModel() instance
lens_light_model_class – LightModel() instance
point_source_class – PointSource() instance
extinction_class – DifferentialExtinction() instance
kwargs_numerics – keyword arguments passed to the Numerics module
likelihood_mask – 2d boolean array of pixels to be counted in the likelihood calculation/linear optimization
psf_error_map_bool_list – list of boolean of length of point source models. Indicates whether PSF error map is used for the point source model stated as the index.
kwargs_pixelbased – keyword arguments with various settings related to the pixel-based solver (see SLITronomy documentation) being applied to the point sources.
- 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). By default, the linear parameters are computed with a weighted linear least square optimization (i.e. flux normalization of the brightness profiles) However in case of pixel-based modelling, pixel values are constrained by an external solver (e.g. SLITronomy).
- 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
inv_bool – if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix. This has no impact in case of pixel-based modelling.
- Returns:
2d 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 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
source_marg – bool, performs a marginalization over the linear parameters
linear_prior – linear prior width in eigenvalues
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), linear parameter list
- likelihood_data_given_model_solution(model, model_error, cov_matrix, param, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, source_marg=False, linear_prior=None, check_positive_flux=False)[source]¶
- Parameters:
model – 2d array, image model
model_error – 2d array, uncertainties in each pixel
cov_matrix – 2d array, covariance matrix
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
kwargs_extinction – list of keyword arguments for extinction model
kwargs_special – list of special keyword arguments
source_marg – bool, performs a marginalization over the linear parameters
linear_prior – linear prior width in eigenvalues
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:
float, likelihood data given model
- num_param_linear(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)[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, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_extinction=None, kwargs_special=None, unconvolved=False)[source]¶
Computes the linear response matrix (m x n), with n being the data size and m being the coefficients.
The calculation is done by - first (optional) computing differential extinctions - adding linear components of the lensed source(s) - adding linear components of the unlensed components (i.e. deflector) - adding point sources (can be multiple lensed or stars in the field)
- 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 – bool, if True, computes components without convolution kernel (will not work for point sources)
- Returns:
response matrix (m x n)
- update_linear_kwargs(param, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)[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
- linear_param_from_kwargs(kwargs_source, kwargs_lens_light, kwargs_ps)[source]¶
Returns list of the linear amplitudes from the keyword arguments.
- 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
- error_map_source(kwargs_source, x_grid, y_grid, cov_param)[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 linear inversion parameters
- Returns:
diagonal covariance errors at the positions (x_grid, y_grid)
- point_source_linear_response_set(kwargs_ps, kwargs_lens, kwargs_special=None, with_amp=True)[source]¶
- Parameters:
kwargs_ps – point source keyword argument list
kwargs_lens – lens model keyword argument list
kwargs_special – special keyword argument list, may include ‘delta_x_image’ and ‘delta_y_image’
with_amp – bool, if True, relative magnification between multiply imaged point sources are held fixed.
- Returns:
list of positions and amplitudes split in different basis components with applied astrometric corrections
- check_positive_flux(kwargs_source, kwargs_lens_light, kwargs_ps)[source]¶
Checks whether the surface brightness profiles contain positive fluxes and returns bool if True.
- Parameters:
kwargs_source – source surface brightness keyword argument list
kwargs_lens_light – lens surface brightness keyword argument list
kwargs_ps – point source keyword argument list
- Returns:
boolean
jaxtronomy.ImSim.image_model module¶
- class ImageModel(data_class, psf_class, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None, extinction_class=None, kwargs_numerics=None, likelihood_mask=None, psf_error_map_bool_list=None, kwargs_pixelbased=None)[source]¶
Bases:
objectThis class uses functions of lens_model and source_model to make a lensed image.
- __init__(data_class, psf_class, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None, extinction_class=None, kwargs_numerics=None, likelihood_mask=None, psf_error_map_bool_list=None, kwargs_pixelbased=None)[source]¶
- Parameters:
data_class – instance of ImageData() or PixelGrid() class
psf_class – instance of PSF() class
lens_model_class – instance of LensModel() class
source_model_class – instance of LightModel() class describing the source parameters
lens_light_model_class – instance of LightModel() class describing the lens light parameters
point_source_class – instance of PointSource() class describing the point sources
kwargs_numerics – keyword arguments with various numeric description (see ImageNumerics class for options)
likelihood_mask – 2d boolean array of pixels to be counted in the likelihood calculation. Must be a np array; cannot be a jnp array.
psf_error_map_bool_list – list of boolean of length of point source models. Indicates whether PSF error map is used for the point source model stated as the index.
kwargs_pixelbased – kwargs for pixelbased solver; not supported in jaxtronomy. Must be None
- 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 dicts, keyword arguments corresponding to the superposition of different lens profiles in the same order of the lens_model_list
kwargs_source – list of dicts, keyword arguments corresponding to the superposition of different source light profiles in the same order of light_model_list
kwargs_lens_light – list of dicts, keyword arguments corresponding to different lens light surface brightness profiles in the same order of lens_light_model_list
kwargs_ps – list of dicts, keyword arguments for the points source models in the same order of point_source_type_list
kwargs_extinction – list of dicts, keyword arguments corresponding to different light profiles in the optical_depth_model
kwargs_special – optional dict including keys “delta_x_image” and “delta_y_image” and array/list values indicating how much to shift each point source image in units of arcseconds
source_marg – bool, performs a marginalization over the linear parameters
linear_prior – linear prior width in eigenvalues
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, if True (default) fixes the linear amplitude parameters ‘amp’ (avoid sampling) such that they get overwritten by the linear solver solution. Should always be false in jaxtronomy
- Returns:
log likelihood (natural logarithm), linear parameter list
- 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 dicts, keyword arguments corresponding to the superposition of different source light profiles in the same order of light_model_list
kwargs_lens – list of dicts, keyword arguments corresponding to the superposition of different lens profiles in the same order of the lens_model_list
kwargs_extinction – list of dicts, keyword arguments corresponding to different light profiles in the optical_depth_model
kwargs_special – optional dict including keys “delta_x_image” and “delta_y_image” and array/list values indicating how much to shift each point source image in units of arcseconds
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, keyword arguments for each point source model in the same order of the point_source_type_list
kwargs_lens – list of dicts, keyword arguments for the full set of lens models in the same order of the lens_model_list
kwargs_special – optional dict including keys “delta_x_image” and “delta_y_image” and array/list values indicating how much to shift each point source image in units of arcseconds
unconvolved – bool, includes point source images if False, excludes ps if True
k – optional int, include only the k-th point source model. If None, includes all
- Returns:
rendered point source images
- 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 dicts, keyword arguments corresponding to the superposition of different lens profiles in the same order of the lens_model_list
kwargs_source – list of dicts, keyword arguments corresponding to the superposition of different source light profiles in the same order of light_model_list
kwargs_lens_light – list of dicts, keyword arguments corresponding to different lens light surface brightness profiles in the same order of lens_light_model_list
kwargs_ps – list of dicts, keyword arguments for the points source models in the same order of point_source_type_list
kwargs_extinction – list of dicts, keyword arguments corresponding to different light profiles in the optical_depth_model
kwargs_special – optional dict including keys “delta_x_image” and “delta_y_image” and array/list values indicating how much to shift each point source image in units of arcseconds
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
- reduced_residuals(model, error_map=0)[source]¶
- Parameters:
model – 2d numpy array of the modeled image
error_map – 2d numpy array of additional noise/error terms from model components (such as PSF model uncertainties)
- Returns:
2d numpy array of reduced residuals per pixel
- reduced_chi2(model, error_map=0)[source]¶
Returns reduced chi2.
- Parameters:
model – 2d numpy array of a model predicted image
error_map – same format as model, additional error component (such as PSF errors)
- Returns:
reduced chi2.
- image2array_masked(image)[source]¶
Returns 1d array of values in image that are not masked out for the likelihood computation/linear minimization.
- Parameters:
image – 2d numpy array of full image
- Returns:
1d array.
- array_masked2image(array)[source]¶
Converts the 1d masked array into a 2d image.
- Parameters:
array – 1d array of values not masked out
- Returns:
2d array of full image
- 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)[source]¶
Returns the 1d array of the error estimate corresponding to the data response.
- Parameters:
kwargs_lens – list of dicts, keyword arguments corresponding to the superposition of different lens profiles in the same order of the lens_model_list
kwargs_ps – list of dicts, keyword arguments for the points source models in the same order of point_source_type_list
kwargs_special – optional dict including keys “delta_x_image” and “delta_y_image” and array/list values indicating how much to shift each point source image in units of arcseconds
- Returns:
1d numpy array of response, 2d array of additional errors (e.g. point source uncertainties)