LSST Applications g02d81e74bb+86cf3d8bc9,g180d380827+7a4e862ed4,g2079a07aa2+86d27d4dc4,g2305ad1205+e1ca1c66fa,g29320951ab+012e1474a1,g295015adf3+341ea1ce94,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+c429d67c83,g48712c4677+f88676dd22,g487adcacf7+27e1e21933,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+b41db86c35,g5a732f18d5+53520f316c,g64a986408d+86cf3d8bc9,g858d7b2824+86cf3d8bc9,g8a8a8dda67+585e252eca,g99cad8db69+84912a7fdc,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+a2b54eae19,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+6681f309db,gc120e1dc64+f0fcc2f6d8,gc28159a63d+0e5473021a,gcf0d15dbbd+c429d67c83,gdaeeff99f8+f9a426f77a,ge6526c86ff+0433e6603d,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+86cf3d8bc9,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
Functions
lsst.afw.image.testUtils Namespace Reference

Functions

 makeGaussianNoiseMaskedImage (dimensions, sigma, variance=1.0)
 
 makeRampImage (bbox, start=0, stop=None, imageClass=ImageF)
 Make an image whose values are a linear ramp.
 
 assertImagesAlmostEqual (testCase, image0, image1, skipMask=None, rtol=1.0e-05, atol=1e-08, msg="Images differ")
 Assert that two images are almost equal, including non-finite values.
 
 assertImagesEqual (*args, **kwds)
 Assert that two images are exactly equal, including non-finite values.
 
 assertMasksEqual (testCase, mask0, mask1, skipMask=None, msg="Masks differ")
 Assert that two masks are equal.
 
 assertMaskedImagesAlmostEqual (testCase, maskedImage0, maskedImage1, doImage=True, doMask=True, doVariance=True, skipMask=None, rtol=1.0e-05, atol=1e-08, msg="Masked images differ")
 Assert that two masked images are nearly equal, including non-finite values.
 
 assertMaskedImagesEqual (*args, **kwds)
 Assert that two masked images are exactly equal, including non-finite values.
 
 imagesDiffer (image0, image1, skipMask=None, rtol=1.0e-05, atol=1e-08)
 Compare the pixels of two image or mask arrays; return True if close, False otherwise.
 

Function Documentation

◆ assertImagesAlmostEqual()

lsst.afw.image.testUtils.assertImagesAlmostEqual ( testCase,
image0,
image1,
skipMask = None,
rtol = 1.0e-05,
atol = 1e-08,
msg = "Images differ" )

Assert that two images are almost equal, including non-finite values.

Parameters
[in]testCaseunittest.TestCase instance the test is part of; an object supporting one method: fail(self, msgStr)
[in]image0image 0, an lsst.afw.image.Image, lsst.afw.image.Mask, or transposed numpy array (see warning)
[in]image1image 1, an lsst.afw.image.Image, lsst.afw.image.Mask, or transposed numpy array (see warning)
[in]skipMaskmask of pixels to skip, or None to compare all pixels; an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning); all non-zero pixels are skipped
[in]rtolmaximum allowed relative tolerance; more info below
[in]atolmaximum allowed absolute tolerance; more info below
[in]msgexception message prefix; details of the error are appended after ": "

The images are nearly equal if all pixels obey: |val1 - val0| <= rtol*|val1| + atol or, for float types, if nan/inf/-inf pixels match.

Warning
the comparison equation is not symmetric, so in rare cases the assertion may give different results depending on which image comes first.
the axes of numpy arrays are transposed with respect to Image and Mask data. Thus for example if image0 and image1 are both lsst.afw.image.ImageD with dimensions (2, 3) and skipMask is a numpy array, then skipMask must have shape (3, 2).
Exceptions
self.failureException(usually AssertionError) if any of the following are true for un-skipped pixels:
  • non-finite values differ in any way (e.g. one is "nan" and another is not)
  • finite values differ by too much, as defined by atol and rtol
TypeErrorif the dimensions of image0, image1 and skipMask do not match, or any are not of a numeric data type.

Definition at line 74 of file testUtils.py.

