Coverage for tests/test_ds9.py: 47%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

76 statements  

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 

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

40 try: 

41 ds9.mtv(afwImage.ImageF(1, 1)) 

42 except Exception as e: 

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

44 ds9 = None 

45 

46 

47class DisplayTestCase(unittest.TestCase): 

48 """A test case for Display""" 

49 

50 def setUp(self): 

51 pass 

52 

53 def tearDown(self): 

54 pass 

55 

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

57 def testMtv(self): 

58 """Test basic image display""" 

59 exp = afwImage.ImageF(10, 20) 

60 ds9.mtv(exp, title="parent") 

61 

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

63 def testMaskPlanes(self): 

64 """Test basic image display""" 

65 ds9.setMaskTransparency(50) 

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

67 

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

69 def testTwoDisplays(self): 

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

71 

72 exp = afwImage.ExposureF(300, 350) 

73 

74 for frame in (0, 1): 

75 ds9.setMaskTransparency(50, frame=frame) 

76 

77 if frame == 1: 

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

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

80 

81 ds9.erase(frame=frame) 

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

83 

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

85 def testZoomPan(self): 

86 ds9.pan(205, 180) 

87 ds9.zoom(4) 

88 

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

90 

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

92 def testStackingOrder(self): 

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

94 ds9.show() 

95 

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

97 def testDrawing(self): 

98 """Test drawing lines and glyphs""" 

99 ds9.erase() 

100 

101 exp = afwImage.ExposureF(300, 350) 

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

103 

104 with ds9.Buffering(): 

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

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

107 (214, 220), (200, 220)] 

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

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

110 

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

112 def testText(self): 

113 """Test drawing text""" 

114 ds9.erase() 

115 

116 exp = afwImage.ExposureF(300, 350) 

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

118 

119 with ds9.Buffering(): 

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

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

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

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

124 

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

126 def testStretch(self): 

127 """Test playing with the lookup table""" 

128 ds9.show() 

129 

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

131 

132 

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

134 pass 

135 

136 

137def setup_module(module): 

138 lsst.utils.tests.init() 

139 

140 

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

142 lsst.utils.tests.init() 

143 unittest.main()