Coverage for tests/test_ds9.py: 45%

77 statements  

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

1# This file is part of afw. 

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""" 

23Tests for the legacy display code in ds9.py (iff lsst.display.ds9 is setup) 

24 

25Run with: 

26 python test_ds9.py 

27or 

28 pytest test_ds9.py 

29""" 

30import unittest 

31 

32import lsst.utils.tests 

33import lsst.afw.image as afwImage 

34try: 

35 import lsst.afw.display.ds9 as ds9 

36except Exception: 

37 ds9 = None 

38 

39FRAME_NUM = 731 # largish, arbitrary number, unlikely to be in use by a user 

40 

41if ds9: 41 ↛ 49line 41 didn't jump to line 49, because the condition on line 41 was never false

42 try: 

43 ds9.mtv(afwImage.ImageF(1, 1), frame=FRAME_NUM) 

44 except Exception as e: 

45 print(f"Unable to use ds9: {e}") 

46 ds9 = None 

47 

48 

49class DisplayTestCase(unittest.TestCase): 

50 """A test case for Display""" 

51 

52 def setUp(self): 

53 pass 

54 

55 def tearDown(self): 

56 pass 

57 

58 @unittest.skipUnless(ds9, "You must setup display.ds9 to run this test") 

59 def testMtv(self): 

60 """Test basic image display""" 

61 exp = afwImage.ImageF(10, 20) 

62 ds9.mtv(exp, title="parent", frame=FRAME_NUM) 

63 

64 @unittest.skipUnless(ds9, "You must setup display.ds9 to run this test") 

65 def testMaskPlanes(self): 

66 """Test basic image display""" 

67 ds9.setMaskTransparency(50) 

68 ds9.setMaskPlaneColor("CROSSTALK", "orange") 

69 

70 @unittest.skipUnless(ds9, "You must setup display.ds9 to run this test") 

71 def testTwoDisplays(self): 

72 """Test that we can do things with two frames""" 

73 

74 exp = afwImage.ExposureF(300, 350) 

75 

76 for frame in (FRAME_NUM, FRAME_NUM+1): 

77 ds9.setMaskTransparency(50, frame=frame) 

78 

79 if frame == FRAME_NUM+1: 

80 ds9.setMaskPlaneColor("CROSSTALK", "ignore", frame=frame) 

81 ds9.mtv(exp, title="parent", frame=frame) 

82 

83 ds9.erase(frame=frame) 

84 ds9.dot('o', 205, 180, size=6, ctype=ds9.RED, frame=frame) 

85 

86 @unittest.skipUnless(ds9, "You must setup display.ds9 to run this test") 

87 def testZoomPan(self): 

88 ds9.pan(205, 180) 

89 ds9.zoom(4) 

90 

91 ds9.zoom(4, 205, 180, frame=1) 

92 

93 @unittest.skipUnless(ds9, "You must setup display.ds9 to run this test") 

94 def testStackingOrder(self): 

95 """ Un-iconise and raise the display to the top of the stacking order if appropriate""" 

96 ds9.show() 

97 

98 @unittest.skipUnless(ds9, "You must setup display.ds9 to run this test") 

99 def testDrawing(self): 

100 """Test drawing lines and glyphs""" 

101 ds9.erase() 

102 

103 exp = afwImage.ExposureF(300, 350) 

104 ds9.mtv(exp, title="parent", frame=FRAME_NUM) # tells display0 about the image's xy0 

105 

106 with ds9.Buffering(): 

107 ds9.dot('o', 200, 220) 

108 vertices = [(200, 220), (210, 230), (224, 230), 

109 (214, 220), (200, 220)] 

110 ds9.line(vertices, ctype=ds9.CYAN) 

111 ds9.line(vertices[:-1], symbs="+x+x", size=3) 

112 

113 @unittest.skipUnless(ds9, "You must setup display.ds9 to run this test") 

114 def testText(self): 

115 """Test drawing text""" 

116 ds9.erase() 

117 

118 exp = afwImage.ExposureF(300, 350) 

119 ds9.mtv(exp, title="parent", frame=FRAME_NUM) # tells display0 about the image's xy0 

120 

121 with ds9.Buffering(): 

122 ds9.dot('hello', 200, 200) 

123 ds9.dot('hello', 200, 210, size=1.25) 

124 ds9.dot('hello', 200, 220, size=3, fontFamily="times") 

125 ds9.dot('hello', 200, 230, fontFamily="helvetica bold italic") 

126 

127 @unittest.skipUnless(ds9, "You must setup display.ds9 to run this test") 

128 def testStretch(self): 

129 """Test playing with the lookup table""" 

130 ds9.show() 

131 

132 ds9.scale("linear", "zscale") 

133 

134 

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

136 pass 

137 

138 

139def setup_module(module): 

140 lsst.utils.tests.init() 

141 

142 

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

144 lsst.utils.tests.init() 

145 unittest.main()