LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
virtualDevice.py
Go to the documentation of this file.
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 
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.displaydisplay = display
35  self.verboseverbose = verbose
36 
37  def __del__(self):
38  self._close_close()
39 
40  def _close(self):
41  """Close the display, cleaning up any allocated resources
42  """
43  if hasattr(self, "verbose") and self.verboseverbose 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.verboseverbose:
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.verboseverbose:
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.verboseverbose:
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.verboseverbose:
99  print("virtual[%s]._erase()" % (self.frame))
100 
101  def _flush(self):
102  """Flush any I/O buffers
103  """
104  if self.verboseverbose:
105  print("virtual[%s]._flush()" % self.frame)
106 
107  def _setCallback(self, what, func):
108  if self.verboseverbose > 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.verboseverbose:
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.verboseverbose:
126  print("virtual[%s]._getMaskTransparency()" % self.frame)
127 
128  def _mtv(self, image, wcs=None, mask=None, title=""):
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  """
142  if self.verboseverbose:
143  print("virtual[%s]._mtv(image=%s, mask=%s, wcs=%s, title=\"%s\")" %
144  (self.frame, "Image" if image else None,
145  "Mask" if mask else None, "Wcs" if wcs else None, title))
146 
147  def _setImageColormap(self, cmap):
148  """Set the desired colormap
149 
150  Parameters
151  ----------
152  cmap : `str`
153  the name of a colormap (e.g. "gray") or a backend-specific object
154  """
155  if self.verboseverbose:
156  print("virtual[%s]._setImageColormap(cmap=\"%s\")" % (self.frame, cmap))
157 
158  def _setMaskTransparency(self, transparency, maskplane):
159  """Set the transparency of a maskplane
160 
161  Parameters
162  ----------
163  transparency : `float`
164  The desired transparency, in the range [0, 100]
165  maskplane
166  The maskplane to set (None: all)
167  """
168  if self.verboseverbose:
169  print("virtual[%s]._setMaskTransparency(%g, maskplane=\"%s\")" %
170  (self.frame, transparency, maskplane))
171 
172  def _scale(self, algorithm, min, max, *args, unit=None, **kwargs):
173  """Set the scaling from DN to displayed pixels
174 
175  Parameters
176  ----------
177  algorithm
178  Scaling algorithm (e.g. linear)
179  min
180  The minimum value of the stretch (or "zscale" or "minmax")
181  max
182  The maximum value of the stretch
183  unit
184  Units for min and max (e.g. Percent, Absolute, Sigma)
185  *args
186  Optional arguments to the backend
187  **kwargs
188  Optional keyword arguments to the backend
189  """
190  if self.verboseverbose:
191  print("virtual[%s]._scale(%s, %s, %s, %s, %s, %s)" % (self.frame, algorithm,
192  min, max, unit, args, kwargs))
193 
194  def _show(self):
195  """Show the requested display
196  """
197  if self.verboseverbose:
198  print("virtual[%s]._show()" % self.frame)
199 
200  def _pan(self, r, c):
201  """Pan to a row and column
202 
203  Parameters
204  ----------
205  c : `float`
206  Desired column (x) position
207  r : `float`
208  Desired row (y) position
209  """
210  if self.verboseverbose:
211  print("virtual[%s]._pan(%.2f, %.2f)" % (self.frame, r, c))
212 
213  def _zoom(self, zoomfac):
214  """Set the zoom
215 
216  Parameters
217  ----------
218  zoomfac : `float`
219  Zoom factor to use
220  """
221  if self.verboseverbose:
222  print("virtual[%s]._zoom(%g)" % (self.frame, zoomfac))
def __init__(self, display, verbose=False)