LSST Applications g04e9c324dd+8c5ae1fdc5,g0644efc3f0+366663dc37,g123d84c11c+8c5ae1fdc5,g1ec0fe41b4+6ec6b74de1,g1fd858c14a+1be88e80db,g3533f9d6cb+366663dc37,g35bb328faa+8c5ae1fdc5,g35ef7ab7cf+285dd5b202,g53246c7159+8c5ae1fdc5,g60b5630c4e+366663dc37,g663da51e9b+41529343ca,g6735e52a0d+29de3d959a,g67b6fd64d1+57193d00fb,g7605de067c+8f72e4d2dc,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g844c57033c+03ddc13274,g8852436030+e345a59dd4,g89139ef638+57193d00fb,g989de1cb63+57193d00fb,g9a0bdda227+852181cf57,g9f33ca652e+a2d35689ce,ga1e959baac+5fbc491aed,ga2f891cd6c+366663dc37,gabe3b4be73+8856018cbb,gabf8522325+cc757f8247,gac2eed3f23+57193d00fb,gb1101e3267+f6b489998a,gb89ab40317+57193d00fb,gcf25f946ba+e345a59dd4,gd107969129+227687db21,gd6cbbdb0b4+8e46defd2a,gde0f65d7ad+2dad650f79,ge278dab8ac+2322f1d6ea,ge410e46f29+57193d00fb,gf30d85a44d+8e3077faf9,gf5e32f922b+8c5ae1fdc5,gff02db199a+5c78c1866e,w.2025.28
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.scarlet.lite.detect Namespace Reference

Classes

class  Footprint
 

Functions

Box bounds_to_bbox (tuple[int, int, int, int] bounds)
 
tuple[int, int, int, int] bbox_to_bounds (Box bbox)
 
Image footprints_to_image (Sequence[Footprint] footprints, Box bbox)
 
np.ndarray get_wavelets (np.ndarray images, np.ndarray variance, int|None scales=None, int generation=2)
 
np.ndarray get_detect_wavelets (np.ndarray images, np.ndarray variance, int scales=3)
 
