deepdisc.astrodet.scarlet_nocatalog

Functions

write_scarlet_results(datas, observation, ...)

Saves images in each channel, with headers for each source in image,

plot_stretch_Q(datas[, stretches, Qs])

Plots different normalizations of your image using the stretch, Q parameters.

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

Creates a detection catalog by combining low and high resolution data

mad_wavelet_own(image)

image: Median absolute deviation of the first wavelet scale.

fit_scarlet_blend(starlet_sources, observation, catalog)

Creates a detection catalog by combining low and high resolution data

_plot_wavelet(datas)

Helper function to plot wavelet transformation diagnostic figures with scarlet

_plot_scene(starlet_sources, observation, norm, catalog)

Helper function to plot scene with scarlet

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

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

overlapped_slices(bbox1, bbox2)

Slices of bbox1 and bbox2 that overlap

get_processed_hsc_DR3_data(filename[, filters, ...])

Get HSC data given tract/patch info or SkyCoord

return_model_objects(fiG[, luptonize, stringcap, dirpath])

return_spliced_sources(sourceG, sourceR, sourceI)

Module Contents

write_scarlet_results(datas, observation, starlet_sources, model_frame, catalog_deblended, segmentation_masks, dirpath, filters, s)[source]

Saves images in each channel, with headers for each source in image, such that the number of headers = number of sources detected in image.

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

  • 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

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

  • dirpath (str) – Path to HSC image file directory

  • filters (list) – A list of filters for your images. Default is [‘g’, ‘r’, ‘i’].

  • s (str) – File basename string

Returns:

filename – dictionary of all paths to the saved scarlet files for the particular dataset. Saved image and model files for each filter, and one total segmentation mask file for all filters.

Return type:

dict

plot_stretch_Q(datas, stretches=[0.01, 0.1, 0.5, 1], Qs=[1, 10, 5, 100])[source]

Plots different normalizations of your image using the stretch, Q parameters.

Parameters:
  • stretches (array) – List of stretch params you want to permutate through to find optimal image normalization. Default is [0.01, 0.1, 0.5, 1]

  • Qs (array) – List of Q params you want to permutate through to find optimal image normalization. Default is [1, 10, 5, 100]

  • from (Code adapted) – https://pmelchior.github.io/scarlet/tutorials/display.html

Returns:

fig

Return type:

Figure object

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)

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

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)

_plot_wavelet(datas)[source]

Helper function to plot wavelet transformation diagnostic figures with scarlet

Parameters:

datas (array) – array of Data objects

_plot_scene(starlet_sources, observation, norm, catalog, 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

run_scarlet(datas, filters, 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, starlet_thresh=0.1, lvl=5, lvl_segmask=2, maskthresh=0.025, segmentation_map=True, 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)[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:
  • subtract_background (boolean) – Whether or not to estimate and subtract the background (often background is already subtracted) Detault is False

  • plot_wavelet_transform (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_full_scene (boolean) – Plot full scene with the model, rendered model, observation, and residual. Default is False.

  • plot_all_sources (boolean) – Plot the model, rendered model, observation, and spectrum across channels for each object. WARNING: dumb 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:

  • FITS file with…

  • TODO (fill this out once I get the exact fits file output generated to Colin’s liking)

overlapped_slices(bbox1, bbox2)[source]

Slices of bbox1 and bbox2 that overlap

Parameters —Z——- bbox1: ~scarlet.bbox.Box bbox2: ~scarlet.bbox.Box

Returns:

slices – The slice of an array bounded by bbox1 and the slice of an array bounded by bbox in the overlapping region.

Return type:

tuple of slices

get_processed_hsc_DR3_data(filename, filters=['g', 'r', 'i'], dirpath='/home/g4merz/deblend/data/processed_HSC_DR3/lvl5/', stringcap=14)[source]

Get HSC data given tract/patch info or SkyCoord

Parameters:
  • dirpath (str) – Path to HSC image file directory

  • filters (list) – A list of filters for your images. Default is [‘g’, ‘r’, ‘i’].

  • tract (int) – An integer used for specifying the tract. Default is 10054

  • patch ([int, int]) – Patch #,#. Default is [0,0]

  • coord (SkyCoord) – Astropy SkyCoord, when specified, overrides tract/patch info and attempts to lookup HSC filename from ra, dec. Default is None

  • cutout_size ([int, int]) – Size of cutout to use (set to None for no cutting). Default is [128, 128]

  • form (The image filepath is in the) – {dirpath}/deepCoadd/HSC-{filter}/{tract}/{patch[0]},{patch[1]}/calexp-HSC-{filter}-{tract}-{patch[0]},{patch[1]}.fits

Returns:

data – HSC data array with dimensions [filters, N, N]

Return type:

ndarray

return_model_objects(fiG, luptonize=False, stringcap=14, dirpath='/home/shared/hsc/HSC/HSC_DR3/data/train/')[source]
return_spliced_sources(sourceG, sourceR, sourceI)[source]