LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Classes | Functions | Variables
lsst.afw.display.ds9 Namespace Reference

Classes

class  Ds9Error
 An error talking to ds9. More...
 
class  Buffer
 
class  Buffering
 

Functions

def selectFrame
 
def setFrame0
 
def setDefaultFrame
 
def getDefaultFrame
 
def incrDefaultFrame
 
def setMaskPlaneColor
 
def getMaskPlaneColor
 
def setMaskPlaneVisibility
 
def getMaskPlaneVisibility
 
def setMaskTransparency
 
def getDesiredMaskTransparency
 
def getMaskTransparency
 
def getXpaAccessPoint
 
def ds9Version
 
def ds9Cmd
 
def initDS9
 
def show
 
def setMaskColor
 
def mtv
 
def _mtv
 
def buffer
 
def erase
 
def dot
 
def line
 
def scale
 
def zoom
 
def pan
 
def interact
 
def noop_callback
 
def setCallback
 
def getActiveCallbackKeys
 Return all callback keys. More...
 
def _h_callback
 

Variables

 needShow = True;
 
 _currentFrame = None
 
string WHITE = "white"
 
string BLACK = "black"
 
string RED = "red"
 
string GREEN = "green"
 
string BLUE = "blue"
 
string CYAN = "cyan"
 
string MAGENTA = "magenta"
 
string YELLOW = "yellow"
 
list _maskColors = [WHITE, BLACK, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW]
 
 _maskTransparency = None
 
int XPA_SZ_LINE = 4096
 
tuple haveGzip = notos.system("gzip < /dev/null > /dev/null 2>&1")
 
tuple flush = lambda:cmdBuffer.flush(silent=True)
 
dictionary callbacks = {}
 
string k = "%c"
 

Function Documentation

def lsst.afw.display.ds9._h_callback (   k,
  x,
  y 
)
private

Definition at line 857 of file ds9.py.

858  def _h_callback(k, x, y):
859  print "Enter q or <ESC> to leave interactive mode, h for this help, or a letter to fire a callback"
860  return False
def lsst.afw.display.ds9._mtv (   data,
  wcs,
  title,
  isMask 
)
private
Internal routine to display an Image or Mask on a DS9 display

Definition at line 525 of file ds9.py.

526 def _mtv(data, wcs, title, isMask):
527  """Internal routine to display an Image or Mask on a DS9 display"""
528 
529  title = str(title) if title else ""
530 
531  if True:
532  if isMask:
533  xpa_cmd = "xpaset %s fits mask" % getXpaAccessPoint()
534  if re.search(r"unsigned short|boost::uint16_t", data.__str__()):
535  data |= 0x8000 # Hack. ds9 mis-handles BZERO/BSCALE in masks. This is a copy we're modifying
536  else:
537  xpa_cmd = "xpaset %s fits" % getXpaAccessPoint()
538 
539  if haveGzip:
540  xpa_cmd = "gzip | " + xpa_cmd
541 
542  pfd = os.popen(xpa_cmd, "w")
543  else:
544  pfd = file("foo.fits", "w")
545 
546  try:
547  displayLib.writeFitsImage(pfd.fileno(), data, wcs, title)
548  except Exception, e:
549  try:
550  pfd.close()
551  except:
552  pass
553 
554  raise e
555 
556  try:
557  pfd.close()
558  except:
559  pass
560 #
561 # Graphics commands
#
def getXpaAccessPoint
Definition: ds9.py:205
def lsst.afw.display.ds9.buffer (   enable = True)

Definition at line 562 of file ds9.py.

563 def buffer(enable=True):
564  if enable:
565  cmdBuffer.pushSize()
566  else:
567  cmdBuffer.popSize()
def lsst.afw.display.ds9.dot (   symb,
  c,
  r,
  frame = None,
  size = 2,
  ctype = None,
  fontFamily = "helvetica",
  silent = True,
  textAngle = None 
)
Draw a symbol onto the specified DS9 frame at (col,row) = (c,r) [0-based coordinates]
Possible values are:
    +                Draw a +
    x                Draw an x
    *                Draw a *
    o                Draw a circle
    @:Mxx,Mxy,Myy    Draw an ellipse with moments (Mxx, Mxy, Myy) (argument size is ignored)
    An object derived from afwGeom.ellipses.BaseCore Draw the ellipse (argument size is ignored)
