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.astrometry.solver.calculateSip =
False
50 self.calibrate.repair.doInterpolate =
False
51 self.calibrate.repair.doCosmicRay =
False
52 self.calibrate.doPhotoCal =
False
53 self.detection.isotropicGrow =
True
54 self.detection.returnOriginalFootprints =
False
56 self.measurement.doReplaceWithNoise =
True
58 self.deblend.maxNumberOfPeaks = 20
61 """Process a Coadd image
64 ConfigClass = ProcessCoaddConfig
65 _DefaultName =
"processCoadd"
68 ProcessImageTask.__init__(self, **kwargs)
70 tableVersion = self.config.measurement.target.tableVersion
73 "detect.is-patch-inner", type=
"Flag",
74 doc=
"true if source is in the inner region of a coadd patch",
77 "detect.is-tract-inner", type=
"Flag",
78 doc=
"true if source is in the inner region of a coadd tract",
81 "detect.is-primary", type=
"Flag",
82 doc=
"true if source has no children and is in the inner region of a coadd patch " \
83 +
"and is in the inner region of a coadd tract",
87 "detect_isPatchInner", type=
"Flag",
88 doc=
"true if source is in the inner region of a coadd patch",
91 "detect_isTractInner", type=
"Flag",
92 doc=
"true if source is in the inner region of a coadd tract",
95 "detect_isPrimary", type=
"Flag",
96 doc=
"true if source has no children and is in the inner region of a coadd patch " \
97 +
"and is in the inner region of a coadd tract",
103 ctrl.setAndMask(~0x0)
104 var = exposure.getMaskedImage().getVariance()
105 mask = exposure.getMaskedImage().getMask()
106 dstats =
afwMath.makeStatistics(exposure.getMaskedImage(), afwMath.VARIANCECLIP, ctrl).getValue(afwMath.VARIANCECLIP)
108 vrat = dstats / vstats
109 self.log.info(
"Renormalising variance by %f" % (vrat))
113 expBits = dataRef.get(self.config.coaddName +
"CoaddId_bits")
114 expId = long(dataRef.get(self.config.coaddName +
"CoaddId"))
115 return afwTable.IdFactory.makeSource(expId, 64 - expBits)
120 """Process a coadd image
122 @param dataRef: butler data reference corresponding to coadd patch
123 @return pipe_base Struct containing these fields:
124 - exposure: calibrated exposure (calexp): as computed if config.doCalibrate,
125 else as upersisted and updated if config.doDetection, else None
126 - calib: object returned by calibration process if config.doCalibrate, else None
127 - sources: detected source if config.doDetection, else None
129 self.log.info(
"Processing %s" % (dataRef.dataId))
134 skyInfo =
getSkyInfo(coaddName=self.config.coaddName, patchRef=dataRef)
136 coadd = dataRef.get(self.config.coaddName +
"Coadd")
137 if self.config.doScaleVariance:
141 result = self.process(dataRef, coadd, enableWriteSources=
False)
144 if result.sources
is not None:
148 if self.config.doWriteSources:
149 dataRef.put(result.sources, self.
dataPrefix +
'src')
154 """Set is-primary and related flags on sources
156 @param[in,out] sources: a SourceTable
157 - reads centroid fields and an nChild field
158 - writes is-patch-inner, is-tract-inner and is-primary flags
159 @param[in] skyInfo: a SkyInfo object as returned by getSkyInfo;
160 reads skyMap, patchInfo, and tractInfo fields
163 @raise RuntimeError if self.config.doDeblend and the nChild key is not found in the table
167 if self.config.measurement.target.tableVersion == 0:
168 nChildKeyName =
"deblend.nchild"
170 nChildKeyName =
"deblend_nChild"
173 nChildKey = self.schema.find(nChildKeyName).key
177 if self.config.doDeblend
and nChildKey
is None:
180 raise RuntimeError(
"Ran the deblender but cannot find %r in the source table" % (nChildKeyName,))
184 innerFloatBBox =
afwGeom.Box2D(skyInfo.patchInfo.getInnerBBox())
185 tractId = skyInfo.tractInfo.getId()
186 for source
in sources:
187 if source.getCentroidFlag():
191 centroidPos = source.getCentroid()
192 isPatchInner = innerFloatBBox.contains(centroidPos)
195 skyPos = source.getCoord()
196 sourceInnerTractId = skyInfo.skyMap.findTract(skyPos).getId()
197 isTractInner = sourceInnerTractId == tractId
200 if nChildKey
is None or source.get(nChildKey) == 0:
201 source.setFlag(self.
isPrimaryKey, isPatchInner
and isTractInner)
205 parser = pipeBase.ArgumentParser(name=cls._DefaultName)
206 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2",
207 ContainerClass=CoaddDataIdContainer)
211 """Return the name of the config dataset
213 return "%s_processCoadd_config" % (self.config.coaddName,)
216 """Return the name of the metadata dataset
218 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.