lsst.afw  16.0-56-g615901931+1
virtualDevice.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010, 2015 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 
26 
27 
29  def __init__(self, display, verbose=False):
30  """! Initialise the display
31  @param display The display object that we're providing the implementation for
32  @param verbose be chatty?
33  """
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  if hasattr(self, "verbose") and self.verbose and hasattr(self, "display"):
43  print("virtual[%s]._close()" % (self.frame))
44 
45  def _buffer(self, enable=True):
46  """!Enable or disable buffering of writes to the display
47  @param enable True or False, as appropriate
48  """
49  if self.verbose:
50  print("virtual[%s]._buffer(%s)" % (self.frame, enable))
51 
52  def _dot(self, symb, c, r, size, ctype, *args, **kwargs):
53  """!Draw symbol a symbol at (c, r)
54  @param symb The desired symbol. See dot() for details
55  @param c (x) column position
56  @param r (y) row position
57  @param size Size of symbol, in pixels
58  @param ctype The desired colour, either e.g. afw.display.RED or a colour name known to X11
59  @param args Extra arguments
60  @param kwargs Extra keyword arguments
61  """
62  if self.verbose:
63  print("virtual[%s]._dot('%s', %.2f, %.2f, size=%g, ctype=%s, %s, %s)" %
64  (self.frame, symb, c, r, size, ctype, args, kwargs))
65 
66  def _drawLines(self, points, ctype):
67  """!Draw line defined by the list points
68  @param points A list of 0-indexed positions [(x, y), (x, y), ...]
69  @param ctype The desired colour, either e.g. afw.display.RED or a colour name known to X11
70  """
71  if self.verbose:
72  print("virtual[%s]._drawLines(%s, ctype=%s)" %
73  (self.frame, points, ctype))
74 
75  def _erase(self):
76  """!Erase all glyphs drawn on display
77  """
78  if self.verbose:
79  print("virtual[%s]._erase()" % (self.frame))
80 
81  def _flush(self):
82  """!Flush any I/O buffers
83  """
84  if self.verbose:
85  print("virtual[%s]._flush()" % self.frame)
86 
87  def _setCallback(self, what, func):
88  if self.verbose > 1:
89  print("setCallback %s -> %s" % (what, func))
90 
91  def _getEvent(self):
92  """Return an event generated by a keypress or mouse click
93  """
94  from .interface import Event
95  ev = Event("q")
96 
97  if self.verbose:
98  print("virtual[%s]._getEvent() -> %s" % (self.frame, ev))
99 
100  return ev
101 
102  def _getMaskTransparency(self):
103  """Return the mask transparency for a display
104  """
105  if self.verbose:
106  print("virtual[%s]._getMaskTransparency()" % self.frame)
107 
108  def _mtv(self, image, wcs=None, mask=None, title=""):
109  """Display an image and maybe a mask overlay on a display
110  @param image afwImage.Image to display
111  @param mask afwImage.Mask to display
112  @param wcs A Wcs to associate with data
113  @param title Name to display with the data
114  """
115  if self.verbose:
116  print("virtual[%s]._mtv(image=%s, mask=%s, wcs=%s, title=\"%s\")" %
117  (self.frame, "Image" if image else None,
118  "Mask" if mask else None, "Wcs" if wcs else None, title))
119 
120  def _setImageColormap(self, cmap):
121  """Set the desired colourmap
122 
123  @param the name of a colourmap (e.g. "gray") or a backend-specific object
124  """
125  if self.verbose:
126  print("virtual[%s]._setImageColormap(cmap=\"%s\")" % (self.frame, cmap))
127 
128  def _setMaskTransparency(self, transparency, maskplane):
129  """Set the transparency of a maskplane
130  @param transparency The desired transparency, in the range [0, 100]
131  @param maskplane The maskplane to set (None: all)
132  """
133  if self.verbose:
134  print("virtual[%s]._setMaskTransparency(%g, maskplane=\"%s\")" %
135  (self.frame, transparency, maskplane))
136 
137  def _scale(self, algorithm, min, max, unit=None, *args, **kwargs):
138  """Set the scaling from DN to displayed pixels
139  @param algorithm Scaling algorithm (e.g. linear)
140  @param min The minimum value of the stretch (or "zscale" or "minmax")
141  @param max The maximum value of the stretch
142  @param unit Units for min and max (e.g. Percent, Absolute, Sigma)
143  @param *args Optional arguments
144  @param **kwargs Optional keyword arguments
145  """
146  if self.verbose:
147  print("virtual[%s]._scale(%s, %s, %s, %s, %s, %s)" % (self.frame, algorithm,
148  min, max, unit, args, kwargs))
149 
150  def _show(self):
151  """Show the requested display
152  """
153  if self.verbose:
154  print("virtual[%s]._show()" % self.frame)
155 
156  def _pan(self, r, c):
157  """Pan to (colc, rowc)
158  @param c Desired column (x) position
159  @param r Desired row (y) position
160  """
161  if self.verbose:
162  print("virtual[%s]._pan(%.2f, %.2f)" % (self.frame, r, c))
163 
164  def _zoom(self, zoomfac):
165  """Set the zoom
166  @param zoomfac Zoom factor to use
167  """
168  if self.verbose:
169  print("virtual[%s]._zoom(%g)" % (self.frame, zoomfac))
def __init__(self, display, verbose=False)
Initialise the display.
A class to handle events such as key presses in image display windows.
Definition: interface.py:685
def _close(self)
Close the display, cleaning up any allocated resources.