1 from __future__
import absolute_import, division, print_function
2 from builtins
import object
24 import lsst.pex.config
as pexConfig
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.MaskU.getPlaneBitMask(
"EDGE"),
102 ConfigClass = WarperConfig
106 interpLength = _DefaultInterpLength,
107 cacheSize = _DefaultCacheSize,
108 maskWarpingKernelName =
"",
109 growFullMask = afwImage.MaskU.getPlaneBitMask(
"EDGE"),
114 - warpingKernelName: argument to lsst.afw.math.makeWarpingKernel
115 - interpLength: interpLength argument to lsst.afw.warpExposure
116 - cacheSize: size of computeCache
117 - maskWarpingKernelName: name of mask warping kernel (if "" then use warpingKernelName);
118 an argument to lsst.afw.math.makeWarpingKernel
121 warpingKernelName, maskWarpingKernelName, cacheSize, interpLength, growFullMask)
125 """Create a Warper from a config
127 @param config: an instance of Warper.ConfigClass
130 warpingKernelName = config.warpingKernelName,
131 maskWarpingKernelName = config.maskWarpingKernelName,
132 interpLength = config.interpLength,
133 cacheSize = config.cacheSize,
134 growFullMask = config.growFullMask,
138 """Get the warping kernel"""
139 return self._warpingControl.getWarpingKernel()
142 """Get the mask warping kernel"""
143 return self._warpingControl.getMaskWarpingKernel()
145 def warpExposure(self, destWcs, srcExposure, border=0, maxBBox=None, destBBox=None):
148 @param destWcs: WCS of warped exposure
149 @param srcExposure: exposure to warp
150 @param border: grow bbox of warped exposure by this amount in all directions (int pixels);
151 if negative then the bbox is shrunk;
152 border is applied before maxBBox;
153 ignored if destBBox is not None
154 @param maxBBox: maximum allowed parent bbox of warped exposure (an afwGeom.Box2I or None);
155 if None then the warped exposure will be just big enough to contain all warped pixels;
156 if provided then the warped exposure may be smaller, and so missing some warped pixels;
157 ignored if destBBox is not None
158 @param destBBox: exact parent bbox of warped exposure (an afwGeom.Box2I or None);
159 if None then border and maxBBox are used to determine the bbox,
160 otherwise border and maxBBox are ignored
162 @return destExposure: warped exposure (of same type as srcExposure)
164 @note: calls mathLib.warpExposure insted of self.warpImage because the former
165 copies attributes such as Calib, and that should be done in one place
169 srcImage = srcExposure.getMaskedImage(),
170 srcWcs = srcExposure.getWcs(),
175 destExposure = srcExposure.Factory(destBBox, destWcs)
179 def warpImage(self, destWcs, srcImage, srcWcs, border=0, maxBBox=None, destBBox=None):
180 """Warp an image or masked image
182 @param destWcs: WCS of warped image
183 @param srcImage: image or masked image to warp
184 @param srcWcs: WCS of image
185 @param border: grow bbox of warped image by this amount in all directions (int pixels);
186 if negative then the bbox is shrunk;
187 border is applied before maxBBox;
188 ignored if destBBox is not None
189 @param maxBBox: maximum allowed parent bbox of warped image (an afwGeom.Box2I or None);
190 if None then the warped image will be just big enough to contain all warped pixels;
191 if provided then the warped image may be smaller, and so missing some warped pixels;
192 ignored if destBBox is not None
193 @param destBBox: exact parent bbox of warped image (an afwGeom.Box2I or None);
194 if None then border and maxBBox are used to determine the bbox,
195 otherwise border and maxBBox are ignored
197 @return destImage: warped image or masked image (of same type as srcImage)
207 destImage = srcImage.Factory(destBBox)
208 mathLib.warpImage(destImage, destWcs, srcImage,
212 def _computeDestBBox(self, destWcs, srcImage, srcWcs, border, maxBBox, destBBox):
213 """Process destBBox argument for warpImage and warpExposure
215 @param destWcs: WCS of warped image
216 @param srcImage: image or masked image to warp
217 @param srcWcs: WCS of image
218 @param border: grow bbox of warped image by this amount in all directions (int pixels);
219 if negative then the bbox is shrunk;
220 border is applied before maxBBox;
221 ignored if destBBox is not None
222 @param maxBBox: maximum allowed parent bbox of warped image (an afwGeom.Box2I or None);
223 if None then the warped image will be just big enough to contain all warped pixels;
224 if provided then the warped image may be smaller, and so missing some warped pixels;
225 ignored if destBBox is not None
226 @param destBBox: exact parent bbox of warped image (an afwGeom.Box2I or None);
227 if None then border and maxBBox are used to determine the bbox,
228 otherwise border and maxBBox are ignored
232 destWcs, srcImage.getBBox(afwImage.PARENT), srcWcs)
234 destBBox.grow(border)
235 if maxBBox
is not None:
236 destBBox.clip(maxBBox)
An integer coordinate rectangle.
A floating-point coordinate rectangle geometry.