75 rtol=1.0e-05, atol=1e-08, msg="Images differ"):
76 """!Assert that two images are almost equal, including non-finite values
77
78 @param[in] testCase unittest.TestCase instance the test is part of;
79 an object supporting one method: fail(self, msgStr)
80 @param[in] image0 image 0, an lsst.afw.image.Image, lsst.afw.image.Mask,
81 or transposed numpy array (see warning)
82 @param[in] image1 image 1, an lsst.afw.image.Image, lsst.afw.image.Mask,
83 or transposed numpy array (see warning)
84 @param[in] skipMask mask of pixels to skip, or None to compare all pixels;
85 an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning);
86 all non-zero pixels are skipped
87 @param[in] rtol maximum allowed relative tolerance; more info below
88 @param[in] atol maximum allowed absolute tolerance; more info below
89 @param[in] msg exception message prefix; details of the error are appended after ": "
90
91 The images are nearly equal if all pixels obey:
92 |val1 - val0| <= rtol*|val1| + atol
93 or, for float types, if nan/inf/-inf pixels match.
94
95 @warning the comparison equation is not symmetric, so in rare cases the assertion
96 may give different results depending on which image comes first.
97
98 @warning the axes of numpy arrays are transposed with respect to Image and Mask data.
99 Thus for example if image0 and image1 are both lsst.afw.image.ImageD with dimensions (2, 3)
100 and skipMask is a numpy array, then skipMask must have shape (3, 2).
101
102 @throw self.failureException (usually AssertionError) if any of the following are true
103 for un-skipped pixels:
104 - non-finite values differ in any way (e.g. one is "nan" and another is not)
105 - finite values differ by too much, as defined by atol and rtol
106
107 @throw TypeError if the dimensions of image0, image1 and skipMask do not match,
108 or any are not of a numeric data type.
109 """
110 errStr = imagesDiffer(
111 image0, image1, skipMask=skipMask, rtol=rtol, atol=atol)
112 if errStr:
113 testCase.fail(f"{msg}: {errStr}")
114
115
116@lsst.utils.tests.inTestCase

◆ assertImagesEqual()

lsst.afw.image.testUtils.assertImagesEqual ( * args,
** kwds )

Assert that two images are exactly equal, including non-finite values.

All arguments are forwarded to assertAnglesAlmostEqual aside from atol and rtol, which are set to zero.

Definition at line 117 of file testUtils.py.

117def assertImagesEqual(*args, **kwds):
118 """!Assert that two images are exactly equal, including non-finite values.
119
120 All arguments are forwarded to assertAnglesAlmostEqual aside from atol and rtol,
121 which are set to zero.
122 """
123 return assertImagesAlmostEqual(*args, atol=0, rtol=0, **kwds)
124
125
126@lsst.utils.tests.inTestCase

◆ assertMaskedImagesAlmostEqual()

lsst.afw.image.testUtils.assertMaskedImagesAlmostEqual ( testCase,
maskedImage0,
maskedImage1,
doImage = True,
doMask = True,
doVariance = True,
skipMask = None,
rtol = 1.0e-05,
atol = 1e-08,
msg = "Masked images differ" )

Assert that two masked images are nearly equal, including non-finite values.

Parameters
[in]testCaseunittest.TestCase instance the test is part of; an object supporting one method: fail(self, msgStr)
[in]maskedImage0masked image 0 (an lsst.afw.image.MaskedImage or collection of three transposed numpy arrays: image, mask, variance)
[in]maskedImage1masked image 1 (an lsst.afw.image.MaskedImage or collection of three transposed numpy arrays: image, mask, variance)
[in]doImagecompare image planes if True
[in]doMaskcompare mask planes if True
[in]doVariancecompare variance planes if True
[in]skipMaskmask of pixels to skip, or None to compare all pixels; an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array; all non-zero pixels are skipped
[in]rtolmaximum allowed relative tolerance; more info below
[in]atolmaximum allowed absolute tolerance; more info below
[in]msgexception message prefix; details of the error are appended after ": "

The mask planes must match exactly. The image and variance planes are nearly equal if all pixels obey: |val1 - val0| <= rtol*|val1| + atol or, for float types, if nan/inf/-inf pixels match.

Warning
the comparison equation is not symmetric, so in rare cases the assertion may give different results depending on which masked image comes first.
the axes of numpy arrays are transposed with respect to MaskedImage data. Thus for example if maskedImage0 and maskedImage1 are both lsst.afw.image.MaskedImageD with dimensions (2, 3) and skipMask is a numpy array, then skipMask must have shape (3, 2).
Exceptions
self.failureException(usually AssertionError) if any of the following are true for un-skipped pixels:
  • non-finite image or variance values differ in any way (e.g. one is "nan" and another is not)
  • finite values differ by too much, as defined by atol and rtol
  • mask pixels differ at all
