30 from .coaddBase
import getSkyInfo
31 from .processImage
import ProcessImageTask
34 """Config for ProcessCoadd"""
35 coaddName = pexConfig.Field(
36 doc =
"coadd name: typically one of deep or goodSeeing",
40 doScaleVariance = pexConfig.Field(dtype=bool, default=
True, doc =
"Scale variance plane using empirical noise")
43 ProcessImageTask.ConfigClass.setDefaults(self)
44 self.calibrate.background.undersampleStyle =
'REDUCE_INTERP_ORDER'
45 self.calibrate.detection.background.undersampleStyle =
'REDUCE_INTERP_ORDER'
46 self.detection.background.undersampleStyle =
'REDUCE_INTERP_ORDER'
47 self.calibrate.doPsf =
False
48 self.calibrate.astrometry.forceKnownWcs =
True
49 self.calibrate.repair.doInterpolate =
False
50 self.calibrate.repair.doCosmicRay =
False
51 self.calibrate.doPhotoCal =
False
52 self.detection.isotropicGrow =
True
53 self.detection.returnOriginalFootprints =
False
55 self.measurement.doReplaceWithNoise =
True
57 self.deblend.maxNumberOfPeaks = 20
60 """Process a Coadd image
63 ConfigClass = ProcessCoaddConfig
64 _DefaultName =
"processCoadd"
67 ProcessImageTask.__init__(self, **kwargs)
70 "detect_isPatchInner", type=
"Flag",
71 doc=
"true if source is in the inner region of a coadd patch",
74 "detect_isTractInner", type=
"Flag",
75 doc=
"true if source is in the inner region of a coadd tract",
78 "detect_isPrimary", type=
"Flag",
79 doc=
"true if source has no children and is in the inner region of a coadd patch " \
80 +
"and is in the inner region of a coadd tract",
87 var = exposure.getMaskedImage().getVariance()
88 mask = exposure.getMaskedImage().getMask()
89 dstats =
afwMath.makeStatistics(exposure.getMaskedImage(), afwMath.VARIANCECLIP, ctrl).getValue(afwMath.VARIANCECLIP)
91 vrat = dstats / vstats
92 self.log.info(
"Renormalising variance by %f" % (vrat))
96 expBits = dataRef.get(self.config.coaddName +
"CoaddId_bits")
97 expId = long(dataRef.get(self.config.coaddName +
"CoaddId"))
98 return afwTable.IdFactory.makeSource(expId, 64 - expBits)
101 return long(dataRef.get(self.config.coaddName +
"CoaddId"))
105 """Process a coadd image
107 @param dataRef: butler data reference corresponding to coadd patch
108 @return pipe_base Struct containing these fields:
109 - exposure: calibrated exposure (calexp): as computed if config.doCalibrate,
110 else as upersisted and updated if config.doDetection, else None
111 - calib: object returned by calibration process if config.doCalibrate, else None
112 - sources: detected source if config.doDetection, else None
114 self.log.info(
"Processing %s" % (dataRef.dataId))
119 skyInfo =
getSkyInfo(coaddName=self.config.coaddName, patchRef=dataRef)
121 coadd = dataRef.get(self.config.coaddName +
"Coadd")
122 if self.config.doScaleVariance:
126 result = self.process(dataRef, coadd, enableWriteSources=
False)
129 if result.sources
is not None:
133 if self.config.doWriteSources:
134 dataRef.put(result.sources, self.
dataPrefix +
'src')
139 """Set is-primary and related flags on sources
141 @param[in,out] sources: a SourceTable
142 - reads centroid fields and an nChild field
143 - writes is-patch-inner, is-tract-inner and is-primary flags
144 @param[in] skyInfo: a SkyInfo object as returned by getSkyInfo;
145 reads skyMap, patchInfo, and tractInfo fields
148 @raise RuntimeError if self.config.doDeblend and the nChild key is not found in the table
152 nChildKeyName =
"deblend_nChild"
155 nChildKey = self.schema.find(nChildKeyName).key
159 if self.config.doDeblend
and nChildKey
is None:
162 raise RuntimeError(
"Ran the deblender but cannot find %r in the source table" % (nChildKeyName,))
166 innerFloatBBox =
afwGeom.Box2D(skyInfo.patchInfo.getInnerBBox())
167 tractId = skyInfo.tractInfo.getId()
168 for source
in sources:
169 if source.getCentroidFlag():
173 centroidPos = source.getCentroid()
174 isPatchInner = innerFloatBBox.contains(centroidPos)
177 skyPos = source.getCoord()
178 sourceInnerTractId = skyInfo.skyMap.findTract(skyPos).getId()
179 isTractInner = sourceInnerTractId == tractId
182 if nChildKey
is None or source.get(nChildKey) == 0:
183 source.setFlag(self.
isPrimaryKey, isPatchInner
and isTractInner)
187 parser = pipeBase.ArgumentParser(name=cls._DefaultName)
188 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2",
189 ContainerClass=CoaddDataIdContainer)
193 """Return the name of the config dataset
195 return "%s_processCoadd_config" % (self.config.coaddName,)
198 """Return the name of the metadata dataset
200 return "%s_processCoadd_metadata" % (self.config.coaddName,)
Pass parameters to a Statistics objectA class to pass parameters which control how the stats are calc...
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
A floating-point coordinate rectangle geometry.