def main(): mimg = afwImage.MaskedImageF(afwGeom.Extent2I(100, 100)) mimValue = (2, 0x0, 1) mimg.set(mimValue) # call with the factory function ... should get stats on the image plane fmt = "%-40s %-16s %3.1f\n" print(fmt % ("Using makeStatistics:", "(should be " + str(mimValue[0]) + ")", afwMath.makeStatistics(mimg, afwMath.MEAN).getValue()), end=' ') # call the constructor directly ... once for image plane, then for variance # - make sure we're not using weighted stats for this sctrl = afwMath.StatisticsControl() sctrl.setWeighted(False) print(fmt % ("Using Statistics on getImage():", "(should be " + str(mimValue[0]) + ")", afwMath.StatisticsF(mimg.getImage(), mimg.getMask(), mimg.getVariance(), afwMath.MEAN, sctrl).getValue()), end=' ') print(fmt % ("Using Statistics on getVariance():", "(should be " + str(mimValue[2]) + ")", afwMath.StatisticsF(mimg.getVariance(), mimg.getMask(), mimg.getVariance(), afwMath.MEAN, sctrl).getValue()), end=' ') # call makeStatistics as a front-end for the constructor print(fmt % ("Using makeStatistics on getImage():", "(should be " + str(mimValue[0]) + ")", afwMath.makeStatistics(mimg.getImage(), mimg.getMask(), afwMath.MEAN).getValue()), end=' ') print(fmt % ("Using makeStatistics on getVariance():", "(should be " + str(mimValue[2]) + ")", afwMath.makeStatistics(mimg.getVariance(), mimg.getMask(), afwMath.MEAN).getValue()), end=' ')
def testStatisticsConstructor(self): if False: statsI = afwMath.StatisticsI(self.mimgI.getImage(), self.mimgI.getMask(), afwMath.NPOINT | afwMath.STDEV | afwMath.MEAN | afwMath.SUM, self.sctrl) statsF = afwMath.StatisticsF(self.mimgF.getImage(), self.mimgF.getMask(), afwMath.NPOINT | afwMath.STDEV | afwMath.MEAN | afwMath.SUM, self.sctrl) statsD = afwMath.StatisticsD(self.mimgD.getImage(), self.mimgD.getMask(), afwMath.NPOINT | afwMath.STDEV | afwMath.MEAN | afwMath.SUM, self.sctrl) self.compareStatistics(statsI, self.mimgI.getWidth()*self.mimgI.getHeight()) self.compareStatistics(statsF, self.mimgF.getWidth()*self.mimgF.getHeight()) self.compareStatistics(statsD, self.mimgD.getWidth()*self.mimgD.getHeight())