Coverage for tests/test_ticket2019.py: 29%

52 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-08-26 02:33 -0700

1 

2import unittest 

3 

4import lsst.utils.tests 

5import lsst.afw.detection as afwDet 

6import lsst.afw.image as afwImage 

7import lsst.afw.table as afwTable 

8import lsst.afw.geom as afwGeom 

9 

10 

11class SourceHeavyFootprintTestCase(unittest.TestCase): 

12 

13 def test1(self): 

14 im = afwImage.ImageF(100, 100) 

15 im += 42. 

16 spanSet = afwGeom.SpanSet.fromShape(10).shiftedBy(50, 50) 

17 fp = afwDet.Footprint(spanSet) 

18 mi = afwImage.MaskedImageF(im) 

19 # set a mask bit before grabbing the heavyfootprint 

20 mi.mask[50, 50, afwImage.LOCAL] = 1 

21 heavy = afwDet.makeHeavyFootprint(fp, mi) 

22 # reset it 

23 mi.mask[50, 50, afwImage.LOCAL] = 0 

24 

25 schema = afwTable.SourceTable.makeMinimalSchema() 

26 table = afwTable.SourceTable.make(schema) 

27 table.preallocate(10) 

28 catalog = afwTable.SourceCatalog(table) 

29 catalog.addNew() 

30 # This used to segfault 

31 catalog[0].setFootprint(heavy) 

32 

33 fp = catalog[0].getFootprint() 

34 # change one pixel... 

35 self.assertEqual(mi.image[50, 50, afwImage.LOCAL], 42) 

36 self.assertEqual(mi.mask[50, 50, afwImage.LOCAL], 0) 

37 mi.image[50, 50, afwImage.LOCAL] = 100 

38 mi.mask[50, 50, afwImage.LOCAL] = 2 

39 mi.mask[51, 50, afwImage.LOCAL] = 2 

40 self.assertEqual(mi.image[50, 50, afwImage.LOCAL], 100) 

41 self.assertEqual(mi.mask[50, 50, afwImage.LOCAL], 2) 

42 self.assertEqual(mi.mask[51, 50, afwImage.LOCAL], 2) 

43 # reinsert the heavy footprint; it should reset the pixel value. 

44 # insert(MaskedImage) 

45 fp.insert(mi) 

46 self.assertEqual(mi.image[50, 50, afwImage.LOCAL], 42) 

47 self.assertEqual(mi.mask[50, 50, afwImage.LOCAL], 1) 

48 self.assertEqual(mi.mask[51, 50, afwImage.LOCAL], 0) 

49 

50 # Also test insert(Image) 

51 im = mi.image 

52 self.assertEqual(im[50, 50, afwImage.LOCAL], 42) 

53 im[50, 50, afwImage.LOCAL] = 100 

54 self.assertEqual(im[50, 50, afwImage.LOCAL], 100) 

55 self.assertEqual(mi.image[50, 50, afwImage.LOCAL], 100) 

56 # reinsert the heavy footprint; it should reset the pixel value. 

57 fp.insert(im) 

58 self.assertEqual(im[50, 50, afwImage.LOCAL], 42) 

59 self.assertEqual(mi.image[50, 50, afwImage.LOCAL], 42) 

60 self.assertEqual(mi.mask[50, 50, afwImage.LOCAL], 1) 

61 self.assertEqual(mi.mask[51, 50, afwImage.LOCAL], 0) 

62 

63 

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

65 pass 

66 

67 

68def setup_module(module): 

69 lsst.utils.tests.init() 

70 

71 

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

73 lsst.utils.tests.init() 

74 unittest.main()