Coverage for tests/test_matchFits.py: 24%

65 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-09-20 02:20 -0700

1# 

2# LSST Data Management System 

3# Copyright 2012 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22 

23""" 

24Test for match persistence via FITS 

25""" 

26import unittest 

27 

28import lsst.utils.tests 

29import lsst.afw.table as afwTable 

30 

31Debug = False # set True to print some debugging information 

32 

33 

34class MatchFitsTestCase(unittest.TestCase): 

35 

36 def setUp(self): 

37 self.size = 10 

38 self.numMatches = self.size//2 

39 self.schema = afwTable.SimpleTable.makeMinimalSchema() 

40 self.cat1 = afwTable.SimpleCatalog(self.schema) 

41 self.cat2 = afwTable.SimpleCatalog(self.schema) 

42 for i in range(self.size): 

43 record1 = self.cat1.table.makeRecord() 

44 record2 = self.cat2.table.makeRecord() 

45 record1.setId(i + 1) 

46 record2.setId(self.size - i) 

47 self.cat1.append(record1) 

48 self.cat2.append(record2) 

49 

50 self.matches = [] 

51 for i in range(self.numMatches): 

52 index = 2*i 

53 match = afwTable.SimpleMatch( 

54 self.cat1[index], self.cat2[self.size - index - 1], index) 

55 if Debug: 

56 print("Inject:", match.first.getId(), match.second.getId()) 

57 self.matches.append(match) 

58 

59 def tearDown(self): 

60 del self.schema 

61 del self.cat1 

62 del self.cat2 

63 del self.matches 

64 

65 def testMatches(self, matches=None): 

66 if matches is None: 

67 matches = self.matches 

68 self.assertEqual(len(matches), self.numMatches) 

69 for m in matches: 

70 str(m) # Check __str__ works 

71 if Debug: 

72 print("Test:", m.first.getId(), m.second.getId()) 

73 self.assertEqual(m.first.getId(), m.second.getId()) 

74 

75 def testIO(self): 

76 packed = afwTable.packMatches(self.matches) 

77 with lsst.utils.tests.getTempFilePath(".fits") as filename: 

78 packed.writeFits(filename) 

79 matches = afwTable.BaseCatalog.readFits(filename) 

80 cat1 = self.cat1.copy() 

81 cat2 = self.cat2.copy() 

82 cat1.sort() 

83 cat2.sort() 

84 unpacked = afwTable.unpackMatches(matches, cat1, cat2) 

85 self.testMatches(unpacked) 

86 

87 def testTicket2080(self): 

88 packed = afwTable.packMatches(self.matches) 

89 cat1 = self.cat1.copy() 

90 cat2 = afwTable.SimpleCatalog(self.schema) 

91 cat1.sort() 

92 cat2.sort() 

93 # just test that the next line doesn't segv 

94 afwTable.unpackMatches(packed, cat1, cat2) 

95 

96 

97class TestMemory(lsst.utils.tests.MemoryTestCase): 

98 pass 

99 

100 

101def setup_module(module): 

102 lsst.utils.tests.init() 

103 

104 

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

106 lsst.utils.tests.init() 

107 unittest.main()