1 from __future__
import absolute_import
2 from builtins
import object
29 __all__ = [
"Warper",
"WarperConfig"]
32 """Compute the bounding box of a warped image
34 The bounding box includes all warped pixels and it may be a bit oversize.
36 @param destWcs: WCS of warped exposure
37 @param srcBBox: parent bounding box of unwarped image
38 @param srcWcs: WCS of unwarped image
40 @return destBBox: bounding box of warped exposure
44 for inX
in (srcPosBox.getMinX(), srcPosBox.getMaxX()):
45 for inY
in (srcPosBox.getMinY(), srcPosBox.getMaxY()):
46 destPos = destWcs.skyToPixel(srcWcs.pixelToSky(
afwGeom.Point2D(inX, inY)))
47 destPosBox.include(destPos)
51 _DefaultInterpLength = 10
52 _DefaultCacheSize = 1000000
55 warpingKernelName = pexConfig.ChoiceField(
57 doc =
"Warping kernel",
60 "bilinear":
"bilinear interpolation",
61 "lanczos3":
"Lanczos kernel of order 3",
62 "lanczos4":
"Lanczos kernel of order 4",
63 "lanczos5":
"Lanczos kernel of order 5",
66 maskWarpingKernelName = pexConfig.ChoiceField(
68 doc =
"Warping kernel for mask (use warpingKernelName if '')",
71 "":
"use the regular warping kernel for the mask plane, as well as the image and variance planes",
72 "bilinear":
"bilinear interpolation",
73 "lanczos3":
"Lanczos kernel of order 3",
74 "lanczos4":
"Lanczos kernel of order 4",
75 "lanczos5":
"Lanczos kernel of order 5",
78 interpLength = pexConfig.Field(
80 doc =
"interpLength argument to lsst.afw.math.warpExposure",
81 default = _DefaultInterpLength,
83 cacheSize = pexConfig.Field(
85 doc =
"cacheSize argument to lsst.afw.math.SeparableKernel.computeCache",
86 default = _DefaultCacheSize,
88 growFullMask = pexConfig.Field(
90 doc =
"mask bits to grow to full width of image/variance kernel,",
91 default = afwImage.MaskU.getPlaneBitMask(
"EDGE"),
97 ConfigClass = WarperConfig
100 interpLength = _DefaultInterpLength,
101 cacheSize = _DefaultCacheSize,
102 maskWarpingKernelName =
"",
103 growFullMask = afwImage.MaskU.getPlaneBitMask(
"EDGE"),
108 - warpingKernelName: argument to lsst.afw.math.makeWarpingKernel
109 - interpLength: interpLength argument to lsst.afw.warpExposure
110 - cacheSize: size of computeCache
111 - maskWarpingKernelName: name of mask warping kernel (if "" then use warpingKernelName);
112 an argument to lsst.afw.math.makeWarpingKernel
115 warpingKernelName, maskWarpingKernelName, cacheSize, interpLength, growFullMask)
119 """Create a Warper from a config
121 @param config: an instance of Warper.ConfigClass
124 warpingKernelName = config.warpingKernelName,
125 maskWarpingKernelName = config.maskWarpingKernelName,
126 interpLength = config.interpLength,
127 cacheSize = config.cacheSize,
128 growFullMask = config.growFullMask,
132 """Get the warping kernel"""
133 return self._warpingControl.getWarpingKernel()
136 """Get the mask warping kernel"""
137 return self._warpingControl.getMaskWarpingKernel()
139 def warpExposure(self, destWcs, srcExposure, border=0, maxBBox=None, destBBox=None):
142 @param destWcs: WCS of warped exposure
143 @param srcExposure: exposure to warp
144 @param border: grow bbox of warped exposure by this amount in all directions (int pixels);
145 if negative then the bbox is shrunk;
146 border is applied before maxBBox;
147 ignored if destBBox is not None
148 @param maxBBox: maximum allowed parent bbox of warped exposure (an afwGeom.Box2I or None);
149 if None then the warped exposure will be just big enough to contain all warped pixels;
150 if provided then the warped exposure may be smaller, and so missing some warped pixels;
151 ignored if destBBox is not None
152 @param destBBox: exact parent bbox of warped exposure (an afwGeom.Box2I or None);
153 if None then border and maxBBox are used to determine the bbox,
154 otherwise border and maxBBox are ignored
156 @return destExposure: warped exposure (of same type as srcExposure)
158 @note: calls mathLib.warpExposure insted of self.warpImage because the former
159 copies attributes such as Calib, and that should be done in one place
163 srcImage = srcExposure.getMaskedImage(),
164 srcWcs = srcExposure.getWcs(),
169 destExposure = srcExposure.Factory(destBBox, destWcs)
173 def warpImage(self, destWcs, srcImage, srcWcs, border=0, maxBBox=None, destBBox=None):
174 """Warp an image or masked image
176 @param destWcs: WCS of warped image
177 @param srcImage: image or masked image to warp
178 @param srcWcs: WCS of image
179 @param border: grow bbox of warped image by this amount in all directions (int pixels);
180 if negative then the bbox is shrunk;
181 border is applied before maxBBox;
182 ignored if destBBox is not None
183 @param maxBBox: maximum allowed parent bbox of warped image (an afwGeom.Box2I or None);
184 if None then the warped image will be just big enough to contain all warped pixels;
185 if provided then the warped image may be smaller, and so missing some warped pixels;
186 ignored if destBBox is not None
187 @param destBBox: exact parent bbox of warped image (an afwGeom.Box2I or None);
188 if None then border and maxBBox are used to determine the bbox,
189 otherwise border and maxBBox are ignored
191 @return destImage: warped image or masked image (of same type as srcImage)
201 destImage = srcImage.Factory(destBBox)
202 mathLib.warpImage(destImage, destWcs, srcImage, srcWcs, self.
_warpingControl)
206 """Process destBBox argument for warpImage and warpExposure
208 @param destWcs: WCS of warped image
209 @param srcImage: image or masked image to warp
210 @param srcWcs: WCS of image
211 @param border: grow bbox of warped image by this amount in all directions (int pixels);
212 if negative then the bbox is shrunk;
213 border is applied before maxBBox;
214 ignored if destBBox is not None
215 @param maxBBox: maximum allowed parent bbox of warped image (an afwGeom.Box2I or None);
216 if None then the warped image will be just big enough to contain all warped pixels;
217 if provided then the warped image may be smaller, and so missing some warped pixels;
218 ignored if destBBox is not None
219 @param destBBox: exact parent bbox of warped image (an afwGeom.Box2I or None);
220 if None then border and maxBBox are used to determine the bbox,
221 otherwise border and maxBBox are ignored
226 destBBox.grow(border)
227 if maxBBox
is not None:
228 destBBox.clip(maxBBox)
An integer coordinate rectangle.
A floating-point coordinate rectangle geometry.