1 from __future__
import absolute_import, division, print_function
2 from builtins
import object
29 __all__ = [
"Warper",
"WarperConfig"]
33 """Compute the bounding box of a warped image 35 The bounding box includes all warped pixels and it may be a bit oversize. 37 @param destWcs: WCS of warped exposure 38 @param srcBBox: parent bounding box of unwarped image 39 @param srcWcs: WCS of unwarped image 41 @return destBBox: bounding box of warped exposure 45 for inX
in (srcPosBox.getMinX(), srcPosBox.getMaxX()):
46 for inY
in (srcPosBox.getMinY(), srcPosBox.getMaxY()):
47 destPos = destWcs.skyToPixel(
49 destPosBox.include(destPos)
54 _DefaultInterpLength = 10
55 _DefaultCacheSize = 1000000
59 warpingKernelName = pexConfig.ChoiceField(
61 doc =
"Warping kernel",
64 "bilinear":
"bilinear interpolation",
65 "lanczos3":
"Lanczos kernel of order 3",
66 "lanczos4":
"Lanczos kernel of order 4",
67 "lanczos5":
"Lanczos kernel of order 5",
70 maskWarpingKernelName = pexConfig.ChoiceField(
72 doc =
"Warping kernel for mask (use warpingKernelName if '')",
75 "":
"use the regular warping kernel for the mask plane, as well as the image and variance planes",
76 "bilinear":
"bilinear interpolation",
77 "lanczos3":
"Lanczos kernel of order 3",
78 "lanczos4":
"Lanczos kernel of order 4",
79 "lanczos5":
"Lanczos kernel of order 5",
82 interpLength = pexConfig.Field(
84 doc =
"interpLength argument to lsst.afw.math.warpExposure",
85 default = _DefaultInterpLength,
87 cacheSize = pexConfig.Field(
89 doc =
"cacheSize argument to lsst.afw.math.SeparableKernel.computeCache",
90 default = _DefaultCacheSize,
92 growFullMask = pexConfig.Field(
94 doc =
"mask bits to grow to full width of image/variance kernel,",
95 default = afwImage.Mask.getPlaneBitMask(
"EDGE"),
102 ConfigClass = WarperConfig
106 interpLength = _DefaultInterpLength,
107 cacheSize = _DefaultCacheSize,
108 maskWarpingKernelName = "",
109 growFullMask = afwImage.Mask.getPlaneBitMask(
"EDGE"),):
113 - warpingKernelName: argument to lsst.afw.math.makeWarpingKernel 114 - interpLength: interpLength argument to lsst.afw.warpExposure 115 - cacheSize: size of computeCache 116 - maskWarpingKernelName: name of mask warping kernel (if "" then use warpingKernelName); 117 an argument to lsst.afw.math.makeWarpingKernel 120 warpingKernelName, maskWarpingKernelName, cacheSize, interpLength, growFullMask)
124 """Create a Warper from a config 126 @param config: an instance of Warper.ConfigClass 129 warpingKernelName = config.warpingKernelName,
130 maskWarpingKernelName = config.maskWarpingKernelName,
131 interpLength = config.interpLength,
132 cacheSize = config.cacheSize,
133 growFullMask = config.growFullMask,
137 """Get the warping kernel""" 141 """Get the mask warping kernel""" 144 def warpExposure(self, destWcs, srcExposure, border=0, maxBBox=None, destBBox=None):
147 @param destWcs: WCS of warped exposure 148 @param srcExposure: exposure to warp 149 @param border: grow bbox of warped exposure by this amount in all directions (int pixels); 150 if negative then the bbox is shrunk; 151 border is applied before maxBBox; 152 ignored if destBBox is not None 153 @param maxBBox: maximum allowed parent bbox of warped exposure (an afwGeom.Box2I or None); 154 if None then the warped exposure will be just big enough to contain all warped pixels; 155 if provided then the warped exposure may be smaller, and so missing some warped pixels; 156 ignored if destBBox is not None 157 @param destBBox: exact parent bbox of warped exposure (an afwGeom.Box2I or None); 158 if None then border and maxBBox are used to determine the bbox, 159 otherwise border and maxBBox are ignored 161 @return destExposure: warped exposure (of same type as srcExposure) 163 @note: calls mathLib.warpExposure insted of self.warpImage because the former 164 copies attributes such as Calib, and that should be done in one place 168 srcImage = srcExposure.getMaskedImage(),
169 srcWcs = srcExposure.getWcs(),
174 destExposure = srcExposure.Factory(destBBox, destWcs)
178 def warpImage(self, destWcs, srcImage, srcWcs, border=0, maxBBox=None, destBBox=None):
179 """Warp an image or masked image 181 @param destWcs: WCS of warped image 182 @param srcImage: image or masked image to warp 183 @param srcWcs: WCS of image 184 @param border: grow bbox of warped image by this amount in all directions (int pixels); 185 if negative then the bbox is shrunk; 186 border is applied before maxBBox; 187 ignored if destBBox is not None 188 @param maxBBox: maximum allowed parent bbox of warped image (an afwGeom.Box2I or None); 189 if None then the warped image will be just big enough to contain all warped pixels; 190 if provided then the warped image may be smaller, and so missing some warped pixels; 191 ignored if destBBox is not None 192 @param destBBox: exact parent bbox of warped image (an afwGeom.Box2I or None); 193 if None then border and maxBBox are used to determine the bbox, 194 otherwise border and maxBBox are ignored 196 @return destImage: warped image or masked image (of same type as srcImage) 206 destImage = srcImage.Factory(destBBox)
207 mathLib.warpImage(destImage, destWcs, srcImage,
211 def _computeDestBBox(self, destWcs, srcImage, srcWcs, border, maxBBox, destBBox):
212 """Process destBBox argument for warpImage and warpExposure 214 @param destWcs: WCS of warped image 215 @param srcImage: image or masked image to warp 216 @param srcWcs: WCS of image 217 @param border: grow bbox of warped image by this amount in all directions (int pixels); 218 if negative then the bbox is shrunk; 219 border is applied before maxBBox; 220 ignored if destBBox is not None 221 @param maxBBox: maximum allowed parent bbox of warped image (an afwGeom.Box2I or None); 222 if None then the warped image will be just big enough to contain all warped pixels; 223 if provided then the warped image may be smaller, and so missing some warped pixels; 224 ignored if destBBox is not None 225 @param destBBox: exact parent bbox of warped image (an afwGeom.Box2I or None); 226 if None then border and maxBBox are used to determine the bbox, 227 otherwise border and maxBBox are ignored 231 destWcs, srcImage.getBBox(afwImage.PARENT), srcWcs)
233 destBBox.grow(border)
234 if maxBBox
is not None:
235 destBBox.clip(maxBBox)
def _computeDestBBox(self, destWcs, srcImage, srcWcs, border, maxBBox, destBBox)
def getMaskWarpingKernel(self)
def warpExposure(self, destWcs, srcExposure, border=0, maxBBox=None, destBBox=None)
def computeWarpedBBox(destWcs, srcBBox, srcWcs)
An integer coordinate rectangle.
def getWarpingKernel(self)
def __init__(self, warpingKernelName, interpLength=_DefaultInterpLength, cacheSize=_DefaultCacheSize, maskWarpingKernelName="", growFullMask=afwImage.Mask.getPlaneBitMask("EDGE"))
def warpImage(self, destWcs, srcImage, srcWcs, border=0, maxBBox=None, destBBox=None)
def fromConfig(cls, config)
A floating-point coordinate rectangle geometry.