Coverage for python/lsst/afw/detection/multiband.py : 73%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# This file is part of afw. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Create a Footprint from a set of Images
Parameters ---------- images: `MultibandImage` or list of `Image`, array Images to extract the footprint from thresh: `float` All pixels above `thresh` will be included in the footprint xy0: `Point2I` Location of the minimum value of the images bounding box (if images is an array, otherwise the image bounding box is used).
Returns ------- spans: `SpanSet` Union of all spans in the images above the threshold imageBBox: `Box2I` Bounding box for the input images. """ # Set the threshold for each band
# If images is a list of `afw Image` objects then # merge the SpanSet in each band into a single Footprint else: # Use thresh to detect the pixels above the threshold in each band
"""Create an image of a HeavyFootprint
Parameters ---------- heavy: `HeavyFootprint` The HeavyFootprint to insert into the image fill: number Number to fill the pixels in the image that are not contained in `heavy`. bbox: `Box2I` Bounding box of the output image. imageType: `type` This should be either a `MaskedImage` or `Image` and describes the type of the output image.
Returns ------- image: `MaskedImage` or `Image` An image defined by `bbox` and padded with `fill` that contains the projected flux in `heavy`. """
"""Multiband Footprint class
A `MultibandFootprint` is a collection of HeavyFootprints that have the same `SpanSet` and `peakCatalog` but different flux in each band.
Parameters ---------- filters: `list` List of filter names. singles: `list` A list of single band `HeavyFootprint` objects. Each `HeavyFootprint` should have the same `PeakCatalog` and the same `SpanSet`, however to save CPU cycles there is no internal check for consistency of the peak catalog. """ # Ensure that all HeavyFootprints have the same SpanSet raise ValueError("All HeavyFootprints in singles are expected to have the same SpanSet")
# Assume that all footprints have the same SpanSet and PeakCatalog
"""Create a `MultibandFootprint` from an `image`, `mask`, `variance`
Parameters ---------- filters: `list` List of filter names. image: array An array to convert into `HeavyFootprint` objects. Only pixels above the `thresh` value for at least one band will be included in the `SpanSet` and resulting footprints. mask: array Mask for the `image` array. variance: array Variance of the `image` array. footprint: `Footprint` `Footprint` that contains the `SpanSet` and `PeakCatalog` to use for the `HeavyFootprint` in each band. If `footprint` is `None` then the `thresh` is used to create a `Footprint` based on the pixels above the `thresh` value. xy0: `Point2I` If `image` is an array and `footprint` is `None` then specifying `xy0` gives the location of the minimum `x` and `y` value of the `images`. thresh: float or list of floats Threshold in each band (or the same threshold to be used in all bands) to include a pixel in the `SpanSet` of the `MultibandFootprint`. If `Footprint` is not `None` then `thresh` is ignored. peaks: `PeakCatalog` Catalog containing information about the peaks located in the footprints.
Returns ------- result: `MultibandFootprint` MultibandFootprint created from the arrays """ # Generate a new Footprint if one has not been specified else: imageBBox = footprint.getBBox()
"""Create a `MultibandFootprint` from an `image`, `mask`, `variance`
Parameters ---------- filters: list List of filter names. image: `MultibandImage`, or list of `Image` A `MultibandImage` (or collection of images in each band) to convert into `HeavyFootprint` objects. Only pixels above the `thresh` value for at least one band will be included in the `SpanSet` and resulting footprints. mask: `MultibandMask` or list of `Mask` Mask for the `image`. variance: `MultibandImage`, or list of `Image` Variance of the `image`. thresh: `float` or `list` of floats Threshold in each band (or the same threshold to be used in all bands) to include a pixel in the `SpanSet` of the `MultibandFootprint`. If `Footprint` is not `None` then `thresh` is ignored. peaks: `PeakCatalog` Catalog containing information about the peaks located in the footprints.
Returns ------- result: `MultibandFootprint` MultibandFootprint created from the image, mask, and variance """ # Generate a new Footprint if one has not been specified
"""Create a `MultibandFootprint` from a list of `MaskedImage`
See `fromImages` for a description of the parameters not listed below
Parameters ---------- maskedImages: `list` of `MaskedImage` MaskedImages to extract the single band heavy footprints from. Like `fromImage`, if a `footprint` is not specified then all pixels above `thresh` will be used, and `peaks` will be added to the `PeakCatalog`.
Returns ------- result: `MultibandFootprint` MultibandFootprint created from the image, mask, and variance """ image = [maskedImage.image for maskedImage in maskedImages] mask = [maskedImage.mask for maskedImage in maskedImages] variance = [maskedImage.variance for maskedImage in maskedImages] return MultibandFootprint.fromImages(filters, image, mask, variance, footprint, thresh, peaks)
"""Get the full `SpanSet`"""
def footprint(self): """Common SpanSet and peak catalog for the single band footprints""" return self._footprint
def mMaskedImage(self): """MultibandMaskedImage that the footprints present a view into""" return self._mMaskedImage
def spans(self): """`SpanSet` of the `MultibandFootprint`""" return self._footprint.getSpans()
"""Get the `PeakCatalog`"""
def peaks(self): """`PeakCatalog` of the `MultibandFootprint`""" return self._footprint.getPeaks()
"""Slice the current object and return the result
`MultibandFootprint` objects cannot be sliced along the image dimension, so an error is thrown if `indices` has any elements.
See `Multiband._slice` for a list of the parameters. """
else:
"""Convert a `MultibandFootprint` to a `MultibandImage`
This returns the heavy footprints converted into an `MultibandImage` or `MultibandMaskedImage` (depending on `imageType`). This might be different than the internal `mMaskedImage` property of the `MultibandFootprint`, as the `mMaskedImage` might contain some non-zero pixels not contained in the footprint but present in the images.
Parameters ---------- bbox: `Box2I` Bounding box of the resulting image. If no bounding box is specified, then the bounding box of the footprint is used. fill: `float` Value to use for any pixel in the resulting image outside of the `SpanSet`. imageType: `type` This should be either a `MultibandMaskedImage` or `MultibandImage` and describes the type of the output image.
Returns ------- result: `MultibandBase` The resulting `MultibandImage` or `MultibandMaskedImage` created from the `MultibandHeavyFootprint`. """ elif imageType == MultibandImage: singleType = Image else: raise TypeError("Expected imageType to be either MultibandImage or MultibandMaskedImage")
"""Copy the current object
Parameters ---------- deep: `bool` Whether or not to make a deep copy
Returns ------- result: `MultibandFootprint` The cloned footprint. """ if deep: footprint = Footprint(self.footprint.getSpans()) for peak in self.footprint.getPeaks(): footprint.addPeak(peak.getX(), peak.getY(), peak.getValue()) mMaskedImage = self.getImage() filters = tuple([f for f in self.filters]) result = MultibandFootprint.fromMaskedImages(filters, mMaskedImage, footprint) else: result = MultibandFootprint(self.filters, self.singles) return result |