LSST Applications g00d0e8bbd7+8c5ae1fdc5,g013ef56533+603670b062,g083dd6704c+2e189452a7,g199a45376c+0ba108daf9,g1c5cce2383+bc9f6103a4,g1fd858c14a+cd69ed4fc1,g210f2d0738+c4742f2e9e,g262e1987ae+612fa42d85,g29ae962dfc+83d129e820,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+5eaa884f2a,g47891489e3+e32160a944,g53246c7159+8c5ae1fdc5,g5b326b94bb+dcc56af22d,g64539dfbff+c4742f2e9e,g67b6fd64d1+e32160a944,g74acd417e5+c122e1277d,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g88cb488625+47d24e4084,g89139ef638+e32160a944,g8d7436a09f+d14b4ff40a,g8ea07a8fe4+b212507b11,g90f42f885a+e1755607f3,g97be763408+34be90ab8c,g98df359435+ec1fa61bf1,ga2180abaac+8c5ae1fdc5,ga9e74d7ce9+43ac651df0,gbf99507273+8c5ae1fdc5,gc2a301910b+c4742f2e9e,gca7fc764a6+e32160a944,gd7ef33dd92+e32160a944,gdab6d2f7ff+c122e1277d,gdb1e2cdc75+1b18322db8,ge410e46f29+e32160a944,ge41e95a9f2+c4742f2e9e,geaed405ab2+0d91c11c6d,w.2025.44
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