LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Functions
lsst.afw.image.testUtils Namespace Reference

Functions

def makeGaussianNoiseMaskedImage
 
def imagesDiffer
 
def masksDiffer
 
def maskedImagesDiffer
 

Function Documentation

def lsst.afw.image.testUtils.imagesDiffer (   imageArr1,
  imageArr2,
  skipMaskArr = None,
  rtol = 1.0e-05,
  atol = 1e-08 
)
Compare the pixels of two image arrays; return True if close, False otherwise

Inputs:
- image1: first image to compare
- image2: second image to compare
- skipMaskArr: pixels to ignore; nonzero values are skipped
- rtol: relative tolerance (see below)
- atol: absolute tolerance (see below)

rtol and atol are positive, typically very small numbers.
The relative difference (rtol * abs(b)) and the absolute difference "atol" are added together
to compare against the absolute difference between "a" and "b".

Return a string describing the error if the images differ significantly, an empty string otherwise

Definition at line 45 of file testUtils.py.

45 
46 def imagesDiffer(imageArr1, imageArr2, skipMaskArr=None, rtol=1.0e-05, atol=1e-08):
47  """Compare the pixels of two image arrays; return True if close, False otherwise
48 
49  Inputs:
50  - image1: first image to compare
51  - image2: second image to compare
52  - skipMaskArr: pixels to ignore; nonzero values are skipped
53  - rtol: relative tolerance (see below)
54  - atol: absolute tolerance (see below)
55 
56  rtol and atol are positive, typically very small numbers.
57  The relative difference (rtol * abs(b)) and the absolute difference "atol" are added together
58  to compare against the absolute difference between "a" and "b".
59 
60  Return a string describing the error if the images differ significantly, an empty string otherwise
61  """
62  retStrs = []
63  if skipMaskArr is not None:
64  maskedArr1 = numpy.ma.array(imageArr1, copy=False, mask = skipMaskArr)
65  maskedArr2 = numpy.ma.array(imageArr2, copy=False, mask = skipMaskArr)
66  filledArr1 = maskedArr1.filled(0.0)
67  filledArr2 = maskedArr2.filled(0.0)
68  else:
69  filledArr1 = imageArr1
70  filledArr2 = imageArr2
71 
72  nan1 = numpy.isnan(filledArr1)
73  nan2 = numpy.isnan(filledArr2)
74  if numpy.any(nan1 != nan2):
75  retStrs.append("NaNs differ")
76 
77  posinf1 = numpy.isposinf(filledArr1)
78  posinf2 = numpy.isposinf(filledArr2)
79  if numpy.any(posinf1 != posinf2):
80  retStrs.append("+infs differ")
81 
82  neginf1 = numpy.isneginf(filledArr1)
83  neginf2 = numpy.isneginf(filledArr2)
84  if numpy.any(neginf1 != neginf2):
85  retStrs.append("-infs differ")
86 
87  # compare values that should be comparable (are neither infinite, nan nor masked)
88  valSkipMaskArr = nan1 | nan2 | posinf1 | posinf2 | neginf1 | neginf2
89  if skipMaskArr is not None:
90  valSkipMaskArr |= skipMaskArr
91  valMaskedArr1 = numpy.ma.array(imageArr1, copy=False, mask = valSkipMaskArr)
92  valMaskedArr2 = numpy.ma.array(imageArr2, copy=False, mask = valSkipMaskArr)
93  valFilledArr1 = valMaskedArr1.filled(0.0)
94  valFilledArr2 = valMaskedArr2.filled(0.0)
95 
96  if not numpy.allclose(valFilledArr1, valFilledArr2, rtol=rtol, atol=atol):
97  errArr = numpy.abs(valFilledArr1 - valFilledArr2)
98  maxErr = errArr.max()
99  maxPosInd = numpy.where(errArr==maxErr)
100  maxPosTuple = (maxPosInd[1][0], maxPosInd[0][0])
101  errStr = "maxDiff=%s at position %s; value=%s vs. %s" % \
102  (maxErr, maxPosTuple, valFilledArr1[maxPosInd][0], valFilledArr2[maxPosInd][0])
103  retStrs.insert(0, errStr)
104  return "; ".join(retStrs)
def lsst.afw.image.testUtils.makeGaussianNoiseMaskedImage (   dimensions,
  sigma,
  variance = 1.0 
)
Make a gaussian noise MaskedImageF

Inputs:
- dimensions: dimensions of output array (cols, rows)
- sigma; sigma of image plane's noise distribution
- variance: constant value for variance plane

Definition at line 30 of file testUtils.py.

