LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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 53 of file testUtils.py.

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

38 
39 def makeGaussianNoiseMaskedImage(dimensions, sigma, variance=1.0):
40  """Make a gaussian noise MaskedImageF
41 
42  Inputs:
43  - dimensions: dimensions of output array (cols, rows)
44  - sigma; sigma of image plane's noise distribution
45  - variance: constant value for variance plane
46  """
47  npSize = (dimensions[1], dimensions[0])
48  image = numpy.random.normal(loc=0.0, scale=sigma, size=npSize).astype(numpy.float32)
49  mask = numpy.zeros(npSize, dtype=numpy.uint16)
50  variance = numpy.zeros(npSize, dtype=numpy.float32) + variance
51 
52  return afwImage.makeMaskedImageFromArrays(image, mask, variance)
def makeMaskedImageFromArrays
Definition: __init__.py:45
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 144 of file testUtils.py.

145  doImage=True, doMask=True, doVariance=True, skipMaskArr=None, rtol=1.0e-05, atol=1e-08):
146  """Compare pixels from two masked images
147 
148  Inputs:
149  - maskedImageArrSet1: first masked image to compare as (image, mask, variance) arrays
150  - maskedImageArrSet2: second masked image to compare as (image, mask, variance) arrays
151  - doImage: compare image planes if True
152  - doMask: compare mask planes if True
153  - doVariance: compare variance planes if True
154  - skipMaskArr: pixels to ingore on the image, mask and variance arrays; nonzero values are skipped
155  - rtol: relative tolerance (see below)
156  - atol: absolute tolerance (see below)
157 
158  rtol and atol are positive, typically very small numbers.
159  The relative difference (rtol * abs(b)) and the absolute difference "atol" are added together
160  to compare against the absolute difference between "a" and "b".
161 
162  Return a string describing the error if the images differ significantly, an empty string otherwise
163  """
164  retStrs = []
165  for ind, (doPlane, planeName) in enumerate(((doImage, "image"),
166  (doMask, "mask"),
167  (doVariance, "variance"))):
168  if not doPlane:
169  continue
170 
171  if planeName == "mask":
172  errStr = masksDiffer(maskedImageArrSet1[ind], maskedImageArrSet2[ind], skipMaskArr=skipMaskArr)
173  if errStr:
174  retStrs.append(errStr)
175  else:
176  errStr = imagesDiffer(maskedImageArrSet1[ind], maskedImageArrSet2[ind],
177  skipMaskArr=skipMaskArr, rtol=rtol, atol=atol)
178  if errStr:
179  retStrs.append("%s planes differ: %s" % (planeName, errStr))
180  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 113 of file testUtils.py.

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