Coverage for python / lsst / afw / display / virtualDevice.py: 0%

57 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-28 01:42 -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 

23class DisplayImpl: 

24 """Back-end for display objects. 

25 

26 Parameters 

27 ---------- 

28 display 

29 The display object that we're providing the implementation for 

30 verbose : `bool` 

31 be chatty? 

32 """ 

33 def __init__(self, display, verbose=False): 

34 self.display = display 

35 self.verbose = verbose 

36 

37 def __del__(self): 

38 self._close() 

39 

40 def _close(self): 

41 """Close the display, cleaning up any allocated resources 

42 """ 

43 if hasattr(self, "verbose") and self.verbose and hasattr(self, "display"): 

44 print("virtual[%s]._close()" % (self.frame)) 

45 

46 def _buffer(self, enable=True): 

47 """Enable or disable buffering of writes to the display 

48 

49 Parameters 

50 ---------- 

51 enable : `bool` 

52 `True` or `False`, as appropriate 

53 """ 

54 if self.verbose: 

55 print("virtual[%s]._buffer(%s)" % (self.frame, enable)) 

56 

57 def _dot(self, symb, c, r, size, ctype, *args, **kwargs): 

58 """Draw a symbol at (c, r) 

59 

60 Parameters 

61 ---------- 

62 symb 

63 The desired symbol. See `dot` for details 

64 c : `float` 

65 (x) column position 

66 r : `float` 

67 (y) row position 

68 size : `int` 

69 Size of symbol, in pixels 

70 ctype : `str` 

71 The desired color, either e.g. `lsst.afw.display.RED` or a color name known to X11 

72 *args 

73 Extra arguments to backend 

74 **kwargs 

75 Extra keyword arguments to backend 

76 """ 

77 if self.verbose: 

78 print("virtual[%s]._dot('%s', %.2f, %.2f, size=%g, ctype=%s, %s, %s)" % 

79 (self.frame, symb, c, r, size, ctype, args, kwargs)) 

80 

81 def _drawLines(self, points, ctype): 

82 """Draw line defined by the list points 

83 

84 Parameters 

85 ---------- 

86 points : `list` of `tuple` of `float` 

87 A list of 0-indexed positions [(x, y), (x, y), ...] 

88 ctype : `str` 

89 The desired color, either e.g. `lsst.afw.display.RED` or a color name known to X11 

90 """ 

91 if self.verbose: 

92 print("virtual[%s]._drawLines(%s, ctype=%s)" % 

93 (self.frame, points, ctype)) 

94 

95 def _erase(self): 

96 """Erase all glyphs drawn on display 

97 """ 

98 if self.verbose: 

99 print("virtual[%s]._erase()" % (self.frame)) 

100 

101 def _flush(self): 

102 """Flush any I/O buffers 

103 """ 

104 if self.verbose: 

105 print("virtual[%s]._flush()" % self.frame) 

106 

107 def _setCallback(self, what, func): 

108 if self.verbose > 1: 

109 print("setCallback %s -> %s" % (what, func)) 

110 

111 def _getEvent(self): 

112 """Return an event generated by a keypress or mouse click 

113 """ 

114 from .interface import Event 

115 ev = Event("q") 

116 

117 if self.verbose: 

118 print("virtual[%s]._getEvent() -> %s" % (self.frame, ev)) 

119 

120 return ev 

121 

122 def _getMaskTransparency(self): 

123 """Return the mask transparency for a display 

124 """ 

125 if self.verbose: 

126 print("virtual[%s]._getMaskTransparency()" % self.frame) 

127 

128 def _mtv(self, image, wcs=None, mask=None, title="", metadata=None): 

129 """Display an image and maybe a mask overlay on a display 

130 

131 Parameters 

132 ---------- 

133 image : `lsst.afw.image.Image` 

134 `~lsst.afw.image.Image` to display 

135 mask : `lsst.afw.image.Mask` 

136 `~lsst.afw.image.Mask` to display 

137 wcs : `lsst.afw.geom.SkyWcs` 

138 A Wcs to associate with data 

139 title : `str` 

140 Name to display with the data 

141 metadata : `lsst.daf.base.PropertySet` 

142 Additional metadata. 

143 """ 

144 if self.verbose: 

145 print("virtual[%s]._mtv(image=%s, mask=%s, wcs=%s, title=\"%s\", metadata=\"%s\")" % 

146 (self.frame, "Image" if image else None, 

147 "Mask" if mask else None, "Wcs" if wcs else None, title, 

148 f"{len(metadata)} cards" if metadata else "None")) 

149 

150 def _setImageColormap(self, cmap): 

151 """Set the desired colormap 

152 

153 Parameters 

154 ---------- 

155 cmap : `str` 

156 the name of a colormap (e.g. "gray") or a backend-specific object 

157 """ 

158 if self.verbose: 

159 print("virtual[%s]._setImageColormap(cmap=\"%s\")" % (self.frame, cmap)) 

160 

161 def _setMaskTransparency(self, transparency, maskplane): 

162 """Set the transparency of a maskplane 

163 

164 Parameters 

165 ---------- 

166 transparency : `float` 

167 The desired transparency, in the range [0, 100] 

168 maskplane 

169 The maskplane to set (None: all) 

170 """ 

171 if self.verbose: 

172 print("virtual[%s]._setMaskTransparency(%g, maskplane=\"%s\")" % 

173 (self.frame, transparency, maskplane)) 

174 

175 def _scale(self, algorithm, min, max, *args, unit=None, **kwargs): 

176 """Set the scaling from DN to displayed pixels 

177 

178 Parameters 

179 ---------- 

180 algorithm 

181 Scaling algorithm (e.g. linear) 

182 min 

183 The minimum value of the stretch (or "zscale" or "minmax") 

184 max 

185 The maximum value of the stretch 

186 unit 

187 Units for min and max (e.g. Percent, Absolute, Sigma) 

188 *args 

189 Optional arguments to the backend 

190 **kwargs 

191 Optional keyword arguments to the backend 

192 """ 

193 if self.verbose: 

194 print("virtual[%s]._scale(%s, %s, %s, %s, %s, %s)" % (self.frame, algorithm, 

195 min, max, unit, args, kwargs)) 

196 

197 def _show(self): 

198 """Show the requested display 

199 """ 

200 if self.verbose: 

201 print("virtual[%s]._show()" % self.frame) 

202 

203 def _pan(self, r, c): 

204 """Pan to a row and column 

205 

206 Parameters 

207 ---------- 

208 c : `float` 

209 Desired column (x) position 

210 r : `float` 

211 Desired row (y) position 

212 """ 

213 if self.verbose: 

214 print("virtual[%s]._pan(%.2f, %.2f)" % (self.frame, r, c)) 

215 

216 def _zoom(self, zoomfac): 

217 """Set the zoom 

218 

219 Parameters 

220 ---------- 

221 zoomfac : `float` 

222 Zoom factor to use 

223 """ 

224 if self.verbose: 

225 print("virtual[%s]._zoom(%g)" % (self.frame, zoomfac))