31 from .forcedPhotImage
import ProcessImageForcedTask, ProcessImageForcedConfig
34 from lsst.meas.mosaic
import applyMosaicResults
36 applyMosaicResults =
None
38 __all__ = (
"ForcedPhotCcdConfig",
"ForcedPhotCcdTask")
41 """A version of DataIdContainer specialized for forced photometry on CCDs.
43 Required because we need to add "tract" to the raw data ID keys, and that's tricky.
44 This IdContainer assumes that a calexp is being measured using the detection information
45 from the set of coadds which intersect with the calexp. a set of reference catalog
46 from a coadd which overlaps it. It needs the calexp id (e.g. visit, raft, sensor), but it
47 also uses the tract to decide what set of coadds to use. The references from the tract
48 whose patches intersect with the calexp are used.
51 """Make self.refList from self.idList
53 for dataId
in self.idList:
54 if "tract" not in dataId:
55 raise argparse.ArgumentError(
None,
"--id must include tract")
56 tract = dataId.pop(
"tract")
58 for srcDataRef
in namespace.butler.subset(
"src", dataId=dataId):
59 forcedDataId = srcDataRef.dataId.copy()
60 forcedDataId[
'tract'] = tract
61 dataRef = namespace.butler.dataRef(
62 datasetType =
"forced_src",
63 dataId = forcedDataId,
65 self.refList.append(dataRef)
68 doApplyUberCal = lsst.pex.config.Field(
70 doc =
"Apply meas_mosaic ubercal results to input calexps?",
83 A command-line driver for performing forced measurement on CCD images
85 This task is a subclass of ForcedPhotImageTask which is specifically for doing forced
86 measurement on a single CCD exposure, using as a reference catalog the detections which
87 were made on overlapping coadds.
89 The run method (inherited from ForcedPhotImageTask) takes a lsst.daf.persistence.ButlerDataRef
90 argument that corresponds to a single CCD. This should contain the data ID keys that correspond to
91 the "forced_src" dataset (the output dataset for ForcedPhotCcdTask), which are typically all those
92 used to specify the "calexp" dataset (e.g. visit, raft, sensor for LSST data) as well as a coadd
93 tract. The tract is used to look up the appropriate coadd measurement catalogs to use as references
94 (e.g. deepCoadd_src; see CoaddSrcReferencesTask for more information). While the tract must be given
95 as part of the dataRef, the patches are determined automatically from the bounding box and WCS of the
96 calexp to be measured, and the filter used to fetch references is set via config
97 (BaseReferencesConfig.filter).
99 In addition to the run method, ForcedPhotCcdTask overrides several methods of ForcedPhotImageTask
100 to specialize it for single-CCD processing, including makeIdFactory(), fetchReferences(), and
101 getExposure(). None of these should be called directly by the user, though it may be useful
102 to override them further in subclasses.
105 ConfigClass = ForcedPhotCcdConfig
106 RunnerClass = lsst.pipe.base.ButlerInitializedTaskRunner
107 _DefaultName =
"forcedPhotCcd"
111 """Create an object that generates globally unique source IDs from per-CCD IDs and the CCD ID.
113 @param dataRef Data reference from butler. The "ccdExposureId_bits" and "ccdExposureId"
114 datasets are accessed. The data ID must have the keys that correspond
115 to ccdExposureId, which is generally the same that correspond to "calexp"
116 (e.g. visit, raft, sensor for LSST data).
118 expBits = dataRef.get(
"ccdExposureId_bits")
119 expId = long(dataRef.get(
"ccdExposureId"))
123 """Return a SourceCatalog of sources which overlap the exposure.
125 The returned catalog is sorted by ID and guarantees that all included children have their
126 parent included and that all Footprints are valid.
128 @param dataRef Data reference from butler corresponding to the image to be measured;
129 should have tract, patch, and filter keys.
130 @param exposure lsst.afw.image.Exposure to be measured (used only to obtain a Wcs and
133 All work is delegated to the references subtask; see CoaddSrcReferencesTask for information
134 about the default behavior.
138 unfiltered = self.references.fetchInBox(dataRef, exposure.getBBox(), exposure.getWcs())
139 for record
in unfiltered:
140 if record.getFootprint()
is None or record.getFootprint().getArea() == 0:
141 if record.getParent() != 0:
142 self.log.warn(
"Skipping reference %s (child of %s) with bad Footprint" %
143 (record.getId(), record.getParent()))
145 self.log.warn(
"Skipping reference parent %s with bad Footprint" % (record.getId(),))
146 badParents.add(record.getId())
147 elif record.getParent()
not in badParents:
148 references.append(record)
153 """Read input exposure to measure
155 @param dataRef Data reference from butler. Only the 'calexp' dataset is used,
156 unless config.doApplyUberCal is true, in which case the corresponding
157 meas_mosaic outputs are used as well.
159 exposure = ProcessImageForcedTask.getExposure(self, dataRef)
160 if not self.config.doApplyUberCal:
162 if applyMosaicResults
is None:
164 "Cannot use improved calibrations for %s because meas_mosaic could not be imported."
172 """!Return the name of the config dataset. Forces config comparison from run-to-run
174 return self.
dataPrefix +
"forcedPhotCcd_config"
177 """!Return the name of the metadata dataset. Forced metadata to be saved
179 return self.
dataPrefix +
"forcedPhotCcd_metadata"
183 parser = lsst.pipe.base.ArgumentParser(name=cls._DefaultName)
184 parser.add_id_argument(
"--id",
"forced_src", help=
"data ID, with raw CCD keys + tract",
185 ContainerClass=ForcedPhotCcdDataIdContainer)
static boost::shared_ptr< IdFactory > makeSource(RecordId expId, int reserved)
Return an IdFactory that includes another, fixed ID in the higher-order bits.
A command-line driver for performing forced measurement on CCD images.
def _getConfigName
Return the name of the config dataset.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
def _getMetadataName
Return the name of the metadata dataset.