LSSTApplications  18.1.0
LSSTDataManagementBasePackage
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 
25  """Back-end for display objects.
26 
27  Parameters
28  ----------
29  display
30  The display object that we're providing the implementation for
31  verbose : `bool`
32  be chatty?
33  """
34  def __init__(self, display, verbose=False):
35  self.display = display
36  self.verbose = verbose
37 
38  def __del__(self):
39  self._close()
40 
41  def _close(self):
42  """Close the display, cleaning up any allocated resources
43  """
44  if hasattr(self, "verbose") and self.verbose and hasattr(self, "display"):
45  print("virtual[%s]._close()" % (self.frame))
46 
47  def _buffer(self, enable=True):
48  """Enable or disable buffering of writes to the display
49 
50  Parameters
51  ----------
52  enable : `bool`
53  `True` or `False`, as appropriate
54  """
55  if self.verbose:
56  print("virtual[%s]._buffer(%s)" % (self.frame, enable))
57 
58  def _dot(self, symb, c, r, size, ctype, *args, **kwargs):
59  """Draw a symbol at (c, r)
60 
61  Parameters
62  ----------
63  symb
64  The desired symbol. See `dot` for details
65  c : `float`
66  (x) column position
67  r : `float`
68  (y) row position
69  size : `int`
70  Size of symbol, in pixels
71  ctype : `str`
72  The desired color, either e.g. `lsst.afw.display.RED` or a color name known to X11
73  *args
74  Extra arguments to backend
75  **kwargs
76  Extra keyword arguments to backend
77  """
78  if self.verbose:
79  print("virtual[%s]._dot('%s', %.2f, %.2f, size=%g, ctype=%s, %s, %s)" %
80  (self.frame, symb, c, r, size, ctype, args, kwargs))
81 
82  def _drawLines(self, points, ctype):
83  """Draw line defined by the list points
84 
85  Parameters
86  ----------
87  points : `list` of `tuple` of `float`
88  A list of 0-indexed positions [(x, y), (x, y), ...]
89  ctype : `str`
90  The desired color, either e.g. `lsst.afw.display.RED` or a color name known to X11
91  """
92  if self.verbose:
93  print("virtual[%s]._drawLines(%s, ctype=%s)" %
94  (self.frame, points, ctype))
95 
96  def _erase(self):
97  """Erase all glyphs drawn on display
98  """
99  if self.verbose:
100  print("virtual[%s]._erase()" % (self.frame))
101 
102  def _flush(self):
103  """Flush any I/O buffers
104  """
105  if self.verbose:
106  print("virtual[%s]._flush()" % self.frame)
107 
108  def _setCallback(self, what, func):
109  if self.verbose > 1:
110  print("setCallback %s -> %s" % (what, func))
111 
112  def _getEvent(self):
113  """Return an event generated by a keypress or mouse click
114  """
115  from .interface import Event
116  ev = Event("q")
117 
118  if self.verbose:
119  print("virtual[%s]._getEvent() -> %s" % (self.frame, ev))
120 
121  return ev
122 
123  def _getMaskTransparency(self):
124  """Return the mask transparency for a display
125  """
126  if self.verbose:
127  print("virtual[%s]._getMaskTransparency()" % self.frame)
128 
129  def _mtv(self, image, wcs=None, mask=None, title=""):
130  """Display an image and maybe a mask overlay on a display
131 
132  Parameters
133  ----------
134  image : `lsst.afw.image.Image`
135  `~lsst.afw.image.Image` to display
136  mask : `lsst.afw.image.Mask`
137  `~lsst.afw.image.Mask` to display
138  wcs : `lsst.afw.geom.SkyWcs`
139  A Wcs to associate with data
140  title : `str`
141  Name to display with the data
142  """
143  if self.verbose:
144  print("virtual[%s]._mtv(image=%s, mask=%s, wcs=%s, title=\"%s\")" %
145  (self.frame, "Image" if image else None,
146  "Mask" if mask else None, "Wcs" if wcs else None, title))
147 
148  def _setImageColormap(self, cmap):
149  """Set the desired colormap
150 
151  Parameters
152  ----------
153  cmap : `str`
154  the name of a colormap (e.g. "gray") or a backend-specific object
155  """
156  if self.verbose:
157  print("virtual[%s]._setImageColormap(cmap=\"%s\")" % (self.frame, cmap))
158 
159  def _setMaskTransparency(self, transparency, maskplane):
160  """Set the transparency of a maskplane
161 
162  Parameters
163  ----------
164  transparency : `float`
165  The desired transparency, in the range [0, 100]
166  maskplane
167  The maskplane to set (None: all)
168  """
169  if self.verbose:
170  print("virtual[%s]._setMaskTransparency(%g, maskplane=\"%s\")" %
171  (self.frame, transparency, maskplane))
172 
173  def _scale(self, algorithm, min, max, *args, unit=None, **kwargs):
174  """Set the scaling from DN to displayed pixels
175 
176  Parameters
177  ----------
178  algorithm
179  Scaling algorithm (e.g. linear)
180  min
181  The minimum value of the stretch (or "zscale" or "minmax")
182  max
183  The maximum value of the stretch
184  unit
185  Units for min and max (e.g. Percent, Absolute, Sigma)
186  *args
187  Optional arguments to the backend
188  **kwargs
189  Optional keyword arguments to the backend
190  """
191  if self.verbose:
192  print("virtual[%s]._scale(%s, %s, %s, %s, %s, %s)" % (self.frame, algorithm,
193  min, max, unit, args, kwargs))
194 
195  def _show(self):
196  """Show the requested display
197  """
198  if self.verbose:
199  print("virtual[%s]._show()" % self.frame)
200 
201  def _pan(self, r, c):
202  """Pan to a row and column
203 
204  Parameters
205  ----------
206  c : `float`
207  Desired column (x) position
208  r : `float`
209  Desired row (y) position
210  """
211  if self.verbose:
212  print("virtual[%s]._pan(%.2f, %.2f)" % (self.frame, r, c))
213 
214  def _zoom(self, zoomfac):
215  """Set the zoom
216 
217  Parameters
218  ----------
219  zoomfac : `float`
220  Zoom factor to use
221  """
222  if self.verbose:
223  print("virtual[%s]._zoom(%g)" % (self.frame, zoomfac))
def __init__(self, display, verbose=False)