126 """Set valid polygon on ccdExposure associated with focal plane polygon.
128 The ccd exposure's valid polygon is the intersection of fpPolygon,
129 a valid polygon in focal plane coordinates, and the ccd corners,
130 in ccd pixel coordinates.
134 ccdExposure : `lsst.afw.image.Exposure`
136 fpPolygon : `lsst.afw.geom.Polygon`
137 Polygon in focal plane coordinates.
138 log : `logging.Logger`, optional
139 Log object to write to.
140 setPolygon : `bool`, optional
141 Actually set the polygon, or just return it?
145 validPolygon : `lsst.afw.geom.Polygon`
146 Valid polygon with the intersection.
149 ccd = ccdExposure.getDetector()
150 fpCorners = ccd.getCorners(cameraGeom.FOCAL_PLANE)
151 ccdPolygon = afwGeom.Polygon(fpCorners)
154 intersect = ccdPolygon.intersectionSingle(fpPolygon)
155 except afwGeom.SinglePolygonException:
157 if intersect
is not None:
159 ccdPoints = ccd.transform(intersect, cameraGeom.FOCAL_PLANE, cameraGeom.PIXELS)
160 validPolygon = afwGeom.Polygon(ccdPoints)
162 ccdExposure.getInfo().setValidPolygon(validPolygon)
165 log.info(
"Ccd exposure does not overlap with focal plane polygon. Not setting validPolygon.")
172 """Add mask bit to image pixels according to vignetted polygon region.
174 NOTE: this function could be used to mask and replace pixels associated
175 with any polygon in the exposure pixel coordinates.
179 exposure : `lsst.afw.image.Exposure`
180 Image whose mask plane is to be updated.
181 polygon : `lsst.afw.geom.Polygon`
182 Polygon region defining the vignetted region in the pixel coordinates
184 maskPlane : `str`, optional
185 Mask plane to assign vignetted pixels to.
186 vignetteValue : `float` or `None`, optional
187 Value to assign to the image array pixels within the ``polygon``
188 region. If `None`, image pixel values are not replaced.
189 log : `logging.Logger`, optional
190 Log object to write to.
195 Raised if no valid polygon exists.
197 log = log
if log
else logging.getLogger(__name__)
199 log.info(
"No polygon provided. Masking nothing.")
202 fullyIlluminated =
True
203 if not all(polygon.contains(exposure.getBBox().getCorners())):
204 fullyIlluminated =
False
205 log.info(
"Exposure is fully illuminated? %s", fullyIlluminated)
207 if not fullyIlluminated:
209 mask = exposure.getMask()
210 xx, yy = np.meshgrid(np.arange(0, mask.getWidth(), dtype=float),
211 np.arange(0, mask.getHeight(), dtype=float))
213 vignMask = ~(polygon.contains(xx, yy))
215 bitMask = mask.getPlaneBitMask(maskPlane)
216 maskArray = mask.getArray()
217 maskArray[vignMask] |= bitMask
218 log.info(
"Exposure contains {} vignetted pixels which are now masked with mask plane {}.".
219 format(np.count_nonzero(vignMask), maskPlane))
221 if vignetteValue
is not None:
222 imageArray = exposure.getImage().getArray()
223 imageArray[vignMask] = vignetteValue
224 log.info(
"Vignetted pixels in image array have been replaced with {}.".format(vignetteValue))