LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions
lsst.ip.isr.vignette Namespace Reference

Classes

class  VignetteConfig
 
class  VignetteTask
 

Functions

 setValidPolygonCcdIntersect (ccdExposure, fpPolygon, log=None)
 
 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 144 of file vignette.py.

144def maskVignettedRegion(exposure, polygon, maskPlane="NO_DATA", vignetteValue=None, log=None):
145 """Add mask bit to image pixels according to vignetted polygon region.
146
147 NOTE: this function could be used to mask and replace pixels associated
148 with any polygon in the exposure pixel coordinates.
149
150 Parameters
151 ----------
152 exposure : `lsst.afw.image.Exposure`
153 Image whose mask plane is to be updated.
154 polygon : `lsst.afw.geom.Polygon`
155 Polygon region defining the vignetted region in the pixel coordinates
156 of ``exposure``.
157 maskPlane : `str`, optional
158 Mask plane to assign vignetted pixels to.
159 vignetteValue : `float` or `None`, optional
160 Value to assign to the image array pixels within the ``polygon``
161 region. If `None`, image pixel values are not replaced.
162 log : `logging.Logger`, optional
163 Log object to write to.
164
165 Raises
166 ------
167 RuntimeError
168 Raised if no valid polygon exists.
169 """
170 log = log if log else logging.getLogger(__name__)
171 if not polygon:
172 log.info("No polygon provided. Masking nothing.")
173 return
174
175 fullyIlluminated = True
176 if not all(polygon.contains(exposure.getBBox().getCorners())):
177 fullyIlluminated = False
178 log.info("Exposure is fully illuminated? %s", fullyIlluminated)
179
180 if not fullyIlluminated:
181 # Scan pixels.
182 mask = exposure.getMask()
183 xx, yy = np.meshgrid(np.arange(0, mask.getWidth(), dtype=float),
184 np.arange(0, mask.getHeight(), dtype=float))
185
186 vignMask = ~(polygon.contains(xx, yy))
187
188 bitMask = mask.getPlaneBitMask(maskPlane)
189 maskArray = mask.getArray()
190 maskArray[vignMask] |= bitMask
191 log.info("Exposure contains {} vignetted pixels which are now masked with mask plane {}.".
192 format(np.count_nonzero(vignMask), maskPlane))
193
194 if vignetteValue is not None:
195 imageArray = exposure.getImage().getArray()
196 imageArray[vignMask] = vignetteValue
197 log.info("Vignetted pixels in image array have been replaced with {}.".format(vignetteValue))

◆ setValidPolygonCcdIntersect()

lsst.ip.isr.vignette.setValidPolygonCcdIntersect ( ccdExposure,
fpPolygon,
log = None )
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.

Definition at line 109 of file vignette.py.

109def setValidPolygonCcdIntersect(ccdExposure, fpPolygon, log=None):
110 """Set valid polygon on ccdExposure associated with focal plane polygon.
111
112 The ccd exposure's valid polygon is the intersection of fpPolygon,
113 a valid polygon in focal plane coordinates, and the ccd corners,
114 in ccd pixel coordinates.
115
116 Parameters
117 ----------
118 ccdExposure : `lsst.afw.image.Exposure`
119 Exposure to process.
120 fpPolygon : `lsst.afw.geom.Polygon`
121 Polygon in focal plane coordinates.
122 log : `logging.Logger`, optional
123 Log object to write to.
124 """
125 # Get ccd corners in focal plane coordinates
126 ccd = ccdExposure.getDetector()
127 fpCorners = ccd.getCorners(cameraGeom.FOCAL_PLANE)
128 ccdPolygon = afwGeom.Polygon(fpCorners)
129 # Get intersection of ccd corners with fpPolygon
130 try:
131 intersect = ccdPolygon.intersectionSingle(fpPolygon)
133 intersect = None
134 if intersect is not None:
135 # Transform back to pixel positions and build new polygon
136 ccdPoints = ccd.transform(intersect, cameraGeom.FOCAL_PLANE, cameraGeom.PIXELS)
137 validPolygon = afwGeom.Polygon(ccdPoints)
138 ccdExposure.getInfo().setValidPolygon(validPolygon)
139 else:
140 if log is not None:
141 log.info("Ccd exposure does not overlap with focal plane polygon. Not setting validPolygon.")
142
143
Cartesian polygons.
Definition Polygon.h:59
An exception that indicates the single-polygon assumption has been violated.
Definition Polygon.h:53