list[Footprintdetect_footprints (np.ndarray images, np.ndarray variance, int scales=1, int generation=2, tuple[int, int]|None origin=None, float min_separation=4, int min_area=4, float peak_thresh=5, float footprint_thresh=5, bool find_peaks=True, bool remove_high_freq=True, int min_pixel_detect=1)
 

Variables

 logger = logging.getLogger("scarlet.detect")
 

Function Documentation

◆ bbox_to_bounds()

tuple[int, int, int, int] lsst.scarlet.lite.detect.bbox_to_bounds ( Box bbox)
Convert a Box into the bounds of a Footprint

Parameters
----------
bbox:
    The `Box` to convert into bounds.

Returns
-------
result:
    The bounds of the `Footprint` as a `tuple` of
    ``(bottom, top, left, right)``.

Notes
-----
Unlike slices, the bounds are _inclusive_ of the end points.

Definition at line 66 of file detect.py.

66def bbox_to_bounds(bbox: Box) -> tuple[int, int, int, int]:
67 """Convert a Box into the bounds of a Footprint
68
69 Parameters
70 ----------
71 bbox:
72 The `Box` to convert into bounds.
73
74 Returns
75 -------
76 result:
77 The bounds of the `Footprint` as a `tuple` of
78 ``(bottom, top, left, right)``.
79
80 Notes
81 -----
82 Unlike slices, the bounds are _inclusive_ of the end points.
83 """
84 bounds = (
85 bbox.origin[0],
86 bbox.origin[0] + bbox.shape[0] - 1,
87 bbox.origin[1],
88 bbox.origin[1] + bbox.shape[1] - 1,
89 )
90 return bounds
91
92
93@continue_class

◆ bounds_to_bbox()

Box lsst.scarlet.lite.detect.bounds_to_bbox ( tuple[int, int, int, int] bounds)
Convert the bounds of a Footprint into a Box

Notes
-----
Unlike slices, the bounds are _inclusive_ of the end points.

Parameters
----------
bounds:
    The bounds of the `Footprint` as a `tuple` of
    ``(bottom, top, left, right)``.
Returns
-------
result:
    The `Box` created from the bounds

Definition at line 43 of file detect.py.

43def bounds_to_bbox(bounds: tuple[int, int, int, int]) -> Box:
44 """Convert the bounds of a Footprint into a Box
45
46 Notes
47 -----
48 Unlike slices, the bounds are _inclusive_ of the end points.
49
50 Parameters
51 ----------
52 bounds:
53 The bounds of the `Footprint` as a `tuple` of
54 ``(bottom, top, left, right)``.
55 Returns
56 -------
57 result:
58 The `Box` created from the bounds
59 """
60 return Box(
61 (bounds[1] + 1 - bounds[0], bounds[3] + 1 - bounds[2]),
62 origin=(bounds[0], bounds[2]),
63 )
64
65

◆ detect_footprints()

list[Footprint] lsst.scarlet.lite.detect.detect_footprints ( np.ndarray images,
np.ndarray variance,
int scales = 1,
int generation = 2,
tuple[int, int] | None origin = None,
float min_separation = 4,
int min_area = 4,
float peak_thresh = 5,
float footprint_thresh = 5,
bool find_peaks = True,
bool remove_high_freq = True,
int min_pixel_detect = 1 )
Detect footprints in an image

Parameters
----------
images:
    The array of images with shape `(bands, Ny, Nx)` for which to
    calculate wavelet coefficients.
variance:
    An array of variances with the same shape as `images`.
scales:
    The maximum number of wavelet scales to use.
    If `remove_high_freq` is `False`, then this argument is ignored.
generation:
    The generation of the starlet transform to use.
    If `remove_high_freq` is `False`, then this argument is ignored.
origin:
    The location (y, x) of the lower corner of the image.
min_separation:
    The minimum separation between peaks in pixels.
min_area:
    The minimum area of a footprint in pixels.
peak_thresh:
    The threshold for peak detection.
footprint_thresh:
    The threshold for footprint detection.
find_peaks:
    If `True`, then detect peaks in the detection image,
    otherwise only the footprints are returned.
remove_high_freq:
    If `True`, then remove high frequency wavelet coefficients
    before detecting peaks.
min_pixel_detect:
    The minimum number of bands that must be above the
    detection threshold for a pixel to be included in a footprint.

Definition at line 249 of file detect.py.

262) -> list[Footprint]:
263 """Detect footprints in an image
264
265 Parameters
266 ----------
267 images:
268 The array of images with shape `(bands, Ny, Nx)` for which to
269 calculate wavelet coefficients.
270 variance:
271 An array of variances with the same shape as `images`.
272 scales:
273 The maximum number of wavelet scales to use.
274 If `remove_high_freq` is `False`, then this argument is ignored.
275 generation:
276 The generation of the starlet transform to use.
277 If `remove_high_freq` is `False`, then this argument is ignored.
278 origin:
279 The location (y, x) of the lower corner of the image.
280 min_separation:
281 The minimum separation between peaks in pixels.
282 min_area:
283 The minimum area of a footprint in pixels.
284 peak_thresh:
285 The threshold for peak detection.
286 footprint_thresh:
287 The threshold for footprint detection.
288 find_peaks:
289 If `True`, then detect peaks in the detection image,
290 otherwise only the footprints are returned.
291 remove_high_freq:
292 If `True`, then remove high frequency wavelet coefficients
293 before detecting peaks.
294 min_pixel_detect:
295 The minimum number of bands that must be above the
296 detection threshold for a pixel to be included in a footprint.
297 """
298
299 if origin is None:
300 origin = (0, 0)
301 if remove_high_freq:
302 # Build the wavelet coefficients
303 wavelets = get_wavelets(
304 images,
305 variance,
306 scales=scales,
307 generation=generation,
308 )
309 # Remove the high frequency wavelets.
310 # This has the effect of preventing high frequency noise
311 # from interfering with the detection of peak positions.
312 wavelets[0] = 0
313 # Reconstruct the image from the remaining wavelet coefficients
314 _images = multiband_starlet_reconstruction(
315 wavelets,
316 generation=generation,
317 )
318 else:
319 _images = images
320 # Build a SNR weighted detection image
321 sigma = np.median(np.sqrt(variance), axis=(1, 2)) / 2
322 detection = np.sum(_images / sigma[:, None, None], axis=0)
323 if min_pixel_detect > 1:
324 mask = np.sum(images > 0, axis=0) >= min_pixel_detect
325 detection[~mask] = 0
326 # Detect peaks on the detection image
327 footprints = get_footprints(
328 detection,
329 min_separation,
330 min_area,
331 peak_thresh,
332 footprint_thresh,
333 find_peaks,
334 origin[0],
335 origin[1],
336 )
337
338 return footprints
std::vector< Footprint > get_footprints(py::EigenDRef< const M > image, const double min_separation, const int min_area, const double peak_thresh, const double footprint_thresh, const bool find_peaks=true, const int y0=0, const int x0=0)
Get all footprints in an image.

◆ footprints_to_image()

Image lsst.scarlet.lite.detect.footprints_to_image ( Sequence[Footprint] footprints,
Box bbox )
Convert a set of scarlet footprints to a pixelized image.

Parameters
----------
footprints:
    The footprints to convert into an image.
box:
    The full box of the image that will contain the footprints.

Returns
-------
result:
    The image created from the footprints.

Definition at line 146 of file detect.py.

