lenstronomy.Plots package

Submodules

lenstronomy.Plots.chain_plot module

lenstronomy.Plots.chain_plot.plot_chain(chain, param_list)[source]
lenstronomy.Plots.chain_plot.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

lenstronomy.Plots.chain_plot.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.chain_plot.psf_iteration_compare(kwargs_psf, **kwargs)[source]
Parameters
  • kwargs_psf

  • kwargs – kwargs to send to matplotlib.pyplot.matshow()

Returns

lenstronomy.Plots.lens_plot module

lenstronomy.Plots.lens_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)[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

Returns

lenstronomy.Plots.lens_plot.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

lenstronomy.Plots.lens_plot.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.lens_plot.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 nnumber 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

lenstronomy.Plots.lens_plot.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)

  • dtan_dtan – tangential eigenvector differential in tangential direction (not implemented yet as illustration)

Returns

lenstronomy.Plots.model_band_plot module

class lenstronomy.Plots.model_band_plot.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: lenstronomy.Analysis.image_reconstruction.ModelBand

class to plot a single band given the modeling results

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

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

data_plot(ax, v_min=None, v_max=None, text='Observed', font_size=15, colorbar_label='log$_{10}$ flux', **kwargs)[source]
Parameters

ax

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

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

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

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

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

plot_extinction_map(ax, v_min=None, v_max=None, **kwargs)[source]
Parameters
  • ax

  • v_min

  • v_max

Returns

plot_main(with_caustics=False)[source]

print the main plots together in a joint frame

Returns

plot_separate()[source]

plot the different model components separately

Returns

plot_subtract_from_data_all()[source]

subtract model components from data

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

subtract_from_data_plot(ax, text='Subtracted', v_min=None, v_max=None, point_source_add=False, source_add=False, lens_light_add=False, font_size=15)[source]

lenstronomy.Plots.model_plot module

class lenstronomy.Plots.model_plot.ModelPlot(multi_band_list, kwargs_model, kwargs_params, arrow_size=0.02, cmap_string='gist_heat', likelihood_mask_list=None, bands_compute=None, multi_band_type='multi-linear', source_marg=False, linear_prior=None, fast_caustic=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.

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

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

data_plot(band_index=0, **kwargs)[source]

illustrates data

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

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

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

model_plot(band_index=0, **kwargs)[source]

illustrates model

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

plot_extinction_map(band_index=0, **kwargs)[source]
Parameters
  • band_index – index of band

  • kwargs – arguments of plotting

Returns

plot instance of differential extinction map

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

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

source(band_index=0, **kwargs)[source]
Parameters
  • band_index – index of band

  • kwargs – keyword arguments accessible in model_band_plot.source()

Returns

2d array of source surface brightness

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

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

lenstronomy.Plots.plot_util module

lenstronomy.Plots.plot_util.cmap_conf(cmap_string)[source]

configures matplotlib color map

Parameters

cmap_string – string of cmap name, or cmap instance

Returns

cmap instance with setting for bad pixels and values below the threshold

lenstronomy.Plots.plot_util.coordinate_arrows(ax, d, coords, color='w', font_size=15, arrow_size=0.05)[source]
lenstronomy.Plots.plot_util.image_position_plot(ax, coords, ra_image, dec_image, color='w', image_name_list=None, origin=None, flipped_x=False, pixel_offset=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

  • pixel_offset – boolean; if True (default plotting), the coordinates are shifted a half a pixel to match with the matshow() command to center the coordinates in the pixel center

Returns

matplotlib axis instance with images plotted on

lenstronomy.Plots.plot_util.plot_line_set(ax, coords, line_set_list_x, line_set_list_y, origin=None, flipped_x=False, points_only=False, pixel_offset=True, *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

  • pixel_offset – boolean; if True (default plotting), the coordinates are shifted a half a pixel to match with the matshow() command to center the coordinates in the pixel center

Returns

plot with line sets on matplotlib axis in pixel coordinates

lenstronomy.Plots.plot_util.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

lenstronomy.Plots.plot_util.scale_bar(ax, d, dist=1.0, text='1"', color='w', font_size=15, flipped=False)[source]
lenstronomy.Plots.plot_util.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

lenstronomy.Plots.plot_util.sqrt(inputArray, scale_min=None, scale_max=None)[source]

Performs sqrt scaling of the input numpy array.

@type inputArray: numpy array @param inputArray: image data array @type scale_min: float @param scale_min: minimum data value @type scale_max: float @param scale_max: maximum data value @rtype: numpy array @return: image data array

lenstronomy.Plots.plot_util.text_description(ax, d, text, color='w', backgroundcolor='k', flipped=False, font_size=15)[source]

Module contents