LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+ffe7eabc7e,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g36da64cc00+ea84795170,g3ddfee87b4+955a963fd8,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+955a963fd8,g591dd9f2cf+bac198a2cb,g5ec818987f+420292cfeb,g858d7b2824+d6c9a0a3b8,g876c692160+aabc49a3c3,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+e6cd765486,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+acd47f83f4,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+12c8382528,gba4ed39666+1ac82b564f,gbb8dafda3b+0574160a1f,gbeb006f7da+dea2fbb49f,gc28159a63d+c6dfa2ddaf,gc86a011abf+d6c9a0a3b8,gcf0d15dbbd+955a963fd8,gdaeeff99f8+1cafcb7cd4,gdc0c513512+d6c9a0a3b8,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,gee10cc3b42+90ebb246c7,gf1cff7945b+d6c9a0a3b8,w.2024.13
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
lsst.display.ds9.ds9.DisplayImpl Class Reference
Inheritance diagram for lsst.display.ds9.ds9.DisplayImpl:

Public Member Functions

 __init__ (self, display, verbose=False, *args, **kwargs)
 

Protected Member Functions

 _close (self)
 
 _setMaskTransparency (self, transparency, maskplane)
 
 _getMaskTransparency (self, maskplane)
 
 _show (self)
 
 _mtv (self, image, mask=None, wcs=None, title="")
 
 _buffer (self, enable=True)
 
 _flush (self)
 
 _erase (self)
 
 _dot (self, symb, c, r, size, ctype, fontFamily="helvetica", textAngle=None)
 
 _drawLines (self, points, ctype)
 
 _scale (self, algorithm, min, max, unit, *args, **kwargs)
 
 _zoom (self, zoomfac)
 
 _pan (self, colc, rowc)
 
 _getEvent (self)
 

Detailed Description

Virtual device display implementation.

Definition at line 344 of file ds9.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.display.ds9.ds9.DisplayImpl.__init__ ( self,
display,
verbose = False,
* args,
** kwargs )

Definition at line 348 of file ds9.py.

348 def __init__(self, display, verbose=False, *args, **kwargs):
349 virtualDevice.DisplayImpl.__init__(self, display, verbose)
350

Member Function Documentation

◆ _buffer()

lsst.display.ds9.ds9.DisplayImpl._buffer ( self,
enable = True )
protected
Push and pop buffer size.

Parameters
----------
enable : `bool`, optional
    If `True` (default), push size; else pop it.

Definition at line 464 of file ds9.py.

464 def _buffer(self, enable=True):
465 """Push and pop buffer size.
466
467 Parameters
468 ----------
469 enable : `bool`, optional
470 If `True` (default), push size; else pop it.
471 """
472 if enable:
473 cmdBuffer.pushSize()
474 else:
475 cmdBuffer.popSize()
476

◆ _close()

lsst.display.ds9.ds9.DisplayImpl._close ( self)
protected
Called when the device is closed.

Definition at line 351 of file ds9.py.

351 def _close(self):
352 """Called when the device is closed.
353 """
354 pass
355

◆ _dot()

lsst.display.ds9.ds9.DisplayImpl._dot ( self,
symb,
c,
r,
size,
ctype,
fontFamily = "helvetica",
textAngle = None )
protected
Draw a symbol onto the specified DS9 frame.

Parameters
----------
symb : `str`, or subclass of `lsst.afw.geom.ellipses.BaseCore`
    Symbol to be drawn. 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);(the ``size`` parameter is ignored)
    - An object derived from `lsst.afw.geom.ellipses.BaseCore`: Draw
      the ellipse (argument size is ignored)

    Any other value is interpreted as a string to be drawn.
c : `int`
    Column to draw symbol [0-based coordinates].
r : `int`
    Row to draw symbol [0-based coordinates].
size : `float`
    Size of symbol.
ctype : `str`
    the name of a colour (e.g. ``"red"``)
fontFamily : `str`, optional
    String font. May be extended with other characteristics,
    e.g. ``"times bold italic"``.
textAngle: `float`, optional
    Text will be drawn rotated by ``textAngle``.

