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