LSST Applications g00d0e8bbd7+edbf708997,g03191d30f7+9ce8016dbd,g1955dfad08+0bd186d245,g199a45376c+5137f08352,g1fd858c14a+a888a50aa2,g262e1987ae+45f9aba685,g29ae962dfc+1c7d47a24f,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3fd5ace14f+eed17d2c67,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+c4107e45b5,g67b6fd64d1+6dc8069a4c,g74acd417e5+f452e9c21a,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+2025e9ce17,g7cc15d900a+2d158402f9,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d4809ba88+c4107e45b5,g8d7436a09f+e96c132b44,g8ea07a8fe4+db21c37724,g98df359435+aae6d409c1,ga2180abaac+edbf708997,gac66b60396+966efe6077,gb632fb1845+88945a90f8,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gca7fc764a6+6dc8069a4c,gd7ef33dd92+6dc8069a4c,gda68eeecaf+7d1e613a8d,gdab6d2f7ff+f452e9c21a,gdbb4c4dda9+c4107e45b5,ge410e46f29+6dc8069a4c,ge41e95a9f2+c4107e45b5,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.ip.isr.vignette Namespace Reference

Classes

class  VignetteConfig
 
class  VignetteTask
 

Functions

 setValidPolygonCcdIntersect (ccdExposure, fpPolygon, log=None, setPolygon=True)
 
 maskVignettedRegion (exposure, polygon, maskPlane="NO_DATA", vignetteValue=None, log=None)
 

Function Documentation

◆ maskVignettedRegion()

lsst.ip.isr.vignette.maskVignettedRegion ( exposure,
polygon,
maskPlane = "NO_DATA",
vignetteValue = None,
log = None )
Add mask bit to image pixels according to vignetted polygon region.

NOTE: this function could be used to mask and replace pixels associated
with any polygon in the exposure pixel coordinates.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    Image whose mask plane is to be updated.
polygon : `lsst.afw.geom.Polygon`
    Polygon region defining the vignetted region in the pixel coordinates
    of ``exposure``.
maskPlane : `str`, optional
    Mask plane to assign vignetted pixels to.
vignetteValue : `float` or `None`, optional
    Value to assign to the image array pixels within the ``polygon``
    region.  If `None`, image pixel values are not replaced.
log : `logging.Logger`, optional
    Log object to write to.

Raises
------
RuntimeError
    Raised if no valid polygon exists.

Definition at line 171 of file vignette.py.

171def maskVignettedRegion(exposure, polygon, maskPlane="NO_DATA", vignetteValue=None, log=None):
172 """Add mask bit to image pixels according to vignetted polygon region.
173
174 NOTE: this function could be used to mask and replace pixels associated
175 with any polygon in the exposure pixel coordinates.
176
177 Parameters
178 ----------
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
183 of ``exposure``.
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.
191
192 Raises
193 ------
194 RuntimeError
195 Raised if no valid polygon exists.
196 """
197 log = log if log else logging.getLogger(__name__)
198 if not polygon:
199 log.info("No polygon provided. Masking nothing.")
200 return
201
202 fullyIlluminated = True
203 if not all(polygon.contains(exposure.getBBox().getCorners())):
204 fullyIlluminated = False
205 log.info("Exposure is fully illuminated? %s", fullyIlluminated)
206
207 if not fullyIlluminated:
208 # Scan pixels.
209 mask = exposure.getMask()
210 xx, yy = np.meshgrid(np.arange(0, mask.getWidth(), dtype=float),
211 np.arange(0, mask.getHeight(), dtype=float))
212
213 vignMask = ~(polygon.contains(xx, yy))
214
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))
220
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))

◆ setValidPolygonCcdIntersect()

lsst.ip.isr.vignette.setValidPolygonCcdIntersect ( ccdExposure,
fpPolygon,
log = None,
setPolygon = True )
Set valid polygon on ccdExposure associated with focal plane polygon.

The ccd exposure's valid polygon is the intersection of fpPolygon,
a valid polygon in focal plane coordinates, and the ccd corners,
in ccd pixel coordinates.

Parameters
----------
ccdExposure : `lsst.afw.image.Exposure`
    Exposure to process.
fpPolygon : `lsst.afw.geom.Polygon`
    Polygon in focal plane coordinates.
log : `logging.Logger`, optional
    Log object to write to.
setPolygon : `bool`, optional
    Actually set the polygon, or just return it?

Returns
-------
validPolygon : `lsst.afw.geom.Polygon`
    Valid polygon with the intersection.

Definition at line 125 of file vignette.py.

125def setValidPolygonCcdIntersect(ccdExposure, fpPolygon, log=None, setPolygon=True):
126 """Set valid polygon on ccdExposure associated with focal plane polygon.
127
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.
131
132 Parameters
133 ----------
134 ccdExposure : `lsst.afw.image.Exposure`
135 Exposure to process.
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?
142
143 Returns
144 -------
145 validPolygon : `lsst.afw.geom.Polygon`
146 Valid polygon with the intersection.
147 """
148 # Get ccd corners in focal plane coordinates
149 ccd = ccdExposure.getDetector()
150 fpCorners = ccd.getCorners(cameraGeom.FOCAL_PLANE)
151 ccdPolygon = afwGeom.Polygon(fpCorners)
152 # Get intersection of ccd corners with fpPolygon
153 try:
154 intersect = ccdPolygon.intersectionSingle(fpPolygon)
156 intersect = None
157 if intersect is not None:
158 # Transform back to pixel positions and build new polygon
159 ccdPoints = ccd.transform(intersect, cameraGeom.FOCAL_PLANE, cameraGeom.PIXELS)
160 validPolygon = afwGeom.Polygon(ccdPoints)
161 if setPolygon:
162 ccdExposure.getInfo().setValidPolygon(validPolygon)
163 else:
164 if log is not None:
165 log.info("Ccd exposure does not overlap with focal plane polygon. Not setting validPolygon.")
166 validPolygon = None
167
168 return validPolygon
169
170
Cartesian polygons.
Definition Polygon.h:59
An exception that indicates the single-polygon assumption has been violated.
Definition Polygon.h:53