24 import lsst.pex.config 
as pexConfig
 
   27 __all__ = [
"ExampleSigmaClippedStatsConfig", 
"ExampleSigmaClippedStatsTask", 
"ExampleSimpleStatsTask"]
 
   43     """!Configuration for ExampleSigmaClippedStatsTask 
   45     badMaskPlanes = pexConfig.ListField(
 
   47         doc=
"Mask planes that, if set, indicate the associated pixel should " 
   48         "not be included when the calculating statistics.",
 
   51     numSigmaClip = pexConfig.Field(
 
   52         doc=
"number of sigmas at which to clip data",
 
   56     numIter = pexConfig.Field(
 
   57         doc=
"number of iterations of sigma clipping",
 
   64     r"""!Example task to compute sigma-clipped mean and standard deviation of an image 
   66     \section pipeTasks_ExampleSigmaClippedStatsTask_Contents Contents 
   68      - \ref pipeTasks_ExampleSigmaClippedStatsTask_Purpose 
   69      - \ref pipeTasks_ExampleSigmaClippedStatsTask_Config 
   70      - \ref pipeTasks_ExampleSigmaClippedStatsTask_Debug 
   71      - \ref pipeTasks_ExampleSigmaClippedStatsTask_Example 
   73     \section pipeTasks_ExampleSigmaClippedStatsTask_Purpose Description 
   75     \copybrief ExampleSigmaClippedStatsTask 
   77     This is a simple example task designed to be run as a subtask by ExampleCmdLineTask. 
   78     See also ExampleSimpleStatsTask as a variant that is even simpler. 
   80     The main method is \ref ExampleSigmaClippedStatsTask.run "run". 
   82     \section pipeTasks_ExampleSigmaClippedStatsTask_Config  Configuration parameters 
   84     See \ref ExampleSigmaClippedStatsConfig 
   86     \section pipeTasks_ExampleSigmaClippedStatsTask_Debug   Debug variables 
   88     This task has no debug variables. 
   90     \section pipeTasks_ExampleSigmaClippedStatsTask_Example A complete example 
   91     of using ExampleSigmaClippedStatsTask 
   93     This code is in examples/exampleStatsTask.py (this one example runs both 
   94     ExampleSigmaClippedStatsTask and ExampleSimpleStatsTask), and can be run as: 
   96     examples/exampleStatsTask.py [fitsFile] 
   99     ConfigClass = ExampleSigmaClippedStatsConfig
 
  100     _DefaultName = 
"exampleSigmaClippedStats" 
  103         """!Construct an ExampleSigmaClippedStatsTask 
  105         The init method may compute anything that that does not require data. 
  106         In this case we create a statistics control object using the config 
  107         (which cannot change once the task is created). 
  109         pipeBase.Task.__init__(self, *args, **kwargs)
 
  111         self.
_badPixelMask = afwImage.Mask.getPlaneBitMask(self.config.badMaskPlanes)
 
  119     def run(self, maskedImage):
 
  120         """!Compute and return statistics for a masked image 
  122         @param[in] maskedImage: masked image (an lsst::afw::MaskedImage) 
  123         @return a pipeBase Struct containing: 
  124         - mean: mean of image plane 
  125         - meanErr: uncertainty in mean 
  126         - stdDev: standard deviation of image plane 
  127         - stdDevErr: uncertainty in standard deviation 
  131         mean, meanErr = statObj.getResult(afwMath.MEANCLIP)
 
  132         stdDev, stdDevErr = statObj.getResult(afwMath.STDEVCLIP)
 
  133         self.log.
info(
"clipped mean=%0.2f; meanErr=%0.2f; stdDev=%0.2f; stdDevErr=%0.2f" %
 
  134                       (mean, meanErr, stdDev, stdDevErr))
 
  135         return pipeBase.Struct(
 
  144     r"""!Example task to compute mean and standard deviation of an image 
  146     \section pipeTasks_ExampleSimpleStatsTask_Contents Contents 
  148      - \ref pipeTasks_ExampleSimpleStatsTask_Purpose 
  149      - \ref pipeTasks_ExampleSimpleStatsTask_Config 
  150      - \ref pipeTasks_ExampleSimpleStatsTask_Debug 
  151      - \ref pipeTasks_ExampleSimpleStatsTask_Example 
  153     \section pipeTasks_ExampleSimpleStatsTask_Purpose Description 
  155     \copybrief ExampleSimpleStatsTask 
  157     This was designed to be run as a subtask by ExampleCmdLineTask. 
  158     It is about as simple as a task can be; it has no configuration parameters and requires no special 
  159     initialization. See also ExampleSigmaClippedStatsTask as a variant that is slightly more complicated. 
  161     The main method is \ref ExampleSimpleTask.run "run". 
  163     \section pipeTasks_ExampleSimpleStatsTask_Config    Configuration parameters 
  165     This task has no configuration parameters. 
  167     \section pipeTasks_ExampleSimpleStatsTask_Debug     Debug variables 
  169     This task has no debug variables. 
  171     \section pipeTasks_ExampleSimpleStatsTask_Example A complete example of using ExampleSimpleStatsTask 
  173     This code is in examples/exampleStatsTask.py (this one example runs both 
  174     ExampleSigmaClippedStatsTask and ExampleSimpleStatsTask), and can be run as: 
  176     examples/exampleStatsTask.py [fitsFile] 
  180     ConfigClass = pexConfig.Config
 
  185     _DefaultName = 
"exampleSimpleStats" 
  192     def run(self, maskedImage):
 
  193         """!Compute and return statistics for a masked image 
  195         @param[in] maskedImage: masked image (an lsst::afw::MaskedImage) 
  196         @return a pipeBase Struct containing: 
  197         - mean: mean of image plane 
  198         - meanErr: uncertainty in mean 
  199         - stdDev: standard deviation of image plane 
  200         - stdDevErr: uncertainty in standard deviation 
  205         mean, meanErr = statObj.getResult(afwMath.MEAN)
 
  206         stdDev, stdDevErr = statObj.getResult(afwMath.STDEV)
 
  207         self.log.
info(
"simple mean=%0.2f; meanErr=%0.2f; stdDev=%0.2f; stdDevErr=%0.2f" %
 
  208                       (mean, meanErr, stdDev, stdDevErr))
 
  210         return pipeBase.Struct(