Notes
-----
Objects derived from `lsst.afw.geom.ellipses.BaseCore` include
`~lsst.afw.geom.ellipses.Axes` and `lsst.afw.geom.ellipses.Quadrupole`.

Definition at line 487 of file ds9.py.

487 def _dot(self, symb, c, r, size, ctype, fontFamily="helvetica", textAngle=None):
488 """Draw a symbol onto the specified DS9 frame.
489
490 Parameters
491 ----------
492 symb : `str`, or subclass of `lsst.afw.geom.ellipses.BaseCore`
493 Symbol to be drawn. Possible values are:
494
495 - ``"+"``: Draw a "+"
496 - ``"x"``: Draw an "x"
497 - ``"*"``: Draw a "*"
498 - ``"o"``: Draw a circle
499 - ``"@:Mxx,Mxy,Myy"``: Draw an ellipse with moments (Mxx, Mxy,
500 Myy);(the ``size`` parameter is ignored)
501 - An object derived from `lsst.afw.geom.ellipses.BaseCore`: Draw
502 the ellipse (argument size is ignored)
503
504 Any other value is interpreted as a string to be drawn.
505 c : `int`
506 Column to draw symbol [0-based coordinates].
507 r : `int`
508 Row to draw symbol [0-based coordinates].
509 size : `float`
510 Size of symbol.
511 ctype : `str`
512 the name of a colour (e.g. ``"red"``)
513 fontFamily : `str`, optional
514 String font. May be extended with other characteristics,
515 e.g. ``"times bold italic"``.
516 textAngle: `float`, optional
517 Text will be drawn rotated by ``textAngle``.
518
519 Notes
520 -----
521 Objects derived from `lsst.afw.geom.ellipses.BaseCore` include
522 `~lsst.afw.geom.ellipses.Axes` and `lsst.afw.geom.ellipses.Quadrupole`.
523 """
524 cmd = selectFrame(self.display.frame) + "; "
525 for region in ds9Regions.dot(symb, c, r, size, ctype, fontFamily, textAngle):
526 cmd += f'regions command {{{region}}}; '
527
528 ds9Cmd(cmd, silent=True)
529

◆ _drawLines()

lsst.display.ds9.ds9.DisplayImpl._drawLines ( self,
points,
ctype )
protected
Connect the points.

Parameters
-----------
points : `list` of (`int`, `int`)
    A list of points specified as (col, row).
ctype : `str`
    The name of a colour (e.g. ``"red"``).

Definition at line 530 of file ds9.py.

530 def _drawLines(self, points, ctype):
531 """Connect the points.
532
533 Parameters
534 -----------
535 points : `list` of (`int`, `int`)
536 A list of points specified as (col, row).
537 ctype : `str`
538 The name of a colour (e.g. ``"red"``).
539 """
540 cmd = selectFrame(self.display.frame) + "; "
541 for region in ds9Regions.drawLines(points, ctype):
542 cmd += f'regions command {{{region}}}; '
543
544 ds9Cmd(cmd)
545

◆ _erase()

lsst.display.ds9.ds9.DisplayImpl._erase ( self)
protected
Erase all regions in current frame.

Definition at line 482 of file ds9.py.

482 def _erase(self):
483 """Erase all regions in current frame.
484 """
485 ds9Cmd("regions delete all", flush=True, frame=self.display.frame)
486

◆ _flush()

lsst.display.ds9.ds9.DisplayImpl._flush ( self)
protected
Flush buffer.

Definition at line 477 of file ds9.py.

477 def _flush(self):
478 """Flush buffer.
479 """
480 cmdBuffer.flush()
481

◆ _getEvent()

lsst.display.ds9.ds9.DisplayImpl._getEvent ( self)
protected
Listen for a key press on a frame in DS9 and return an event.

Returns
-------
event : `Ds9Event`
    Event with (key, x, y).

Definition at line 607 of file ds9.py.

607 def _getEvent(self):
608 """Listen for a key press on a frame in DS9 and return an event.
609
610 Returns
611 -------
612 event : `Ds9Event`
613 Event with (key, x, y).
614 """
615 vals = ds9Cmd("imexam key coordinate", get=True).split()
616 if vals[0] == "XPA$ERROR":
617 if vals[1:4] == ['unknown', 'option', '"-state"']:
618 pass # a ds9 bug --- you get this by hitting TAB
619 else:
620 print("Error return from imexam:", " ".join(vals), file=sys.stderr)
621 return None
622
623 k = vals.pop(0)
624 try:
625 x = float(vals[0])
626 y = float(vals[1])
627 except Exception:
628 x = float("NaN")
629 y = float("NaN")
630
631 return Ds9Event(k, x, y)
632
633

