LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+f5613e8b4f,g1470d8bcf6+190ad2ba91,g14a832a312+311607e4ab,g2079a07aa2+86d27d4dc4,g2305ad1205+a8e3196225,g295015adf3+b67ee847e5,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+a761f810f3,g487adcacf7+17c8fdbcbd,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+65b5bd823e,g5a732f18d5+53520f316c,g64a986408d+f5613e8b4f,g6c1bc301e9+51106c2951,g858d7b2824+f5613e8b4f,g8a8a8dda67+585e252eca,g99cad8db69+6729933424,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e9bba80f27,gc120e1dc64+eee469a5e5,gc28159a63d+0e5473021a,gcf0d15dbbd+a761f810f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+d4c1d4bfef,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf1cff7945b+f5613e8b4f,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Static Protected Attributes | List of all members
lsst.pipe.tasks.repair.RepairTask Class Reference
Inheritance diagram for lsst.pipe.tasks.repair.RepairTask:

Public Member Functions

 __init__ (self, **kwargs)
 
 run (self, exposure, defects=None, keepCRs=None)
 
 cosmicRay (self, exposure, keepCRs=None)
 

Static Public Attributes

 ConfigClass = RepairConfig
 

Static Protected Attributes

str _DefaultName = "repair"
 

Detailed Description

Repair an exposures defects and cosmic rays via interpolation.

This task operates on an lsst.afw.image.Exposure in place to
interpolate over a set of `~lsst.meas.algorithms.Defect` objects.

It will also, optionally, find and interpolate any cosmic rays in the lsst.afw.image.Exposure.

Notes
-----
Debugging:
The available debug variables in RepairTask are:

display :
    A dictionary containing debug point names as keys with frame number as value. Valid keys are:
repair.before :
    display image before any repair is done
repair.after :
    display image after cosmic ray and defect correction
displayCR :
    If True, display the exposure on ds9's frame 1 and overlay bounding boxes around detects CRs.

To investigate the pipe_tasks_repair_Debug, put something like

.. code-block :: none

    import lsstDebug
    def DebugInfo(name):
        di = lsstDebug.getInfo(name)        # N.b. lsstDebug.Info(name) would call us recursively
        if name == "lsst.pipe.tasks.repair":
            di.display = {'repair.before':2, 'repair.after':3}
            di.displayCR = True
        return di

lsstDebug.Info = DebugInfo
into your debug.py file and run runRepair.py with the --debug flag.

Conversion notes:
    Display code should be updated once we settle on a standard way of controlling what is displayed.

Definition at line 61 of file repair.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pipe.tasks.repair.RepairTask.__init__ ( self,
** kwargs )

Definition at line 105 of file repair.py.

105 def __init__(self, **kwargs):
106 pipeBase.Task.__init__(self, **kwargs)
107 if self.config.doInterpolate:
108 self.makeSubtask("interp")
109

Member Function Documentation

◆ cosmicRay()

lsst.pipe.tasks.repair.RepairTask.cosmicRay ( self,
exposure,
keepCRs = None )
Mask cosmic rays.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    Exposure to process.
keepCRs : `Unknown` or `None`, optional
    Don't interpolate over the CR pixels (defer to ``pex_config`` if `None`).

Definition at line 151 of file repair.py.