TypeErrorif the dimensions of maskedImage0, maskedImage1 and skipMask do not match, either image or variance plane is not of a numeric data type, either mask plane is not of an integer type (unsigned or signed), or skipMask is not of a numeric data type.

Definition at line 156 of file testUtils.py.

160):
161 """!Assert that two masked images are nearly equal, including non-finite values
162
163 @param[in] testCase unittest.TestCase instance the test is part of;
164 an object supporting one method: fail(self, msgStr)
165 @param[in] maskedImage0 masked image 0 (an lsst.afw.image.MaskedImage or
166 collection of three transposed numpy arrays: image, mask, variance)
167 @param[in] maskedImage1 masked image 1 (an lsst.afw.image.MaskedImage or
168 collection of three transposed numpy arrays: image, mask, variance)
169 @param[in] doImage compare image planes if True
170 @param[in] doMask compare mask planes if True
171 @param[in] doVariance compare variance planes if True
172 @param[in] skipMask mask of pixels to skip, or None to compare all pixels;
173 an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array;
174 all non-zero pixels are skipped
175 @param[in] rtol maximum allowed relative tolerance; more info below
176 @param[in] atol maximum allowed absolute tolerance; more info below
177 @param[in] msg exception message prefix; details of the error are appended after ": "
178
179 The mask planes must match exactly. The image and variance planes are nearly equal if all pixels obey:
180 |val1 - val0| <= rtol*|val1| + atol
181 or, for float types, if nan/inf/-inf pixels match.
182
183 @warning the comparison equation is not symmetric, so in rare cases the assertion
184 may give different results depending on which masked image comes first.
185
186 @warning the axes of numpy arrays are transposed with respect to MaskedImage data.
187 Thus for example if maskedImage0 and maskedImage1 are both lsst.afw.image.MaskedImageD
188 with dimensions (2, 3) and skipMask is a numpy array, then skipMask must have shape (3, 2).
189
190 @throw self.failureException (usually AssertionError) if any of the following are true
191 for un-skipped pixels:
192 - non-finite image or variance values differ in any way (e.g. one is "nan" and another is not)
193 - finite values differ by too much, as defined by atol and rtol
194 - mask pixels differ at all
195
196 @throw TypeError if the dimensions of maskedImage0, maskedImage1 and skipMask do not match,
197 either image or variance plane is not of a numeric data type,
198 either mask plane is not of an integer type (unsigned or signed),
199 or skipMask is not of a numeric data type.
200 """
201 if hasattr(maskedImage0, "image"):
202 maskedImageArrList0 = (maskedImage0.image.array,
203 maskedImage0.mask.array,
204 maskedImage0.variance.array)
205 else:
206 maskedImageArrList0 = maskedImage0
207 if hasattr(maskedImage1, "image"):
208 maskedImageArrList1 = (maskedImage1.image.array,
209 maskedImage1.mask.array,
210 maskedImage1.variance.array)
211 else:
212 maskedImageArrList1 = maskedImage1
213
214 for arrList, arg, name in (
215 (maskedImageArrList0, maskedImage0, "maskedImage0"),
216 (maskedImageArrList1, maskedImage1, "maskedImage1"),
217 ):
218 try:
219 assert len(arrList) == 3
220 # check that array shapes are all identical
221 # check that image and variance are float or int of some kind
222 # and mask is int of some kind
223 for i in (0, 2):
224 assert arrList[i].shape == arrList[1].shape
225 assert arrList[i].dtype.kind in ("b", "i", "u", "f", "c")
226 assert arrList[1].dtype.kind in ("b", "i", "u")
227 except Exception:
228 raise TypeError(f"{name}={arg!r} is not a supported type")
229
230 errStrList = []
231 for ind, (doPlane, planeName) in enumerate(((doImage, "image"),
232 (doMask, "mask"),
233 (doVariance, "variance"))):
234 if not doPlane:
235 continue
236
237 if planeName == "mask":
238 errStr = imagesDiffer(maskedImageArrList0[ind], maskedImageArrList1[ind], skipMask=skipMask,
239 rtol=0, atol=0)
240 if errStr:
241 errStrList.append(errStr)
242 else:
243 errStr = imagesDiffer(maskedImageArrList0[ind], maskedImageArrList1[ind],
244 skipMask=skipMask, rtol=rtol, atol=atol)
245 if errStr:
246 errStrList.append(f"{planeName} planes differ: {errStr}")
247
248 if errStrList:
249 errStr = "; ".join(errStrList)
250 testCase.fail(f"{msg}: {errStr}")
251
252
253@lsst.utils.tests.inTestCase

