22__all__ = [
"RepairConfig",
"RepairTask"]
29from lsstDebug
import getDebugFrame
32from lsst.utils.timer
import timeMethod
36 doInterpolate = pexConfig.Field(
38 doc=
"Interpolate over defects? (ignored unless you provide a list of defects)",
41 doCosmicRay = pexConfig.Field(
43 doc=
"Find and mask out cosmic rays?",
46 cosmicray = pexConfig.ConfigField(
47 dtype=measAlg.FindCosmicRaysConfig,
48 doc=
"Options for finding and masking cosmic rays",
50 interp = pexConfig.ConfigurableField(
51 target=InterpImageTask,
52 doc=
"Interpolate over bad image pixels",
56 self.
interp.useFallbackValueAtEdge =
True
57 self.
interp.fallbackValueType =
"MEANCLIP"
58 self.
interp.negativeFallbackAllowed =
True
62 """Repair an exposures defects and cosmic rays via interpolation.
72 The available debug variables
in RepairTask are:
75 A dictionary containing debug point names
as keys
with frame number
as value. Valid keys are:
77 display image before any repair
is done
79 display image after cosmic ray
and defect correction
81 If
True, display the exposure on ds9
's frame 1 and overlay bounding boxes around detects CRs.
83 To investigate the pipe_tasks_repair_Debug, put something like
90 if name ==
"lsst.pipe.tasks.repair":
91 di.display = {
'repair.before':2,
'repair.after':3}
96 into your debug.py file
and run runRepair.py
with the --debug flag.
99 Display code should be updated once we settle on a standard way of controlling what
is displayed.
102 ConfigClass = RepairConfig
103 _DefaultName = "repair"
106 pipeBase.Task.__init__(self, **kwargs)
107 if self.config.doInterpolate:
108 self.makeSubtask(
"interp")
111 def run(self, exposure, defects=None, keepCRs=None):
112 """Repair an Exposure's defects and cosmic rays.
117 Exposure must have a valid Psf.
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`).
127 Raised if any of the following occur:
128 - No exposure provided.
129 - The object provided
as exposure evaluates to
False.
131 - The Exposure has no associated Psf.
133 assert exposure,
"No exposure provided"
134 psf = exposure.getPsf()
135 assert psf,
"No PSF provided"
137 frame = getDebugFrame(self._display,
"repair.before")
139 afwDisplay.Display(frame).mtv(exposure)
141 if defects
is not None and self.config.doInterpolate:
142 self.interp.run(exposure, defects=defects)
144 if self.config.doCosmicRay:
145 self.
cosmicRay(exposure, keepCRs=keepCRs)
147 frame = getDebugFrame(self._display,
"repair.after")
149 afwDisplay.Display(frame).mtv(exposure)
158 keepCRs : `Unknown` or `
None`, optional
159 Don
't interpolate over the CR pixels (defer to ``pex_config`` if `None`).
165 assert exposure,
"No exposure provided"
166 psf = exposure.getPsf()
167 assert psf,
"No psf provided"
171 mask = exposure.getMaskedImage().getMask()
172 crBit = mask.getMaskPlane(
"CR")
173 mask.clearMaskPlane(crBit)
178 binSize = self.config.cosmicray.background.binSize
179 nx, ny = exposure.getWidth()/binSize, exposure.getHeight()/binSize
189 exposure = exposure.Factory(exposure,
True)
190 subtractBackgroundTask = measAlg.SubtractBackgroundTask(config=self.config.cosmicray.background)
191 modelBg = subtractBackgroundTask.run(exposure).background
195 keepCRs = self.config.cosmicray.keepCRs
197 crs = measAlg.findCosmicRays(exposure.getMaskedImage(), psf, medianBg,
198 pexConfig.makePropertySet(self.config.cosmicray), keepCRs)
201 img = exposure.getMaskedImage()
202 img += modelBg.getImageF()
205 exposure0.setMaskedImage(exposure.getMaskedImage())
209 afwDisplay.Display().mtv(exposure0, title=
"Failed CR")
214 mask = exposure0.getMaskedImage().getMask()
215 crBit = mask.getPlaneBitMask(
"CR")
216 afwDet.setMaskFromFootprintList(mask, crs, crBit)
219 if display
and displayCR:
220 disp = afwDisplay.Display()
221 disp.incrDefaultFrame()
222 disp.mtv(exposure0, title=
"Post-CR")
224 with disp.Buffering():
226 afwDisplay.utils.drawBBox(cr.getBBox(), borderWidth=0.55)
228 self.log.info(
"Identified %s cosmic rays.", num)
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Encapsulate information about a bad portion of a detector.
cosmicRay(self, exposure, keepCRs=None)
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)