1 from builtins
import zip
29 from .forcedPhotImage
import ForcedPhotImageConfig, ForcedPhotImageTask
31 __all__ = (
"ForcedPhotCoaddConfig",
"ForcedPhotCoaddTask")
35 footprintDatasetName = lsst.pex.config.Field(
36 doc=
"Dataset (without coadd prefix) that should be used to obtain (Heavy)Footprints for sources. "
37 "Must have IDs that match those of the reference catalog."
38 "If None, Footprints will be generated by transforming the reference Footprints.",
45 ForcedPhotImageTask.ConfigClass.setDefaults(self)
46 self.references.removePatchOverlaps =
False
49 ForcedPhotImageTask.ConfigClass.validate(self)
51 and self.references.removePatchOverlaps):
52 raise ValueError(
"Cannot use removePatchOverlaps=True with deblended footprints, as parent "
53 "sources may be rejected while their children are not.")
65 A command-line driver for performing forced measurement on coadd images
67 This task is a subclass of ForcedPhotImageTask which is specifically for doing forced
68 measurement on a coadd, using as a reference catalog detections which were made on overlapping
69 coadds (i.e. in other bands).
71 The run method (inherited from ForcedPhotImageTask) takes a lsst.daf.persistence.ButlerDataRef
72 argument that corresponds to a coadd image. This is used to provide all the inputs and outputs
74 - A "*Coadd_src" (e.g. "deepCoadd_src") dataset is used as the reference catalog. This not loaded
75 directly from the passed dataRef, however; only the patch and tract are used, while the filter
76 is set by the configuration for the references subtask (see CoaddSrcReferencesTask).
77 - A "*Coadd_calexp" (e.g. "deepCoadd_calexp") dataset is used as the measurement image. Note that
78 this means that ProcessCoaddTask must be run on an image before ForcedPhotCoaddTask, in order
79 to generate the "*Coadd_calexp" dataset.
80 - A "*Coadd_forced_src" (e.g. "deepCoadd_forced_src") dataset will be written with the output
83 In addition to the run method, ForcedPhotCcdTask overrides several methods of ForcedPhotImageTask
84 to specialize it for coadd processing, including makeIdFactory() and fetchReferences(). None of these
85 should be called directly by the user, though it may be useful to override them further in subclasses.
88 ConfigClass = ForcedPhotCoaddConfig
89 RunnerClass = lsst.pipe.base.ButlerInitializedTaskRunner
90 _DefaultName =
"forcedPhotCoadd"
91 dataPrefix =
"deepCoadd_"
94 name = self.config.coaddName +
"Coadd_calexp"
95 return dataRef.get(name)
if dataRef.datasetExists(name)
else None
98 """Create an object that generates globally unique source IDs from per-CCD IDs and the CCD ID.
100 @param dataRef Data reference from butler. The "CoaddId_bits" and "CoaddId"
101 datasets are accessed. The data ID must have tract and patch keys.
108 expBits = dataRef.get(self.config.coaddName +
"CoaddId_bits")
109 expId = int(dataRef.get(self.config.coaddName +
"CoaddId"))
113 return int(dataRef.get(self.config.coaddName +
"CoaddId"))
116 """Return an iterable of reference sources which overlap the exposure
118 @param dataRef Data reference from butler corresponding to the image to be measured;
119 should have tract, patch, and filter keys.
120 @param exposure lsst.afw.image.Exposure to be measured (not used by this implementation)
122 All work is delegated to the references subtask; see CoaddSrcReferencesTask for information
123 about the default behavior.
125 skyMap = dataRef.get(self.
dataPrefix +
"skyMap", immediate=
True)
126 tractInfo = skyMap[dataRef.dataId[
"tract"]]
127 patch = tuple(int(v)
for v
in dataRef.dataId[
"patch"].split(
","))
128 patchInfo = tractInfo.getPatchInfo(patch)
130 references.extend(self.references.fetchInPatches(dataRef, patchList=[patchInfo]))
134 """For coadd forced photometry, we use the deblended HeavyFootprints from the single-band
135 measurements of the same band - because we've guaranteed that the peaks (and hence child sources)
136 will be consistent across all bands before we get to measurement, this should yield reasonable
137 deblending for most sources. It's most likely limitation is that it will not provide good flux
138 upper limits for sources that were not detected in this band but were blended with sources that
141 if self.config.footprintDatasetName
is None:
142 return ForcedPhotImageTask.attachFootprints(self, sources, refCat, exposure, refWcs, dataRef)
143 self.log.info(
"Loading deblended footprints for sources from %s, %s" %
144 (self.config.footprintDatasetName, dataRef.dataId))
145 fpCat = dataRef.get(
"%sCoadd_%s" % (self.config.coaddName, self.config.footprintDatasetName),
147 for refRecord, srcRecord
in zip(refCat, sources):
148 fpRecord = fpCat.find(refRecord.getId())
150 raise LookupError(
"Cannot find Footprint for source %s; please check that %sCoadd_%s "
151 "IDs are compatible with reference source IDs" %
152 (srcRecord.getId(), self.config.coaddName,
153 self.config.footprintDatasetName))
154 srcRecord.setFootprint(fpRecord.getFootprint())
158 parser = lsst.pipe.base.ArgumentParser(name=cls._DefaultName)
159 parser.add_id_argument(
"--id",
"deepCoadd_forced_src", help=
"data ID, with raw CCD keys + tract",
160 ContainerClass=lsst.coadd.utils.CoaddDataIdContainer)
static boost::shared_ptr< IdFactory > makeSource(RecordId expId, int reserved)
Return an IdFactory that includes another, fixed ID in the higher-order bits.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
A command-line driver for performing forced measurement on coadd images.
tuple footprintDatasetName