◆ _getMaskTransparency()

lsst.display.ds9.ds9.DisplayImpl._getMaskTransparency ( self,
maskplane )
protected
Return the current DS9's mask transparency.

Parameters
----------
maskplane : unused
    This parameter does nothing.

Definition at line 373 of file ds9.py.

373 def _getMaskTransparency(self, maskplane):
374 """Return the current DS9's mask transparency.
375
376 Parameters
377 ----------
378 maskplane : unused
379 This parameter does nothing.
380 """
381 selectFrame(self.display.frame)
382 return float(ds9Cmd("mask transparency", get=True))
383

◆ _mtv()

lsst.display.ds9.ds9.DisplayImpl._mtv ( self,
image,
mask = None,
wcs = None,
title = "" )
protected
Display an Image and/or Mask on a DS9 display.

Parameters
----------
image : subclass of `lsst.afw.image.Image`
    Image to display.
mask : subclass of `lsst.afw.image.Mask`, optional
    Mask.
wcs : `lsst.afw.geom.SkyWcs`, optional
    WCS of data
title : `str`, optional
    Title of image.

Definition at line 393 of file ds9.py.

393 def _mtv(self, image, mask=None, wcs=None, title=""):
394 """Display an Image and/or Mask on a DS9 display.
395
396 Parameters
397 ----------
398 image : subclass of `lsst.afw.image.Image`
399 Image to display.
400 mask : subclass of `lsst.afw.image.Mask`, optional
401 Mask.
402 wcs : `lsst.afw.geom.SkyWcs`, optional
403 WCS of data
404 title : `str`, optional
405 Title of image.
406 """
407
408 for i in range(3):
409 try:
410 initDS9(i == 0)
411 except Ds9Error:
412 print("waiting for ds9...\r", end="")
413 sys.stdout.flush()
414 time.sleep(0.5)
415 else:
416 if i > 0:
417 print(" \r", end="")
418 sys.stdout.flush()
419 break
420
421 ds9Cmd(selectFrame(self.display.frame))
422 ds9Cmd("smooth no")
423 self._erase()
424
425 if image:
426 _i_mtv(image, wcs, title, False)
427
428 if mask:
429 maskPlanes = mask.getMaskPlaneDict()
430 nMaskPlanes = max(maskPlanes.values()) + 1
431
432 planes = {} # build inverse dictionary
433 for key in maskPlanes:
434 planes[maskPlanes[key]] = key
435
436 planeList = range(nMaskPlanes)
437 usedPlanes = int(afwMath.makeStatistics(mask, afwMath.SUM).getValue())
438 mask1 = mask.Factory(mask.getBBox()) # Mask containing just one bitplane
439
440 colorGenerator = self.display.maskColorGenerator(omitBW=True)
441 for p in planeList:
442 if planes.get(p):
443 pname = planes[p]
444
445 if not ((1 << p) & usedPlanes): # no pixels have this bitplane set
446 continue
447
448 mask1[:] = mask
449 mask1 &= (1 << p)
450
451 color = self.display.getMaskPlaneColor(pname)
452
453 if not color: # none was specified
454 color = next(colorGenerator)
455 elif color.lower() == "ignore":
456 continue
457
458 ds9Cmd(f"mask color {color}")
459 _i_mtv(mask1, wcs, title, True)
int max
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
Definition Statistics.h:361

◆ _pan()

lsst.display.ds9.ds9.DisplayImpl._pan ( self,
colc,
rowc )
protected
Pan frame.

Parameters
----------
colc : `int`
    Physical column to which to pan.
rowc : `int`
    Physical row to which to pan.

Definition at line 591 of file ds9.py.

