scarlet.detect

class scarlet.detect.QuadTreeRegion(bbox, capacity=5, sub_regions=None, boxes=None, depth=0, detect=None)[source]

Bases: object

An implementation of a QuadTree that inserts boxes as opposed to points

Attributes:
peaks

Generate a list of peaks contained in the tree

Methods

add(other_box)

Add a box to the region.

add_footprints(footprints)

Add bounding boxes for a list of scarlet footprints.

footprint_image([bbox])

Get an image array of all of the footprints in the tree

query([other_box])

Return all of the boxes that overlap with a given box

split()

Sub-divide this region into 4 sub-regions.

add(other_box)[source]

Add a box to the region.

Parameters:
other_box: `scarlet.bbox.Box`

The box to add to the region.

add_footprints(footprints)[source]

Add bounding boxes for a list of scarlet footprints.

Parameters:
footprints: `list` of `scarlet.detect_pybind11.Footprint`

A list of footprints detected by scarlet.

footprint_image(bbox=None)[source]

Get an image array of all of the footprints in the tree

property peaks

Generate a list of peaks contained in the tree

query(other_box=None)[source]

Return all of the boxes that overlap with a given box

Parameters:
other_box: `scarlet.bbox.Box`

The box to use for the search. All boxes in this region or one of its sub-regions that overlap with other_box will be returned.

Returns:
result: set of scarlet.bbox.BoundingBox

The set of all boxes that overlap with other_box. We use a set instead of a list because some boxes may be in multiple sub-regions and we only want to have one copy of each.

split()[source]

Sub-divide this region into 4 sub-regions.

class scarlet.detect.SingleScaleStructure(scale, footprint)[source]

Bases: object

A structure at a single scale with quadtrees to lookup child boxes at different scales.

Using the terminology from Starck et al. 2011 we refere to a connected set of pixels with a common set of peaks at a single scale as a structure.

Attributes:
scale: `int`

The wavelet scale of this structure.

footprint: `scarlet.detect_pybind11.Footprint`

The footprint of this structure at its given scale.

bbox: `scarlet.bbox.Box`

The bounding box of this region.

peaks: `dict`: {`int`, `list` of `scarlet.detect_pybind11.Peak`}

The dictionary with each wavelet scale as a key with lists of `Peak`s as values.

Methods

add_footprint(scale, footprint)

Add a footprint to the strcuture

add_scale_tree(scale, tree)

Add all of the footprints from a region at a different scale that overlap with this structure.

add_footprint(scale, footprint)[source]

Add a footprint to the strcuture

Parameters:
scale: `int`

The scale of the footprint that is added.

`footprint`: `scarlet.detect_pybind11.Footprint`

The footprint to be added to the structure.

add_scale_tree(scale, tree)[source]

Add all of the footprints from a region at a different scale that overlap with this structure.

Parameters:
scale: `int`

The scale of the tree that is added.

tree: `QuadTreeRegion`

The quad tree that is added at scale scale.

property all_peaks

All of the peaks contained in this Structure

Returns:
all_peaks: set

The set of all peaks in the structure, including those at different scales.

scarlet.detect.bounds_to_bbox(bounds)[source]

Convert the bounds of a Footprint into a Box

Parameters:
bounds: `tuple` of `(bottom, top, left, right)`

The bounds of the Footprint

scarlet.detect.box_intersect(box1, box2)[source]

Check if two boxes overlap

Parameters:
box1, box2: `scarlet.bbox.Box`

The boxes to check for overlap

Returns:
overlap: bool

True when the two boxes overlap

scarlet.detect.draw_box(box, ax, color)[source]

Draw a box on an axis

Parameters:
box: `scarlet.bbox.Box`

The box to draw

ax: `matplotlib.Axis`

The axis on which to draw the box

color: `str`

The name of the color to use for the box

scarlet.detect.draw_footprint_box(footprint, ax)[source]

Draw a scarlet Footprint in a plot

Parameters:
footprint: `scarlet.detect_pybind11.Footprint`

The footprint to draw

ax: `matplotlib.Axis`

The axis on which to draw the box

scarlet.detect.draw_region(region, ax)[source]

Draw a QuadTreeRegion in a plot

Parameters:
region: `QuadTreeRegion`

The region to draw

ax: `matplotlib.Axis`

The axis on which to draw the box

scarlet.detect.footprint_intersect(footprint1, box1, footprint2, box2)[source]

Check if two footprints overlap

Parameters:
box1, box2: `scarlet.bbox.Box`

The boxes of the footprints to check for overlap.

footprint1, footprint2: `scarlet.detect_pybind11.Footprint`

The boolean mask for the two footprints.

Returns:
overlap: bool

True when the two footprints overlap.

scarlet.detect.get_blend_structures(detect)[source]

Generate a set of structures for the 3rd wavelet scale

This is a convenience function to generate a hierarchy connecting all of the footprints at lower scales to the higher scale structures that overlap with them.

scarlet.detect.get_blend_trees(detect)[source]

Get the tree at each wavelet level, and all of the footprints at each level

Parameters:
detect: `numpy.ndarray`

A 2D image to use for detecting footprints and peaks

Returns:
trees: list of QuadTreeRegion

A tree at each scale used to match peaks/footprints across scales

all_footprints: lsit of list of Footprint

A list of all of all of the footprints at each scale.

scarlet.detect.get_detect_wavelets(images, variance, scales=3)[source]

Get an array of wavelet coefficents to use for detection

Parameters images: array-like

The array of images with shape (bands, Ny, Nx) for which to calculate wavelet coefficients.

variance: array-like

An array of variances with the same shape as images.

scales: int

The maximum number of wavelet scales to use. Note that the result will have scales+1 total arrays, where the last set of coefficients is the image of all flux with frequency greater than the last wavelet scale.

scarlet.detect.get_peaks(detect=None, images=None, variance=None, bbox=None, scales=3)[source]

Detect all of the peaks in the 2nd wavelet scale

This is not meant to be a permanent solution, as there are some objects that don’t have a detection on the 2nd wavelet scale, however through testing it has been confirmed that this algorithm works better than the LSST science pipelines detection algorithm and is a good replacement until the hierarchical detection tree can be better understood and finalized.

Parameters:
detect: `numpy.ndarray`

A set of wavelet coefficents used to detect sources. If detect is None then images and `variance`must be specified.

images: `numpy.ndarray`

The set of 3D images (band, height, width) to use for creating the wavelet coefficients. This is ignored if detect is not None.

variance: `numpy.ndarray`

The variance of images. This is ignored if detect is not None.

bbox: `scarlet.bbox.Box`

The bounding box for the full image. If this is None, then a bounding box that is the shape of images with an origin at (0,0,0) is used.

scales: `int`

The number of wavelet scales to use for creating the detection wavelet coefficients. This is ignored if detect is not None.

Returns:
peaks: list

A list of peaks that have been detected at the 2nd wavelet scale.

scarlet.detect.get_wavelets(images, variance, scales=3)[source]

Calculate wavelet coefficents given a set of images and their variances

Parameters:
images: array-like

The array of images with shape (bands, Ny, Nx) for which to calculate wavelet coefficients.

variance: array-like

An array of variances with the same shape as images.

scales: `int`

The maximum number of wavelet scales to use. Note that the result will have scales+1 total arrays, where the last set of coefficients is the image of all flux with frequency greater than the last wavelet scale.

Returns:
coeffs: numpy.ndarray

The array of coefficents with shape (scales+1, bands, Ny, Nx).