Coverage for tests/test_ccdImage.py: 34%

48 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-25 13:47 +0000

1# This file is part of jointcal. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

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

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

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

12# (at your option) any later version. 

13# 

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

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

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

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22"""Test creation and use of the CcdImage class.""" 

23import unittest 

24 

25import lsst.utils.tests 

26from lsst.jointcal import testUtils 

27 

28import lsst.geom 

29import lsst.jointcal 

30import lsst.obs.base 

31 

32 

33class CcdImageTestCase(lsst.utils.tests.TestCase): 

34 def setUp(self): 

35 self.nStars1 = 4 

36 self.nStars2 = 100 

37 struct = testUtils.createTwoFakeCcdImages(num1=self.nStars1, num2=self.nStars2) 

38 self.ccdImage1 = struct.ccdImageList[0] 

39 self.ccdImage2 = struct.ccdImageList[1] 

40 self.bbox = struct.bbox 

41 

42 self.associations = lsst.jointcal.Associations(struct.ccdImageList) 

43 

44 def checkCountStars(self, ccdImage, nStars): 

45 """Check that ccdImage.countStars() is correct under various conditions. 

46 

47 Parameters 

48 ---------- 

49 ccdImage : `lsst.jointcal.CcdImage` 

50 The ccdImage to test. 

51 nStars : `int` 

52 Number of stars in ccdImage's catalog. 

53 

54 Notes 

55 ----- 

56 Does not test the case where some ``measuredStars`` are not ``valid``, 

57 as there is no interface for modifying that the python level. To test 

58 that would require creating a `Fitter` and a fake outlier list and 

59 calling ``removeMeasOutliers`` and/or ``removeRefOutliers``, which 

60 cannot be easily made part of the python API. 

61 """ 

62 # By default there are no stars because catalogForFit is uninitialized. 

63 measStars, refStars = ccdImage.countStars() 

64 self.assertEqual(measStars, 0) 

65 self.assertEqual(refStars, 0) 

66 

67 # With no associations, the catalog should have exactly as many valid 

68 # measuredStars as were created. 

69 ccdImage.resetCatalogForFit() 

70 measStars, refStars = ccdImage.countStars() 

71 self.assertEqual(measStars, nStars) 

72 self.assertEqual(refStars, 0) 

73 

74 # Cross match catalogs: there will still be no refcat matches. 

75 matchCut = 3.0 * lsst.geom.arcseconds 

76 # There should be no fittedStars until we associate the catalogs. 

77 self.assertEqual(self.associations.fittedStarListSize(), 0) 

78 self.associations.computeCommonTangentPoint() 

79 self.associations.associateCatalogs(matchCut) 

80 # Confirm that every measuredStar (in both ccdImages) got a fittedStar associated to it. 

81 self.assertEqual(self.associations.fittedStarListSize(), self.nStars1 + self.nStars2) 

82 # measuredStars and refStars should be unchanged after association. 

83 self.assertEqual(measStars, nStars) 

84 self.assertEqual(refStars, 0) 

85 

86 # Make a fake reference catalog; will match the catalog one-to-one. 

87 skyWcs = ccdImage.getReadWcs().getSkyWcs() 

88 self.refCat = testUtils.createFakeCatalog(nStars, self.bbox, "refFlux", skyWcs=skyWcs, refCat=True) 

89 # associate the reference stars 

90 self.associations.collectRefStars(self.refCat, matchCut, 'refFlux_instFlux', 0.1) 

91 measStars, refStars = ccdImage.countStars() 

92 self.assertEqual(measStars, nStars) 

93 self.assertEqual(refStars, nStars) 

94 

95 def testCcdImage1(self): 

96 self.checkCountStars(self.ccdImage1, self.nStars1) 

97 

98 def testCcdImage2(self): 

99 self.checkCountStars(self.ccdImage2, self.nStars2) 

100 

101 

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

103 pass 

104 

105 

106def setup_module(module): 

107 lsst.utils.tests.init() 

108 

109 

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

111 lsst.utils.tests.init() 

112 unittest.main()