22 from __future__
import absolute_import, division, print_function
23 import lsst.afw.image
as afwImage
24 import lsst.afw.math
as afwMath
25 import lsst.pex.config
as pexConfig
26 import lsst.pipe.base
as pipeBase
28 __all__ = [
"ExampleSigmaClippedStatsConfig",
"ExampleSigmaClippedStatsTask",
"ExampleSimpleStatsTask"]
46 """!Configuration for ExampleSigmaClippedStatsTask
48 badMaskPlanes = pexConfig.ListField(
50 doc=
"Mask planes that, if set, indicate the associated pixel should "
51 "not be included when the calculating statistics.",
54 numSigmaClip = pexConfig.Field(
55 doc=
"number of sigmas at which to clip data",
59 numIter = pexConfig.Field(
60 doc=
"number of iterations of sigma clipping",
67 """!Example task to compute sigma-clipped mean and standard deviation of an image
69 \section pipeTasks_ExampleSigmaClippedStatsTask_Contents Contents
71 - \ref pipeTasks_ExampleSigmaClippedStatsTask_Purpose
72 - \ref pipeTasks_ExampleSigmaClippedStatsTask_Config
73 - \ref pipeTasks_ExampleSigmaClippedStatsTask_Debug
74 - \ref pipeTasks_ExampleSigmaClippedStatsTask_Example
76 \section pipeTasks_ExampleSigmaClippedStatsTask_Purpose Description
78 \copybrief ExampleSigmaClippedStatsTask
80 This is a simple example task designed to be run as a subtask by ExampleCmdLineTask.
81 See also ExampleSimpleStatsTask as a variant that is even simpler.
83 The main method is \ref ExampleSigmaClippedStatsTask.run "run".
85 \section pipeTasks_ExampleSigmaClippedStatsTask_Config Configuration parameters
87 See \ref ExampleSigmaClippedStatsConfig
89 \section pipeTasks_ExampleSigmaClippedStatsTask_Debug Debug variables
91 This task has no debug variables.
93 \section pipeTasks_ExampleSigmaClippedStatsTask_Example A complete example of using ExampleSigmaClippedStatsTask
95 This code is in examples/exampleStatsTask.py (this one example runs both
96 ExampleSigmaClippedStatsTask and ExampleSimpleStatsTask), and can be run as:
98 examples/exampleStatsTask.py [fitsFile]
101 ConfigClass = ExampleSigmaClippedStatsConfig
102 _DefaultName =
"exampleSigmaClippedStats"
105 """!Construct an ExampleSigmaClippedStatsTask
107 The init method may compute anything that that does not require data.
108 In this case we create a statistics control object using the config
109 (which cannot change once the task is created).
111 pipeBase.Task.__init__(self, *args, **kwargs)
113 self.
_badPixelMask = afwImage.Mask.getPlaneBitMask(self.config.badMaskPlanes)
116 self._statsControl.setNumSigmaClip(self.config.numSigmaClip)
117 self._statsControl.setNumIter(self.config.numIter)
121 def run(self, maskedImage):
122 """!Compute and return statistics for a masked image
124 @param[in] maskedImage: masked image (an lsst::afw::MaskedImage)
125 @return a pipeBase Struct containing:
126 - mean: mean of image plane
127 - meanErr: uncertainty in mean
128 - stdDev: standard deviation of image plane
129 - stdDevErr: uncertainty in standard deviation
131 statObj = afwMath.makeStatistics(maskedImage, afwMath.MEANCLIP | afwMath.STDEVCLIP | afwMath.ERRORS,
133 mean, meanErr = statObj.getResult(afwMath.MEANCLIP)
134 stdDev, stdDevErr = statObj.getResult(afwMath.STDEVCLIP)
135 self.log.info(
"clipped mean=%0.2f; meanErr=%0.2f; stdDev=%0.2f; stdDevErr=%0.2f" %
136 (mean, meanErr, stdDev, stdDevErr))
137 return pipeBase.Struct(
148 """!Example task to compute mean and standard deviation of an image
150 \section pipeTasks_ExampleSimpleStatsTask_Contents Contents
152 - \ref pipeTasks_ExampleSimpleStatsTask_Purpose
153 - \ref pipeTasks_ExampleSimpleStatsTask_Config
154 - \ref pipeTasks_ExampleSimpleStatsTask_Debug
155 - \ref pipeTasks_ExampleSimpleStatsTask_Example
157 \section pipeTasks_ExampleSimpleStatsTask_Purpose Description
159 \copybrief ExampleSimpleStatsTask
161 This was designed to be run as a subtask by ExampleCmdLineTask.
162 It is about as simple as a task can be; it has no configuration parameters and requires no special
163 initialization. See also ExampleSigmaClippedStatsTask as a variant that is slightly more complicated.
165 The main method is \ref ExampleSimpleTask.run "run".
167 \section pipeTasks_ExampleSimpleStatsTask_Config Configuration parameters
169 This task has no configuration parameters.
171 \section pipeTasks_ExampleSimpleStatsTask_Debug Debug variables
173 This task has no debug variables.
175 \section pipeTasks_ExampleSimpleStatsTask_Example A complete example of using ExampleSimpleStatsTask
177 This code is in examples/exampleStatsTask.py (this one example runs both
178 ExampleSigmaClippedStatsTask and ExampleSimpleStatsTask), and can be run as:
180 examples/exampleStatsTask.py [fitsFile]
184 ConfigClass = pexConfig.Config
189 _DefaultName =
"exampleSimpleStats"
196 def run(self, maskedImage):
197 """!Compute and return statistics for a masked image
199 @param[in] maskedImage: masked image (an lsst::afw::MaskedImage)
200 @return a pipeBase Struct containing:
201 - mean: mean of image plane
202 - meanErr: uncertainty in mean
203 - stdDev: standard deviation of image plane
204 - stdDevErr: uncertainty in standard deviation
207 statObj = afwMath.makeStatistics(maskedImage, afwMath.MEAN | afwMath.STDEV | afwMath.ERRORS,
209 mean, meanErr = statObj.getResult(afwMath.MEAN)
210 stdDev, stdDevErr = statObj.getResult(afwMath.STDEV)
211 self.log.info(
"simple mean=%0.2f; meanErr=%0.2f; stdDev=%0.2f; stdDevErr=%0.2f" %
212 (mean, meanErr, stdDev, stdDevErr))
214 return pipeBase.Struct(
Example task to compute sigma-clipped mean and standard deviation of an image.
def run
Compute and return statistics for a masked image.
def run
Compute and return statistics for a masked image.
Configuration for ExampleSigmaClippedStatsTask.
Example task to compute mean and standard deviation of an image.
def __init__
Construct an ExampleSigmaClippedStatsTask.