29 from .coaddBase
import getSkyInfo
30 from .processImage
import ProcessImageTask
33 """Config for ProcessCoadd"""
34 coaddName = pexConfig.Field(
35 doc =
"coadd name: typically one of deep or goodSeeing",
39 doScaleVariance = pexConfig.Field(
40 doc =
"Scale variance plane using empirical noise",
46 ProcessImageTask.ConfigClass.setDefaults(self)
47 self.calibrate.background.undersampleStyle =
'REDUCE_INTERP_ORDER'
48 self.calibrate.detection.background.undersampleStyle =
'REDUCE_INTERP_ORDER'
49 self.detection.background.undersampleStyle =
'REDUCE_INTERP_ORDER'
50 self.calibrate.doPsf =
False
51 self.calibrate.measureApCorr.inputFilterFlag =
"calib_psfCandidate"
52 self.calibrate.astrometry.forceKnownWcs =
True
53 self.calibrate.repair.doInterpolate =
False
54 self.calibrate.repair.doCosmicRay =
False
55 self.calibrate.doPhotoCal =
False
56 self.detection.isotropicGrow =
True
57 self.detection.returnOriginalFootprints =
False
59 self.measurement.doReplaceWithNoise =
True
62 self.measurement.doApplyApCorr =
"noButWarn"
64 self.deblend.maxNumberOfPeaks = 20
67 """Process a Coadd image
69 ConfigClass = ProcessCoaddConfig
70 _DefaultName =
"processCoadd"
73 ProcessImageTask.__init__(self, **kwargs)
76 "detect_isPatchInner", type=
"Flag",
77 doc=
"true if source is in the inner region of a coadd patch",
80 "detect_isTractInner", type=
"Flag",
81 doc=
"true if source is in the inner region of a coadd tract",
84 "detect_isPrimary", type=
"Flag",
85 doc=
"true if source has no children and is in the inner region of a coadd patch " \
86 +
"and is in the inner region of a coadd tract",
93 var = exposure.getMaskedImage().getVariance()
94 mask = exposure.getMaskedImage().getMask()
95 dstats =
afwMath.makeStatistics(exposure.getMaskedImage(), afwMath.VARIANCECLIP, ctrl).getValue(afwMath.VARIANCECLIP)
97 vrat = dstats / vstats
98 self.log.info(
"Renormalising variance by %f" % (vrat))
102 expBits = dataRef.get(self.config.coaddName +
"CoaddId_bits")
103 expId = long(dataRef.get(self.config.coaddName +
"CoaddId"))
104 return afwTable.IdFactory.makeSource(expId, 64 - expBits)
107 return long(dataRef.get(self.config.coaddName +
"CoaddId"))
111 """Process a coadd image
113 @param dataRef: butler data reference corresponding to coadd patch
114 @return pipe_base Struct containing these fields:
115 - exposure: calibrated exposure (calexp): as computed if config.doCalibrate,
116 else as upersisted and updated if config.doDetection, else None
117 - calib: object returned by calibration process if config.doCalibrate, else None
118 - sources: detected source if config.doDetection, else None
120 self.log.info(
"Processing %s" % (dataRef.dataId))
125 skyInfo =
getSkyInfo(coaddName=self.config.coaddName, patchRef=dataRef)
127 coadd = dataRef.get(self.config.coaddName +
"Coadd")
128 if self.config.doScaleVariance:
132 result = self.process(dataRef, coadd, enableWriteSources=
False)
135 if result.sources
is not None:
139 if self.config.doWriteSources:
140 dataRef.put(result.sources, self.
dataPrefix +
'src')
145 """Set is-primary and related flags on sources
147 @param[in,out] sources: a SourceTable
148 - reads centroid fields and an nChild field
149 - writes is-patch-inner, is-tract-inner and is-primary flags
150 @param[in] skyInfo: a SkyInfo object as returned by getSkyInfo;
151 reads skyMap, patchInfo, and tractInfo fields
153 @raise RuntimeError if self.config.doDeblend and the nChild key is not found in the table
157 nChildKeyName =
"deblend_nChild"
160 nChildKey = self.schema.find(nChildKeyName).key
164 if self.config.doDeblend
and nChildKey
is None:
167 raise RuntimeError(
"Ran the deblender but cannot find %r in the source table" % (nChildKeyName,))
171 innerFloatBBox =
afwGeom.Box2D(skyInfo.patchInfo.getInnerBBox())
172 tractId = skyInfo.tractInfo.getId()
173 for source
in sources:
174 if source.getCentroidFlag():
178 centroidPos = source.getCentroid()
179 isPatchInner = innerFloatBBox.contains(centroidPos)
182 skyPos = source.getCoord()
183 sourceInnerTractId = skyInfo.skyMap.findTract(skyPos).getId()
184 isTractInner = sourceInnerTractId == tractId
187 if nChildKey
is None or source.get(nChildKey) == 0:
188 source.setFlag(self.
isPrimaryKey, isPatchInner
and isTractInner)
192 parser = pipeBase.ArgumentParser(name=cls._DefaultName)
193 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2",
194 ContainerClass=CoaddDataIdContainer)
198 """Return the name of the config dataset
200 return "%s_processCoadd_config" % (self.config.coaddName,)
203 """Return the name of the metadata dataset
205 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.
def getSkyInfo
Return SkyMap, tract and patch.
A floating-point coordinate rectangle geometry.