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).
33 from .references
import MultiBandReferencesTask
34 from .forcedMeasurement
import ForcedMeasurementTask
36 __all__ = (
"ProcessImageForcedConfig",
"ProcessImageForcedTask")
39 """!Config class for forced measurement driver task."""
41 references = lsst.pex.config.ConfigurableField(
42 target=MultiBandReferencesTask,
43 doc=
"subtask to retrieve reference source catalog"
45 measurement = lsst.pex.config.ConfigurableField(
46 target=ForcedMeasurementTask,
47 doc=
"subtask to do forced measurement"
49 coaddName = lsst.pex.config.Field(
50 doc =
"coadd name: typically one of deep or goodSeeing",
54 copyColumns = lsst.pex.config.DictField(
55 keytype=str, itemtype=str, doc=
"Mapping of reference columns to source columns",
56 default={
"id":
"objectId",
"parent":
"parentObjectId",
"deblend_nChild":
"deblend_nChild"}
62 self.measurement.doApplyApCorr =
"noButWarn"
72 """!A base class for command-line forced measurement drivers.
74 This is a an abstract class, which is the common ancestor for ForcedPhotCcdTask
75 and ForcedPhotCoaddTask. It provides the run() method that does most of the
76 work, while delegating a few customization tasks to other methods that are
77 overridden by subclasses.
79 This task is not directly usable as a CmdLineTask; subclasses must:
80 - Set the _DefaultName class attribute
81 - Implement makeIdFactory
82 - Implement fetchReferences
83 - (optional) Implement attachFootprints
85 ConfigClass = ProcessImageForcedConfig
86 _DefaultName =
"processImageForcedTask"
88 def __init__(self, butler=None, refSchema=None, **kwds):
89 """Initialize the task.
91 ForcedPhotImageTask takes two keyword arguments beyond the usual CmdLineTask arguments:
92 - refSchema: the Schema of the reference catalog, passed to the constructor of the references
94 - butler: a butler that will be passed to the references subtask to allow it to load its Schema
96 At least one of these arguments must be present; if both are, schema takes precedence.
98 super(lsst.pipe.base.CmdLineTask, self).
__init__(**kwds)
99 self.makeSubtask(
"references", butler=butler, schema=refSchema)
100 if refSchema
is None:
101 refSchema = self.references.schema
102 self.makeSubtask(
"measurement", refSchema=refSchema)
105 """!Measure a single exposure using forced detection for a reference catalog.
107 @param[in] dataRef An lsst.daf.persistence.ButlerDataRef. It is passed to the
108 references subtask to obtain the reference WCS, the getExposure()
109 method (implemented by derived classes) to read the measurement
110 image, and the fetchReferences() method (implemented by derived
111 classes) to get the exposure and load the reference catalog (see
112 the CoaddSrcReferencesTask for more information). Sources are
113 generated with generateMeasCat() in the measurement subtask. These
114 are passed to measurement's run method which fills the source
115 catalog with the forced measurement results. The sources are then
116 passed to the writeOutputs() method (implemented by derived classes)
117 which writes the outputs. See derived class documentation for which
118 datasets and data ID keys are used.
120 refWcs = self.references.getWcs(dataRef)
123 measCat = self.measurement.generateMeasCat(exposure, refCat, refWcs,
125 self.log.info(
"Performing forced measurement on %s" % dataRef.dataId)
127 self.measurement.run(measCat, exposure, refCat, refWcs)
131 """!Hook for derived classes to define how to make an IdFactory for forced sources.
133 Note that this is for forced source IDs, not object IDs, which are usually handled by
134 the copyColumns config option.
136 raise NotImplementedError()
139 """!Hook for derived classes to define how to get references objects.
141 Derived classes should call one of the fetch* methods on the references subtask,
142 but which one they call depends on whether the region to get references for is a
143 easy to describe in patches (as it would be when doing forced measurements on a
144 coadd), or is just an arbitrary box (as it would be for CCD forced measurements).
146 raise NotImplementedError()
149 """!Hook for derived classes to define how to attach Footprints to blank sources prior to measurement
151 Footprints for forced photometry must be in the pixel coordinate system of the image being
152 measured, while the actual detections may start out in a different coordinate system.
154 Subclasses for ForcedPhotImageTask must implement this method to define how those Footprints
157 The default implementation (defined in forcedMeasurement.py) transforms the Footprints from
158 the reference catalog from the refWcs to the exposure's Wcs, which downgrades HeavyFootprints
159 into regular Footprints, destroying deblend information.
161 return self.measurement.attachTransformedFootprints(sources, refCat, exposure, refWcs)
164 """!Read input exposure on which to perform the measurements
166 @param dataRef Data reference from butler.
168 return dataRef.get(self.dataPrefix +
"calexp", immediate=
True)
171 """!Write forced source table
173 @param dataRef Data reference from butler; the forced_src dataset (with self.dataPrefix included)
174 is all that will be modified.
175 @param sources SourceCatalog to save
177 dataRef.put(sources, self.dataPrefix +
"forced_src")
180 """!Get a dict of Schema catalogs that will be used by this Task.
182 In the case of forced taks, there is only one schema for each type of forced measurement.
183 The dataset type for this measurement is defined in the mapper.
186 catalog.getTable().setMetadata(self.measurement.algMetadata)
187 datasetType = self.dataPrefix +
"forced_src"
188 return {datasetType:catalog}
191 """!Return the name of the config dataset. Forces config comparison from run-to-run
193 return self.dataPrefix +
"forced_config"
196 """!Return the name of the metadata dataset. Forced metadata to be saved
198 return self.dataPrefix +
"forced_metadata"
Config class for forced measurement driver task.
def fetchReferences
Hook for derived classes to define how to get references objects.
def attachFootprints
Hook for derived classes to define how to attach Footprints to blank sources prior to measurement...
def run
Measure a single exposure using forced detection for a reference catalog.
def getExposure
Read input exposure on which to perform the measurements.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
def _getConfigName
Return the name of the config dataset.
def makeIdFactory
Hook for derived classes to define how to make an IdFactory for forced sources.
def getSchemaCatalogs
Get a dict of Schema catalogs that will be used by this Task.
def _getMetadataName
Return the name of the metadata dataset.
def writeOutput
Write forced source table.
A base class for command-line forced measurement drivers.