25 from .exampleStatsTasks
import ExampleSigmaClippedStatsTask
27 __all__ = [
"ExampleCmdLineConfig",
"ExampleCmdLineTask"]
40 """!Configuration for ExampleCmdLineTask 42 stats = pexConfig.ConfigurableField(
43 doc=
"Subtask to compute statistics of an image",
44 target=ExampleSigmaClippedStatsTask,
46 doFail = pexConfig.Field(
47 doc=
"Raise an lsst.base.TaskError exception when processing each image? " 48 "This allows one to see the effects of the --doraise command line flag",
55 r"""!Example command-line task that computes simple statistics on an image 57 \section pipeTasks_ExampleCmdLineTask_Contents Contents 59 - \ref pipeTasks_ExampleCmdLineTask_Purpose 60 - \ref pipeTasks_ExampleCmdLineTask_Config 61 - \ref pipeTasks_ExampleCmdLineTask_Debug 62 - \ref pipeTasks_ExampleCmdLineTask_Example 64 \section pipeTasks_ExampleCmdLineTask_Purpose Description 66 \copybrief ExampleCmdLineTask 68 This task was written as an example for the documents \ref pipeTasks_writeTask 69 and \ref pipeTasks_writeCmdLineTask. 70 The task reads in a "calexp" (a calibrated science \ref lsst::afw::image::Exposure "exposure"), 71 computes statistics on the image plane, and logs and returns the statistics. 72 In addition, if debugging is enabled, it displays the image in current display backend. 74 The image statistics are computed using a subtask, in order to show how to call subtasks and how to 75 \ref pipeBase_argumentParser_retargetSubtasks "retarget" (replace) them with variant subtasks. 77 The main method is \ref ExampleCmdLineTask.runDataRef "runDataRef". 79 \section pipeTasks_ExampleCmdLineTask_Config Configuration parameters 81 See \ref ExampleCmdLineConfig 83 \section pipeTasks_ExampleCmdLineTask_Debug Debug variables 85 This task supports the following debug variables: 88 <dd>If True then display the exposure in current display backend 91 To enable debugging, see \ref baseDebug. 93 \section pipeTasks_ExampleCmdLineTask_Example A complete example of using ExampleCmdLineTask 95 This code is in examples/exampleCmdLineTask.py, and can be run as follows: 97 examples/exampleCmdLineTask.py $OBS_TEST_DIR/data/input --id 98 # that will process all data; you can also try any combination of these flags: 100 --config doFail=True --doraise 104 ConfigClass = ExampleCmdLineConfig
105 _DefaultName =
"exampleTask" 108 """Construct an ExampleCmdLineTask 110 Call the parent class constructor and make the "stats" subtask from the config field of the same name. 112 pipeBase.CmdLineTask.__init__(self, *args, **kwargs)
113 self.makeSubtask(
"stats")
117 """!Compute a few statistics on the image plane of an exposure 119 @param dataRef: data reference for a calibrated science exposure ("calexp") 120 @return a pipeBase Struct containing: 121 - mean: mean of image plane 122 - meanErr: uncertainty in mean 123 - stdDev: standard deviation of image plane 124 - stdDevErr: uncertainty in standard deviation 126 self.log.
info(
"Processing data ID %s" % (dataRef.dataId,))
127 if self.config.doFail:
128 raise pipeBase.TaskError(
"Raising TaskError by request (config.doFail=True)")
131 rawExp = dataRef.get(
"raw")
132 maskedImage = rawExp.getMaskedImage()
140 disp = afwDisplay.Display(frame=frame)
141 disp.mtv(rawExp, title=
"exposure")
144 return self.stats.
run(maskedImage)
146 def _getConfigName(self):
147 """!Get the name prefix for the task config's dataset type, or None to prevent persisting the config 149 This override returns None to avoid persisting metadata for this trivial task. 151 However, if the method returns a name, then the full name of the dataset type will be <name>_config. 152 The default CmdLineTask._getConfigName returns _DefaultName, 153 which for this task would result in a dataset name of "exampleTask_config". 155 Normally you can use the default CmdLineTask._getConfigName, but here are two reasons 156 why you might want to override it: 157 - If you do not want your task to write its config, then have the override return None. 158 That is done for this example task, because I didn't want to clutter up the 159 repository with config information for a trivial task. 160 - If the default name would not be unique. An example is 161 \ref lsst.pipe.tasks.makeSkyMap.MakeSkyMapTask "MakeSkyMapTask": it makes a 162 \ref lsst.skymap.SkyMap "sky map" (sky pixelization for a coadd) 163 for any of several different types of coadd, such as deep or goodSeeing. 164 As such, the name of the persisted config must include the coadd type in order to be unique. 166 Normally if you override _getConfigName then you override _getMetadataName to match. 170 def _getMetadataName(self):
171 """!Get the name prefix for the task metadata's dataset type, or None to prevent persisting metadata 173 This override returns None to avoid persisting metadata for this trivial task. 175 However, if the method returns a name, then the full name of the dataset type will be <name>_metadata. 176 The default CmdLineTask._getConfigName returns _DefaultName, 177 which for this task would result in a dataset name of "exampleTask_metadata". 179 See the description of _getConfigName for reasons to override this method. def runDataRef(self, dataRef)
Compute a few statistics on the image plane of an exposure.
Configuration for ExampleCmdLineTask.
def __init__(self, args, kwargs)
Example command-line task that computes simple statistics on an image.