Any other value is interpreted as a string to be drawn. Strings obey the fontFamily (which may be extended
with other characteristics, e.g. "times bold italic".  Text will be drawn rotated by textAngle (textAngle is
ignored otherwise).

N.b. objects derived from BaseCore include Axes and Quadrupole.
Examples:
image2.cc, and maskedImage2.cc.

Definition at line 591 of file ds9.py.

592 def dot(symb, c, r, frame=None, size=2, ctype=None, fontFamily="helvetica", silent=True, textAngle=None):
593  """Draw a symbol onto the specified DS9 frame at (col,row) = (c,r) [0-based coordinates]
594 Possible values are:
595  + Draw a +
596  x Draw an x
597  * Draw a *
598  o Draw a circle
599  @:Mxx,Mxy,Myy Draw an ellipse with moments (Mxx, Mxy, Myy) (argument size is ignored)
600  An object derived from afwGeom.ellipses.BaseCore Draw the ellipse (argument size is ignored)
601 Any other value is interpreted as a string to be drawn. Strings obey the fontFamily (which may be extended
602 with other characteristics, e.g. "times bold italic". Text will be drawn rotated by textAngle (textAngle is
603 ignored otherwise).
604 
605 N.b. objects derived from BaseCore include Axes and Quadrupole.
606 """
607  if frame is None:
608  frame = getDefaultFrame()
609 
610  if frame is None:
611  return
612 
613  if isinstance(symb, int):
614  symb = "%d" % (symb)
615 
616  if ctype == None:
617  color = "" # the default
618  else:
619  color = ' # color=%s' % ctype
620 
621  cmd = selectFrame(frame) + "; "
622  r += 1
623  c += 1 # ds9 uses 1-based coordinates
624  if isinstance(symb, afwGeom.ellipses.BaseCore) or re.search(r"^@:", symb):
625  try:
626  mat = re.search(r"^@:([^,]+),([^,]+),([^,]+)", symb)
627  except TypeError:
628  pass
629  else:
630  if mat:
631  mxx, mxy, myy = [float(_) for _ in mat.groups()]
632  symb = afwGeom.ellipses.Quadrupole(mxx, myy, mxy)
633 
634  symb = afwGeom.ellipses.Axes(symb)
635  cmd += 'regions command {ellipse %g %g %g %g %g%s}; ' % (c, r, symb.getA(), symb.getB(),
636  math.degrees(symb.getTheta()), color)
637  elif symb == '+':
638  cmd += 'regions command {line %g %g %g %g%s}; ' % (c, r+size, c, r-size, color)
639  cmd += 'regions command {line %g %g %g %g%s}; ' % (c-size, r, c+size, r, color)
640  elif symb == 'x':
641  size = size/math.sqrt(2)
642  cmd += 'regions command {line %g %g %g %g%s}; ' % (c+size, r+size, c-size, r-size, color)
643  cmd += 'regions command {line %g %g %g %g%s}; ' % (c-size, r+size, c+size, r-size, color)
644  elif symb == '*':
645  size30 = 0.5*size
646  size60 = 0.5*math.sqrt(3)*size
647  cmd += 'regions command {line %g %g %g %g%s}; ' % (c+size, r, c-size, r, color)
648  cmd += 'regions command {line %g %g %g %g%s}; ' % (c-size30, r+size60, c+size30, r-size60, color)
649  cmd += 'regions command {line %g %g %g %g%s}; ' % (c+size30, r+size60, c-size30, r-size60, color)
650  elif symb == 'o':
651  cmd += 'regions command {circle %g %g %g%s}; ' % (c, r, size, color)
652  else:
653  try:
654  # We have to check for the frame's existance with show() as the text command crashed ds9 5.4
655  # if it doesn't
656  if needShow:
657  show(frame)
658 
659  color = re.sub("^ # ", "", color) # skip the leading " # "
660 
661  angle = ""
662  if textAngle is not None:
663  angle += " textangle=%.1f"%(textAngle)
664 
665  font = ""
666  if size != 2 or fontFamily != "helvetica":
667  fontFamily = fontFamily.split()
668  font += ' font="%s %d' % (fontFamily.pop(0), int(10*size/2.0 + 0.5))
669  if fontFamily:
670  font += " %s" % " ".join(fontFamily)
671  font += '"'
672  extra = ""
673  if color or angle or font:
674  extra = " # "
675  extra += color
676  extra += angle
677  extra += font
678 
679  cmd += 'regions command {text %g %g \"%s\"%s };' % (c, r, symb, extra)
680  except Exception, e:
681  print >> sys.stderr, ("Ds9 frame %d doesn't exist" % frame), e
682 
683  ds9Cmd(cmd, silent=silent)
def getDefaultFrame
Definition: ds9.py:78
def lsst.afw.display.ds9.ds9Cmd (   cmd = None,
  trap = True,
  flush = False,
  silent = True,
  frame = None,
  get = False 
)
Issue a ds9 command, raising errors as appropriate

Definition at line 313 of file ds9.py.

314 def ds9Cmd(cmd=None, trap=True, flush=False, silent=True, frame=None, get=False):
315  """Issue a ds9 command, raising errors as appropriate"""
316 
317  if getDefaultFrame() is None:
318  return
319 
320  global cmdBuffer
321  if cmd:
322  if frame is not None:
323  cmd = "%s;" % selectFrame(frame) + cmd
324 
325  if get:
326  return xpa.get(None, getXpaAccessPoint(), cmd, "").strip()
327 
328  # Work around xpa's habit of silently truncating long lines
329  if cmdBuffer._lenCommands + len(cmd) > XPA_SZ_LINE - 5: # 5 to handle newlines and such like
330  ds9Cmd(flush=True, silent=silent)
331 
332  cmdBuffer._commands += ";" + cmd
333  cmdBuffer._lenCommands += 1 + len(cmd)
334 
335  if flush or cmdBuffer._lenCommands >= cmdBuffer._getSize():
336  cmd = cmdBuffer._commands + "\n"
337  cmdBuffer._commands = ""
338  cmdBuffer._lenCommands = 0
339  else:
340  return
341 
342  cmd = cmd.rstrip()
343  if not cmd:
344  return
345 
346  try:
347  ret = xpa.set(None, getXpaAccessPoint(), cmd, "", "", 0)
348  if ret:
349  raise IOError(ret)
350  except IOError, e:
351  if not trap:
352  raise Ds9Error, "XPA: %s, (%s)" % (e, cmd)
353  elif not silent:
354  print >> sys.stderr, "Caught ds9 exception processing command \"%s\": %s" % (cmd, e)
def getXpaAccessPoint
Definition: ds9.py:205
def getDefaultFrame
Definition: ds9.py:78
def lsst.afw.display.ds9.ds9Version ( )
Return the version of ds9 in use, as a string

Definition at line 221 of file ds9.py.

222 def ds9Version():
223  """Return the version of ds9 in use, as a string"""
224  try:
225  v = ds9Cmd("about", get=True)
226  return v.splitlines()[1].split()[1]
227  except Exception, e:
228  print >> sys.stderr, "Error reading version: %s" % e
229  return "0.0.0"
230 
231 try:
cmdBuffer
def lsst.afw.display.ds9.erase (   frame = None)
Erase the specified DS9 frame
Examples:
forEachPixel.cc.

Definition at line 581 of file ds9.py.

582 def erase(frame=None):
583  """Erase the specified DS9 frame"""
584  if frame is None:
585  frame = getDefaultFrame()
586 
587  if frame is None:
588  return
589 
590  ds9Cmd("regions delete all", flush=True, frame=frame)
def getDefaultFrame
Definition: ds9.py:78
def lsst.afw.display.ds9.getActiveCallbackKeys (   onlyActive = True)

Return all callback keys.

Parameters
onlyActiveIf true only return keys that do something

Definition at line 832 of file ds9.py.

833 def getActiveCallbackKeys(onlyActive=True):
834  """!Return all callback keys
835 \param onlyActive If true only return keys that do something
836  """
837 
838  return sorted([k for k, func in callbacks.items() if not (onlyActive and func == noop_callback)])
839 
840 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
841 
842 try:
callbacks
def getActiveCallbackKeys
Return all callback keys.
Definition: ds9.py:832
def lsst.afw.display.ds9.getDefaultFrame ( )
Get the default frame for ds9

Definition at line 78 of file ds9.py.

78 
79  def getDefaultFrame():
80  """Get the default frame for ds9"""
81  return _defaultFrame
def getDefaultFrame
Definition: ds9.py:78
def lsst.afw.display.ds9.getDesiredMaskTransparency ( )
Return requested ds9's mask transparency

Definition at line 193 of file ds9.py.

195  """Return requested ds9's mask transparency"""
196 
197  return _maskTransparency
def getDesiredMaskTransparency
Definition: ds9.py:193
def lsst.afw.display.ds9.getMaskPlaneColor (   name)
Return the colour associated with the specified mask plane name

Definition at line 137 of file ds9.py.

138 def getMaskPlaneColor(name):
139  """Return the colour associated with the specified mask plane name"""
140 
141  if _maskPlaneColors.has_key(name):
142  return _maskPlaneColors[name]
143  else:
144  return None
def getMaskPlaneColor
Definition: ds9.py:137
def lsst.afw.display.ds9.getMaskPlaneVisibility (   name)
Should we display the specified mask plane name?

Definition at line 164 of file ds9.py.

165 def getMaskPlaneVisibility(name):
166  """Should we display the specified mask plane name?"""
167 
168  if _maskPlaneVisibility.has_key(name):
169  return _maskPlaneVisibility[name]
170  else:
171  return True
172 
173 try:
_maskTransparency
def getMaskPlaneVisibility
Definition: ds9.py:164
def lsst.afw.display.ds9.getMaskTransparency (   frame = None)
Return the current ds9's mask transparency

Definition at line 198 of file ds9.py.

199 def getMaskTransparency(frame=None):
200  """Return the current ds9's mask transparency"""
201 
202  return float(ds9Cmd("mask transparency", get=True))
203 
204 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def getMaskTransparency
Definition: ds9.py:198
def lsst.afw.display.ds9.getXpaAccessPoint ( )
Parse XPA_PORT and send return an identifier to send ds9 commands there, instead of "ds9"
If you don't have XPA_PORT set, the usual xpans tricks will be played when we return "ds9".

Definition at line 205 of file ds9.py.

206 def getXpaAccessPoint():
207  """Parse XPA_PORT and send return an identifier to send ds9 commands there, instead of "ds9"
208  If you don't have XPA_PORT set, the usual xpans tricks will be played when we return "ds9".
209  """
210  xpa_port = os.environ.get("XPA_PORT")
211  if xpa_port:
212  mat = re.search(r"^DS9:ds9\s+(\d+)\s+(\d+)", xpa_port)
213  if mat:
214  port1, port2 = mat.groups()
215 
216  return "127.0.0.1:%s" % (port1)
217  else:
218  print >> sys.stderr, "Failed to parse XPA_PORT=%s" % xpa_port
219 
220  return "ds9"
def getXpaAccessPoint
Definition: ds9.py:205
def lsst.afw.display.ds9.incrDefaultFrame ( )
Increment the default frame for ds9

Definition at line 82 of file ds9.py.

82 
83  def incrDefaultFrame():
84  """Increment the default frame for ds9"""
85  global _defaultFrame
86  _defaultFrame += 1
87  return _defaultFrame
def incrDefaultFrame
Definition: ds9.py:82
def lsst.afw.display.ds9.initDS9 (   execDs9 = True)

Definition at line 355 of file ds9.py.

356 def initDS9(execDs9=True):
357  try:
358  xpa.reset()
359  ds9Cmd("iconify no; raise", False)
360  ds9Cmd("wcs wcsa", False) # include the pixel coordinates WCS (WCSA)
361 
362  v0, v1 = ds9Version().split('.')[0:2]
363  global needShow
364  needShow = False
365  try:
366  if int(v0) == 5:
367  needShow = (int(v1) <= 4)
368  except:
369  pass
370  except Ds9Error, e:
371  if execDs9:
372  print "ds9 doesn't appear to be running (%s), I'll exec it for you" % e
373  if not re.search('xpa', os.environ['PATH']):
374  raise Ds9Error, 'You need the xpa binaries in your path to use ds9 with python'
375 
376  os.system('ds9 &')
377  for i in range(10):
378  try:
379  ds9Cmd(selectFrame(1), False)
380  break
381  except Ds9Error:
382  print "waiting for ds9...\r",
383  sys.stdout.flush()
384  time.sleep(0.5)
385  else:
386  print " \r",
387  break
388 
389  sys.stdout.flush()
390 
391  raise Ds9Error
def lsst.afw.display.ds9.interact ( )
Enter an interactive loop, listening for key presses in ds9 and firing callbacks.

Exit with q, <carriage return>, or <escape>

Definition at line 781 of file ds9.py.

782 def interact():
783  """Enter an interactive loop, listening for key presses in ds9 and firing callbacks.
784 
785  Exit with q, <carriage return>, or <escape>
786 """
787 
788  while True:
789  vals = ds9Cmd("imexam key coordinate", get=True).split()
790  if vals[0] == "XPA$ERROR":
791  if vals[1:4] == ['unknown', 'option', '"-state"']:
792  pass # a ds9 bug --- you get this by hitting TAB
793  else:
794  print >> sys.stderr, "Error return from imexam:", " ".join(vals)
795  continue
796 
797  k = vals.pop(0)
798  try:
799  x = float(vals[0]); y = float(vals[1])
800  except:
801  x = float("NaN"); y = float("NaN")
802 
803  try:
804  if callbacks[k](k, x, y):
805  break
806  except KeyError:
807  print >> sys.stderr, "No callback is registered for %s" % k
808  except Exception, e:
809  print >> sys.stderr, "ds9.callbacks[%s](%s, %s, %s) failed: %s" % \
810  (k, k, x, y, e)
811 
812 #
813 # Default fallback function
#
def lsst.afw.display.ds9.line (   points,
  frame = None,
  symbs = False,
  ctype = None 
)
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.  Ctype is the name of a colour (e.g. 'red')

Definition at line 684 of file ds9.py.

685 def line(points, frame=None, symbs=False, ctype=None):
686  """Draw a set of symbols or connect the points, a list of (col,row)
687 If symbs is True, draw points at the specified points using the desired symbol,
688 otherwise connect the dots. Ctype is the name of a colour (e.g. 'red')"""
689 
690  if frame is None:
691  frame = getDefaultFrame()
692 
693  if frame is None:
694  return
695 
696  if symbs:
697  for (c, r) in points:
698  dot(symbs, r, c, frame=frame, size=0.5, ctype=ctype)
699  else:
700  if ctype == None: # default
701  color = ""
702  else:
703  color = "# color=%s" % ctype
704 
705  if len(points) > 0:
706  cmd = selectFrame(frame) + "; "
707 
708  c0, r0 = points[0]
709  r0 += 1
710  c0 += 1 # ds9 uses 1-based coordinates
711  for (c, r) in points[1:]:
712  r += 1
713  c += 1 # ds9 uses 1-based coordinates
714  cmd += 'regions command { line %g %g %g %g %s};' % (c0, r0, c, r, color)
715  c0, r0 = c, r
716 
717  ds9Cmd(cmd)
718 #
719 # Set gray scale
#
def getDefaultFrame
Definition: ds9.py:78
def lsst.afw.display.ds9.mtv (   data,
  frame = None,
  init = True,
  wcs = None,
  isMask = False,
  lowOrderBits = False,
  title = None,
  settings = None 
)
Display an Image or Mask on a DS9 display

If lowOrderBits is True, give low-order-bits priority in display (i.e.
overlay them last)

Historical note: the name "mtv" comes from Jim Gunn's forth imageprocessing
system, Mirella (named after Mirella Freni); The "m" stands for Mirella.

Definition at line 407 of file ds9.py.

408 def mtv(data, frame=None, init=True, wcs=None, isMask=False, lowOrderBits=False, title=None, settings=None):
409  """Display an Image or Mask on a DS9 display
410 
411  If lowOrderBits is True, give low-order-bits priority in display (i.e.
412  overlay them last)
413 
414  Historical note: the name "mtv" comes from Jim Gunn's forth imageprocessing
415  system, Mirella (named after Mirella Freni); The "m" stands for Mirella.
416  """
417 
418  if frame is None:
419  frame = getDefaultFrame()
420 
421  if frame is None:
422  return
423 
424  if init:
425  for i in range(3):
426  try:
427  initDS9(i == 0)
428  except Ds9Error:
429  print "waiting for ds9...\r",
430  sys.stdout.flush()
431  time.sleep(0.5)
432  else:
433  if i > 0:
434  print " \r",
435  sys.stdout.flush()
436  break
437 
438  ds9Cmd(selectFrame(frame))
439  ds9Cmd("smooth no")
440  erase(frame)
441 
442  if settings:
443  for setting in settings:
444  ds9Cmd("%s %s" % (setting, settings[setting]))
445 
446  if re.search("::DecoratedImage<", repr(data)): # it's a DecorateImage; display it
447  _mtv(data.getImage(), wcs, title, False)
448  elif re.search("::MaskedImage<", repr(data)): # it's a MaskedImage; display Image and overlay Mask
449  _mtv(data.getImage(), wcs, title, False)
450  mask = data.getMask(True)
451  if mask:
452  mtv(mask, frame, False, wcs, True, lowOrderBits=lowOrderBits, title=title, settings=settings)
453  if getDesiredMaskTransparency() is not None:
454  ds9Cmd("mask transparency %d" % getDesiredMaskTransparency())
455 
456  elif re.search("::Exposure<", repr(data)): # it's an Exposure; display the MaskedImage with the WCS
457  if wcs:
458  raise RuntimeError, "You may not specify a wcs with an Exposure"
459 
460  mtv(data.getMaskedImage(), frame, False, data.getWcs(),
461  False, lowOrderBits=lowOrderBits, title=title, settings=settings)
462 
463  elif re.search("::Mask<", repr(data)): # it's a Mask; display it, bitplane by bitplane
464  maskPlanes = data.getMaskPlaneDict()
465  nMaskPlanes = max(maskPlanes.values()) + 1
466 
467  planes = {} # build inverse dictionary
468  for key in maskPlanes.keys():
469  planes[maskPlanes[key]] = key
470 
471  colorIndex = 0 # index into maskColors
472 
473  if lowOrderBits:
474  planeList = range(nMaskPlanes - 1, -1, -1)
475  else:
476  planeList = range(nMaskPlanes)
477 
478  usedPlanes = long(afwMath.makeStatistics(data, afwMath.SUM).getValue())
479  mask = data.Factory(data.getDimensions())
480  #
481  # ds9 can't display a Mask without an image; so display an Image first
482  #
483  if not isMask:
484  im = afwImage.ImageU(data.getDimensions())
485  mtv(im, frame=frame)
486 
487  for p in planeList:
488  if planes.get(p):
489  pname = planes[p]
490  if not getMaskPlaneVisibility(pname):
491  continue
492  else:
493  pname = "unknown"
494 
495  if not getMaskPlaneVisibility(pname):
496  continue
497 
498  if not ((1 << p) & usedPlanes): # no pixels have this bitplane set
499  continue
500 
501  mask <<= data
502  mask &= (1 << p)
503 
504  color = getMaskPlaneColor(pname)
505 
506  if not color: # none was specified
507  while True:
508  color = _maskColors[colorIndex % len(_maskColors)]
509  colorIndex += 1
510  if color != WHITE and color != BLACK:
511  break
512 
513  setMaskColor(color)
514  _mtv(mask, wcs, title, True)
515  return
516  elif re.search("::Image<", repr(data)): # it's an Image; display it
517  _mtv(data, wcs, title, False)
518  else:
519  raise RuntimeError, "Unsupported type %s" % repr(data)
520 
521 try:
haveGzip
def getMaskPlaneVisibility
Definition: ds9.py:164
def getMaskPlaneColor
Definition: ds9.py:137
double max
Definition: attributes.cc:218
def getDefaultFrame
Definition: ds9.py:78
def getDesiredMaskTransparency
Definition: ds9.py:193
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1023
def lsst.afw.display.ds9.noop_callback (   k,
  x,
  y 
)
Callback function: arguments key, x, y

Definition at line 814 of file ds9.py.

815 def noop_callback(k, x, y):
816  """Callback function: arguments key, x, y"""
817  return False
def lsst.afw.display.ds9.pan (   colc = None,
  rowc = None,
  frame = None 
)
Pan to (rowc, colc); see also zoom

Definition at line 768 of file ds9.py.

769 def pan(colc=None, rowc=None, frame=None):
770  """Pan to (rowc, colc); see also zoom"""
771 
772  if frame is None:
773  frame = getDefaultFrame()
774 
775  if frame is None:
776  return
777 
778  zoom(None, colc, rowc, frame)
779 
780 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def getDefaultFrame
Definition: ds9.py:78
def lsst.afw.display.ds9.scale (   min = None,
  max = None,
  type = None,
  frame = None 
)

Definition at line 720 of file ds9.py.

721 def scale(min=None, max=None, type=None, frame=None):
722  if type is None:
723  if min is None and max is None:
724  raise Ds9Error("Please specify min and max, or a stretch type, or both")
725  else:
726  ds9Cmd("scale %s" % type, frame=frame)
727 
728  if min is None:
729  if max is not None:
730  raise Ds9Error("Please specify min")
731  else:
732  if max is None:
733  raise Ds9Error("Please specify max")
734  ds9Cmd("scale limits %g %g" % (min, max), frame=frame)
735 
736 #
737 # Zoom and Pan
#
An error talking to ds9.
Definition: ds9.py:47
def lsst.afw.display.ds9.selectFrame (   frame)

Definition at line 55 of file ds9.py.

55 
56  def selectFrame(frame):
57  global _currentFrame
58  if frame != _currentFrame:
59  ds9Cmd(flush=True)
60  _currentFrame = frame
61 
62  return "frame %d" % (frame + _frame0)
def lsst.afw.display.ds9.setCallback (   k,
  func = noop_callback,
  noRaise = False 
)
Set the callback for key k to be func, returning the old callback

Definition at line 818 of file ds9.py.

819 def setCallback(k, func=noop_callback, noRaise=False):
820  """Set the callback for key k to be func, returning the old callback
821  """
822 
823  if k in "f":
824  if noRaise:
825  return
826  raise RuntimeError("Key '%s' is already in use by ds9, so I can't add a callback for it" % k)
827 
828  ofunc = callbacks.get(k)
829  callbacks[k] = func
830 
831  return ofunc
def lsst.afw.display.ds9.setDefaultFrame (   frame = 0)
Set the default frame for ds9

Definition at line 73 of file ds9.py.

73 
74  def setDefaultFrame(frame=0):
75  """Set the default frame for ds9"""
76  global _defaultFrame
77  _defaultFrame = frame
def setDefaultFrame
Definition: ds9.py:73
def lsst.afw.display.ds9.setFrame0 (   frame0)
Add frame0 to all frame specifications

Definition at line 63 of file ds9.py.

63 
64  def setFrame0(frame0):
65  """Add frame0 to all frame specifications"""
66  global _frame0
67  _frame0 = frame0
def lsst.afw.display.ds9.setMaskColor (   color = GREEN)
Set the ds9 mask colour to; eg. setMaskColor(RED)

Definition at line 402 of file ds9.py.

403 def setMaskColor(color=GREEN):
404  """Set the ds9 mask colour to; eg. setMaskColor(RED)"""
405  ds9Cmd("mask color %s" % color)
406 
def lsst.afw.display.ds9.setMaskPlaneColor (   name,
  color = None 
)
Request that mask plane name be displayed as color; name may be a dictionary
(in which case color should be omitted

Definition at line 102 of file ds9.py.

103 def setMaskPlaneColor(name, color=None):
104  """Request that mask plane name be displayed as color; name may be a dictionary
105  (in which case color should be omitted"""
106 
107  if isinstance(name, dict):
108  assert color == None
109  for k in name.keys():
110  setMaskPlaneColor(k, name[k])
111  return
112 
113  global _maskPlaneColors
114  try:
115  type(_maskPlaneColors)
116  except:
117  _maskPlaneColors = {}
118 
119  _maskPlaneColors[name] = color
120 
121 #
122 # Default mapping from mask plane names to colours
123 #
125  "BAD": RED,
126  "CR" : MAGENTA,
127  "EDGE": YELLOW,
128  "INTERPOLATED" : GREEN,
129  "SATURATED" : GREEN,
130  "DETECTED" : BLUE,
131  "DETECTED_NEGATIVE" : CYAN,
132  "SUSPECT" : YELLOW,
133  # deprecated names
134  "INTRP" : GREEN,
135  "SAT" : GREEN,
136  })
def setMaskPlaneColor
Definition: ds9.py:102
def lsst.afw.display.ds9.setMaskPlaneVisibility (   name,
  show = True 
)
Specify the visibility of a given mask plane;
name may be a dictionary (in which case show will be ignored)

