25from lsst.utils.timer
import timeMethod
26from .exampleStatsTasks
import ExampleSigmaClippedStatsTask
28__all__ = [
"ExampleCmdLineConfig",
"ExampleCmdLineTask"]
41 """!Configuration for ExampleCmdLineTask
43 stats = pexConfig.ConfigurableField(
44 doc="Subtask to compute statistics of an image",
45 target=ExampleSigmaClippedStatsTask,
47 doFail = pexConfig.Field(
48 doc=
"Raise an lsst.base.TaskError exception when processing each image? "
49 "This allows one to see the effects of the --doraise command line flag",
57 Example command-line task that computes simple statistics on an image
59 \section pipeTasks_ExampleCmdLineTask_Contents Contents
61 - \ref pipeTasks_ExampleCmdLineTask_Purpose
62 - \ref pipeTasks_ExampleCmdLineTask_Config
63 - \ref pipeTasks_ExampleCmdLineTask_Debug
64 - \ref pipeTasks_ExampleCmdLineTask_Example
66 \section pipeTasks_ExampleCmdLineTask_Purpose Description
68 \copybrief ExampleCmdLineTask
70 This task was written as an example
for the documents
71 <a href=
"https://pipelines.lsst.io/modules/lsst.pipe.base/creating-a-task.html">Creating a task</a>
72 and <a href=
"https://pipelines.lsst.io/modules/lsst.pipe.base/creating-a-command-line-task.html">
73 Creating a command-line task</a>.
74 The task reads
in a
"calexp" (a calibrated science \ref lsst::afw::image::Exposure
"exposure"),
75 computes statistics on the image plane,
and logs
and returns the statistics.
76 In addition,
if debugging
is enabled, it displays the image
in current display backend.
78 The image statistics are computed using a subtask,
in order to show how to call subtasks
and how to
79 <a href=
"https://pipelines.lsst.io/modules/lsst.pipe.base/command-line-task-retargeting-howto.html">
80 retarget</a> (replace) them
with variant subtasks.
82 The main method
is \ref ExampleCmdLineTask.runDataRef
"runDataRef".
84 \section pipeTasks_ExampleCmdLineTask_Config Configuration parameters
86 See \ref ExampleCmdLineConfig
88 \section pipeTasks_ExampleCmdLineTask_Debug Debug variables
90 This task supports the following debug variables:
93 <dd>If
True then display the exposure
in current display backend
96 To enable debugging, see
97 <a href=
"https://pipelines.lsst.io/modules/lsstDebug/">the lsstDebug documentation</a>.
99 \section pipeTasks_ExampleCmdLineTask_Example A complete example of using ExampleCmdLineTask
101 This code
is in examples/exampleCmdLineTask.py,
and can be run
as follows:
103 examples/exampleCmdLineTask.py $OBS_TEST_DIR/data/input --id
106 --config doFail=
True --doraise
110 ConfigClass = ExampleCmdLineConfig
111 _DefaultName = "exampleTask"
114 """Construct an ExampleCmdLineTask
116 Call the parent class constructor and make the
"stats" subtask
from the config
field of the same
name.
118 pipeBase.CmdLineTask.__init__(self, *args, **kwargs)
119 self.makeSubtask("stats")
123 """!Compute a few statistics on the image plane of an exposure
125 @param dataRef: data reference
for a calibrated science exposure (
"calexp")
126 @return a pipeBase Struct containing:
127 - mean: mean of image plane
128 - meanErr: uncertainty
in mean
129 - stdDev: standard deviation of image plane
130 - stdDevErr: uncertainty
in standard deviation
132 self.log.info("Processing data ID %s", dataRef.dataId)
133 if self.config.doFail:
134 raise pipeBase.TaskError(
"Raising TaskError by request (config.doFail=True)")
137 rawExp = dataRef.get(
"raw")
138 maskedImage = rawExp.getMaskedImage()
146 disp = afwDisplay.Display(frame=frame)
147 disp.mtv(rawExp, title=
"exposure")
150 return self.stats.
run(maskedImage)
152 def _getConfigName(self):
153 """!Get the name prefix for the task config's dataset type, or None to prevent persisting the config
155 This override returns None to avoid persisting metadata
for this trivial task.
157 However,
if the method returns a name, then the full name of the dataset type will be <name>_config.
158 The default CmdLineTask._getConfigName returns _DefaultName,
159 which
for this task would result
in a dataset name of
"exampleTask_config".
161 Normally you can use the default CmdLineTask._getConfigName, but here are two reasons
162 why you might want to override it:
163 - If you do
not want your task to write its config, then have the override
return None.
164 That
is done
for this example task, because I didn
't want to clutter up the
165 repository with config information
for a trivial task.
166 - If the default name would
not be unique. An example
is
168 \ref lsst.skymap.SkyMap
"sky map" (sky pixelization
for a coadd)
169 for any of several different types of coadd, such
as deep
or goodSeeing.
170 As such, the name of the persisted config must include the coadd type
in order to be unique.
172 Normally
if you override _getConfigName then you override _getMetadataName to match.
176 def _getMetadataName(self):
177 """!Get the name prefix for the task metadata's dataset type, or None to prevent persisting metadata
179 This override returns None to avoid persisting metadata
for this trivial task.
181 However,
if the method returns a name, then the full name of the dataset type will be <name>_metadata.
182 The default CmdLineTask._getConfigName returns _DefaultName,
183 which
for this task would result
in a dataset name of
"exampleTask_metadata".
185 See the description of _getConfigName
for reasons to override this method.
table::Key< std::string > name
Configuration for ExampleCmdLineTask.
Example command-line task that computes simple statistics on an image.
def __init__(self, *args, **kwargs)
def runDataRef(self, dataRef)
Compute a few statistics on the image plane of an exposure.
Make a sky map in a repository.
def run(self, coaddExposures, bbox, wcs, dataIds, **kwargs)