◆ assertMaskedImagesEqual()

lsst.afw.image.testUtils.assertMaskedImagesEqual ( * args,
** kwds )

Assert that two masked images are exactly equal, including non-finite values.

All arguments are forwarded to assertMaskedImagesAlmostEqual aside from atol and rtol, which are set to zero.

Definition at line 254 of file testUtils.py.

254def assertMaskedImagesEqual(*args, **kwds):
255 """!Assert that two masked images are exactly equal, including non-finite values.
256
257 All arguments are forwarded to assertMaskedImagesAlmostEqual aside from atol and rtol,
258 which are set to zero.
259 """
260 return assertMaskedImagesAlmostEqual(*args, atol=0, rtol=0, **kwds)
261
262

◆ assertMasksEqual()

lsst.afw.image.testUtils.assertMasksEqual ( testCase,
mask0,
mask1,
skipMask = None,
msg = "Masks differ" )

Assert that two masks are equal.

Parameters
[in]testCaseunittest.TestCase instance the test is part of; an object supporting one method: fail(self, msgStr)
[in]mask0mask 0, an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning)
[in]mask1mask 1, an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning)
[in]skipMaskmask of pixels to skip, or None to compare all pixels; an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning); all non-zero pixels are skipped
[in]msgexception message prefix; details of the error are appended after ": "
Warning
the axes of numpy arrays are transposed with respect to Mask and Image. Thus for example if mask0 and mask1 are both lsst.afw.image.Mask with dimensions (2, 3) and skipMask is a numpy array, then skipMask must have shape (3, 2).
Exceptions
self.failureException(usually AssertionError) if any any un-skipped pixels differ
TypeErrorif the dimensions of mask0, mask1 and skipMask do not match, or any are not of a numeric data type.

Definition at line 127 of file testUtils.py.

127def assertMasksEqual(testCase, mask0, mask1, skipMask=None, msg="Masks differ"):
128 """!Assert that two masks are equal
129
130 @param[in] testCase unittest.TestCase instance the test is part of;
131 an object supporting one method: fail(self, msgStr)
132 @param[in] mask0 mask 0, an lsst.afw.image.Mask, lsst.afw.image.Image,
133 or transposed numpy array (see warning)
134 @param[in] mask1 mask 1, an lsst.afw.image.Mask, lsst.afw.image.Image,
135 or transposed numpy array (see warning)
136 @param[in] skipMask mask of pixels to skip, or None to compare all pixels;
137 an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning);
138 all non-zero pixels are skipped
139 @param[in] msg exception message prefix; details of the error are appended after ": "
140
141 @warning the axes of numpy arrays are transposed with respect to Mask and Image.
142 Thus for example if mask0 and mask1 are both lsst.afw.image.Mask with dimensions (2, 3)
143 and skipMask is a numpy array, then skipMask must have shape (3, 2).
144
145 @throw self.failureException (usually AssertionError) if any any un-skipped pixels differ
146
147 @throw TypeError if the dimensions of mask0, mask1 and skipMask do not match,
148 or any are not of a numeric data type.
149 """
150 errStr = imagesDiffer(mask0, mask1, skipMask=skipMask, rtol=0, atol=0)
151 if errStr:
152 testCase.fail(f"{msg}: {errStr}")
153
154
155@lsst.utils.tests.inTestCase

◆ imagesDiffer()

lsst.afw.image.testUtils.imagesDiffer ( image0,
image1,
skipMask = None,
rtol = 1.0e-05,
atol = 1e-08 )

Compare the pixels of two image or mask arrays; return True if close, False otherwise.

Parameters
[in]image0image 0, an lsst.afw.image.Image, lsst.afw.image.Mask, or transposed numpy array (see warning)
[in]image1image 1, an lsst.afw.image.Image, lsst.afw.image.Mask, or transposed numpy array (see warning)
[in]skipMaskmask of pixels to skip, or None to compare all pixels; an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning); all non-zero pixels are skipped
[in]rtolmaximum allowed relative tolerance; more info below
[in]atolmaximum allowed absolute tolerance; more info below

The images are nearly equal if all pixels obey: |val1 - val0| <= rtol*|val1| + atol or, for float types, if nan/inf/-inf pixels match.

