26 from .exampleStatsTasks
import ExampleSigmaClippedStatsTask
38 """!Configuration for ExampleCmdLineTask
40 stats = pexConfig.ConfigurableField(
41 doc =
"Subtask to compute statistics of an image",
42 target = ExampleSigmaClippedStatsTask,
44 doFail = pexConfig.Field(
45 doc =
"Raise an lsst.base.TaskError exception when processing each image? " \
46 +
"This allows one to see the effects of the --doraise command line flag",
52 """!Example command-line task that computes simple statistics on an image
54 \section pipeTasks_ExampleCmdLineTask_Contents Contents
56 - \ref pipeTasks_ExampleCmdLineTask_Purpose
57 - \ref pipeTasks_ExampleCmdLineTask_Config
58 - \ref pipeTasks_ExampleCmdLineTask_Debug
59 - \ref pipeTasks_ExampleCmdLineTask_Example
61 \section pipeTasks_ExampleCmdLineTask_Purpose Description
63 \copybrief ExampleCmdLineTask
65 This task was written as an example for the documents \ref pipeTasks_writeTask
66 and \ref pipeTasks_writeCmdLineTask.
67 The task reads in a "calexp" (a calibrated science \ref lsst::afw::image::Exposure "exposure"),
68 computes statistics on the image plane, and logs and returns the statistics.
69 In addition, if debugging is enabled, it displays the image in ds9.
71 The image statistics are computed using a subtask, in order to show how to call subtasks and how to
72 \ref pipeBase_argumentParser_retargetSubtasks "retarget" (replace) them with variant subtasks.
74 The main method is \ref ExampleCmdLineTask.run "run".
76 \section pipeTasks_ExampleCmdLineTask_Config Configuration parameters
78 See \ref ExampleCmdLineConfig
80 \section pipeTasks_ExampleCmdLineTask_Debug Debug variables
82 This task supports the following debug variables:
85 <dd>If True then display the exposure in ds9
88 To enable debugging, see \ref baseDebug.
90 \section pipeTasks_ExampleCmdLineTask_Example A complete example of using ExampleCmdLineTask
92 This code is in examples/exampleCmdLineTask.py, and can be run as follows:
94 examples/exampleCmdLineTask.py $OBS_TEST_DIR/data/input --id
95 # that will process all data; you can also try any combination of these flags:
97 --config doFail=True --doraise
101 ConfigClass = ExampleCmdLineConfig
102 _DefaultName =
"exampleTask"
105 """Construct an ExampleCmdLineTask
107 Call the parent class constructor and make the "stats" subtask from the config field of the same name.
109 pipeBase.CmdLineTask.__init__(self, *args, **kwargs)
110 self.makeSubtask(
"stats")
114 """!Compute a few statistics on the image plane of an exposure
116 @param dataRef: data reference for a calibrated science exposure ("calexp")
117 @return a pipeBase Struct containing:
118 - mean: mean of image plane
119 - meanErr: uncertainty in mean
120 - stdDev: standard deviation of image plane
121 - stdDevErr: uncertainty in standard deviation
123 self.log.info(
"Processing data ID %s" % (dataRef.dataId,))
124 if self.config.doFail:
125 raise pipeBase.TaskError(
"Raising TaskError by request (config.doFail=True)")
128 rawExp = dataRef.get(
"raw")
129 maskedImage = rawExp.getMaskedImage()
137 mtv(rawExp, frame=frame, title=
"exposure")
140 return self.stats.run(maskedImage)
143 """!Get the name prefix for the task config's dataset type, or None to prevent persisting the config
145 This override returns None to avoid persisting metadata for this trivial task.
147 However, if the method returns a name, then the full name of the dataset type will be <name>_config.
148 The default CmdLineTask._getConfigName returns _DefaultName,
149 which for this task would result in a dataset name of "exampleTask_config".
151 Normally you can use the default CmdLineTask._getConfigName, but here are two reasons
152 why you might want to override it:
153 - If you do not want your task to write its config, then have the override return None.
154 That is done for this example task, because I didn't want to clutter up the
155 repository with config information for a trivial task.
156 - If the default name would not be unique. An example is
157 \ref lsst.pipe.tasks.makeSkyMap.MakeSkyMapTask "MakeSkyMapTask": it makes a
158 \ref lsst.skymap.SkyMap "sky map" (sky pixelization for a coadd)
159 for any of several different types of coadd, such as deep or goodSeeing.
160 As such, the name of the persisted config must include the coadd type in order to be unique.
162 Normally if you override _getConfigName then you override _getMetadataName to match.
167 """!Get the name prefix for the task metadata's dataset type, or None to prevent persisting metadata
169 This override returns None to avoid persisting metadata for this trivial task.
171 However, if the method returns a name, then the full name of the dataset type will be <name>_metadata.
172 The default CmdLineTask._getConfigName returns _DefaultName,
173 which for this task would result in a dataset name of "exampleTask_metadata".
175 See the description of _getConfigName for reasons to override this method.
def _getConfigName
Get the name prefix for the task config's dataset type, or None to prevent persisting the config...
def _getMetadataName
Get the name prefix for the task metadata's dataset type, or None to prevent persisting metadata...
Configuration for ExampleCmdLineTask.
Example command-line task that computes simple statistics on an image.
def run
Compute a few statistics on the image plane of an exposure.