Definition at line 145 of file ds9.py.

146 def setMaskPlaneVisibility(name, show=True):
147  """Specify the visibility of a given mask plane;
148  name may be a dictionary (in which case show will be ignored)"""
149 
150  global _maskPlaneVisibility
151  try:
152  type(_maskPlaneVisibility)
153  except NameError, e:
154  _maskPlaneVisibility = {}
155 
156  if isinstance(name, dict):
157  for k in name.keys():
158  setMaskPlaneVisibility(k, name[k])
159  return
160 
161  _maskPlaneVisibility[name] = show
162 
def setMaskPlaneVisibility
Definition: ds9.py:145
def lsst.afw.display.ds9.setMaskTransparency (   transparency = None,
  frame = None 
)
Specify ds9's mask transparency (percent); or None to not set it when loading masks

Definition at line 177 of file ds9.py.

178 def setMaskTransparency(transparency=None, frame=None):
179  """Specify ds9's mask transparency (percent); or None to not set it when loading masks"""
180 
181  global _maskTransparency
182  if transparency is not None and (transparency < 0 or transparency > 100):
183  print >> sys.stderr, "Mask transparency should be in the range [0, 100]; clipping"
184  if transparency < 0:
185  transparency = 0
186  else:
187  transparency = 100
188 
189  _maskTransparency = transparency
190 
191  if transparency is not None:
192  ds9Cmd("mask transparency %d" % transparency, frame=frame)
def setMaskTransparency
Definition: ds9.py:177
def lsst.afw.display.ds9.show (   frame = None)
Uniconify and Raise ds9.  N.b. throws an exception if frame doesn't exit