591 def _pan(self, colc, rowc):
592 """Pan frame.
593
594 Parameters
595 ----------
596 colc : `int`
597 Physical column to which to pan.
598 rowc : `int`
599 Physical row to which to pan.
600 """
601 cmd = selectFrame(self.display.frame) + "; "
602 # ds9 is 1-indexed. Grrr
603 cmd += f"pan to {colc + 1:g} {rowc + 1:g} physical; "
604
605 ds9Cmd(cmd, flush=True)
606

◆ _scale()

lsst.display.ds9.ds9.DisplayImpl._scale ( self,
algorithm,
min,
max,
unit,
* args,
** kwargs )
protected
Set image color scale.

Parameters
----------
algorithm : {``"linear"``, ``"log"``, ``"pow"``, ``"sqrt"``, ``"squared"``, ``"asinh"``, ``"sinh"``, ``"histequ"``}  # noqa: E501
    Scaling algorithm. May be any value supported by DS9.
min : `float`
    Minimum value for scale.
max : `float`
    Maximum value for scale.
unit : `str`
    Ignored.
*args
    Ignored.
**kwargs
    Ignored

Definition at line 546 of file ds9.py.

546 def _scale(self, algorithm, min, max, unit, *args, **kwargs):
547 """Set image color scale.
548
549 Parameters
550 ----------
551 algorithm : {``"linear"``, ``"log"``, ``"pow"``, ``"sqrt"``, ``"squared"``, ``"asinh"``, ``"sinh"``, ``"histequ"``} # noqa: E501
552 Scaling algorithm. May be any value supported by DS9.
553 min : `float`
554 Minimum value for scale.
555 max : `float`
556 Maximum value for scale.
557 unit : `str`
558 Ignored.
559 *args
560 Ignored.
561 **kwargs
562 Ignored
563 """
564 if algorithm:
565 ds9Cmd(f"scale {algorithm}", frame=self.display.frame)
566
567 if min in ("minmax", "zscale"):
568 ds9Cmd(f"scale mode {min}")
569 else:
570 if unit:
571 print(f"ds9: ignoring scale unit {unit}")
572
573 ds9Cmd(f"scale limits {min:g} {max:g}", frame=self.display.frame)

◆ _setMaskTransparency()

lsst.display.ds9.ds9.DisplayImpl._setMaskTransparency ( self,
transparency,
maskplane )
protected
Specify DS9's mask transparency.

Parameters
----------
transparency : `int`
    Percent transparency.
maskplane : `NoneType`
    If `None`, transparency is enabled. Otherwise, this parameter is
    ignored.

Definition at line 356 of file ds9.py.

356 def _setMaskTransparency(self, transparency, maskplane):
357 """Specify DS9's mask transparency.
358
359 Parameters
360 ----------
361 transparency : `int`
362 Percent transparency.
363 maskplane : `NoneType`
364 If `None`, transparency is enabled. Otherwise, this parameter is
365 ignored.
366 """
367 if maskplane is not None:
368 print(f"ds9 is unable to set transparency for individual maskplanes ({maskplane})",
369 file=sys.stderr)
370 return
371 ds9Cmd(f"mask transparency {transparency}", frame=self.display.frame)
372

◆ _show()

lsst.display.ds9.ds9.DisplayImpl._show ( self)
protected
Uniconify and raise DS9.

Notes
-----
Raises if ``self.display.frame`` doesn't exist.

Definition at line 384 of file ds9.py.

384 def _show(self):
385 """Uniconify and raise DS9.
386
387 Notes
388 -----
389 Raises if ``self.display.frame`` doesn't exist.
390 """
391 ds9Cmd("raise", trap=False, frame=self.display.frame)
392

◆ _zoom()

lsst.display.ds9.ds9.DisplayImpl._zoom ( self,
zoomfac )
protected
Zoom frame by specified amount.

Parameters
----------
zoomfac : `int`
    DS9 zoom factor.

Definition at line 578 of file ds9.py.

578 def _zoom(self, zoomfac):
579 """Zoom frame by specified amount.
580
581 Parameters
582 ----------
583 zoomfac : `int`
584 DS9 zoom factor.
585 """
586 cmd = selectFrame(self.display.frame) + "; "
587 cmd += f"zoom to {zoomfac}; "
588
589 ds9Cmd(cmd, flush=True)
590

The documentation for this class was generated from the following file: