37 "WHITE",
"BLACK",
"RED",
"GREEN",
"BLUE",
"CYAN",
"MAGENTA",
"YELLOW",
"ORANGE",
"IGNORE",
38 "Display",
"Event",
"noop_callback",
"h_callback",
39 "setDefaultBackend",
"getDefaultBackend",
40 "setDefaultFrame",
"getDefaultFrame",
"incrDefaultFrame",
41 "setDefaultMaskTransparency",
"setDefaultMaskPlaneColor",
42 "getDisplay",
"delAllDisplays",
60 def _makeDisplayImpl(display, backend, *args, **kwargs):
61 """!Return the DisplayImpl for the named backend 63 @param display Name of device. Should be importable, either absolutely or relative to lsst.display 64 @param backend The desired backend 65 @param args Arguments passed to DisplayImpl.__init__ 66 @param kwargs Keywords arguments passed to DisplayImpl.__init__ 69 import lsst.afw.display as afwDisplay 70 display = afwDisplay.Display(display=1, backend="ds9") 72 _makeDisplayImpl(..., "ds9", 1) 73 and import the ds9 implementation of DisplayImpl from lsst.display.ds9 77 for dt
in (
"lsst.display.%s" % backend, backend,
".%s" % backend,
"lsst.afw.display.%s" % backend):
81 if dt.startswith(
"."):
82 impargs[
"package"] =
"lsst.display" 84 _disp = importlib.import_module(dt, **impargs)
86 except (ImportError, SystemError)
as e:
92 if not _disp
or not hasattr(_disp.DisplayImpl,
"_show"):
98 "Could not load the requested backend: {}".format(backend))
101 _impl = _disp.DisplayImpl(display, *args, **kwargs)
102 if not hasattr(_impl,
"frame"):
103 _impl.frame = display.frame
112 _defaultBackend =
None 114 _defaultMaskPlaneColor = dict(
121 DETECTED_NEGATIVE=CYAN,
128 _defaultMaskTransparency = {}
130 def __init__(self, frame=None, backend=None, *args, **kwargs):
131 """!Create an object able to display images and overplot glyphs 133 @param frame An identifier for the display 134 @param backend The backend to use (defaults to value set by setDefaultBackend()) 135 @param args Arguments to pass to the backend 136 @param kwargs Arguments to pass to the backend 142 if Display._defaultBackend
is None:
148 backend = Display._defaultBackend
151 self.
_impl = _makeDisplayImpl(self, backend, *args, **kwargs)
161 for ik
in range(ord(
'a'), ord(
'z') + 1):
166 for k
in (
'Return',
'Shift_L',
'Shift_R'):
169 for k
in (
'q',
'Escape'):
172 def _h_callback(k, x, y):
177 print(
" %-6s %s" % (k, doc.split(
"\n")[0]
if doc
else "???"))
181 Display._displays[frame] = self
184 """!Support for python's with statement""" 188 """!Support for python's with statement""" 195 """Return the attribute of self._impl, or ._impl if it is requested 199 name of the attribute requested 203 the attribute of self._impl for the requested name 207 return object.__getattr__(self, name)
209 if not (hasattr(self,
"_impl")
and self.
_impl):
210 raise AttributeError(
"Device has no _impl attached")
213 return getattr(self.
_impl, name)
214 except AttributeError:
215 raise AttributeError(
216 "Device %s has no attribute \"%s\"" % (self.
name, name))
219 if getattr(self,
"_impl",
None)
is not None:
224 if self.
frame in Display._displays:
225 del Display._displays[self.
frame]
229 """!The backend's verbosity""" 230 return self.
_impl.verbose
235 self.
_impl.verbose = value
238 return "Display[%s]" % (self.
frame)
246 _makeDisplayImpl(
None, backend)
247 except Exception
as e:
249 "Unable to set backend to %s: \"%s\"" % (backend, e))
251 Display._defaultBackend = backend
255 return Display._defaultBackend
259 """Set the default frame for display""" 260 Display._defaultFrame = frame
264 """Get the default frame for display""" 265 return Display._defaultFrame
269 """Increment the default frame for display""" 270 Display._defaultFrame += 1
271 return Display._defaultFrame
275 if hasattr(maskPlaneTransparency,
"copy"):
276 maskPlaneTransparency = maskPlaneTransparency.copy()
278 Display._defaultMaskTransparency = maskPlaneTransparency
282 """!Set the default mapping from mask plane names to colours 283 @param name name of mask plane, or a dict mapping names to colours 284 @param color Desired color, or None if name is a dict 286 If name is None, use the hard-coded default dictionary 290 name = Display._defaultMaskPlaneColor
292 if isinstance(name, dict):
294 for k, v
in name.items():
300 Display._defaultMaskPlaneColor[name] = color
303 def getDisplay(frame=None, backend=None, create=True, verbose=False, *args, **kwargs):
304 """!Return the Display indexed by frame, creating it if needs be 306 @param frame The desired frame (None => use defaultFrame (see setDefaultFrame)) 307 @param backend create the specified frame using this backend (or the default if None) \ 308 if it doesn't already exist. If backend == "", it's an error to specify a non-existent frame 309 @param create create the display if it doesn't already exist. 310 @param verbose Allow backend to be chatty 311 @param args arguments passed to Display constructor 312 @param kwargs keyword arguments passed to Display constructor 316 frame = Display._defaultFrame
318 if frame
not in Display._displays:
320 raise RuntimeError(
"Frame %s does not exist" % frame)
322 Display._displays[frame] =
Display(
323 frame, backend, verbose=verbose, *args, **kwargs)
325 Display._displays[frame].verbose = verbose
326 return Display._displays[frame]
330 """!Delete and close all known display 332 for disp
in list(Display._displays.values()):
334 Display._displays = {}
337 """!A generator for "standard" colours 339 @param omitBW Don't include Black and White 342 colorGenerator = interface.maskColorGenerator(omitBW=True) 344 print p, next(colorGenerator) 346 _maskColors = [WHITE, BLACK, RED, GREEN,
347 BLUE, CYAN, MAGENTA, YELLOW, ORANGE]
352 color = _maskColors[i%len(_maskColors)]
353 if omitBW
and color
in (BLACK, WHITE):
359 """!Request that mask plane name be displayed as color 361 @param name Name of mask plane or a dictionary of name -> colourName 362 @param color The name of the colour to use (must be None if name is a dict) 364 Colours may be specified as any X11-compliant string (e.g. <tt>"orchid"</tt>), or by one 365 of the following constants defined in @c afwDisplay: @c BLACK, @c WHITE, @c RED, @c BLUE, 366 @c GREEN, @c CYAN, @c MAGENTA, @c YELLOW. 368 If the colour is "ignore" (or @c IGNORE) then that mask plane is not displayed 370 The advantage of using the symbolic names is that the python interpreter can detect typos. 374 if isinstance(name, dict):
376 for k, v
in name.items():
383 """!Return the colour associated with the specified mask plane name 385 @param name Desired mask plane; if None, return entire dict 394 """!Specify display's mask transparency (percent); or None to not set it when loading masks""" 396 if isinstance(transparency, dict):
398 for k, v
in transparency.items():
402 if transparency
is not None and (transparency < 0
or transparency > 100):
404 "Mask transparency should be in the range [0, 100]; clipping", file=sys.stderr)
410 if transparency
is not None:
411 self.
_impl._setMaskTransparency(transparency, name)
414 """!Return the current display's mask transparency""" 416 return self.
_impl._getMaskTransparency(name)
419 """!Uniconify and Raise display. N.b. throws an exception if frame doesn't exit""" 420 return self.
_impl._show()
422 def mtv(self, data, title="", wcs=None):
423 """!Display an Image or Mask on a DISPLAY display 425 Historical note: the name "mtv" comes from Jim Gunn's forth imageprocessing 426 system, Mirella (named after Mirella Freni); The "m" stands for Mirella. 428 if hasattr(data,
"getXY0"):
429 self.
_xy0 = data.getXY0()
437 "You may not specify a wcs with an Exposure")
438 data, wcs = data.getMaskedImage(), data.getWcs()
440 data, wcs = data.getImage(), afwGeom.makeSkyWcs(data.getMetadata())
441 self.
_xy0 = data.getXY0()
444 self.
_impl._mtv(data,
None, wcs, title)
451 self.
_impl._mtv(afwImage.ImageI(data.getArray()), data, wcs, title)
454 self.
_impl._mtv(data.getImage(), data.getMask(), wcs, title)
456 raise RuntimeError(
"Unsupported type %s" % repr(data))
462 """A class intended to be used with python's with statement""" 468 self.
_impl._buffer(
True)
471 self.
_impl._buffer(
False)
475 """Return a class intended to be used with python's with statement 477 with display.Buffering(): 478 display.dot("+", xc, yc) 483 """!Flush the buffers""" 487 """!Erase the specified DISPLAY frame 491 def dot(self, symb, c, r, size=2, ctype=None, origin=afwImage.PARENT, *args, **kwargs):
492 """!Draw a symbol onto the specified DISPLAY frame at (col,row) = (c,r) 493 [0-based coordinates] 500 @:Mxx,Mxy,Myy Draw an ellipse with moments (Mxx, Mxy, Myy) (argument size is ignored) 501 An object derived from afwGeom.ellipses.BaseCore Draw the ellipse (argument size is ignored) 502 Any other value is interpreted as a string to be drawn. Strings obey the fontFamily (which may be 503 extended with other characteristics, e.g. "times bold italic". Text will be drawn rotated by 504 textAngle (textAngle is ignored otherwise). 506 N.b. objects derived from BaseCore include Axes and Quadrupole. 508 if isinstance(symb, int):
511 if origin == afwImage.PARENT
and self.
_xy0 is not None:
516 if isinstance(symb, afwGeom.ellipses.BaseCore)
or re.search(
r"^@:", symb):
518 mat = re.search(
r"^@:([^,]+),([^,]+),([^,]+)", symb)
523 mxx, mxy, myy = [float(_)
for _
in mat.groups()]
524 symb = afwGeom.Quadrupole(mxx, myy, mxy)
526 symb = afwGeom.ellipses.Axes(symb)
528 self.
_impl._dot(symb, c, r, size, ctype, **kwargs)
530 def line(self, points, origin=afwImage.PARENT, symbs=False, ctype=None, size=0.5):
531 """!Draw a set of symbols or connect the points, a list of (col,row) 532 If symbs is True, draw points at the specified points using the desired symbol, 533 otherwise connect the dots. Ctype is the name of a colour (e.g. 'red') 535 If symbs supports indexing (which includes a string -- caveat emptor) the 536 elements are used to label the points 542 symbs = len(points)*
list(symbs)
544 for i, xy
in enumerate(points):
545 self.
dot(symbs[i], *xy, size=size, ctype=ctype)
548 if origin == afwImage.PARENT
and self.
_xy0 is not None:
550 _points =
list(points)
551 for i, p
in enumerate(points):
552 _points[i] = (p[0] - x0, p[1] - y0)
555 self.
_impl._drawLines(points, ctype)
560 def scale(self, algorithm, min, max=None, unit=None, *args, **kwargs):
561 """!Set the range of the scaling from DN in the image to the image display 562 @param algorithm Desired scaling (e.g. "linear" or "asinh") 563 @param min Minimum value, or "minmax" or "zscale" 564 @param max Maximum value (must be None for minmax|zscale) 565 @param unit Units for min and max (e.g. Percent, Absolute, Sigma; None if min==minmax|zscale) 566 @param *args Optional arguments 567 @param **kwargs Optional keyword arguments 569 if min
in (
"minmax",
"zscale"):
570 assert max
is None,
"You may not specify \"%s\" and max" % min
571 assert unit
is None,
"You may not specify \"%s\" and unit" % min
573 raise RuntimeError(
"Please specify max")
575 self.
_impl._scale(algorithm, min, max, unit, *args, **kwargs)
580 def zoom(self, zoomfac=None, colc=None, rowc=None, origin=afwImage.PARENT):
581 """!Zoom frame by specified amount, optionally panning also""" 583 if (rowc
and colc
is None)
or (colc
and rowc
is None):
585 "Please specify row and column center to pan about")
588 if origin == afwImage.PARENT
and self.
_xy0 is not None:
593 self.
_impl._pan(colc, rowc)
595 if zoomfac
is None and rowc
is None:
598 if zoomfac
is not None:
599 self.
_impl._zoom(zoomfac)
601 def pan(self, colc=None, rowc=None, origin=afwImage.PARENT):
602 """!Pan to (rowc, colc); see also zoom""" 604 self.
zoom(
None, colc, rowc, origin)
607 """!Enter an interactive loop, listening for key presses in display and firing callbacks. 608 Exit with q, @c CR, @c ESC, or any other callback function that returns a ``True`` value. 610 interactFinished =
False 612 while not interactFinished:
613 ev = self.
_impl._getEvent()
616 k, x, y = ev.k, ev.x, ev.y
619 logger.warn(
"No callback registered for {0}".format(k))
622 interactFinished = self.
_callbacks[k](k, x, y)
623 except Exception
as e:
625 "Display._callbacks['{0}']({0},{1},{2}) failed: {3}".format(k, x, y, e))
628 """!Set the callback for key k to be func, returning the old callback 635 "Key '%s' is already in use by display, so I can't add a callback for it" % k)
638 self.
_callbacks[k] = func
if func
else noop_callback
645 """!Return all callback keys 646 @param onlyActive If true only return keys that do something 650 not (onlyActive
and func == noop_callback)])
658 """!A class to handle events such as key presses in image display windows""" 660 def __init__(self, k, x=float(
'nan'), y=float(
'nan')):
666 return "%s (%.2f, %.2f)" % (self.
k, self.
x, self.
y)
673 """!Callback function: arguments key, x, y""" 678 print(
"Enter q or <ESC> to leave interactive mode, h for this help, or a letter to fire a callback")
689 Display.setDefaultBackend(backend)
693 return Display.getDefaultBackend()
697 return Display.setDefaultFrame(frame)
701 """Get the default frame for display""" 702 return Display.getDefaultFrame()
706 """Increment the default frame for display""" 707 return Display.incrDefaultFrame()
711 return Display.setDefaultMaskTransparency(maskPlaneTransparency)
715 """!Set the default mapping from mask plane names to colours 716 @param name name of mask plane, or a dict mapping names to colours 717 @param color Desired color, or None if name is a dict 719 If name is None, use the hard-coded default dictionary 722 return Display.setDefaultMaskPlaneColor(name, color)
725 def getDisplay(frame=None, backend=None, create=True, verbose=False, *args, **kwargs):
726 """!Return the Display indexed by frame, creating it if needs be 728 See Display.getDisplay 730 @param frame The desired frame (None => use defaultFrame (see setDefaultFrame)) 731 @param backend create the specified frame using this backend (or the default if None) \ 732 if it doesn't already exist. If backend == "", it's an error to specify a non-existent frame 733 @param create create the display if it doesn't already exist. 734 @param verbose Allow backend to be chatty 735 @param args arguments passed to Display constructor 736 @param kwargs keyword arguments passed to Display constructor 739 return Display.getDisplay(frame, backend, create, verbose, *args, **kwargs)
743 """!Delete and close all known display 745 return Display.delAllDisplays()
def pan(self, colc=None, rowc=None, origin=afwImage.PARENT)
Pan to (rowc, colc); see also zoom.
def dot(self, symb, c, r, size=2, ctype=None, origin=afwImage.PARENT, args, kwargs)
Draw a symbol onto the specified DISPLAY frame at (col,row) = (c,r) [0-based coordinates].
def maskColorGenerator(self, omitBW=True)
A generator for "standard" colours.
def verbose(self)
The backend's verbosity.
def getDisplay(frame=None, backend=None, create=True, verbose=False, args, kwargs)
Return the Display indexed by frame, creating it if needs be.
def noop_callback(k, x, y)
Callback function: arguments key, x, y.
std::vector< SchemaItem< Flag > > * items
A class to contain the data, WCS, and other information needed to describe an image of the sky...
def setDefaultMaskPlaneColor(name=None, color=None)
Set the default mapping from mask plane names to colours.
def __getattr__(self, name)
def setDefaultMaskTransparency(maskPlaneTransparency={})
def getDisplay(frame=None, backend=None, create=True, verbose=False, args, kwargs)
Return the Display indexed by frame, creating it if needs be.
def setCallback(self, k, func=None, noRaise=False)
Set the callback for key k to be func, returning the old callback.
def __init__(self, k, x=float('nan'), y=float('nan'))
def erase(self)
Erase the specified DISPLAY frame.
def flush(self)
Flush the buffers.
def delAllDisplays()
Delete and close all known display.
def getActiveCallbackKeys(self, onlyActive=True)
Return all callback keys.
A class to handle events such as key presses in image display windows.
Represent a 2-dimensional array of bitmask pixels.
def getMaskPlaneColor(self, name=None)
Return the colour associated with the specified mask plane name.
def setDefaultFrame(frame=0)
def setDefaultBackend(backend)
def __enter__(self)
Support for python's with statement.
def scale(self, algorithm, min, max=None, unit=None, args, kwargs)
Set the range of the scaling from DN in the image to the image display.
A class to manipulate images, masks, and variance as a single object.
def __init__(self, _impl)
def __init__(self, frame=None, backend=None, args, kwargs)
Create an object able to display images and overplot glyphs.
def mtv(self, data, title="", wcs=None)
Display an Image or Mask on a DISPLAY display.
def __exit__(self, args)
Support for python's with statement.
def setDefaultMaskPlaneColor(name=None, color=None)
Set the default mapping from mask plane names to colours.
def line(self, points, origin=afwImage.PARENT, symbs=False, ctype=None, size=0.5)
Draw a set of symbols or connect the points, a list of (col,row) If symbs is True, draw points at the specified points using the desired symbol, otherwise connect the dots.
def setMaskPlaneColor(self, name, color=None)
Request that mask plane name be displayed as color.
def getMaskTransparency(self, name=None)
Return the current display's mask transparency.
def delAllDisplays()
Delete and close all known display.
def setDefaultBackend(backend)
def interact(self)
Enter an interactive loop, listening for key presses in display and firing callbacks.
daf::base::PropertyList * list
def setDefaultFrame(frame=0)
static Log getLogger(std::string const &loggername)
def setMaskTransparency(self, transparency=None, name=None)
Specify display's mask transparency (percent); or None to not set it when loading masks...
def zoom(self, zoomfac=None, colc=None, rowc=None, origin=afwImage.PARENT)
Zoom frame by specified amount, optionally panning also.
A class to represent a 2-dimensional array of pixels.
def setDefaultMaskTransparency(maskPlaneTransparency={})
A container for an Image and its associated metadata.
def show(self)
Uniconify and Raise display.