Warning
the comparison equation is not symmetric, so in rare cases the assertion may give different results depending on which image comes first.
the axes of numpy arrays are transposed with respect to Image and Mask data. Thus for example if image0 and image1 are both lsst.afw.image.ImageD with dimensions (2, 3) and skipMask is a numpy array, then skipMask must have shape (3, 2).
Returns
a string which is non-empty if the images differ
Exceptions
TypeErrorif the dimensions of image0, image1 and skipMask do not match, or any are not of a numeric data type.

Definition at line 263 of file testUtils.py.

263def imagesDiffer(image0, image1, skipMask=None, rtol=1.0e-05, atol=1e-08):
264 """!Compare the pixels of two image or mask arrays; return True if close, False otherwise
265
266 @param[in] image0 image 0, an lsst.afw.image.Image, lsst.afw.image.Mask,
267 or transposed numpy array (see warning)
268 @param[in] image1 image 1, an lsst.afw.image.Image, lsst.afw.image.Mask,
269 or transposed numpy array (see warning)
270 @param[in] skipMask mask of pixels to skip, or None to compare all pixels;
271 an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning);
272 all non-zero pixels are skipped
273 @param[in] rtol maximum allowed relative tolerance; more info below
274 @param[in] atol maximum allowed absolute tolerance; more info below
275
276 The images are nearly equal if all pixels obey:
277 |val1 - val0| <= rtol*|val1| + atol
278 or, for float types, if nan/inf/-inf pixels match.
279
280 @warning the comparison equation is not symmetric, so in rare cases the assertion
281 may give different results depending on which image comes first.
282
283 @warning the axes of numpy arrays are transposed with respect to Image and Mask data.
284 Thus for example if image0 and image1 are both lsst.afw.image.ImageD with dimensions (2, 3)
285 and skipMask is a numpy array, then skipMask must have shape (3, 2).
286
287 @return a string which is non-empty if the images differ
288
289 @throw TypeError if the dimensions of image0, image1 and skipMask do not match,
290 or any are not of a numeric data type.
291 """
292 errStrList = []
293 imageArr0 = image0.getArray() if hasattr(image0, "getArray") else image0
294 imageArr1 = image1.getArray() if hasattr(image1, "getArray") else image1
295 skipMaskArr = skipMask.getArray() if hasattr(skipMask, "getArray") else skipMask
296
297 # check the inputs
298 arrArgNameList = [
299 (imageArr0, image0, "image0"),
300 (imageArr1, image1, "image1"),
301 ]
302 if skipMask is not None:
303 arrArgNameList.append((skipMaskArr, skipMask, "skipMask"))
304 for i, (arr, arg, name) in enumerate(arrArgNameList):
305 try:
306 assert arr.dtype.kind in ("b", "i", "u", "f", "c")
307 except Exception:
308 raise TypeError(f"{name!r}={arg!r} is not a supported type")
309 if i != 0:
310 if arr.shape != imageArr0.shape:
311 raise TypeError(f"{name} shape = {arr.shape} != {imageArr0.shape} = image0 shape")
312
313 # np.allclose mis-handled unsigned ints in numpy 1.8
314 # and subtraction doesn't give the desired answer in any case
315 # so cast unsigned arrays into int64 (there may be a simple
316 # way to safely use a smaller data type but I've not found it)
317 if imageArr0.dtype.kind == "u":
318 imageArr0 = imageArr0.astype(
319 np.promote_types(imageArr0.dtype, np.int8))
320 if imageArr1.dtype.kind == "u":
321 imageArr1 = imageArr1.astype(
322 np.promote_types(imageArr1.dtype, np.int8))
323
324 if skipMaskArr is not None:
325 skipMaskArr = np.array(skipMaskArr, dtype=bool)
326 maskedArr0 = np.ma.array(imageArr0, copy=False, mask=skipMaskArr)
327 maskedArr1 = np.ma.array(imageArr1, copy=False, mask=skipMaskArr)
328 filledArr0 = maskedArr0.filled(0.0)
329 filledArr1 = maskedArr1.filled(0.0)
330 else:
331 skipMaskArr = None
332 filledArr0 = imageArr0
333 filledArr1 = imageArr1
334
335 try:
336 np.array([np.nan], dtype=imageArr0.dtype)
337 np.array([np.nan], dtype=imageArr1.dtype)
338 except Exception:
339 # one or both images does not support non-finite values (nan, etc.)
340 # so just use value comparison
341 valSkipMaskArr = skipMaskArr
342 else:
343 # both images support non-finite values, of which numpy has exactly three: nan, +inf and -inf;
344 # compare those individually in order to give useful diagnostic output
345 nan0 = np.isnan(filledArr0)
346 nan1 = np.isnan(filledArr1)
347 if np.any(nan0 != nan1):
348 errStrList.append("NaNs differ")
349
350 posinf0 = np.isposinf(filledArr0)
351 posinf1 = np.isposinf(filledArr1)
352 if np.any(posinf0 != posinf1):
353 errStrList.append("+infs differ")
354
355 neginf0 = np.isneginf(filledArr0)
356 neginf1 = np.isneginf(filledArr1)
357 if np.any(neginf0 != neginf1):
358 errStrList.append("-infs differ")
359
360 valSkipMaskArr = nan0 | nan1 | posinf0 | posinf1 | neginf0 | neginf1
361 if skipMaskArr is not None:
362 valSkipMaskArr |= skipMaskArr
363
364 # compare values that should be comparable (are finite and not masked)
365 valMaskedArr1 = np.ma.array(imageArr0, copy=False, mask=valSkipMaskArr)
366 valMaskedArr2 = np.ma.array(imageArr1, copy=False, mask=valSkipMaskArr)
367 valFilledArr1 = valMaskedArr1.filled(0.0)
368 valFilledArr2 = valMaskedArr2.filled(0.0)
369
370 if not np.allclose(valFilledArr1, valFilledArr2, rtol=rtol, atol=atol):
371 errArr = np.abs(valFilledArr1 - valFilledArr2)
372 maxErr = errArr.max()
373 maxPosInd = np.where(errArr == maxErr)
374 maxPosTuple = (maxPosInd[1][0], maxPosInd[0][0])
375 errStr = f"maxDiff={maxErr} at position {maxPosTuple}; " \
376 f"value={valFilledArr1[maxPosInd][0]} vs. {valFilledArr2[maxPosInd][0]}"
377 errStrList.insert(0, errStr)
378
379 return "; ".join(errStrList)

