28 __all__ = [
"Warper",
"WarperConfig"]
31 """Compute the bounding box of a warped image
33 The bounding box includes all warped pixels and it may be a bit oversize.
35 @param destWcs: WCS of warped exposure
36 @param srcBBox: parent bounding box of unwarped image
37 @param srcWcs: WCS of unwarped image
39 @return destBBox: bounding box of warped exposure
43 for inX
in (srcPosBox.getMinX(), srcPosBox.getMaxX()):
44 for inY
in (srcPosBox.getMinY(), srcPosBox.getMaxY()):
45 destPos = destWcs.skyToPixel(srcWcs.pixelToSky(
afwGeom.Point2D(inX, inY)))
46 destPosBox.include(destPos)
50 _DefaultInterpLength = 10
54 warpingKernelName = pexConfig.ChoiceField(
56 doc =
"Warping kernel",
59 "bilinear":
"bilinear interpolation",
60 "lanczos3":
"Lanczos kernel of order 3",
61 "lanczos4":
"Lanczos kernel of order 4",
62 "lanczos5":
"Lanczos kernel of order 5",
65 maskWarpingKernelName = pexConfig.ChoiceField(
67 doc =
"Warping kernel for mask (use warpingKernelName if '')",
70 "":
"use the regular warping kernel for the mask plane, as well as the image and variance planes",
71 "bilinear":
"bilinear interpolation",
72 "lanczos3":
"Lanczos kernel of order 3",
73 "lanczos4":
"Lanczos kernel of order 4",
74 "lanczos5":
"Lanczos kernel of order 5",
77 interpLength = pexConfig.Field(
79 doc =
"interpLength argument to lsst.afw.math.warpExposure",
80 default = _DefaultInterpLength,
82 cacheSize = pexConfig.Field(
84 doc =
"cacheSize argument to lsst.afw.math.SeparableKernel.computeCache",
85 default = _DefaultCacheSize,
87 devicePreference = pexConfig.Field(
89 doc =
"use GPU acceleration?",
90 default = afwGpu.DEFAULT_DEVICE_PREFERENCE,
92 growFullMask = pexConfig.Field(
94 doc =
"mask bits to grow to full width of image/variance kernel,",
95 default = afwImage.MaskU.getPlaneBitMask(
"EDGE"),
101 ConfigClass = WarperConfig
104 interpLength = _DefaultInterpLength,
105 cacheSize = _DefaultCacheSize,
106 maskWarpingKernelName =
"",
107 devicePreference = afwGpu.DEFAULT_DEVICE_PREFERENCE,
108 growFullMask = afwImage.MaskU.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, devicePreference, 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 devicePreference = config.devicePreference,
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, srcWcs, self.
_warpingControl)
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
232 destBBox.grow(border)
233 if maxBBox
is not None:
234 destBBox.clip(maxBBox)
An integer coordinate rectangle.
A floating-point coordinate rectangle geometry.