btk.plot_utils module

The plot_utils module contains useful plotting functions.

Utility functions for plotting and displaying images in BTK.

btk.plot_utils.get_image(image, bands, rgb=False, norm='linear')

Returns the rgb image if rgb is true, or a monochromatic image if it is false.

Parameters:
  • image (numpy Array) – Contains the image [bands,height,width]

  • bands (list) – list of the bands to be used. Should be of length 3 for RGB images and 1 for monochromatic images.

  • rgb (bool) – indicates if the returned image should be RGB or monochromatic.

  • norm (str) – Stretch to apply to the RGB images. Must be one of “linear” or “asinh”.

Returns:

The requested image.

btk.plot_utils.get_quadrant(center, image_size)

Get the correct quadrant coordinates for plotting an inset plot.

Parameters:
  • center (tuple) – Coordinates the inset plot is centered on.

  • image_size (int) – Size of the image.

Returns:

The coordinates to pass to matplotlib.

btk.plot_utils.get_rgb(image, min_val=None, max_val=None)

Function to normalize 3 band input image to RGB 0-255 image.

Parameters:
  • image (array_like) – Image array to convert to RGB image with dtype uint8 [bands, height, width].

  • min_val (array_like) – Pixel values in

  • output. (image less than or equal to this are set to zero in the RGB) –

  • max_val (array_like) – Pixel values in image greater than or equal to this are set to zero in the RGB output.

Returns:

uint8 array [height, width, bands] of the input image.

btk.plot_utils.get_rgb_image(image, norm='linear', Q=0.1)

Returns RGB (0-255) image corresponding to the input 3 band image.

If scarlet.display is imported then the normalization is performed by scarlet Asinh function. If not, a basic normalization is performed.

Parameters:
  • image (array_like) – Image array to convert to RGB [bands, height, width].

  • norm (str) – Stretch to apply to the images. Must be one of “linear” or “asinh”.

  • Q (float) – Smoothing parameter for the “asinh” norm.

Returns:

uint8 array [height, width, bands] of the input image.

btk.plot_utils.plot_blends(blend_images, blend_list, detected_centers=None, limits=None, band_indices=None, norm='linear', Q=0.1)

Plots blend images as RGB image, sum in all bands, and RGB image with centers of objects.

Outputs of btk draw are plotted here. Blend_list must contain true centers of the objects. If detected_centers are input, then the centers are also shown in the third panel along with the true centers.

Parameters:
  • blend_images (array_like) – Array of blend scene images to plot [batch, bands, height, width].

  • blend_list (list) – List of astropy.table.Table with entries of true objects. Length of list must be the batch size.

  • detected_centers (list, default=`None`) – List of numpy.ndarray or lists with centers of detected centers for each image in batch. Length of list must be the batch size. Each list entry must be a list or numpy.ndarray of dimensions [N, 2].

  • limits (list, default=`None`) – List of start and end coordinates to display image within. Note: limits are applied to both height and width dimensions.

  • band_indices (list, default=None) – list of length 3 with indices of bands that are to be plotted in the RGB image. If pass in None, then default value of [3, 2, 1] is used.

  • norm (str) – Stretch to apply to the images. Must be one of “linear” or “asinh”.

  • Q (float) – Smoothing parameter for the “asinh” norm.

btk.plot_utils.plot_efficiency_matrix(eff_matrix, ax=None, wspace=0.2, skip_zero=True)

Plot detection summary as a matrix of detection efficiency.

Parameters:
  • eff_matrix (numpy.array) – Efficiency matrix

  • ax (matplotlib.axes, default=`None`) – Matplotlib axis on which to draw the plot. If not provided, one is created inside.

  • wspace (float) – Amount of width reserved for space between subplots, expressed as a fraction of the average axis width.

  • skip_zero (bool) – If True, then column corresponding to 0 true objects is not shown (default is True).

btk.plot_utils.plot_gal_parameters(blend_list, context='talk')

Plots histograms for the magnitude and the size of the galaxies in a batch.

Parameters:
  • blend_list (list) – List of astropy Table. Should be obtained from the output of a DrawBlendsGenerator.

  • context (str) – Context for seaborn; see seaborn documentation for details. Can be one of “paper”, “notebook”, “talk”, and “poster”.

btk.plot_utils.plot_metrics_correlation(metric_x, metric_y, metric_x_name, metric_y_name, ax=None, upper_quantile=1.0, style='scatter')

