22 """Base command-line driver task for forced measurement. 24 Must be inherited to specialize for a specific dataset to be used (see 25 `ForcedPhotCcdTask`, `ForcedPhotCoaddTask`). 34 from .references
import MultiBandReferencesTask
35 from .forcedMeasurement
import ForcedMeasurementTask
36 from .applyApCorr
import ApplyApCorrTask
37 from .catalogCalculation
import CatalogCalculationTask
39 __all__ = (
"ForcedPhotImageConfig",
"ForcedPhotImageTask")
43 """Config class for forced measurement driver task.""" 45 references = lsst.pex.config.ConfigurableField(
46 target=MultiBandReferencesTask,
47 doc=
"subtask to retrieve reference source catalog" 49 measurement = lsst.pex.config.ConfigurableField(
50 target=ForcedMeasurementTask,
51 doc=
"subtask to do forced measurement" 53 coaddName = lsst.pex.config.Field(
54 doc=
"coadd name: typically one of deep or goodSeeing",
58 doApCorr = lsst.pex.config.Field(
61 doc=
"Run subtask to apply aperture corrections" 63 applyApCorr = lsst.pex.config.ConfigurableField(
64 target=ApplyApCorrTask,
65 doc=
"Subtask to apply aperture corrections" 67 catalogCalculation = lsst.pex.config.ConfigurableField(
68 target=CatalogCalculationTask,
69 doc=
"Subtask to run catalogCalculation plugins on catalog" 80 """A base class for command-line forced measurement drivers. 84 butler : `lsst.daf.persistence.butler.Butler`, optional 85 A Butler which will be passed to the references subtask to allow it to 86 load its schema from disk. Optional, but must be specified if 87 ``refSchema`` is not; if both are specified, ``refSchema`` takes 89 refSchema : `lsst.afw.table.Schema`, optional 90 The schema of the reference catalog, passed to the constructor of the 91 references subtask. Optional, but must be specified if ``butler`` is 92 not; if both are specified, ``refSchema`` takes precedence. 94 Keyword arguments are passed to the supertask constructor. 98 This is a an abstract class, which is the common ancestor for 99 `ForcedPhotCcdTask` and `ForcedPhotCoaddTask`. It provides the 100 `runDataRef` method that does most of the work, while delegating a few 101 customization tasks to other methods that are overridden by subclasses. 103 This task is not directly usable as a command line task. Subclasses must: 105 - Set the `_DefaultName` class attribute; 106 - Implement `makeIdFactory`; 107 - Implement `fetchReferences`; 108 - Optionally, implement `attachFootprints`. 111 ConfigClass = ForcedPhotImageConfig
112 _DefaultName =
"processImageForcedTask" 114 def __init__(self, butler=None, refSchema=None, **kwds):
115 super(lsst.pipe.base.CmdLineTask, self).
__init__(**kwds)
116 self.makeSubtask(
"references", butler=butler, schema=refSchema)
117 if refSchema
is None:
118 refSchema = self.references.schema
119 self.makeSubtask(
"measurement", refSchema=refSchema)
122 if self.config.doApCorr:
123 self.makeSubtask(
"applyApCorr", schema=self.measurement.schema)
124 self.makeSubtask(
'catalogCalculation', schema=self.measurement.schema)
127 """Perform forced measurement on a single exposure. 131 dataRef : `lsst.daf.persistence.ButlerDataRef` 132 Passed to the ``references`` subtask to obtain the reference WCS, 133 the ``getExposure`` method (implemented by derived classes) to 134 read the measurment image, and the ``fetchReferences`` method to 135 get the exposure and load the reference catalog (see 136 :lsst-task`lsst.meas.base.references.CoaddSrcReferencesTask`). 137 Refer to derived class documentation for details of the datasets 138 and data ID keys which are used. 139 psfCache : `int`, optional 140 Size of PSF cache, or `None`. The size of the PSF cache can have 141 a significant effect upon the runtime for complicated PSF models. 145 Sources are generated with ``generateMeasCat`` in the ``measurement`` 146 subtask. These are passed to ``measurement``'s ``run`` method, which 147 fills the source catalog with the forced measurement results. The 148 sources are then passed to the ``writeOutputs`` method (implemented by 149 derived classes) which writes the outputs. 151 refWcs = self.references.getWcs(dataRef)
153 if psfCache
is not None:
154 exposure.getPsf().setCacheSize(psfCache)
157 measCat = self.measurement.generateMeasCat(exposure, refCat, refWcs,
159 self.log.info(
"Performing forced measurement on %s" % (dataRef.dataId,))
164 forcedPhotResult = self.
run(measCat, exposure, refCat, refWcs, exposureId=exposureId)
166 self.
writeOutput(dataRef, forcedPhotResult.measCat)
168 def run(self, measCat, exposure, refCat, refWcs, exposureId=None):
169 """Perform forced measurement on a single exposure. 173 measCat : `lsst.afw.table.SourceCatalog` 174 The measurement catalog, based on the sources listed in the 176 exposure : `lsst.afw.image.Exposure` 177 The measurement image upon which to perform forced detection. 178 refCat : `lsst.afw.table.SourceCatalog` 179 The reference catalog of sources to measure. 180 refWcs : `lsst.afw.image.SkyWcs` 181 The WCS for the references. 183 Optional unique exposureId used for random seed in measurement 188 result : `lsst.pipe.base.Struct` 189 Structure with fields: 192 Catalog of forced measurement results 193 (`lsst.afw.table.SourceCatalog`). 195 self.measurement.
run(measCat, exposure, refCat, refWcs, exposureId=exposureId)
196 if self.config.doApCorr:
197 self.applyApCorr.
run(
199 apCorrMap=exposure.getInfo().getApCorrMap()
201 self.catalogCalculation.
run(measCat)
203 return lsst.pipe.base.Struct(measCat=measCat)
206 """Hook for derived classes to make an ID factory for forced sources. 210 That this applies to forced *source* IDs, not object IDs, which are 211 usually handled by the ``measurement.copyColumns`` config option. 214 raise NotImplementedError()
217 raise NotImplementedError()
220 """Hook for derived classes to define how to get reference objects. 224 Derived classes should call one of the ``fetch*`` methods on the 225 ``references`` subtask, but which one they call depends on whether the 226 region to get references for is a easy to describe in patches (as it 227 would be when doing forced measurements on a coadd), or is just an 228 arbitrary box (as it would be for CCD forced measurements). 230 raise NotImplementedError()
233 r"""Attach footprints to blank sources prior to measurements. 237 `~lsst.afw.detection.Footprint`\ s for forced photometry must be in the 238 pixel coordinate system of the image being measured, while the actual 239 detections may start out in a different coordinate system. 241 Subclasses of this class must implement this method to define how 242 those `~lsst.afw.detection.Footprint`\ s should be generated. 244 This default implementation transforms the 245 `~lsst.afw.detection.Footprint`\ s from the reference catalog from the 246 reference WCS to the exposure's WcS, which downgrades 247 `lsst.afw.detection.heavyFootprint.HeavyFootprint`\ s into regular 248 `~lsst.afw.detection.Footprint`\ s, destroying deblend information. 250 return self.measurement.attachTransformedFootprints(sources, refCat, exposure, refWcs)
253 """Read input exposure on which measurement will be performed. 257 dataRef : `lsst.daf.persistence.ButlerDataRef` 258 Butler data reference. 260 return dataRef.get(self.dataPrefix +
"calexp", immediate=
True)
263 """Write forced source table 267 dataRef : `lsst.daf.persistence.ButlerDataRef` 268 Butler data reference. The forced_src dataset (with 269 self.dataPrefix prepended) is all that will be modified. 270 sources : `lsst.afw.table.SourceCatalog` 271 Catalog of sources to save. 273 dataRef.put(sources, self.dataPrefix +
"forced_src", flags=lsst.afw.table.SOURCE_IO_NO_FOOTPRINTS)
276 """The schema catalogs that will be used by this task. 280 schemaCatalogs : `dict` 281 Dictionary mapping dataset type to schema catalog. 285 There is only one schema for each type of forced measurement. The 286 dataset type for this measurement is defined in the mapper. 289 catalog.getTable().setMetadata(self.measurement.algMetadata)
290 datasetType = self.dataPrefix +
"forced_src" 291 return {datasetType: catalog}
293 def _getConfigName(self):
295 return self.dataPrefix +
"forced_config" 297 def _getMetadataName(self):
299 return self.dataPrefix +
"forced_metadata"
def getExposure(self, dataRef)
def runDataRef(self, dataRef, psfCache=None)
def fetchReferences(self, dataRef, exposure)
def run(self, measCat, exposure, refCat, refWcs, exposureId=None)
def makeIdFactory(self, dataRef)
def getExposureId(self, dataRef)
def __init__(self, butler=None, refSchema=None, kwds)
def getSchemaCatalogs(self)
def writeOutput(self, dataRef, sources)
def attachFootprints(self, sources, refCat, exposure, refWcs, dataRef)