151 def cosmicRay(self, exposure, keepCRs=None):
152 """Mask cosmic rays.
153
154 Parameters
155 ----------
156 exposure : `lsst.afw.image.Exposure`
157 Exposure to process.
158 keepCRs : `Unknown` or `None`, optional
159 Don't interpolate over the CR pixels (defer to ``pex_config`` if `None`).
160 """
161 import lsstDebug
162 display = lsstDebug.Info(__name__).display
163 displayCR = lsstDebug.Info(__name__).displayCR
164
165 assert exposure, "No exposure provided"
166 psf = exposure.getPsf()
167 assert psf, "No psf provided"
168
169 # Blow away old mask
170 try:
171 mask = exposure.getMaskedImage().getMask()
172 crBit = mask.getMaskPlane("CR")
173 mask.clearMaskPlane(crBit)
174 except Exception:
175 pass
176
177 exposure0 = exposure # initial value of exposure
178 binSize = self.config.cosmicray.background.binSize
179 nx, ny = exposure.getWidth()/binSize, exposure.getHeight()/binSize
180 # Treat constant background as a special case to avoid the extra complexity in calling
181 # measAlg.SubtractBackgroundTask().
182 if nx*ny <= 1:
183 medianBg = afwMath.makeStatistics(exposure.getMaskedImage(), afwMath.MEDIAN).getValue()
184 modelBg = None
185 else:
186 # make a deep copy of the exposure before subtracting its background,
187 # because this routine is only allowed to modify the exposure by setting mask planes
188 # and interpolating over defects, not changing the background level
189 exposure = exposure.Factory(exposure, True)
190 subtractBackgroundTask = measAlg.SubtractBackgroundTask(config=self.config.cosmicray.background)
191 modelBg = subtractBackgroundTask.run(exposure).background
192 medianBg = 0.0
193
194 if keepCRs is None:
195 keepCRs = self.config.cosmicray.keepCRs
196 try:
197 crs = measAlg.findCosmicRays(exposure.getMaskedImage(), psf, medianBg,
198 pexConfig.makePropertySet(self.config.cosmicray), keepCRs)
199 if modelBg:
200 # Add back background image
201 img = exposure.getMaskedImage()
202 img += modelBg.getImageF()
203 del img
204 # Replace original image with CR subtracted image
205 exposure0.setMaskedImage(exposure.getMaskedImage())
206
207 except Exception:
208 if display:
209 afwDisplay.Display().mtv(exposure0, title="Failed CR")
210 raise
211
212 num = 0
213 if crs is not None:
214 mask = exposure0.getMaskedImage().getMask()
215 crBit = mask.getPlaneBitMask("CR")
216 afwDet.setMaskFromFootprintList(mask, crs, crBit)
217 num = len(crs)
218
219 if display and displayCR:
220 disp = afwDisplay.Display()
221 disp.incrDefaultFrame()
222 disp.mtv(exposure0, title="Post-CR")
223
224 with disp.Buffering():
225 for cr in crs:
226 afwDisplay.utils.drawBBox(cr.getBBox(), borderWidth=0.55)
227
228 text = "kept" if keepCRs else "interpolated over"
229 self.log.info("Identified and %s %s cosmic rays.", text, num)
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
Definition Statistics.h:361

◆ run()

lsst.pipe.tasks.repair.RepairTask.run ( self,
exposure,
defects = None,
keepCRs = None )
Repair an Exposure's defects and cosmic rays.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    Exposure must have a valid Psf.
    Modified in place.
defects : `lsst.meas.algorithms.DefectListT` or `None`, optional
    If `None`, do no defect correction.
keepCRs : `Unknown` or `None`, optional
    Don't interpolate over the CR pixels (defer to ``RepairConfig`` if `None`).

Raises
------
AssertionError
    Raised if any of the following occur:
    - No exposure provided.
    - The object provided as exposure evaluates to False.
    - No PSF provided.
    - The Exposure has no associated Psf.

Definition at line 111 of file repair.py.

111 def run(self, exposure, defects=None, keepCRs=None):
112 """Repair an Exposure's defects and cosmic rays.
113
114 Parameters
115 ----------
116 exposure : `lsst.afw.image.Exposure`
117 Exposure must have a valid Psf.
118 Modified in place.
119 defects : `lsst.meas.algorithms.DefectListT` or `None`, optional
120 If `None`, do no defect correction.
121 keepCRs : `Unknown` or `None`, optional
122 Don't interpolate over the CR pixels (defer to ``RepairConfig`` if `None`).
123
124 Raises
125 ------
126 AssertionError
127 Raised if any of the following occur:
128 - No exposure provided.
129 - The object provided as exposure evaluates to False.
130 - No PSF provided.
131 - The Exposure has no associated Psf.
132 """
133 assert exposure, "No exposure provided"
134 psf = exposure.getPsf()
135 assert psf, "No PSF provided"
136
137 frame = getDebugFrame(self._display, "repair.before")
138 if frame:
139 afwDisplay.Display(frame).mtv(exposure)
140
141 if defects is not None and self.config.doInterpolate:
142 self.interp.run(exposure, defects=defects)
143
144 if self.config.doCosmicRay:
145 self.cosmicRay(exposure, keepCRs=keepCRs)
146
147 frame = getDebugFrame(self._display, "repair.after")
148 if frame:
149 afwDisplay.Display(frame).mtv(exposure)
150

Member Data Documentation

◆ _DefaultName

str lsst.pipe.tasks.repair.RepairTask._DefaultName = "repair"
staticprotected

Definition at line 103 of file repair.py.

◆ ConfigClass

lsst.pipe.tasks.repair.RepairTask.ConfigClass = RepairConfig
static

Definition at line 102 of file repair.py.


The documentation for this class was generated from the following file: