Coverage for tests/test_computeHolePositions.py: 24%

53 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-09 03:09 -0700

1# This file is part of cbp. 

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 

22import unittest 

23 

24from lsst.geom import degrees 

25from lsst.cbp import computeHolePositions, MaskInfo 

26import lsst.utils.tests 

27from lsst.cbp.testUtils import SampleCoordinateConverter 

28 

29 

30class ComputeHolePositionsTestCase(lsst.utils.tests.TestCase): 

31 

32 def setUp(self): 

33 self.scc = SampleCoordinateConverter() 

34 self.cco = self.scc.coordinateConverter 

35 # point the telescope and CBP right at each other 

36 self.cco.setFocalPlanePos(pupilPos=(0, 0)) 

37 

38 def tearDown(self): 

39 del self.scc 

40 del self.cco 

41 

42 def testSetup(self): 

43 self.assertAnglesAlmostEqual(self.cco.telAzAltInternal.separation(self.cco.cbpAzAltInternal), 

44 180*degrees) 

45 self.assertAnglesAlmostEqual(self.cco.telRotInternal, 0*degrees) 

46 

47 def testOneDetector(self): 

48 detectorPositions = ((100, 250), (250, 100), (500, 1500)) 

49 for detector in self.cco.cameraGeom: 

50 detectorName = detector.getName() 

51 holePositions = computeHolePositions( 

52 detectorNames=[detectorName], 

53 detectorPositions=detectorPositions, 

54 cameraGeom=self.cco.cameraGeom, 

55 cbpFlipX=self.cco.config.cbpFlipX, 

56 cbpFocalLength=self.cco.config.cbpFocalLength, 

57 ) 

58 self.assertEqual(len(holePositions), len(detectorPositions)) 

59 self.cco.maskInfo = MaskInfo( 

60 name="OneDetector", 

61 holePositions=holePositions, 

62 defaultHole=0, 

63 ) 

64 self.assertEqual(len(self.cco), len(detectorPositions)) 

65 for i, beamInfo in enumerate(self.cco): 

66 self.assertTrue(beamInfo.isOnDetector) 

67 self.assertEqual(beamInfo.detectorName, detectorName) 

68 self.assertPairsAlmostEqual(beamInfo.detectorPos, detectorPositions[i]) 

69 

70 def testOneHoleAllDetectors(self): 

71 detectorPosition = (449.2, 732.1) 

72 detectorNames = set(self.cco.cameraGeom.getNameIter()) 

73 numDetectors = len(self.cco.cameraGeom) 

74 flippedHolePositions = None # garbage value; compute correct value the first time through the loop 

75 for cbpFlipX in (False, True): 

76 # Note: test False first so flippedHolePositions 

77 # can be computed before it is needed. 

78 self.cco.config.cbpFlipX = cbpFlipX 

79 holePositions = computeHolePositions( 

80 detectorNames=None, 

81 detectorPositions=[detectorPosition], 

82 cameraGeom=self.cco.cameraGeom, 

83 cbpFlipX=self.cco.config.cbpFlipX, 

84 cbpFocalLength=self.cco.config.cbpFocalLength, 

85 ) 

86 if not cbpFlipX: 

87 # hopePositions are not flipped; compute flipped hole positions 

88 # so they can be compared to holePositions 

89 # when cbpFlipX is True. 

90 flippedHolePositions = [(-val[0], val[1]) for val in holePositions] 

91 else: 

92 self.assertPairListsAlmostEqual(holePositions, flippedHolePositions) 

93 self.assertEqual(len(holePositions), numDetectors) 

94 self.cco.maskInfo = MaskInfo( 

95 name="AllDetectors", 

96 holePositions=holePositions, 

97 defaultHole=0, 

98 ) 

99 self.assertEqual(len(self.cco), numDetectors) 

100 for beamInfo in self.cco: 

101 self.assertTrue(beamInfo.isOnDetector) 

102 self.assertIn(beamInfo.detectorName, detectorNames) 

103 self.assertPairsAlmostEqual(beamInfo.detectorPos, detectorPosition) 

104 

105 

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

107 pass 

108 

109 

110def setup_module(module): 

111 lsst.utils.tests.init() 

112 

113 

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

115 lsst.utils.tests.init() 

116 unittest.main()