30 
31 def makeGaussianNoiseMaskedImage(dimensions, sigma, variance=1.0):
32  """Make a gaussian noise MaskedImageF
33 
34  Inputs:
35  - dimensions: dimensions of output array (cols, rows)
36  - sigma; sigma of image plane's noise distribution
37  - variance: constant value for variance plane
38  """
39  npSize = (dimensions[1], dimensions[0])
40  image = numpy.random.normal(loc=0.0, scale=sigma, size=npSize).astype(numpy.float32)
41  mask = numpy.zeros(npSize, dtype=numpy.uint16)
42  variance = numpy.zeros(npSize, dtype=numpy.float32) + variance
43 
44  return afwImage.makeMaskedImageFromArrays(image, mask, variance)
def lsst.afw.image.testUtils.maskedImagesDiffer (   maskedImageArrSet1,
  maskedImageArrSet2,
  doImage = True,
  doMask = True,
  doVariance = True,
  skipMaskArr = None,
  rtol = 1.0e-05,
  atol = 1e-08 
)
Compare pixels from two masked images

Inputs:
- maskedImageArrSet1: first masked image to compare as (image, mask, variance) arrays
- maskedImageArrSet2: second masked image to compare as (image, mask, variance) arrays
- doImage: compare image planes if True
- doMask: compare mask planes if True
- doVariance: compare variance planes if True
- skipMaskArr: pixels to ingore on the image, mask and variance arrays; nonzero values are skipped
- rtol: relative tolerance (see below)
- atol: absolute tolerance (see below)

rtol and atol are positive, typically very small numbers.
The relative difference (rtol * abs(b)) and the absolute difference "atol" are added together
to compare against the absolute difference between "a" and "b".

Return a string describing the error if the images differ significantly, an empty string otherwise

Definition at line 136 of file testUtils.py.

137  doImage=True, doMask=True, doVariance=True, skipMaskArr=None, rtol=1.0e-05, atol=1e-08):
138  """Compare pixels from two masked images
139 
140  Inputs:
141  - maskedImageArrSet1: first masked image to compare as (image, mask, variance) arrays
142  - maskedImageArrSet2: second masked image to compare as (image, mask, variance) arrays
143  - doImage: compare image planes if True
144  - doMask: compare mask planes if True
145  - doVariance: compare variance planes if True
146  - skipMaskArr: pixels to ingore on the image, mask and variance arrays; nonzero values are skipped
147  - rtol: relative tolerance (see below)
148  - atol: absolute tolerance (see below)
149 
150  rtol and atol are positive, typically very small numbers.
151  The relative difference (rtol * abs(b)) and the absolute difference "atol" are added together
152  to compare against the absolute difference between "a" and "b".
153 
154  Return a string describing the error if the images differ significantly, an empty string otherwise
155  """
156  retStrs = []
157  for ind, (doPlane, planeName) in enumerate(((doImage, "image"),
158  (doMask, "mask"),
159  (doVariance, "variance"))):
160  if not doPlane:
161  continue
162 
163  if planeName == "mask":
164  errStr = masksDiffer(maskedImageArrSet1[ind], maskedImageArrSet2[ind], skipMaskArr=skipMaskArr)
165  if errStr:
166  retStrs.append(errStr)
167  else:
168  errStr = imagesDiffer(maskedImageArrSet1[ind], maskedImageArrSet2[ind],
169  skipMaskArr=skipMaskArr, rtol=rtol, atol=atol)
170  if errStr:
171  retStrs.append("%s planes differ: %s" % (planeName, errStr))
172  return " | ".join(retStrs)
def lsst.afw.image.testUtils.masksDiffer (   maskArr1,
  maskArr2,
  skipMaskArr = None 
)
Compare the pixels of two mask arrays; return True if they match, False otherwise

Inputs:
- mask1: first image to compare
- mask2: second image to compare
- skipMaskArr: pixels to ignore; nonzero values are skipped

Return a string describing the error if the images differ significantly, an empty string otherwise

Definition at line 105 of file testUtils.py.

106 def masksDiffer(maskArr1, maskArr2, skipMaskArr=None):
107  """Compare the pixels of two mask arrays; return True if they match, False otherwise
108 
109  Inputs:
110  - mask1: first image to compare
111  - mask2: second image to compare
112  - skipMaskArr: pixels to ignore; nonzero values are skipped
113 
114  Return a string describing the error if the images differ significantly, an empty string otherwise
115  """
116  retStr = ""
117  if skipMaskArr is not None:
118  maskedArr1 = numpy.ma.array(maskArr1, copy=False, mask = skipMaskArr)
119  maskedArr2 = numpy.ma.array(maskArr2, copy=False, mask = skipMaskArr)
120  filledArr1 = maskedArr1.filled(0.0)
121  filledArr2 = maskedArr2.filled(0.0)
122  else:
123  filledArr1 = maskArr1
124  filledArr2 = maskArr2
125 
126  if numpy.any(filledArr1 != filledArr2):
127  errArr = numpy.abs(filledArr1 - filledArr2)
128  maxErr = errArr.max()
129  maxPosInd = numpy.where(errArr==maxErr)
130  maxPosTuple = (maxPosInd[1][0], maxPosInd[0][0])
131  retStr = "maxDiff=%s at position %s; value=%s vs. %s" % \
132  (maxErr, maxPosTuple, filledArr1[maxPosInd][0], filledArr2[maxPosInd][0])
133  retStr = "masks differ"
134  return retStr