146def footprints_to_image(footprints: Sequence[Footprint], bbox: Box) -> Image:
147 """Convert a set of scarlet footprints to a pixelized image.
148
149 Parameters
150 ----------
151 footprints:
152 The footprints to convert into an image.
153 box:
154 The full box of the image that will contain the footprints.
155
156 Returns
157 -------
158 result:
159 The image created from the footprints.
160 """
161 result = Image.from_box(bbox, dtype=int)
162 for k, footprint in enumerate(footprints):
163 slices = overlapped_slices(result.bbox, footprint.bbox)
164 result.data[slices[0]] += footprint.data[slices[1]] * (k + 1)
165 return result
166
167

◆ get_detect_wavelets()

np.ndarray lsst.scarlet.lite.detect.get_detect_wavelets ( np.ndarray images,
np.ndarray variance,
int scales = 3 )
Get an array of wavelet coefficents to use for detection

Parameters
----------
images:
    The array of images with shape `(bands, Ny, Nx)` for which to
    calculate wavelet coefficients.
variance:
    An array of variances with the same shape as `images`.
scales:
    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
-------
starlets:
    The array of wavelet coefficients for pixels with siignificant
    amplitude in each scale.

Definition at line 212 of file detect.py.

212def get_detect_wavelets(images: np.ndarray, variance: np.ndarray, scales: int = 3) -> np.ndarray:
213 """Get an array of wavelet coefficents to use for detection
214
215 Parameters
216 ----------
217 images:
218 The array of images with shape `(bands, Ny, Nx)` for which to
219 calculate wavelet coefficients.
220 variance:
221 An array of variances with the same shape as `images`.
222 scales:
223 The maximum number of wavelet scales to use.
224 Note that the result will have `scales+1` total arrays,
225 where the last set of coefficients is the image of all
226 flux with frequency greater than the last wavelet scale.
227
228 Returns
229 -------
230 starlets:
231 The array of wavelet coefficients for pixels with siignificant
232 amplitude in each scale.
233 """
234 sigma = np.median(np.sqrt(variance))
235 # Create the wavelet coefficients for the significant pixels
236 detect = np.sum(images, axis=0)
237 _coeffs = starlet_transform(detect, scales=scales)
238 support = get_multiresolution_support(
239 image=detect,
240 starlets=_coeffs,
241 sigma=sigma, # type: ignore
242 sigma_scaling=3,
243 epsilon=1e-1,
244 max_iter=20,
245 )
246 return (support.support * _coeffs).astype(images.dtype)
247
248

◆ get_wavelets()

np.ndarray lsst.scarlet.lite.detect.get_wavelets ( np.ndarray images,
np.ndarray variance,
int | None scales = None,
int generation = 2 )
Calculate wavelet coefficents given a set of images and their variances

Parameters
----------
images:
    The array of images with shape `(bands, Ny, Nx)` for which to
    calculate wavelet coefficients.
variance:
    An array of variances with the same shape as `images`.
scales:
    The maximum number of wavelet scales to use.

Returns
-------
coeffs:
    The array of coefficents with shape `(scales+1, bands, Ny, Nx)`.
    Note that the result has `scales+1` total arrays,
    since the last set of coefficients is the image of all
    flux with frequency greater than the last wavelet scale.

Definition at line 168 of file detect.py.

173) -> np.ndarray:
174 """Calculate wavelet coefficents given a set of images and their variances
175
176 Parameters
177 ----------
178 images:
179 The array of images with shape `(bands, Ny, Nx)` for which to
180 calculate wavelet coefficients.
181 variance:
182 An array of variances with the same shape as `images`.
183 scales:
184 The maximum number of wavelet scales to use.
185
186 Returns
187 -------
188 coeffs:
189 The array of coefficents with shape `(scales+1, bands, Ny, Nx)`.
190 Note that the result has `scales+1` total arrays,
191 since the last set of coefficients is the image of all
192 flux with frequency greater than the last wavelet scale.
193 """
194 sigma = np.median(np.sqrt(variance), axis=(1, 2))
195 # Create the wavelet coefficients for the significant pixels
196 scales = get_starlet_scales(images[0].shape, scales)
197 coeffs = np.empty((scales + 1,) + images.shape, dtype=images.dtype)
198 for b, image in enumerate(images):
199 _coeffs = starlet_transform(image, scales=scales, generation=generation)
200 support = get_multiresolution_support(
201 image=image,
202 starlets=_coeffs,
203 sigma=sigma[b],
204 sigma_scaling=3,
205 epsilon=1e-1,
206 max_iter=20,
207 )
208 coeffs[:, b] = (support.support * _coeffs).astype(images.dtype)
209 return coeffs
210
211

Variable Documentation

◆ logger

lsst.scarlet.lite.detect.logger = logging.getLogger("scarlet.detect")

Definition at line 40 of file detect.py.