Coverage for tests/test_ds9.py: 43%

88 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-15 02:24 -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 

36 import lsst.display.ds9 

37except Exception: 

38 ds9 = None 

39 

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

41 

42if ds9: 42 ↛ 43line 42 didn't jump to line 43, because the condition on line 42 was never true

43 try: 

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

45 except Exception as e: 

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

47 ds9 = None 

48 

49 

50class DisplayTestCase(unittest.TestCase): 

51 """A test case for Display""" 

52 

53 def setUp(self): 

54 pass 

55 

56 def tearDown(self): 

57 pass 

58 

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

60 def testMtv(self): 

61 """Test basic image display""" 

62 exp = afwImage.ImageF(10, 20) 

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

64 

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

66 def testMaskPlanes(self): 

67 """Test basic image display""" 

68 ds9.setMaskTransparency(50) 

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

70 

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

72 def testTwoDisplays(self): 

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

74 

75 exp = afwImage.ExposureF(300, 350) 

76 

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

78 ds9.setMaskTransparency(50, frame=frame) 

79 

80 if frame == FRAME_NUM+1: 

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

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

83 

84 ds9.erase(frame=frame) 

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

86 

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

88 def testZoomPan(self): 

89 ds9.pan(205, 180) 

90 ds9.zoom(4) 

91 

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

93 

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

95 def testStackingOrder(self): 

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

97 try: 

98 ds9.show() 

99 except lsst.display.ds9.Ds9Error as e: 

100 if "XPASet returned 0" in str(e): 

101 raise unittest.SkipTest("DS9 does not appear to be installed.") 

102 raise 

103 

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

105 def testDrawing(self): 

106 """Test drawing lines and glyphs""" 

107 ds9.erase() 

108 

109 exp = afwImage.ExposureF(300, 350) 

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

111 

112 with ds9.Buffering(): 

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

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

115 (214, 220), (200, 220)] 

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

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

118 

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

120 def testText(self): 

121 """Test drawing text""" 

122 ds9.erase() 

123 

124 exp = afwImage.ExposureF(300, 350) 

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

126 

127 with ds9.Buffering(): 

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

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

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

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

132 

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

134 def testStretch(self): 

135 """Test playing with the lookup table""" 

136 try: 

137 ds9.show() 

138 except lsst.display.ds9.Ds9Error as e: 

139 if "XPASet returned 0" in str(e): 

140 raise unittest.SkipTest("DS9 does not appear to be installed.") 

141 raise 

142 

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

144 

145 

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

147 pass 

148 

149 

150def setup_module(module): 

151 lsst.utils.tests.init() 

152 

153 

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

155 lsst.utils.tests.init() 

156 unittest.main()