lenstronomy.Plots package¶
Submodules¶
lenstronomy.Plots.chain_plot module¶
- plot_chain_list(chain_list, index=0, num_average=100)[source]¶
Plots the output of a chain of samples (MCMC or PSO) with the some diagnostics of convergence. This routine is an example and more tests might be appropriate to analyse a specific chain.
- Parameters:
chain_list – list of chains with arguments [type string, samples etc…]
index – index of chain to be plotted
num_average – in chains, number of steps to average over in plotting diagnostics
- Returns:
plotting instance figure, axes (potentially multiple)
- plot_mcmc_behaviour(ax, samples_mcmc, param_mcmc, dist_mcmc=None, num_average=100)[source]¶
Plots the MCMC behaviour and looks for convergence of the chain.
- Parameters:
ax – matplotlib.axis instance
samples_mcmc – parameters sampled 2d numpy array
param_mcmc – list of parameters
dist_mcmc – log likelihood of the chain
num_average – number of samples to average (should coincide with the number of samples in the emcee process)
- Returns:
lenstronomy.Plots.lens_plot module¶
- lens_model_plot(ax, lensModel, kwargs_lens, numPix=500, deltaPix=0.01, sourcePos_x=0, sourcePos_y=0, point_source=False, with_caustics=False, with_convergence=True, coord_center_ra=0, coord_center_dec=0, coord_inverse=False, fast_caustic=True, **kwargs)[source]¶
Plots a lens model (convergence) and the critical curves and caustics.
- Parameters:
ax – matplotlib axis instance
lensModel – LensModel() class instance
kwargs_lens – lens model keyword argument list
numPix – total number of pixels (for convergence map)
deltaPix – width of pixel (total frame size is deltaPix x numPix)
sourcePos_x – float, x-position of point source (image positions computed by the lens equation)
sourcePos_y – float, y-position of point source (image positions computed by the lens equation)
point_source – bool, if True, illustrates and computes the image positions of the point source
with_caustics – bool, if True, illustrates the critical curve and caustics of the system
with_convergence – bool, if True, illustrates the convergence map
coord_center_ra – float, x-coordinate of the center of the frame
coord_center_dec – float, y-coordinate of the center of the frame
coord_inverse – bool, if True, inverts the x-coordinates to go from right-to- left (effectively the RA definition)
fast_caustic – boolean, if True, uses faster but less precise caustic calculation (might have troubles for the outer caustic (inner critical curve)
with_convergence – boolean, if True, plots the convergence of the deflector
- Returns:
matplotlib axis instance with plot
- arrival_time_surface(ax, lensModel, kwargs_lens, numPix=500, deltaPix=0.01, sourcePos_x=0, sourcePos_y=0, with_caustics=False, point_source=False, n_levels=10, kwargs_contours=None, image_color_list=None, letter_font_size=20, name_list=None)[source]¶
- Parameters:
ax – matplotlib axis instance
lensModel – LensModel() class instance
kwargs_lens – lens model keyword argument list
numPix –
deltaPix –
sourcePos_x –
sourcePos_y –
with_caustics –
point_source –
name_list (list of strings, longer or equal the number of point sources) – list of names of images
- Returns:
- curved_arc_illustration(ax, lensModel, kwargs_lens, with_centroid=True, stretch_scale=0.1, color='k')[source]¶
- Parameters:
ax – matplotlib axis instance
lensModel – LensModel() instance
kwargs_lens – list of lens model keyword arguments (only those of CURVED_ARC considered
with_centroid – plots the center of the curvature radius
stretch_scale – float, relative scale of banana to the tangential and radial stretches (effectively intrinsic source size)
color – string, matplotlib color for plot
- Returns:
matplotlib axis instance
- plot_arc(ax, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y, stretch_scale=0.1, with_centroid=True, linewidth=1, color='k', dtan_dtan=0)[source]¶
- Parameters:
ax – matplotlib.axes instance
tangential_stretch – float, stretch of intrinsic source in tangential direction
radial_stretch – float, stretch of intrinsic source in radial direction
curvature – 1/curvature radius
direction – float, angle in radian
center_x – center of source in image plane
center_y – center of source in image plane
with_centroid – plots the center of the curvature radius
stretch_scale – float, relative scale of banana to the tangential and radial stretches (effectively intrinsic source size)
linewidth – linewidth
color (string in matplotlib color convention) – color
dtan_dtan – tangential eigenvector differential in tangential direction (not implemented yet as illustration)
- Returns:
- distortions(lensModel, kwargs_lens, num_pix=100, delta_pix=0.05, center_ra=0, center_dec=0, differential_scale=0.0001, smoothing_scale=None, **kwargs)[source]¶
- Parameters:
lensModel – LensModel instance
kwargs_lens – lens model keyword argument list
num_pix – number of pixels per axis
delta_pix – pixel scale per axis
center_ra – center of the grid
center_dec – center of the grid
differential_scale – scale of the finite derivative length in units of angles
smoothing_scale – float or None, Gaussian FWHM of a smoothing kernel applied before plotting
- Returns:
matplotlib instance with different panels
lenstronomy.Plots.model_band_plot module¶
- class ModelBandPlot(multi_band_list, kwargs_model, model, error_map, cov_param, param, kwargs_params, likelihood_mask_list=None, band_index=0, arrow_size=0.02, cmap_string='gist_heat', fast_caustic=True)[source]¶
Bases:
ModelBand
Class to plot a single band given the modeling results.
- __init__(multi_band_list, kwargs_model, model, error_map, cov_param, param, kwargs_params, likelihood_mask_list=None, band_index=0, arrow_size=0.02, cmap_string='gist_heat', fast_caustic=True)[source]¶
- Parameters:
multi_band_list – list of imaging data configuration [[kwargs_data, kwargs_psf, kwargs_numerics], […]]
kwargs_model – model keyword argument list for the full multi-band modeling
model – 2d numpy array of modeled image for the specified band
error_map – 2d numpy array of size of the image, additional error in the pixels coming from PSF uncertainties
cov_param – covariance matrix of the linear inversion
param – 1d numpy array of the linear coefficients of this imaging band
kwargs_params – keyword argument of keyword argument lists of the different model components selected for the imaging band, NOT including linear amplitudes (not required as being overwritten by the param list)
likelihood_mask_list – list of 2d numpy arrays of likelihood masks (for all bands)
band_index – integer of the band to be considered in this class
arrow_size – size of the scale and orientation arrow
cmap_string – string of color map (or cmap matplotlib object)
fast_caustic – boolean; if True, uses fast (but less accurate) caustic calculation method
- data_plot(ax, v_min=None, v_max=None, text='Observed', font_size=15, colorbar_label='log$_{10}$ flux', **kwargs)[source]¶
- Parameters:
ax –
- Returns:
- model_plot(ax, v_min=None, v_max=None, image_names=False, colorbar_label='log$_{10}$ flux', font_size=15, text='Reconstructed', **kwargs)[source]¶
- Parameters:
ax – matplotib axis instance
v_min –
v_max –
- Returns:
- convergence_plot(ax, text='Convergence', v_min=None, v_max=None, font_size=15, colorbar_label='$\\log_{10}\\ \\kappa$', **kwargs)[source]¶
- Parameters:
ax – matplotib axis instance
- Returns:
convergence plot in ax instance
- substructure_plot(ax, index_macromodel, text='Substructure convergence', subtract_mean=True, v_min=-0.05, v_max=0.05, font_size=15, colorbar_label='$\\kappa - \\kappa_{\\rm{macro}}$', cmap='bwr', with_critical_curves=False, crit_curve_color='k', image_name_list=None, **kwargs)[source]¶
Plots the convergence of a full lens model minus the convergence from a few specified lens models to more clearly show the presence of substructure.
- Parameters:
ax – matplotib axis instance
index_macromodel – a list of indexes corresponding to the lens models with convergence to be subtracted
text – text appearing in frame
subtract_mean – bool; displays the substructure convergence relative to the mean convergence in the frame
v_min – minimum color scale
v_max – max color scale
font_size – font size for text appearing in image
colorbar_label – label for the color bar
cmap – colormap for use in the visualization
with_critical_curves – bool; plots the critical curves in the frame
crit_curve_color – color of the critical curves
image_name_list – labels the images, default is A, B, C, …
kwargs – any additional keyword arguments
- Returns:
matplotib axis
- normalized_residual_plot(ax, v_min=-6, v_max=6, font_size=15, text='Normalized Residuals', colorbar_label='(f${}_{\\rm model}$ - f${}_{\\rm data}$)/$\\sigma$', no_arrow=False, color_bar=True, **kwargs)[source]¶
- Parameters:
ax –
v_min –
v_max –
kwargs – kwargs to send to matplotlib.pyplot.matshow()
color_bar – Option to display the color bar
- Returns:
- absolute_residual_plot(ax, v_min=-1, v_max=1, font_size=15, text='Residuals', colorbar_label='(f$_{model}$-f$_{data}$)')[source]¶
- Parameters:
ax –
- Returns:
- source(numPix, deltaPix, center=None, image_orientation=True)[source]¶
- Parameters:
numPix – number of pixels per axes
deltaPix – pixel size
image_orientation – bool, if True, uses frame in orientation of the image, otherwise in RA-DEC coordinates
- Returns:
2d surface brightness grid of the reconstructed source and Coordinates() instance of source grid
- source_plot(ax, numPix, deltaPix_source, center=None, v_min=None, v_max=None, with_caustics=False, caustic_color='yellow', font_size=15, plot_scale='log', scale_size=0.1, text='Reconstructed source', colorbar_label='log$_{10}$ flux', point_source_position=True, **kwargs)[source]¶
- Parameters:
ax –
numPix –
deltaPix_source –
center – [center_x, center_y], if specified, uses this as the center
v_min –
v_max –
caustic_color –
font_size –
plot_scale – string, log or linear, scale of surface brightness plot
kwargs –
- Returns:
- error_map_source_plot(ax, numPix, deltaPix_source, v_min=None, v_max=None, with_caustics=False, font_size=15, point_source_position=True)[source]¶
Plots the uncertainty in the surface brightness in the source from the linear inversion by taking the diagonal elements of the covariance matrix of the inversion of the basis set to be propagated to the source plane. #TODO illustration of the uncertainties in real space with the full covariance matrix is subtle. # The best way is probably to draw realizations from the covariance matrix.
- Parameters:
ax – matplotlib axis instance
numPix – number of pixels in plot per axis
deltaPix_source – pixel spacing in the source resolution illustrated in plot
v_min – minimum plotting scale of the map
v_max – maximum plotting scale of the map
with_caustics – plot the caustics on top of the source reconstruction (may take some time)
font_size – font size of labels
point_source_position – boolean, if True, plots a point at the position of the point source
- Returns:
plot of source surface brightness errors in the reconstruction on the axis instance
- magnification_plot(ax, v_min=-10, v_max=10, image_name_list=None, font_size=15, no_arrow=False, text='Magnification model', colorbar_label='$\\det\\ (\\mathsf{A}^{-1})$', **kwargs)[source]¶
- Parameters:
ax – matplotib axis instance
v_min – minimum range of plotting
v_max – maximum range of plotting
kwargs – kwargs to send to matplotlib.pyplot.matshow()
- Returns:
- deflection_plot(ax, v_min=None, v_max=None, axis=0, with_caustics=False, image_name_list=None, text='Deflection model', font_size=15, colorbar_label='arcsec')[source]¶
- Returns:
- decomposition_plot(ax, text='Reconstructed', v_min=None, v_max=None, unconvolved=False, point_source_add=False, font_size=15, source_add=False, lens_light_add=False, **kwargs)[source]¶
- Parameters:
ax –
text –
v_min –
v_max –
unconvolved –
point_source_add –
source_add –
lens_light_add –
kwargs – kwargs to send matplotlib.pyplot.matshow()
- Returns:
lenstronomy.Plots.model_plot module¶
- class ModelPlot(multi_band_list, kwargs_model, kwargs_params, image_likelihood_mask_list=None, bands_compute=None, multi_band_type='multi-linear', source_marg=False, linear_prior=None, arrow_size=0.02, cmap_string='gist_heat', fast_caustic=True, linear_solver=True)[source]¶
Bases:
object
Class that manages the summary plots of a lens model The class uses the same conventions as being used in the FittingSequence and interfaces with the ImSim module.
The linear inversion is re-done given the likelihood settings in the init of this class (make sure this is the same as you perform the FittingSequence) to make sure the linear amplitude parameters are computed as they are not part of the output of the FittingSequence results.
- __init__(multi_band_list, kwargs_model, kwargs_params, image_likelihood_mask_list=None, bands_compute=None, multi_band_type='multi-linear', source_marg=False, linear_prior=None, arrow_size=0.02, cmap_string='gist_heat', fast_caustic=True, linear_solver=True)[source]¶
- Parameters:
multi_band_list – list of [[kwargs_data, kwargs_psf, kwargs_numerics], [], ..]
multi_band_type – string, option when having multiple imaging data sets modelled simultaneously. Options are: - ‘multi-linear’: linear amplitudes are inferred on single data set - ‘linear-joint’: linear amplitudes ae jointly inferred - ‘single-band’: single band
kwargs_model – model keyword arguments
bands_compute – (optional), bool list to indicate which band to be included in the modeling
image_likelihood_mask_list – list of image likelihood mask (same size as image_data with 1 indicating being evaluated and 0 being left out)
kwargs_params – keyword arguments of ‘kwargs_lens’, ‘kwargs_source’ etc. as coming as kwargs_result from FittingSequence class
source_marg –
linear_prior –
arrow_size –
cmap_string –
fast_caustic – boolean; if True, uses fast (but less accurate) caustic calculation method
linear_solver – bool, if True (default) fixes the linear amplitude parameters ‘amp’ (avoid sampling) such that they get overwritten by the linear solver solution.
- reconstruction_all_bands(**kwargs)[source]¶
- Parameters:
kwargs – arguments of plotting
- Returns:
3 x n_data plot with data, model, reduced residual plots of all the images/bands that are being modeled
- data_plot(band_index=0, **kwargs)[source]¶
Illustrates data.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- model_plot(band_index=0, **kwargs)[source]¶
Illustrates model.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- convergence_plot(band_index=0, **kwargs)[source]¶
Illustrates lensing convergence in data frame.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- substructure_plot(band_index=0, **kwargs)[source]¶
Illustrates substructure in the lens system.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- normalized_residual_plot(band_index=0, **kwargs)[source]¶
Illustrates normalized residuals between data and model fit.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- absolute_residual_plot(band_index=0, **kwargs)[source]¶
Illustrates absolute residuals between data and model fit.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- source_plot(band_index=0, **kwargs)[source]¶
Illustrates reconstructed source (de-lensed de-convolved)
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- error_map_source_plot(band_index=0, **kwargs)[source]¶
Illustrates surface brightness variance in the reconstruction in the source plane.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- magnification_plot(band_index=0, **kwargs)[source]¶
Illustrates lensing magnification in the field of view of the data frame.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- deflection_plot(band_index=0, **kwargs)[source]¶
Illustrates lensing deflections on the field of view of the data frame.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- decomposition_plot(band_index=0, **kwargs)[source]¶
Illustrates decomposition of model components.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- subtract_from_data_plot(band_index=0, **kwargs)[source]¶
Subtracts individual model components from the data.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- plot_main(band_index=0, **kwargs)[source]¶
Plot a set of ‘main’ modelling diagnostics.
- Parameters:
band_index – index of band
kwargs – arguments of plotting
- Returns:
plot instance
- plot_separate(band_index=0)[source]¶
Plot a set of ‘main’ modelling diagnostics.
- Parameters:
band_index – index of band
- Returns:
plot instance
- plot_subtract_from_data_all(band_index=0)[source]¶
Plot a set of ‘main’ modelling diagnostics.
- Parameters:
band_index – index of band
- Returns:
plot instance
lenstronomy.Plots.plot_util module¶
- sqrt(inputArray, scale_min=None, scale_max=None)[source]¶
Performs sqrt scaling of the input numpy array.
- Parameters:
inputArray (numpy array) – image data array
scale_min (float) – minimum data value
scale_max (float) – maximum data value
- Return type:
numpy array
- Returns:
image data array
- scale_bar(ax, d, dist=1.0, text='1"', color='w', font_size=15, flipped=False)[source]¶
- Parameters:
ax – matplotlib.axes instance
d – diameter of frame
dist – distance scale printed
text – string printed on scale bar
color – color of scale bar
font_size – font size
flipped – boolean
- Returns:
None, updated ax instance
- coordinate_arrows(ax, d, coords, color='w', font_size=15, arrow_size=0.05)[source]¶
- Parameters:
ax – matplotlib axes instance
d – diameter of frame in ax
coords – lenstronomy.Data.coord_transforms Coordinates() instance
color – color string
font_size – font size of length scale
arrow_size – size of arrow
- Returns:
updated ax instance
- plot_line_set(ax, coords, line_set_list_x, line_set_list_y, origin=None, flipped_x=False, points_only=False, *args, **kwargs)[source]¶
Plotting a line set on a matplotlib instance where the coordinates are defined in pixel units with the lower left corner (defined as origin) is by default (0, 0). The coordinates are moved by 0.5 pixels to be placed in the center of the pixel in accordance with the matplotlib.matshow() routine.
- Parameters:
ax – matplotlib.axis instance
coords – Coordinates() class instance
origin – [x0, y0], lower left pixel coordinate in the frame of the pixels
line_set_list_x – numpy arrays corresponding of different disconnected regions of the line (e.g. caustic or critical curve)
line_set_list_y – numpy arrays corresponding of different disconnected regions of the line (e.g. caustic or critical curve)
color – string with matplotlib color
flipped_x – bool, if True, flips x-axis
points_only – bool, if True, sets plotting keywords to plot single points without connecting lines
- Returns:
plot with line sets on matplotlib axis in pixel coordinates
- image_position_plot(ax, coords, ra_image, dec_image, color='w', image_name_list=None, origin=None, flipped_x=False, plot_out_of_image=True)[source]¶
- Parameters:
ax – matplotlib axis instance
coords – Coordinates() class instance or inherited class (such as PixelGrid(), or Data())
ra_image – Ra/x-coordinates of image positions (list of arrays in angular units)
dec_image – Dec/y-coordinates of image positions (list of arrays in angular units)
color – color of ticks and text
image_name_list – list of strings for names of the images in the same order as the positions
origin – [x0, y0], lower left pixel coordinate in the frame of the pixels
flipped_x – bool, if True, flips x-axis
plot_out_of_image (bool) – if True, plots images even appearing out of the Coordinate frame
- Returns:
matplotlib axis instance with images plotted on
- source_position_plot(ax, coords, ra_source, dec_source, marker='*', markersize=10, **kwargs)[source]¶
- Parameters:
ax – matplotlib axis instance
coords – Coordinates() class instance or inherited class (such as PixelGrid(), or Data())
ra_source – list of source position in angular units
dec_source – list of source position in angular units
marker – marker style for matplotlib
markersize – marker size for matplotlib
- Returns:
matplotlib axis instance with images plotted on
- result_string(x, weights=None, title_fmt='.2f', label=None)[source]¶
- Parameters:
x – marginalized 1-d posterior
weights – weights of posteriors (optional)
title_fmt – format to what digit the results are presented
label – string of parameter label (optional)
- Returns:
string with mean \(\pm\) quartile