◆ makeGaussianNoiseMaskedImage()

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 34 of file testUtils.py.

34def makeGaussianNoiseMaskedImage(dimensions, sigma, variance=1.0):
35 """Make a gaussian noise MaskedImageF
36
37 Inputs:
38 - dimensions: dimensions of output array (cols, rows)
39 - sigma; sigma of image plane's noise distribution
40 - variance: constant value for variance plane
41 """
42 npSize = (dimensions[1], dimensions[0])
43 image = np.random.normal(loc=0.0, scale=sigma,
44 size=npSize).astype(np.float32)
45 mask = np.zeros(npSize, dtype=np.int32)
46 variance = np.zeros(npSize, dtype=np.float32) + variance
47
48 return makeMaskedImageFromArrays(image, mask, variance)
49
50

◆ makeRampImage()

lsst.afw.image.testUtils.makeRampImage ( bbox,
start = 0,
stop = None,
imageClass = ImageF )

Make an image whose values are a linear ramp.

Parameters
[in]bboxbounding box of image (an lsst.geom.Box2I)
[in]startstarting ramp value, inclusive
[in]stopending ramp value, inclusive; if None, increase by integer values
[in]imageClasstype of image (e.g. lsst.afw.image.ImageF)

Definition at line 51 of file testUtils.py.

51def makeRampImage(bbox, start=0, stop=None, imageClass=ImageF):
52 """!Make an image whose values are a linear ramp
53
54 @param[in] bbox bounding box of image (an lsst.geom.Box2I)
55 @param[in] start starting ramp value, inclusive
56 @param[in] stop ending ramp value, inclusive; if None, increase by integer values
57 @param[in] imageClass type of image (e.g. lsst.afw.image.ImageF)
58 """
59 im = imageClass(bbox)
60 imDim = im.getDimensions()
61 numPix = imDim[0]*imDim[1]
62 imArr = im.getArray()
63 if stop is None:
64 # increase by integer values
65 stop = start + numPix - 1
66 rampArr = np.linspace(start=start, stop=stop,
67 endpoint=True, num=numPix, dtype=imArr.dtype)
68 # numpy arrays are transposed w.r.t. afwImage
69 imArr[:] = np.reshape(rampArr, (imDim[1], imDim[0]))
70 return im
71
72
73@lsst.utils.tests.inTestCase