24 """Base command-line driver task for forced measurement. Must be inherited to specialize for 25 a specific dataset to be used (see 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" 86 """!A base class for command-line forced measurement drivers. 88 This is a an abstract class, which is the common ancestor for ForcedPhotCcdTask 89 and ForcedPhotCoaddTask. It provides the run() method that does most of the 90 work, while delegating a few customization tasks to other methods that are 91 overridden by subclasses. 93 This task is not directly usable as a CmdLineTask; subclasses must: 94 - Set the _DefaultName class attribute 95 - Implement makeIdFactory 96 - Implement fetchReferences 97 - (optional) Implement attachFootprints 99 ConfigClass = ForcedPhotImageConfig
100 _DefaultName =
"processImageForcedTask" 102 def __init__(self, butler=None, refSchema=None, **kwds):
103 """Initialize the task. 105 ForcedPhotImageTask takes two keyword arguments beyond the usual CmdLineTask arguments: 106 - refSchema: the Schema of the reference catalog, passed to the constructor of the references 108 - butler: a butler that will be passed to the references subtask to allow it to load its Schema 110 At least one of these arguments must be present; if both are, schema takes precedence. 112 super(lsst.pipe.base.CmdLineTask, self).
__init__(**kwds)
113 self.makeSubtask(
"references", butler=butler, schema=refSchema)
114 if refSchema
is None:
115 refSchema = self.references.schema
116 self.makeSubtask(
"measurement", refSchema=refSchema)
119 if self.config.doApCorr:
120 self.makeSubtask(
"applyApCorr", schema=self.measurement.schema)
121 self.makeSubtask(
'catalogCalculation', schema=self.measurement.schema)
124 """!Measure a single exposure using forced detection for a reference catalog. 126 @param[in] dataRef An lsst.daf.persistence.ButlerDataRef. It is passed to the 127 references subtask to obtain the reference WCS, the getExposure() 128 method (implemented by derived classes) to read the measurement 129 image, and the fetchReferences() method (implemented by derived 130 classes) to get the exposure and load the reference catalog (see 131 the CoaddSrcReferencesTask for more information). Sources are 132 generated with generateMeasCat() in the measurement subtask. These 133 are passed to measurement's run method which fills the source 134 catalog with the forced measurement results. The sources are then 135 passed to the writeOutputs() method (implemented by derived classes) 136 which writes the outputs. See derived class documentation for which 137 datasets and data ID keys are used. 139 refWcs = self.references.getWcs(dataRef)
142 measCat = self.measurement.generateMeasCat(exposure, refCat, refWcs,
144 self.log.info(
"Performing forced measurement on %s" % (dataRef.dataId,))
147 self.measurement.
run(measCat, exposure, refCat, refWcs, exposureId=self.
getExposureId(dataRef))
149 if self.config.doApCorr:
150 self.applyApCorr.
run(
152 apCorrMap=exposure.getInfo().getApCorrMap()
154 self.catalogCalculation.
run(measCat)
159 """!Hook for derived classes to define how to make an IdFactory for forced sources. 161 Note that this is for forced source IDs, not object IDs, which are usually handled by 162 the measurement.copyColumns config option. 164 raise NotImplementedError()
167 raise NotImplementedError()
170 """!Hook for derived classes to define how to get references objects. 172 Derived classes should call one of the fetch* methods on the references subtask, 173 but which one they call depends on whether the region to get references for is a 174 easy to describe in patches (as it would be when doing forced measurements on a 175 coadd), or is just an arbitrary box (as it would be for CCD forced measurements). 177 raise NotImplementedError()
180 """!Hook for derived classes to define how to attach Footprints to blank sources prior to measurement 182 Footprints for forced photometry must be in the pixel coordinate system of the image being 183 measured, while the actual detections may start out in a different coordinate system. 185 Subclasses for ForcedPhotImageTask must implement this method to define how those Footprints 188 The default implementation (defined in forcedMeasurement.py) transforms the Footprints from 189 the reference catalog from the refWcs to the exposure's Wcs, which downgrades HeavyFootprints 190 into regular Footprints, destroying deblend information. 192 return self.measurement.attachTransformedFootprints(sources, refCat, exposure, refWcs)
195 """!Read input exposure on which to perform the measurements 197 @param dataRef Data reference from butler. 199 return dataRef.get(self.dataPrefix +
"calexp", immediate=
True)
202 """!Write forced source table 204 @param dataRef Data reference from butler; the forced_src dataset (with self.dataPrefix included) 205 is all that will be modified. 206 @param sources SourceCatalog to save 208 dataRef.put(sources, self.dataPrefix +
"forced_src", flags=lsst.afw.table.SOURCE_IO_NO_FOOTPRINTS)
211 """!Get a dict of Schema catalogs that will be used by this Task. 213 In the case of forced taks, there is only one schema for each type of forced measurement. 214 The dataset type for this measurement is defined in the mapper. 217 catalog.getTable().setMetadata(self.measurement.algMetadata)
218 datasetType = self.dataPrefix +
"forced_src" 219 return {datasetType: catalog}
221 def _getConfigName(self):
222 """!Return the name of the config dataset. Forces config comparison from run-to-run 224 return self.dataPrefix +
"forced_config" 226 def _getMetadataName(self):
227 """!Return the name of the metadata dataset. Forced metadata to be saved 229 return self.dataPrefix +
"forced_metadata" A base class for command-line forced measurement drivers.
def getExposure(self, dataRef)
Read input exposure on which to perform the measurements.
def fetchReferences(self, dataRef, exposure)
Hook for derived classes to define how to get references objects.
def run(self, dataRef)
Measure a single exposure using forced detection for a reference catalog.
def makeIdFactory(self, dataRef)
Hook for derived classes to define how to make an IdFactory for forced sources.
def getExposureId(self, dataRef)
def __init__(self, butler=None, refSchema=None, kwds)
def getSchemaCatalogs(self)
Get a dict of Schema catalogs that will be used by this Task.
def writeOutput(self, dataRef, sources)
Write forced source table.
def attachFootprints(self, sources, refCat, exposure, refWcs, dataRef)
Hook for derived classes to define how to attach Footprints to blank sources prior to measurement...
Config class for forced measurement driver task.