Definition at line 392 of file ds9.py.

393 def show(frame=None):
394  """Uniconify and Raise ds9. N.b. throws an exception if frame doesn't exit"""
395  if frame is None:
396  frame = getDefaultFrame()
397 
398  if frame is None:
399  return
400 
401  ds9Cmd("raise", trap=False, frame=frame)
def getDefaultFrame
Definition: ds9.py:78
def lsst.afw.display.ds9.zoom (   zoomfac = None,
  colc = None,
  rowc = None,
  frame = None 
)
Zoom frame by specified amount, optionally panning also

Definition at line 738 of file ds9.py.

739 def zoom(zoomfac=None, colc=None, rowc=None, frame=None):
740  """Zoom frame by specified amount, optionally panning also"""
741 
742  if frame < 0:
743  frame = getDefaultFrame()
744 
745  if frame is None:
746  return
747 
748  if frame is None:
749  frame = getDefaultFrame()
750 
751  if frame is None:
752  return
753 
754  if (rowc and colc is None) or (colc and rowc is None):
755  raise Ds9Error, "Please specify row and column center to pan about"
756 
757  if zoomfac == None and rowc == None:
758  zoomfac = 2
759 
760  cmd = selectFrame(frame) + "; "
761  if zoomfac != None:
762  cmd += "zoom to %d; " % zoomfac
763 
764  if rowc != None:
765  cmd += "pan to %g %g physical; " % (colc + 1, rowc + 1) # ds9 is 1-indexed. Grrr
766 
767  ds9Cmd(cmd, flush=True)
def getDefaultFrame
Definition: ds9.py:78

