Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

 

import unittest 

 

import lsst.utils.tests 

import lsst.afw.detection as afwDet 

import lsst.afw.image as afwImage 

import lsst.afw.table as afwTable 

import lsst.afw.geom as afwGeom 

 

 

class SourceHeavyFootprintTestCase(unittest.TestCase): 

 

def test1(self): 

im = afwImage.ImageF(100, 100) 

im += 42. 

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

fp = afwDet.Footprint(spanSet) 

mi = afwImage.MaskedImageF(im) 

# set a mask bit before grabbing the heavyfootprint 

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

heavy = afwDet.makeHeavyFootprint(fp, mi) 

# reset it 

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

 

schema = afwTable.SourceTable.makeMinimalSchema() 

table = afwTable.SourceTable.make(schema) 

table.preallocate(10) 

catalog = afwTable.SourceCatalog(table) 

catalog.addNew() 

# This used to segfault 

catalog[0].setFootprint(heavy) 

 

fp = catalog[0].getFootprint() 

# change one pixel... 

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

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

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

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

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

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

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

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

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

# insert(MaskedImage) 

fp.insert(mi) 

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

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

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

 

# Also test insert(Image) 

im = mi.image 

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

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

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

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

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

fp.insert(im) 

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

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

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

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

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()