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",
56 r"""!Example command-line task that computes simple statistics on an image
58 \section pipeTasks_ExampleCmdLineTask_Contents Contents
60 - \ref pipeTasks_ExampleCmdLineTask_Purpose
61 - \ref pipeTasks_ExampleCmdLineTask_Config
62 - \ref pipeTasks_ExampleCmdLineTask_Debug
63 - \ref pipeTasks_ExampleCmdLineTask_Example
65 \section pipeTasks_ExampleCmdLineTask_Purpose Description
67 \copybrief ExampleCmdLineTask
69 This task was written as an example
for the documents \ref pipeTasks_writeTask
70 and \ref pipeTasks_writeCmdLineTask.
71 The task reads
in a
"calexp" (a calibrated science \ref lsst::afw::image::Exposure
"exposure"),
72 computes statistics on the image plane,
and logs
and returns the statistics.
73 In addition,
if debugging
is enabled, it displays the image
in current display backend.
75 The image statistics are computed using a subtask,
in order to show how to call subtasks
and how to
76 \ref pipeBase_argumentParser_retargetSubtasks
"retarget" (replace) them
with variant subtasks.
78 The main method
is \ref ExampleCmdLineTask.runDataRef
"runDataRef".
80 \section pipeTasks_ExampleCmdLineTask_Config Configuration parameters
82 See \ref ExampleCmdLineConfig
84 \section pipeTasks_ExampleCmdLineTask_Debug Debug variables
86 This task supports the following debug variables:
89 <dd>If
True then display the exposure
in current display backend
92 To enable debugging, see \ref baseDebug.
94 \section pipeTasks_ExampleCmdLineTask_Example A complete example of using ExampleCmdLineTask
96 This code
is in examples/exampleCmdLineTask.py,
and can be run
as follows:
98 examples/exampleCmdLineTask.py $OBS_TEST_DIR/data/input --id
101 --config doFail=
True --doraise
105 ConfigClass = ExampleCmdLineConfig
106 _DefaultName = "exampleTask"
109 """Construct an ExampleCmdLineTask
111 Call the parent class constructor and make the
"stats" subtask from the config field of the same name.
113 pipeBase.CmdLineTask.__init__(self, *args, **kwargs)
114 self.makeSubtask("stats")
118 """!Compute a few statistics on the image plane of an exposure
120 @param dataRef: data reference
for a calibrated science exposure (
"calexp")
121 @return a pipeBase Struct containing:
122 - mean: mean of image plane
123 - meanErr: uncertainty
in mean
124 - stdDev: standard deviation of image plane
125 - stdDevErr: uncertainty
in standard deviation
127 self.log.info("Processing data ID %s", dataRef.dataId)
128 if self.config.doFail:
129 raise pipeBase.TaskError(
"Raising TaskError by request (config.doFail=True)")
132 rawExp = dataRef.get(
"raw")
133 maskedImage = rawExp.getMaskedImage()
141 disp = afwDisplay.Display(frame=frame)
142 disp.mtv(rawExp, title=
"exposure")
145 return self.stats.run(maskedImage)
147 def _getConfigName(self):
148 """!Get the name prefix for the task config's dataset type, or None to prevent persisting the config
150 This override returns None to avoid persisting metadata
for this trivial task.
152 However,
if the method returns a name, then the full name of the dataset type will be <name>_config.
153 The default CmdLineTask._getConfigName returns _DefaultName,
154 which
for this task would result
in a dataset name of
"exampleTask_config".
156 Normally you can use the default CmdLineTask._getConfigName, but here are two reasons
157 why you might want to override it:
158 - If you do
not want your task to write its config, then have the override
return None.
159 That
is done
for this example task, because I didn
't want to clutter up the
160 repository with config information
for a trivial task.
161 - If the default name would
not be unique. An example
is
163 \ref lsst.skymap.SkyMap
"sky map" (sky pixelization
for a coadd)
164 for any of several different types of coadd, such
as deep
or goodSeeing.
165 As such, the name of the persisted config must include the coadd type
in order to be unique.
167 Normally
if you override _getConfigName then you override _getMetadataName to match.
171 def _getMetadataName(self):
172 """!Get the name prefix for the task metadata's dataset type, or None to prevent persisting metadata
174 This override returns None to avoid persisting metadata
for this trivial task.
176 However,
if the method returns a name, then the full name of the dataset type will be <name>_metadata.
177 The default CmdLineTask._getConfigName returns _DefaultName,
178 which
for this task would result
in a dataset name of
"exampleTask_metadata".
180 See the description of _getConfigName
for reasons to override this method.
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.