1 from __future__
import absolute_import
2 from builtins
import object
30 __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(srcWcs.pixelToSky(
afwGeom.Point2D(inX, inY)))
48 destPosBox.include(destPos)
52 _DefaultInterpLength = 10
53 _DefaultCacheSize = 1000000
56 warpingKernelName = pexConfig.ChoiceField(
58 doc =
"Warping kernel",
61 "bilinear":
"bilinear interpolation",
62 "lanczos3":
"Lanczos kernel of order 3",
63 "lanczos4":
"Lanczos kernel of order 4",
64 "lanczos5":
"Lanczos kernel of order 5",
67 maskWarpingKernelName = pexConfig.ChoiceField(
69 doc =
"Warping kernel for mask (use warpingKernelName if '')",
72 "":
"use the regular warping kernel for the mask plane, as well as the image and variance planes",
73 "bilinear":
"bilinear interpolation",
74 "lanczos3":
"Lanczos kernel of order 3",
75 "lanczos4":
"Lanczos kernel of order 4",
76 "lanczos5":
"Lanczos kernel of order 5",
79 interpLength = pexConfig.Field(
81 doc =
"interpLength argument to lsst.afw.math.warpExposure",
82 default = _DefaultInterpLength,
84 cacheSize = pexConfig.Field(
86 doc =
"cacheSize argument to lsst.afw.math.SeparableKernel.computeCache",
87 default = _DefaultCacheSize,
89 devicePreference = pexConfig.Field(
91 doc =
"use GPU acceleration?",
92 default = afwGpu.DEFAULT_DEVICE_PREFERENCE,
94 growFullMask = pexConfig.Field(
96 doc =
"mask bits to grow to full width of image/variance kernel,",
97 default = afwImage.MaskU.getPlaneBitMask(
"EDGE"),
103 ConfigClass = WarperConfig
106 interpLength = _DefaultInterpLength,
107 cacheSize = _DefaultCacheSize,
108 maskWarpingKernelName =
"",
109 devicePreference = afwGpu.DEFAULT_DEVICE_PREFERENCE,
110 growFullMask = afwImage.MaskU.getPlaneBitMask(
"EDGE"),
115 - warpingKernelName: argument to lsst.afw.math.makeWarpingKernel
116 - interpLength: interpLength argument to lsst.afw.warpExposure
117 - cacheSize: size of computeCache
118 - maskWarpingKernelName: name of mask warping kernel (if "" then use warpingKernelName);
119 an argument to lsst.afw.math.makeWarpingKernel
122 warpingKernelName, maskWarpingKernelName, cacheSize, interpLength, devicePreference, growFullMask)
126 """Create a Warper from a config
128 @param config: an instance of Warper.ConfigClass
131 warpingKernelName = config.warpingKernelName,
132 maskWarpingKernelName = config.maskWarpingKernelName,
133 interpLength = config.interpLength,
134 cacheSize = config.cacheSize,
135 devicePreference = config.devicePreference,
136 growFullMask = config.growFullMask,
140 """Get the warping kernel"""
141 return self._warpingControl.getWarpingKernel()
144 """Get the mask warping kernel"""
145 return self._warpingControl.getMaskWarpingKernel()
147 def warpExposure(self, destWcs, srcExposure, border=0, maxBBox=None, destBBox=None):
150 @param destWcs: WCS of warped exposure
151 @param srcExposure: exposure to warp
152 @param border: grow bbox of warped exposure by this amount in all directions (int pixels);
153 if negative then the bbox is shrunk;
154 border is applied before maxBBox;
155 ignored if destBBox is not None
156 @param maxBBox: maximum allowed parent bbox of warped exposure (an afwGeom.Box2I or None);
157 if None then the warped exposure will be just big enough to contain all warped pixels;
158 if provided then the warped exposure may be smaller, and so missing some warped pixels;
159 ignored if destBBox is not None
160 @param destBBox: exact parent bbox of warped exposure (an afwGeom.Box2I or None);
161 if None then border and maxBBox are used to determine the bbox,
162 otherwise border and maxBBox are ignored
164 @return destExposure: warped exposure (of same type as srcExposure)
166 @note: calls mathLib.warpExposure insted of self.warpImage because the former
167 copies attributes such as Calib, and that should be done in one place
171 srcImage = srcExposure.getMaskedImage(),
172 srcWcs = srcExposure.getWcs(),
177 destExposure = srcExposure.Factory(destBBox, destWcs)
181 def warpImage(self, destWcs, srcImage, srcWcs, border=0, maxBBox=None, destBBox=None):
182 """Warp an image or masked image
184 @param destWcs: WCS of warped image
185 @param srcImage: image or masked image to warp
186 @param srcWcs: WCS of image
187 @param border: grow bbox of warped image by this amount in all directions (int pixels);
188 if negative then the bbox is shrunk;
189 border is applied before maxBBox;
190 ignored if destBBox is not None
191 @param maxBBox: maximum allowed parent bbox of warped image (an afwGeom.Box2I or None);
192 if None then the warped image will be just big enough to contain all warped pixels;
193 if provided then the warped image may be smaller, and so missing some warped pixels;
194 ignored if destBBox is not None
195 @param destBBox: exact parent bbox of warped image (an afwGeom.Box2I or None);
196 if None then border and maxBBox are used to determine the bbox,
197 otherwise border and maxBBox are ignored
199 @return destImage: warped image or masked image (of same type as srcImage)
209 destImage = srcImage.Factory(destBBox)
210 mathLib.warpImage(destImage, destWcs, srcImage, srcWcs, self.
_warpingControl)
214 """Process destBBox argument for warpImage and warpExposure
216 @param destWcs: WCS of warped image
217 @param srcImage: image or masked image to warp
218 @param srcWcs: WCS of image
219 @param border: grow bbox of warped image by this amount in all directions (int pixels);
220 if negative then the bbox is shrunk;
221 border is applied before maxBBox;
222 ignored if destBBox is not None
223 @param maxBBox: maximum allowed parent bbox of warped image (an afwGeom.Box2I or None);
224 if None then the warped image will be just big enough to contain all warped pixels;
225 if provided then the warped image may be smaller, and so missing some warped pixels;
226 ignored if destBBox is not None
227 @param destBBox: exact parent bbox of warped image (an afwGeom.Box2I or None);
228 if None then border and maxBBox are used to determine the bbox,
229 otherwise border and maxBBox are ignored
234 destBBox.grow(border)
235 if maxBBox
is not None:
236 destBBox.clip(maxBBox)
An integer coordinate rectangle.
A floating-point coordinate rectangle geometry.