LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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.display.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.display.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  """
62  if self.verbose:
63  print("virtual[%s]._dot('%s', %.2f, %.2f, size=%g, ctype=%s, %s, %s)" % \
64  (self.display.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 symb A list of 0-indexed positions (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)" % (self.display.frame, points, ctype))
73 
74  def _erase(self):
75  """!Erase all glyphs drawn on display
76  """
77  if self.verbose:
78  print("virtual[%s]._erase()" % (self.display.frame))
79 
80  def _flush(self):
81  """!Flush any I/O buffers
82  """
83  if self.verbose:
84  print("virtual[%s]._flush()" % self.display.frame)
85 
86  def _setCallback(self, what, func):
87  if self.verbose > 1:
88  print("setCallback %s -> %s" % (what, func))
89 
90  def _getEvent(self):
91  """Return an event generated by a keypress or mouse click
92  """
93  from .interface import Event
94  ev = Event("q")
95 
96  if self.verbose:
97  print("virtual[%s]._getEvent() -> %s" % (self.display.frame, ev))
98 
99  return ev
100 
102  """Return the mask transparency for a display
103  """
104  if self.verbose:
105  print("virtual[%s]._getMaskTransparency()" % self.display.frame)
106 
107  def _mtv(self, image, wcs=None, mask=None, title=""):
108  """Display an image and maybe a mask overlay on a display
109  \param image afwImage.Image to display
110  \param mask afwImage.Mask to display
111  \param wcs A Wcs to associate with data
112  \param title Name to display with the data
113  """
114  if self.verbose:
115  print("virtual[%s]._mtv(image=%s, mask=%s, wcs=%s, title=\"%s\")" % \
116  (self.display.frame, "Image" if image else None,
117  "Mask" if mask else None, "Wcs" if wcs else None, title))
118 
119  def _setMaskTransparency(self, transparency, maskplane):
120  """Set the transparency of a maskplane
121  \param transparency The desired transparency, in the range [0, 100]
122  \param maskplane The maskplane to set (None: all)
123  """
124  if self.verbose:
125  print("virtual[%s]._setMaskTransparency(%g, maskplane=\"%s\")" % (self.display.frame, transparency, maskplane))
126 
127  def _scale(self, algorithm, min, max, unit=None, *args, **kwargs):
128  """Set the scaling from DN to displayed pixels
129  \param algorithm Scaling algorithm (e.g. linear)
130  \param min The minimum value of the stretch (or "zscale" or "minmax")
131  \param max The maximum value of the stretch
132  \param unit Units for min and max (e.g. Percent, Absolute, Sigma)
133  \param *args Optional arguments
134  \param **kwargs Optional keyword arguments
135  """
136  if self.verbose:
137  print("virtual[%s]._scale(%s, %s, %s, %s, %s, %s)" % (self.display.frame, algorithm,
138  min, max, unit, args, kwargs))
139 
140  def _show(self):
141  """Show the requested display
142  """
143  if self.verbose:
144  print("virtual[%s]._show()" % self.display.frame)
145 
146  def _pan(self, r, c):
147  """Pan to (colc, rowc)
148  \param c Desired column (x) position
149  \param r Desired row (y) position
150  """
151  if self.verbose:
152  print("virtual[%s]._pan(%.2f, %.2f)" % (self.display.frame, r, c))
153 
154  def _zoom(self, zoomfac):
155  """Set the zoom
156  \param zoomfac Zoom factor to use
157  """
158  if self.verbose:
159  print("virtual[%s]._zoom(%g)" % (self.display.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.