deepdisc.preprocessing.detection

Functions

mad_wavelet_own(image)

image: Median absolute deviation of the first wavelet scale.

make_catalog(datas[, lvl, wave, segmentation_map, ...])

Creates a detection catalog by combining low and high resolution data

fit_scarlet_blend(starlet_sources, observation, catalog)

Creates a detection catalog by combining low and high resolution data

run_scarlet(datas, filters[, catalog, stretch, Q, ...])

Run P. Melchior's scarlet (https://github.com/pmelchior/scarlet) implementation

_plot_scene(starlet_sources, observation, norm, catalog)

Helper function to plot scene with scarlet

Module Contents

mad_wavelet_own(image)[source]

image: Median absolute deviation of the first wavelet scale. (WARNING: sorry to disapoint, this is not a wavelet for mad scientists)

Have to use astropy mad as scipy mad does not like ignoring NaN and computing over multiple axes

Parameters:

image (array) – An image or cube of images

Returns:

mad – median absolute deviation for each image in the cube

Return type:

array

make_catalog(datas, lvl=4, wave=True, segmentation_map=False, maskthresh=10.0, object_limit=100000)[source]

Creates a detection catalog by combining low and high resolution data

Parameters:
  • datas (array) – array of Data objects

  • lvl (int) – detection lvl

  • wave (Bool) – set to True to use wavelet decomposition of images before combination

  • subtract_background (Bool) – if you want to subtract the background and retrieve an estimate, change to True. But default is False because HSC images are already background subtracted.

  • segmentation_map (Bool) – Whether to run sep segmentation map

  • maskthresh (float) – Mask threshold for sep segmentation

  • object_limit (int) – Limit on number of objects to detect in image

  • https (Code adapted from)

Returns:

  • catalog (sextractor catalog) – catalog of detected sources (use ‘catalog.dtype.names’ for info)

  • bg_rms (array) – background level for each data set (set to None if subtract_background is False)

fit_scarlet_blend(starlet_sources, observation, catalog, max_iters=15, e_rel=0.0001, plot_likelihood=True, savefigs=False, figpath='')[source]

Creates a detection catalog by combining low and high resolution data

Parameters:
  • datas (array) – array of Data objects

  • converge (Will end early if likelihood and constraints)

run_scarlet(datas, filters, catalog=None, stretch=0.1, Q=5, sigma_model=1, sigma_obs=5, psf=None, subtract_background=False, max_chi2=5000, max_iters=15, morph_thresh=0.1, lvl=5, lvl_segmask=2, maskthresh=0.025, segmentation_map=True, wave_cat=False, plot_wavelet=False, plot_likelihood=True, plot_scene=False, plot_sources=False, add_ellipses=True, add_labels=False, add_boxes=False, percentiles=(1, 99), savefigs=False, figpath='', weights=None, return_models=True)[source]

Run P. Melchior’s scarlet (https://github.com/pmelchior/scarlet) implementation for source separation. This function will create diagnostic plots, a source detection catalog, and fit a model for all sources in the observation scene (image).

Parameters:
  • datas (ndarray) – multichannel array of data, shape (Nfilters x N x N)

  • filters (list) – str list of filters, e.g. (‘u’,’g’,’r)

  • catalog (pandas df) – external source catalog used to initialize source positions and get additional source information

  • stretch (float) – plotting parameter

  • Q (float) – plotting parameter

  • sigma_model (float) – scarlet model psf

  • sigma_obs (FWHM for observational psf. Use psf argument instead if you have an image of the psf)

  • psf (ndarray) – psf image array

  • max_iters (int) – max number of iterations for scarlet to fit

  • morph_thresh (float) – parameter for source initialization

  • lvl (int) – detection level for wavelet catalog detection

  • lvl_segmask (int) – segmentation mask detection level

  • subtract_background (boolean) – Whether or not to estimate and subtract the background (often background is already subtracted) Detault is False

  • plot_wavelet (boolean) – Plot starlet wavelet transform and inverse transform at different scales. NOTE: Not really useful at large image sizes (> ~few hundred pixels length/height) Default is False

  • plot_detections (boolean) – Plot detection catalog results. Default is False

  • plot_likelihood (boolean) – Plot likelihood as function of iterations from Blend fit function. Default is True

  • plot_scene (boolean) – Plot full scene with the model, rendered model, observation, and residual. Default is False.

  • plot_sources (boolean) – Plot the model, rendered model, observation, and spectrum across channels for each object. WARNING: Not advised to do this with a large image with many sources! Default is False

  • plot_first_isolated_comp (boolean) – Plot the subtracted and isolated first (or any) starlet component. Recommended for finding a bright component. Default is False.

Returns:

  • observation (scarlet function) – Scarlet observation objects

  • starlet_sources (list) – List of ScarletSource objects

  • model_frame (scarlet function) – Image frame of source model

  • catalog_deblended (list) – Deblended source detection catalog

  • source_catalog (pandas df) – External catalog of source detections

  • segmentation_masks (list) – List of segmentation mask of each object in image

_plot_scene(starlet_sources, observation, norm, catalog, wave_cat=True, show_model=True, show_rendered=True, show_observed=True, show_residual=True, add_labels=True, add_boxes=True, add_ellipses=True, savefigs=False, figpath='')[source]

Helper function to plot scene with scarlet

Parameters:
  • starlet_sources (List) – List of ScarletSource objects

  • observation – Scarlet observation objects

  • norm – Scarlet normalization for plotting

  • catalog (list) – Source detection catalog

  • show_model (bool) – Whether to show model

  • show_rendered (bool) – Whether to show rendered model

  • show_observed (bool) – Whether to show observed

  • show_residual (bool) – Whether to show residual

  • add_labels (bool) – Whether to add labels

  • add_boxes (bool) – Whether to add bounding boxes to each panel

  • add_ellipses (bool) – Whether to add ellipses to each panel

Returns:

fig – Figure object

Return type:

matplotlib Figure