LSST Applications 24.1.6,g063fba187b+56b85ce14a,g0f08755f38+df8a265115,g12f32b3c4e+891a09f10d,g1524ad2192+7a5d7b3fbd,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g28da252d5a+07cb1400be,g2bbee38e9b+ae03bbfc84,g2bc492864f+ae03bbfc84,g3156d2b45e+6e55a43351,g347aa1857d+ae03bbfc84,g35bb328faa+a8ce1bb630,g3a166c0a6a+ae03bbfc84,g3e281a1b8c+c5dd892a6c,g414038480c+6b9177ef31,g41af890bb2+8f257c4c0b,g781aacb6e4+a8ce1bb630,g7af13505b9+7137b3b17d,g80478fca09+6df6903293,g82479be7b0+091ce1d07f,g858d7b2824+df8a265115,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,g9726552aa6+414189b318,ga5288a1d22+4a2bca08d7,gacef1a1666+c9a8ff65f4,gb58c049af0+d64f4d3760,gbcfae0f0a0+de1d42d831,gc28159a63d+ae03bbfc84,gcf0d15dbbd+72117bf34e,gda6a2b7d83+72117bf34e,gdaeeff99f8+1711a396fd,ge500cccec5+c8c9c9af63,ge79ae78c31+ae03bbfc84,gf0baf85859+c1f95f4921,gfa517265be+df8a265115,gfa999e8aa5+17cd334064,gfb92a5be7c+df8a265115
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