23 from builtins
import zip
25 import lsst.pex.config
27 import lsst.coadd.utils
30 from .forcedPhotImage
import ForcedPhotImageConfig, ForcedPhotImageTask
32 __all__ = (
"ForcedPhotCoaddConfig",
"ForcedPhotCoaddTask")
36 footprintDatasetName = lsst.pex.config.Field(
37 doc=
"Dataset (without coadd prefix) that should be used to obtain (Heavy)Footprints for sources. " 38 "Must have IDs that match those of the reference catalog." 39 "If None, Footprints will be generated by transforming the reference Footprints.",
46 ForcedPhotImageTask.ConfigClass.setDefaults(self)
55 ForcedPhotImageTask.ConfigClass.validate(self)
58 raise ValueError(
"Cannot use removePatchOverlaps=True with deblended footprints, as parent " 59 "sources may be rejected while their children are not.")
71 A command-line driver for performing forced measurement on coadd images 73 This task is a subclass of ForcedPhotImageTask which is specifically for doing forced 74 measurement on a coadd, using as a reference catalog detections which were made on overlapping 75 coadds (i.e. in other bands). 77 The run method (inherited from ForcedPhotImageTask) takes a lsst.daf.persistence.ButlerDataRef 78 argument that corresponds to a coadd image. This is used to provide all the inputs and outputs 80 - A "*Coadd_src" (e.g. "deepCoadd_src") dataset is used as the reference catalog. This not loaded 81 directly from the passed dataRef, however; only the patch and tract are used, while the filter 82 is set by the configuration for the references subtask (see CoaddSrcReferencesTask). 83 - A "*Coadd_calexp" (e.g. "deepCoadd_calexp") dataset is used as the measurement image. Note that 84 this means that ProcessCoaddTask must be run on an image before ForcedPhotCoaddTask, in order 85 to generate the "*Coadd_calexp" dataset. 86 - A "*Coadd_forced_src" (e.g. "deepCoadd_forced_src") dataset will be written with the output 89 In addition to the run method, ForcedPhotCcdTask overrides several methods of ForcedPhotImageTask 90 to specialize it for coadd processing, including makeIdFactory() and fetchReferences(). None of these 91 should be called directly by the user, though it may be useful to override them further in subclasses. 94 ConfigClass = ForcedPhotCoaddConfig
95 RunnerClass = lsst.pipe.base.ButlerInitializedTaskRunner
96 _DefaultName =
"forcedPhotCoadd" 97 dataPrefix =
"deepCoadd_" 100 name = self.config.coaddName +
"Coadd_calexp" 101 return dataRef.get(name)
if dataRef.datasetExists(name)
else None 104 """Create an object that generates globally unique source IDs from per-CCD IDs and the CCD ID. 106 @param dataRef Data reference from butler. The "CoaddId_bits" and "CoaddId" 107 datasets are accessed. The data ID must have tract and patch keys. 114 expBits = dataRef.get(self.config.coaddName +
"CoaddId_bits")
115 expId = int(dataRef.get(self.config.coaddName +
"CoaddId"))
116 return lsst.afw.table.IdFactory.makeSource(expId, 64 - expBits)
119 return int(dataRef.get(self.config.coaddName +
"CoaddId"))
122 """Return an iterable of reference sources which overlap the exposure 124 @param dataRef Data reference from butler corresponding to the image to be measured; 125 should have tract, patch, and filter keys. 126 @param exposure lsst.afw.image.Exposure to be measured (not used by this implementation) 128 All work is delegated to the references subtask; see CoaddSrcReferencesTask for information 129 about the default behavior. 131 skyMap = dataRef.get(self.
dataPrefix +
"skyMap", immediate=
True)
132 tractInfo = skyMap[dataRef.dataId[
"tract"]]
133 patch = tuple(int(v)
for v
in dataRef.dataId[
"patch"].split(
","))
134 patchInfo = tractInfo.getPatchInfo(patch)
135 references = lsst.afw.table.SourceCatalog(self.references.schema)
136 references.extend(self.references.fetchInPatches(dataRef, patchList=[patchInfo]))
140 """For coadd forced photometry, we use the deblended HeavyFootprints from the single-band 141 measurements of the same band - because we've guaranteed that the peaks (and hence child sources) 142 will be consistent across all bands before we get to measurement, this should yield reasonable 143 deblending for most sources. It's most likely limitation is that it will not provide good flux 144 upper limits for sources that were not detected in this band but were blended with sources that 147 if self.config.footprintDatasetName
is None:
148 return ForcedPhotImageTask.attachFootprints(self, sources, refCat, exposure, refWcs, dataRef)
149 self.log.info(
"Loading deblended footprints for sources from %s, %s" %
150 (self.config.footprintDatasetName, dataRef.dataId))
151 fpCat = dataRef.get(
"%sCoadd_%s" % (self.config.coaddName, self.config.footprintDatasetName),
153 for refRecord, srcRecord
in zip(refCat, sources):
154 fpRecord = fpCat.find(refRecord.getId())
156 raise LookupError(
"Cannot find Footprint for source %s; please check that %sCoadd_%s " 157 "IDs are compatible with reference source IDs" %
158 (srcRecord.getId(), self.config.coaddName,
159 self.config.footprintDatasetName))
160 srcRecord.setFootprint(fpRecord.getFootprint())
163 def _makeArgumentParser(cls):
164 parser = lsst.pipe.base.ArgumentParser(name=cls.
_DefaultName)
165 parser.add_id_argument(
"--id",
"deepCoadd_forced_src", help=
"data ID, with raw CCD keys + tract",
166 ContainerClass=lsst.coadd.utils.CoaddDataIdContainer)
A base class for command-line forced measurement drivers.
def getExposure(self, dataRef)
def attachFootprints(self, sources, refCat, exposure, refWcs, dataRef)
A command-line driver for performing forced measurement on coadd images.
def makeIdFactory(self, dataRef)
def getExposureId(self, dataRef)
Config class for forced measurement driver task.
def fetchReferences(self, dataRef, exposure)