Coverage for python/lsst/afw/display/ds9.py : 64%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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#
23import lsst.afw.display
24import lsst.afw.image as afwImage
25from .interface import getDisplay as _getDisplay, getDefaultBackend, setDefaultBackend
26# Backwards compatibility. Downstream code should be converted to use display.RED etc.
27from .interface import BLACK, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, WHITE # noqa: F401
28try:
29 loaded
30except NameError:
31 try:
32 if getDefaultBackend() is None: 32 ↛ 34line 32 didn't jump to line 34, because the condition on line 32 was never false
33 setDefaultBackend("lsst.display.ds9")
34 getDisplay = _getDisplay
35 except Exception as e:
36 # No usable version of display_ds9.
37 # Let's define a version of getDisplay() which will throw an exception.
39 # Prior to DM-9433, we used a closure to implicitly capture the
40 # exception being thrown for future reference. Following changes to
41 # exception scope rules in Python 3 (see PEP 3110), it's now regarded
42 # as clearer to make the capture explicit using the following class.
43 class _RaiseException:
44 def __init__(self, exception):
45 # The exception being caught above may have a bulky context which we
46 # don't want to capture in a closure for all time: see DM-9504 for a
47 # full discussion. We therefore define a new exception of the same
48 # type, which just encodes the error text.
49 self.exception = type(exception)(f"{exception} (is display_ds9 setup?)")
51 def __call__(self, *args, **kwargs):
52 raise self.exception
54 getDisplay = _RaiseException(e)
56 class DisplayImpl:
57 __init__ = getDisplay
59 loaded = False
60 else:
61 loaded = True
64def Buffering():
65 # always use the real one
66 return _getDisplay(None, create=True).Buffering()
68#
69# Functions provided for backwards compatibility
70#
73def setMaskPlaneColor(name, color=None, frame=None):
74 return getDisplay(frame, create=True).setMaskPlaneColor(name, color)
77def getMaskPlaneColor(name, frame=None):
78 return getDisplay(frame, create=True).getMaskPlaneColor(name)
81def setMaskTransparency(name, frame=None):
82 return getDisplay(frame, create=True).setMaskTransparency(name)
85def getMaskTransparency(name, frame=None):
86 return getDisplay(frame, create=True).getMaskTransparency(name)
89def show(frame=None):
90 return getDisplay(frame, create=True).show()
93def mtv(data, frame=None, title="", wcs=None, *args, **kwargs):
94 return getDisplay(frame, create=True).mtv(data, title, wcs, *args, **kwargs)
97def erase(frame=None):
98 return getDisplay(frame, create=True).erase()
101def dot(symb, c, r, frame=None, size=2, ctype=None, origin=afwImage.PARENT, *args, **kwargs):
102 return getDisplay(frame, create=True).dot(symb, c, r, size, ctype, origin, *args, **kwargs)
105def line(points, frame=None, origin=afwImage.PARENT, symbs=False, ctype=None, size=0.5):
106 return getDisplay(frame, create=True).line(points, origin, symbs, ctype, size)
109def scale(algorithm, min, max=None, frame=None):
110 return getDisplay(frame, create=True).scale(algorithm, min, max)
113def pan(colc=None, rowc=None, frame=None, origin=afwImage.PARENT):
114 disp = getDisplay(frame, create=True)
116 disp.pan(colc, rowc, origin)
119def zoom(zoomfac=None, colc=None, rowc=None, frame=None, origin=afwImage.PARENT):
120 disp = getDisplay(frame, create=True)
122 disp.zoom(zoomfac)
123 disp.pan(colc, rowc, origin)
126def interact(frame=None):
127 return getDisplay(frame, create=True).interact()
130def setCallback(k, func=lsst.afw.display.noop_callback, noRaise=False, frame=None):
131 return getDisplay(frame, create=True).setCallback(k, noRaise=False)
134def getActiveCallbackKeys(onlyActive=True, frame=None):
135 return getDisplay(frame, create=True).getActiveCallbackKeys(onlyActive)