deepdisc.astrodet.scarlet_catalog
Functions
|
Saves images in each channel, with headers for each source in image, |
|
Plots different normalizations of your image using the stretch, Q parameters. |
|
Creates a detection catalog by combining low and high resolution data |
|
image: Median absolute deviation of the first wavelet scale. |
|
Creates a detection catalog by combining low and high resolution data |
|
Helper function to plot wavelet transformation diagnostic figures with scarlet |
|
Helper function to plot scene with scarlet |
|
Run P. Melchior's scarlet (https://github.com/pmelchior/scarlet) implementation |
|
Slices of bbox1 and bbox2 that overlap |
|
Get HSC data given tract/patch info or SkyCoord |
|
|
|
Module Contents
- write_scarlet_results(datas, observation, starlet_sources, model_frame, catalog_deblended, segmentation_masks, dirpath, filters, s, source_catalog=None)[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
source_catalog (pandas df) – External catalog of source detections
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, source_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, source_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)[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)
source_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
- 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