23 __all__ = [
"clipImage",
"resetFilters",
"defineFilter",
24 "defineFiltersFromPolicy",
"CalibNoThrow",
"projectImage",
"getProjectionIndices"]
30 from .maskedImage
import MaskedImage, makeMaskedImage
31 from .image
import Mask
32 from .filter
import Filter, FilterProperty
33 from .calib
import Calib
37 """Clip an image to lie between minClip and maxclip (None to ignore)""" 38 if isinstance(im, MaskedImage):
43 if minClip
is not None:
46 afwDetect.setImageFromFootprintList(
47 mi.getImage(), ds.getFootprints(), minClip)
49 if maxClip
is not None:
51 afwDetect.setImageFromFootprintList(
52 mi.getImage(), ds.getFootprints(), maxClip)
56 """Reset registry of filters and filter properties""" 58 FilterProperty.reset()
61 def defineFilter(name, lambdaEff, lambdaMin=np.nan, lambdaMax=np.nan, alias=[], force=False):
62 """Define a filter and its properties in the filter registry""" 63 prop = FilterProperty(name, lambdaEff, lambdaMin, lambdaMax, force)
65 if isinstance(alias, str):
66 Filter.defineAlias(name, alias)
69 Filter.defineAlias(name, a)
73 """Process a Policy and define the filters""" 77 FilterProperty.reset()
82 "afw",
"FilterDictionary.paf",
"policy")
83 defPolicy = pexPolicy.Policy.createPolicy(
84 policyFile, policyFile.getRepositoryPath(),
True)
86 filterPolicy.mergeDefaults(defPolicy.getDictionary())
88 for p
in filterPolicy.getArray(
"Filter"):
89 Filter.define(FilterProperty(p.get(
"name"), p))
91 for a
in p.getArray(
"alias"):
92 Filter.defineAlias(p.get(
"name"), a)
96 """A class intended to be used with python's with statement, to return NaNs for negative fluxes 97 instead of raising exceptions (exceptions may be raised for other purposes). 101 ax.plot([exposure.getCalib().getMagnitude(a) for a in candAmps], zGood[:,k], 'b+') 106 Calib.setThrowOnNegativeFlux(
False)
113 """Get the indices to project an image 115 Given an image and target bounding box, 116 calculate the indices needed to appropriately 117 slice the input image and target image to 118 project the image to the target. 123 Bounding box of the input image 125 Bounding box of the target image 130 Slices of the target image in the form (by, bx), (iy, ix). 132 Slices of the input image in the form (by, bx), (iy, ix). 135 """Get minimum indices""" 142 return bxStart, ixStart
145 """Get maximum indices""" 156 dXmin = targetBBox.getMinX() - imageBBox.getMinX()
157 dXmax = targetBBox.getMaxX() - imageBBox.getMaxX()
158 dYmin = targetBBox.getMinY() - imageBBox.getMinY()
159 dYmax = targetBBox.getMaxY() - imageBBox.getMaxY()
161 bxStart, ixStart = getMin(dXmin)
162 byStart, iyStart = getMin(dYmin)
163 bxEnd, ixEnd = getMax(dXmax)
164 byEnd, iyEnd = getMax(dYmax)
166 bx = slice(bxStart, bxEnd)
167 by = slice(byStart, byEnd)
168 ix = slice(ixStart, ixEnd)
169 iy = slice(iyStart, iyEnd)
170 return (by, bx), (iy, ix)
174 """Project an image into a bounding box 176 Return a new image whose pixels are equal to those of 177 `image` within `bbox`, and equal to `fill` outside. 181 image: `afw.Image` or `afw.MaskedImage` 184 The bounding box to project onto. 186 The value to fill the region of the new 187 image outside the bounding box of the original. 191 newImage: `afw.Image` or `afw.MaskedImage` 192 The new image with the input image projected 193 into its bounding box. 195 if image.getBBox() == bbox:
199 if isinstance(image, MaskedImage):
200 newImage =
type(image.image)(bbox)
201 newImage.array[by, bx] = image.image.array[iy, ix]
202 newMask =
type(image.mask)(bbox)
203 newMask.array[by, bx] = image.mask.array[iy, ix]
204 newVariance =
type(image.image)(bbox)
205 newVariance.array[by, bx] = image.variance.array[iy, ix]
206 newImage =
MaskedImage(image=newImage, mask=newMask, variance=newVariance, dtype=newImage.array.dtype)
208 newImage =
type(image)(bbox)
211 newImage.array[by, bx] = image.array[iy, ix]
def defineFiltersFromPolicy(filterPolicy, reset=False)
a representation of a default Policy file that is stored as a file in the installation directory of a...
A Threshold is used to pass a threshold value to detection algorithms.
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT >> image, typename std::shared_ptr< Mask< MaskPixelT >> mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT >> variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.
def defineFilter(name, lambdaEff, lambdaMin=np.nan, lambdaMax=np.nan, alias=[], force=False)
Represent a 2-dimensional array of bitmask pixels.
def clipImage(im, minClip, maxClip)
def projectImage(image, bbox, fill=0)
def getProjectionIndices(imageBBox, targetBBox)