117 """Set valid polygon on ccdExposure associated with focal plane polygon.
119 The ccd exposure's valid polygon is the intersection of fpPolygon,
120 a valid polygon in focal plane coordinates, and the ccd corners,
121 in ccd pixel coordinates.
125 ccdExposure : `lsst.afw.image.Exposure`
127 fpPolygon : `lsst.afw.geom.Polygon`
128 Polygon in focal plane coordinates.
129 log : `logging.Logger`, optional
130 Log object to write to.
133 ccd = ccdExposure.getDetector()
134 fpCorners = ccd.getCorners(cameraGeom.FOCAL_PLANE)
135 ccdPolygon = afwGeom.Polygon(fpCorners)
138 intersect = ccdPolygon.intersectionSingle(fpPolygon)
139 except afwGeom.SinglePolygonException:
141 if intersect
is not None:
143 ccdPoints = ccd.transform(intersect, cameraGeom.FOCAL_PLANE, cameraGeom.PIXELS)
144 validPolygon = afwGeom.Polygon(ccdPoints)
145 ccdExposure.getInfo().setValidPolygon(validPolygon)
148 log.info(
"Ccd exposure does not overlap with focal plane polygon. Not setting validPolygon.")
152 """Add mask bit to image pixels according to vignetted polygon region.
154 NOTE: this function could be used to mask and replace pixels associated
155 with any polygon in the exposure pixel coordinates.
159 exposure : `lsst.afw.image.Exposure`
160 Image whose mask plane is to be updated.
161 polygon : `lsst.afw.geom.Polygon`
162 Polygon region defining the vignetted region in the pixel coordinates
164 maskPlane : `str`, optional
165 Mask plane to assign vignetted pixels to.
166 vignetteValue : `float` or `None`, optional
167 Value to assign to the image array pixels within the ``polygon``
168 region. If `None`, image pixel values are not replaced.
169 log : `logging.Logger`, optional
170 Log object to write to.
175 Raised if no valid polygon exists.
177 log = log
if log
else logging.getLogger(__name__)
179 log.info(
"No polygon provided. Masking nothing.")
182 fullyIlluminated =
True
183 if not all(polygon.contains(exposure.getBBox().getCorners())):
184 fullyIlluminated =
False
185 log.info(
"Exposure is fully illuminated? %s", fullyIlluminated)
187 if not fullyIlluminated:
189 mask = exposure.getMask()
190 xx, yy = np.meshgrid(np.arange(0, mask.getWidth(), dtype=float),
191 np.arange(0, mask.getHeight(), dtype=float))
193 vignMask = ~(polygon.contains(xx, yy))
195 bitMask = mask.getPlaneBitMask(maskPlane)
196 maskArray = mask.getArray()
197 maskArray[vignMask] |= bitMask
198 log.info(
"Exposure contains {} vignetted pixels which are now masked with mask plane {}.".
199 format(np.count_nonzero(vignMask), maskPlane))
201 if vignetteValue
is not None:
202 imageArray = exposure.getImage().getArray()
203 imageArray[vignMask] = vignetteValue
204 log.info(
"Vignetted pixels in image array have been replaced with {}.".format(vignetteValue))