Coverage for tests/test_imageTestUtils.py: 23%

43 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-01 15:48 -0700

1import unittest 

2 

3import numpy as np 

4 

5import lsst.utils.tests 

6import lsst.geom 

7import lsst.afw.image as afwImage 

8from lsst.afw.image.testUtils import makeRampImage 

9 

10 

11class MakeRampImageTestCase(lsst.utils.tests.TestCase): 

12 """!Unit tests for makeRampImage""" 

13 

14 def testUnitInterval(self): 

15 """!Test small ramp images with unit interval for known values 

16 """ 

17 for imageClass in (afwImage.ImageU, afwImage.ImageF, afwImage.ImageD): 

18 dim = lsst.geom.Extent2I(7, 9) 

19 box = lsst.geom.Box2I(lsst.geom.Point2I(-1, 3), dim) 

20 numPix = dim[0]*dim[1] 

21 for start in (-5, 0, 4): 

22 if imageClass == afwImage.ImageU and start < 0: 

23 continue 

24 predStop = start + numPix - 1 # for integer steps 

25 for stop in (None, predStop): 

26 rampImage = makeRampImage( 

27 bbox=box, start=start, stop=predStop, imageClass=imageClass) 

28 predArr = np.arange(start, predStop+1) 

29 self.assertEqual(len(predArr), numPix) 

30 predArr.shape = (dim[1], dim[0]) 

31 self.assertImagesAlmostEqual(rampImage, predArr) 

32 

33 def testNonUnitIntervals(self): 

34 """!Test a small ramp image with non-integer increments 

35 """ 

36 for imageClass in (afwImage.ImageU, afwImage.ImageF, afwImage.ImageD): 

37 dim = lsst.geom.Extent2I(7, 9) 

38 box = lsst.geom.Box2I(lsst.geom.Point2I(-1, 3), dim) 

39 numPix = dim[0]*dim[1] 

40 for start in (-5.1, 0, 4.3): 

41 if imageClass == afwImage.ImageU and start < 0: 

42 continue 

43 for stop in (7, 1001.5, 5.4): 

44 rampImage = makeRampImage( 

45 bbox=box, start=start, stop=stop, imageClass=imageClass) 

46 dtype = rampImage.getArray().dtype 

47 predArr = np.linspace( 

48 start, stop, num=numPix, endpoint=True, dtype=dtype) 

49 predArr.shape = (dim[1], dim[0]) 

50 self.assertImagesAlmostEqual(rampImage, predArr) 

51 

52 

53class MemoryTester(lsst.utils.tests.MemoryTestCase): 

54 pass 

55 

56 

57def setup_module(module): 

58 lsst.utils.tests.init() 

59 

60 

61if __name__ == "__main__": 61 ↛ 62line 61 didn't jump to line 62, because the condition on line 61 was never true

62 lsst.utils.tests.init() 

63 unittest.main()