LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
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