Coverage for tests/test_ds9.py: 45%
77 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-30 02:30 -0700
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-30 02:30 -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/>.
22"""
23Tests for the legacy display code in ds9.py (iff lsst.display.ds9 is setup)
25Run with:
26 python test_ds9.py
27or
28 pytest test_ds9.py
29"""
30import unittest
32import lsst.utils.tests
33import lsst.afw.image as afwImage
34try:
35 import lsst.afw.display.ds9 as ds9
36except Exception:
37 ds9 = None
39FRAME_NUM = 731 # largish, arbitrary number, unlikely to be in use by a user
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
49class DisplayTestCase(unittest.TestCase):
50 """A test case for Display"""
52 def setUp(self):
53 pass
55 def tearDown(self):
56 pass
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)
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")
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"""
74 exp = afwImage.ExposureF(300, 350)
76 for frame in (FRAME_NUM, FRAME_NUM+1):
77 ds9.setMaskTransparency(50, frame=frame)
79 if frame == FRAME_NUM+1:
80 ds9.setMaskPlaneColor("CROSSTALK", "ignore", frame=frame)
81 ds9.mtv(exp, title="parent", frame=frame)
83 ds9.erase(frame=frame)
84 ds9.dot('o', 205, 180, size=6, ctype=ds9.RED, frame=frame)
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)
91 ds9.zoom(4, 205, 180, frame=1)
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()
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()
103 exp = afwImage.ExposureF(300, 350)
104 ds9.mtv(exp, title="parent", frame=FRAME_NUM) # tells display0 about the image's xy0
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)
113 @unittest.skipUnless(ds9, "You must setup display.ds9 to run this test")
114 def testText(self):
115 """Test drawing text"""
116 ds9.erase()
118 exp = afwImage.ExposureF(300, 350)
119 ds9.mtv(exp, title="parent", frame=FRAME_NUM) # tells display0 about the image's xy0
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")
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()
132 ds9.scale("linear", "zscale")
135class TestMemory(lsst.utils.tests.MemoryTestCase):
136 pass
139def setup_module(module):
140 lsst.utils.tests.init()
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()