31 doInterpolate = pexConfig.Field(
33 doc =
"Interpolate over defects? (ignored unless you provide a list of defects)",
36 doCosmicRay = pexConfig.Field(
38 doc =
"Find and mask out cosmic rays?",
41 cosmicray = pexConfig.ConfigField(
42 dtype = measAlg.FindCosmicRaysConfig,
43 doc =
"Options for finding and masking cosmic rays",
57 \brief Interpolate over defects in an exposure and handle cosmic rays
59 \section pipe_tasks_repair_Contents Contents
61 - \ref pipe_tasks_repair_Purpose
62 - \ref pipe_tasks_repair_Initialize
63 - \ref pipe_tasks_repair_IO
64 - \ref pipe_tasks_repair_Config
65 - \ref pipe_tasks_repair_Debug
66 - \ref pipe_tasks_repair_Example
68 \section pipe_tasks_repair_Purpose Description
72 This task operates on an lsst.afw.image.Exposure in place to interpolate over a set of
73 lsst.meas.algorithms.Defect objects.
74 It will also, optionally, find and interpolate any cosmic rays in the lsst.afw.image.Exposure.
76 \section pipe_tasks_repair_Initialize Task initialization
78 See: lsst.pipe.base.task.Task.__init__
80 \section pipe_tasks_repair_IO Inputs/Outputs to the run method
84 \section pipe_tasks_repair_Config Configuration parameters
88 \section pipe_tasks_repair_Debug Debug variables
90 The \link lsst.pipe.base.cmdLineTask.CmdLineTask command line task\endlink interface supports a
91 flag \c -d to import \b debug.py from your \c PYTHONPATH; see <a
92 href="http://lsst-web.ncsa.illinois.edu/~buildbot/doxygen/x_masterDoxyDoc/base_debug.html">
93 Using lsstDebug to control debugging output</a> for more about \b debug.py files.
95 The available variables in RepairTask are:
98 <DD> A dictionary containing debug point names as keys with frame number as value. Valid keys are:
101 <DD> display image before any repair is done
103 <DD> display image after cosmic ray and defect correction
106 <DD> If True, display the exposure on ds9's frame 1 and overlay bounding boxes around detects CRs.
108 \section pipe_tasks_repair_Example A complete example of using RepairTask
110 This code is in runRepair.py in the examples directory, and can be run as \em e.g.
112 examples/runRepair.py
114 \dontinclude runRepair.py
115 Import the task. There are other imports. Read the source file for more info.
118 For this example, we manufacture a test image to run on.
120 First, create a pure Poisson noise image and a Psf to go with it. The mask plane
121 and variance can be constructed at the same time.
125 Inject some cosmic rays and generate the Exposure. Exposures are MaskedImages (image + mask + variance)
126 with other metadata (e.g. Psf and Wcs objects).
130 Defects are represented as bad columns of random lengths. A defect list must be constructed to pass
131 on to the RepairTask.
132 \bug This is addressed in <a href="https://jira.lsstcorp.org/browse/DM-963"> DM-963</a>
137 Finally, the exposure can be repaired. Create an instance of the task and run it. The exposure is modified in place.
142 To investigate the \ref pipe_tasks_repair_Debug, put something like
146 di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively
147 if name == "lsst.pipe.tasks.repair":
148 di.display = {'repair.before':2, 'repair.after':3}
152 lsstDebug.Info = DebugInfo
154 into your debug.py file and run runRepair.py with the \c --debug flag.
158 Display code should be updated once we settle on a standard way of controlling what is displayed.
160 ConfigClass = RepairConfig
163 def run(self, exposure, defects=None, keepCRs=None):
164 """!Repair an Exposure's defects and cosmic rays
166 \param[in, out] exposure lsst.afw.image.Exposure to process. Exposure must have a valid Psf. Modified in place.
167 \param[in] defects an lsst.meas.algorithms.DefectListT object. If None, do no defect correction.
168 \param[in] keepCRs don't interpolate over the CR pixels (defer to RepairConfig if None)
170 \throws AssertionError with the following strings:
173 <DT> No exposure provided
174 <DD> The object provided as exposure evaluates to False
176 <DD> The Exposure has no associated Psf
179 assert exposure,
"No exposure provided"
180 psf = exposure.getPsf()
181 assert psf,
"No PSF provided"
183 self.display(
'repair.before', exposure=exposure)
184 if defects
is not None and self.config.doInterpolate:
187 if self.config.doCosmicRay:
188 self.
cosmicRay(exposure, keepCRs=keepCRs)
190 self.display(
'repair.after', exposure=exposure)
193 """Interpolate over defects
195 @param[in,out] exposure Exposure to process
196 @param defects Defect list
198 assert exposure,
"No exposure provided"
199 assert defects
is not None,
"No defects provided"
200 psf = exposure.getPsf()
201 assert psf,
"No psf provided"
203 mi = exposure.getMaskedImage()
206 self.log.info(
"Interpolated over %d defects." % len(defects))
211 @param[in,out] exposure Exposure to process
212 @param keepCRs Don't interpolate over the CR pixels (defer to pex_config if None)
218 assert exposure,
"No exposure provided"
219 psf = exposure.getPsf()
220 assert psf,
"No psf provided"
224 mask = exposure.getMaskedImage().getMask()
225 crBit = mask.getMaskPlane(
"CR")
226 mask.clearMaskPlane(crBit)
230 mi = exposure.getMaskedImage()
234 keepCRs = self.config.cosmicray.keepCRs
240 ds9.mtv(exposure, title=
"Failed CR")
246 crBit = mask.getPlaneBitMask(
"CR")
250 if display
and displayCR:
254 ds9.incrDefaultFrame()
255 ds9.mtv(exposure, title=
"Post-CR")
257 with ds9.Buffering():
259 displayUtils.drawBBox(cr.getBBox(), borderWidth=0.55)
261 self.log.info(
"Identified %s cosmic rays." % (num,))
void interpolateOverDefects(MaskedImageT &image, lsst::afw::detection::Psf const &psf, std::vector< Defect::Ptr > &badList, double fallbackValue=0.0, bool useFallbackValueAtEdge=false)
Process a set of known bad pixels in an image.
def run
Repair an Exposure's defects and cosmic rays.
std::vector< detection::Footprint::Ptr > findCosmicRays(MaskedImageT &mimage, detection::Psf const &psf, double const bkgd, lsst::pex::policy::Policy const &policy, bool const keep)
Find cosmic rays in an Image, and mask and remove them.
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
MaskT setMaskFromFootprintList(lsst::afw::image::Mask< MaskT > *mask, boost::shared_ptr< std::vector< boost::shared_ptr< Footprint >> const > const &footprints, MaskT const bitmask)
OR bitmask into all the Mask's pixels which are in the set of Footprints.
Interpolate over defects in an exposure and handle cosmic rays.