Plot a scatter plot between two quantities.

Parameters:
  • metric_x – Contains the data for the x axis

  • metric_y – Contains the data for the y axis

  • metric_x_name (str) – name of the x metric

  • metric_y_name (str) – name of the y metric

  • ax (matplotlib.axes.Axes) – ax on which the plot should be drawn

  • upper_quantile (float) – Quantile from which to cut

  • style (str) – Style of the plot, can be “scatter” or “heatmap”

btk.plot_utils.plot_metrics_distribution(metric_array, metric_name, ax=None, bins=50, upper_quantile=1.0)

Plot an histogram of the distribution with mean and median.

Parameters:
  • metric_array – Contains the data

  • metric_name (str) – name(s) of the metric(s)

  • ax (matplotlib.axes.Axes) – ax on which the plot should be drawn

  • bins (int) – Optional argument for the number of bins.

  • upper_quantile (float) – Quantile from which to cut

btk.plot_utils.plot_metrics_summary(metrics_results, target_meas_keys=[], target_meas_limits=[], n_bins_target=30, aliases={}, save_path=None, context='talk', interactive=False)

Plot metrics directly from the MetricsGenerator output.

Parameters:
  • metrics_results (dict) – Output of a MetricsGenerator.

  • target_meas_keys (list) – List of the keys for the target measures.

  • target_meas_limits (list) – List of tuples indicating the limits for the plots of the target measures

  • n_bins_target (int) – Number of bins for the target measure plots

  • aliases (dict) – Replaces the names contained in the keys by their associated values. Used to get proper names in the figures.

  • save_path (str) – Path to the folder where the figures should be saved.

  • context (str) – Context for seaborn; see seaborn documentation for details. Can be one of “paper”, “notebook”, “talk”, and “poster”.

  • interactive (bool) – Specifies if the plot should be interactive.

btk.plot_utils.plot_with_deblended(blend_images, isolated_images, blend_list, detection_catalogs, deblended_images, matches, indexes=[0], band_indices=[3, 2, 1], norm='linear', noise_level=1.0)

Plots blend images, along with isolated, deblended and residual images of objects in a blend.

Outputs of btk draw are plotted here. blend_images, isolated_images and blend_list are expected to be the corresponding entries from the output of a DrawBlendsGenerator, detection_catalogs and deblended_images are taken from the output of a MeasureGenerator, and matches is the matches entry of a MetricsGenerator (or the compute_metrics function).

Parameters:
  • blend_images (array_like) – Array of blend scene images to plot [batch, height, width, bands].

  • isolated_images (array_like) – Array of isolated object images to plot [batch, max number of objects, bands, height, width].

  • blend_list (list) – List of astropy.table.Table with entries of true objects. Length of list must be the batch size.

  • detection_catalogs (list) – List of astropy.table.Table with entries of detected objects.

  • deblended_images (list) – List of arrays containing the deblended images with length ‘batch’ and array shape [bands,height,width]

  • matches (list) – List of astropy.table.Table with entries corresponding to the true galaxies. The column ‘match_detected_id’ must contain the id of the matching true galaxy.

  • indexes (list) – List of the indexes of the blends you want to plot.

  • band_indices (list) – List of the bands to plot. Should have either 3 elements for RGB images, or 1 for monochromatic images.

  • norm (str) – Stretch to apply to the RGB images. Must be one of “linear” or “asinh”.

  • noise_level (float) – Normalization to apply to monochromatic images. Should be the standard deviation of the noise.

btk.plot_utils.plot_with_isolated(blend_images, isolated_images, blend_list, limits=None, band_indices=None, norm='linear')

Plots blend images and isolated images of all objects in the blend as RGB images.

Outputs of btk draw are plotted here. Blend_list must contain true centers of the objects.

Parameters:
  • blend_images (array_like) – Array of blend scene images to plot [batch, height, width, bands].

  • isolated_images (array_like) – Array of isolated object images to plot [batch, max number of objects, height, width, bands].

  • blend_list (list) – List of astropy.table.Table with entries of true objects. Length of list must be the batch size.

  • limits (list, default=`None`) – List of start and end coordinates to display image within. Note: limits are applied to both height and width dimensions.

  • band_indices (list, default=None) – list of length 3 with indices of bands that are to be plotted in the RGB image. If pass in None, then default value of [3, 2, 1] is used.

  • norm (str) – Stretch to apply to the images. Must be one of “linear” or “asinh”.