Variable Documentation

lsst.afw.display.ds9._currentFrame = None

Definition at line 53 of file ds9.py.

list lsst.afw.display.ds9._maskColors = [WHITE, BLACK, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW]

Definition at line 100 of file ds9.py.

lsst.afw.display.ds9._maskTransparency = None

Definition at line 175 of file ds9.py.

string lsst.afw.display.ds9.BLACK = "black"

Definition at line 93 of file ds9.py.

string lsst.afw.display.ds9.BLUE = "blue"

Definition at line 96 of file ds9.py.

dictionary lsst.afw.display.ds9.callbacks = {}

Definition at line 844 of file ds9.py.

string lsst.afw.display.ds9.CYAN = "cyan"

Definition at line 97 of file ds9.py.

tuple lsst.afw.display.ds9.flush = lambda:cmdBuffer.flush(silent=True)

Definition at line 568 of file ds9.py.

string lsst.afw.display.ds9.GREEN = "green"

Definition at line 95 of file ds9.py.

tuple lsst.afw.display.ds9.haveGzip = notos.system("gzip < /dev/null > /dev/null 2>&1")

Definition at line 523 of file ds9.py.

string lsst.afw.display.ds9.k = "%c"
Examples:
imageStatistics.cc, and tunnelDs9.

Definition at line 847 of file ds9.py.

string lsst.afw.display.ds9.MAGENTA = "magenta"

Definition at line 98 of file ds9.py.

lsst.afw.display.ds9.needShow = True;

Definition at line 44 of file ds9.py.

string lsst.afw.display.ds9.RED = "red"

Definition at line 94 of file ds9.py.

string lsst.afw.display.ds9.WHITE = "white"

Definition at line 92 of file ds9.py.

int lsst.afw.display.ds9.XPA_SZ_LINE = 4096

Definition at line 233 of file ds9.py.

string lsst.afw.display.ds9.YELLOW = "yellow"

Definition at line 99 of file ds9.py.