LSST Applications g02d81e74bb+86cf3d8bc9,g180d380827+7a4e862ed4,g2079a07aa2+86d27d4dc4,g2305ad1205+e1ca1c66fa,g29320951ab+012e1474a1,g295015adf3+341ea1ce94,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+c429d67c83,g48712c4677+f88676dd22,g487adcacf7+27e1e21933,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+b41db86c35,g5a732f18d5+53520f316c,g64a986408d+86cf3d8bc9,g858d7b2824+86cf3d8bc9,g8a8a8dda67+585e252eca,g99cad8db69+84912a7fdc,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+a2b54eae19,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+6681f309db,gc120e1dc64+f0fcc2f6d8,gc28159a63d+0e5473021a,gcf0d15dbbd+c429d67c83,gdaeeff99f8+f9a426f77a,ge6526c86ff+0433e6603d,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+86cf3d8bc9,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lsst.display.matplotlib.matplotlib.DisplayImpl Class Reference
Inheritance diagram for lsst.display.matplotlib.matplotlib.DisplayImpl:

Public Member Functions

 __init__ (self, display, verbose=False, interpretMaskBits=True, mtvOrigin=afwImage.PARENT, fastMaskDisplay=False, reopenPlot=False, useSexagesimal=False, dpi=None, *args, **kwargs)
 
 savefig (self, *args, **kwargs)
 
 show_colorbar (self, show=True, where="right", axSize="5%", axPad=None, **kwargs)
 
 useSexagesimal (self, useSexagesimal)
 
 wait (self, prompt="[c(ontinue) p(db)] :", allowPdb=True)
 

Protected Member Functions

 _close (self)
 Close the display, cleaning up any allocated resources.
 
 _show (self)
 
 _setMaskTransparency (self, transparency, maskplane)
 
 _getMaskTransparency (self, maskplane=None)
 
 _mtv (self, image, mask=None, wcs=None, title="")
 
 _i_mtv (self, data, wcs, title, isMask)
 
 _i_setImage (self, image, mask=None, wcs=None)
 
 _setImageColormap (self, cmap)
 
 _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, minval, maxval, unit, *args, **kwargs)
 
 _i_scale (self, algorithm, minval, maxval, unit, *args, **kwargs)
 
 _zoom (self, zoomfac)
 
 _pan (self, colc, rowc)
 
 _getEvent (self, timeout=-1)
 

Protected Attributes

 _figure
 
 _display
 
 _maskTransparency
 
 _interpretMaskBits
 
 _fastMaskDisplay
 
 _useSexagesimal
 
 _mtvOrigin
 
 _mappable_ax
 
 _colorbar_ax
 
 _image_colormap
 
 _scaleArgs
 
 _normalize
 
 _image
 
 _mask
 
 _wcs
 
 _title
 
 _xy0
 
 _zoomfac
 
 _width
 
 _height
 
 _xcen
 
 _ycen
 

Detailed Description

Provide a matplotlib backend for afwDisplay

Recommended backends in notebooks are:
  %matplotlib notebook
or
  %matplotlib ipympl
or
  %matplotlib qt
  %gui qt
or
  %matplotlib inline
or
  %matplotlib osx

Apparently only qt supports Display.interact(); the list of interactive
backends is given by lsst.display.matplotlib.interactiveBackends

Definition at line 82 of file matplotlib.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.display.matplotlib.matplotlib.DisplayImpl.__init__ ( self,
display,
verbose = False,
interpretMaskBits = True,
mtvOrigin = afwImage.PARENT,
fastMaskDisplay = False,
reopenPlot = False,
useSexagesimal = False,
dpi = None,
* args,
** kwargs )
Initialise a matplotlib display

@param fastMaskDisplay      If True only show the first bitplane that's
                            set in each pixel
                            (e.g. if (SATURATED & DETECTED)
                            ignore DETECTED)
                            Not really what we want, but a bit faster
@param interpretMaskBits    Interpret the mask value under the cursor
@param mtvOrigin            Display pixel coordinates with LOCAL origin
                            (bottom left == 0,0 not XY0)
@param reopenPlot           If true, close the plot before opening it.
                            (useful with e.g. %ipympl)
@param useSexagesimal       If True, display coordinates in sexagesimal
                            E.g. hh:mm:ss.ss (default:False)
                            May be changed by calling
                                  display.useSexagesimal()
@param dpi                  Number of dpi (passed to pyplot.figure)

The `frame` argument to `Display` may be a matplotlib figure; this
permits code such as
   fig, axes = plt.subplots(1, 2)

   disp = afwDisplay.Display(fig)
   disp.scale('asinh', 'zscale', Q=0.5)

   for axis, exp in zip(axes, exps):
      fig.sca(axis)    # make axis active
      disp.mtv(exp)

Definition at line 100 of file matplotlib.py.

102 reopenPlot=False, useSexagesimal=False, dpi=None, *args, **kwargs):
103 """
104 Initialise a matplotlib display
105
106 @param fastMaskDisplay If True only show the first bitplane that's
107 set in each pixel
108 (e.g. if (SATURATED & DETECTED)
109 ignore DETECTED)
110 Not really what we want, but a bit faster
111 @param interpretMaskBits Interpret the mask value under the cursor
112 @param mtvOrigin Display pixel coordinates with LOCAL origin
113 (bottom left == 0,0 not XY0)
114 @param reopenPlot If true, close the plot before opening it.
115 (useful with e.g. %ipympl)
116 @param useSexagesimal If True, display coordinates in sexagesimal
117 E.g. hh:mm:ss.ss (default:False)
118 May be changed by calling
119 display.useSexagesimal()
120 @param dpi Number of dpi (passed to pyplot.figure)
121
122 The `frame` argument to `Display` may be a matplotlib figure; this
123 permits code such as
124 fig, axes = plt.subplots(1, 2)
125
126 disp = afwDisplay.Display(fig)
127 disp.scale('asinh', 'zscale', Q=0.5)
128
129 for axis, exp in zip(axes, exps):
130 fig.sca(axis) # make axis active
131 disp.mtv(exp)
132 """
133 fig_class = matplotlib.figure.FigureBase
134
135 if isinstance(display.frame, fig_class):
136 figure = display.frame
137 else:
138 figure = None
139
140 virtualDevice.DisplayImpl.__init__(self, display, verbose)
141
142 if reopenPlot:
143 import matplotlib.pyplot as pyplot
144 pyplot.close(display.frame)
145
146 if figure is not None:
147 self._figure = figure
148 else:
149 import matplotlib.pyplot as pyplot
150 self._figure = pyplot.figure(display.frame, dpi=dpi)
151 self._figure.clf()
152
153 self._display = display
154 self._maskTransparency = {None: 0.7}
155 self._interpretMaskBits = interpretMaskBits # interpret mask bits in mtv
156 self._fastMaskDisplay = fastMaskDisplay
157 self._useSexagesimal = [useSexagesimal] # use an array so we can modify the value in format_coord
158 self._mtvOrigin = mtvOrigin
159 self._mappable_ax = None
160 self._colorbar_ax = None
161 self._image_colormap = matplotlib.cm.gray
162 #
163 self.__alpha = unicodedata.lookup("GREEK SMALL LETTER alpha") # used in cursor display string
164 self.__delta = unicodedata.lookup("GREEK SMALL LETTER delta") # used in cursor display string
165 #
166 # Support self._scale()
167 #
168 self._scaleArgs = dict()
169 self._normalize = None
170 #
171 # Support self._erase(), reporting pixel/mask values, and
172 # zscale/minmax; set in mtv
173 #
174 self._i_setImage(None)
175

Member Function Documentation

◆ _buffer()

lsst.display.matplotlib.matplotlib.DisplayImpl._buffer ( self,
enable = True )
protected

Definition at line 525 of file matplotlib.py.

525 def _buffer(self, enable=True):
526 if sys.modules.get('matplotlib.pyplot') is not None:
527 import matplotlib.pyplot as pyplot
528 if enable:
529 pyplot.ioff()
530 else:
531 pyplot.ion()
532 self._figure.show()
533

◆ _close()

lsst.display.matplotlib.matplotlib.DisplayImpl._close ( self)
protected

Close the display, cleaning up any allocated resources.

Definition at line 176 of file matplotlib.py.

176 def _close(self):
177 """!Close the display, cleaning up any allocated resources"""
178 self._image = None
179 self._mask = None
180 self._wcs = None
181 self._figure.gca().format_coord = lambda x, y: None # keeps a copy of _wcs
182

◆ _dot()

lsst.display.matplotlib.matplotlib.DisplayImpl._dot ( self,
symb,
c,
r,
size,
ctype,
fontFamily = "helvetica",
textAngle = None )
protected
Draw a symbol 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 afwGeom.ellipses.Axes 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).

Definition at line 546 of file matplotlib.py.

547 fontFamily="helvetica", textAngle=None):
548 """Draw a symbol at (col,row) = (c,r) [0-based coordinates]
549 Possible values are:
550 + Draw a +
551 x Draw an x
552 * Draw a *
553 o Draw a circle
554 @:Mxx,Mxy,Myy Draw an ellipse with moments
555 (Mxx, Mxy, Myy) (argument size is ignored)
556 An afwGeom.ellipses.Axes Draw the ellipse (argument size is
557 ignored)
558
559 Any other value is interpreted as a string to be drawn. Strings obey the
560 fontFamily (which may be extended with other characteristics, e.g.
561 "times bold italic". Text will be drawn rotated by textAngle
562 (textAngle is ignored otherwise).
563 """
564 if not ctype:
565 ctype = afwDisplay.GREEN
566
567 axis = self._figure.gca()
568 x0, y0 = self._xy0
569
570 if isinstance(symb, afwGeom.ellipses.Axes):
571 from matplotlib.patches import Ellipse
572
573 # Following matplotlib.patches.Ellipse documentation 'width' and
574 # 'height' are diameters while 'angle' is rotation in degrees
575 # (anti-clockwise)
576 axis.add_artist(Ellipse((c + x0, r + y0), height=2*symb.getA(), width=2*symb.getB(),
577 angle=90.0 + math.degrees(symb.getTheta()),
578 edgecolor=mapCtype(ctype), facecolor='none'))
579 elif symb == 'o':
580 from matplotlib.patches import CirclePolygon as Circle
581
582 axis.add_artist(Circle((c + x0, r + y0), radius=size, color=mapCtype(ctype), fill=False))
583 else:
584 from matplotlib.lines import Line2D
585
586 for ds9Cmd in ds9Regions.dot(symb, c + x0, r + y0, size, fontFamily="helvetica", textAngle=None):
587 tmp = ds9Cmd.split('#')
588 cmd = tmp.pop(0).split()
589
590 cmd, args = cmd[0], cmd[1:]
591
592 if cmd == "line":
593 args = np.array(args).astype(float) - 1.0
594
595 x = np.empty(len(args)//2)
596 y = np.empty_like(x)
597 i = np.arange(len(args), dtype=int)
598 x = args[i%2 == 0]
599 y = args[i%2 == 1]
600
601 axis.add_line(Line2D(x, y, color=mapCtype(ctype)))
602 elif cmd == "text":
603 x, y = np.array(args[0:2]).astype(float) - 1.0
604 axis.text(x, y, symb, color=mapCtype(ctype),
605 horizontalalignment='center', verticalalignment='center')
606 else:
607 raise RuntimeError(ds9Cmd)
608

◆ _drawLines()

lsst.display.matplotlib.matplotlib.DisplayImpl._drawLines ( self,
points,
ctype )
protected
Connect the points, a list of (col,row)
Ctype is the name of a colour (e.g. 'red')

Definition at line 609 of file matplotlib.py.

609 def _drawLines(self, points, ctype):
610 """Connect the points, a list of (col,row)
611 Ctype is the name of a colour (e.g. 'red')"""
612
613 from matplotlib.lines import Line2D
614
615 if not ctype:
616 ctype = afwDisplay.GREEN
617
618 points = np.array(points)
619 x = points[:, 0] + self._xy0[0]
620 y = points[:, 1] + self._xy0[1]
621
622 self._figure.gca().add_line(Line2D(x, y, color=mapCtype(ctype)))
623

◆ _erase()

lsst.display.matplotlib.matplotlib.DisplayImpl._erase ( self)
protected
Erase the display

Definition at line 537 of file matplotlib.py.

537 def _erase(self):
538 """Erase the display"""
539
540 for axis in self._figure.axes:
541 axis.lines = []
542 axis.texts = []
543
544 self._figure.canvas.draw_idle()
545

◆ _flush()

lsst.display.matplotlib.matplotlib.DisplayImpl._flush ( self)
protected

Definition at line 534 of file matplotlib.py.

534 def _flush(self):
535 pass
536

◆ _getEvent()

lsst.display.matplotlib.matplotlib.DisplayImpl._getEvent ( self,
timeout = -1 )
protected
Listen for a key press, returning (key, x, y)

Definition at line 731 of file matplotlib.py.

731 def _getEvent(self, timeout=-1):
732 """Listen for a key press, returning (key, x, y)"""
733
734 if timeout < 0:
735 timeout = 24*3600 # -1 generates complaints in QTimer::singleShot. A day is a long time
736
737 mpBackend = matplotlib.get_backend()
738 if mpBackend not in interactiveBackends:
739 print("The %s matplotlib backend doesn't support display._getEvent()" %
740 (matplotlib.get_backend(),), file=sys.stderr)
741 return interface.Event('q')
742
743 event = None
744
745 # We set up a blocking event loop. On receipt of a keypress, the
746 # callback records the event and unblocks the loop.
747
748 def recordKeypress(keypress):
749 """Matplotlib callback to record keypress and unblock"""
750 nonlocal event
751 event = interface.Event(keypress.key, keypress.xdata, keypress.ydata)
752 self._figure.canvas.stop_event_loop()
753
754 conn = self._figure.canvas.mpl_connect("key_press_event", recordKeypress)
755 try:
756 self._figure.canvas.start_event_loop(timeout=timeout) # Blocks on keypress
757 finally:
758 self._figure.canvas.mpl_disconnect(conn)
759 return event
760
761
762# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
763
764

◆ _getMaskTransparency()

lsst.display.matplotlib.matplotlib.DisplayImpl._getMaskTransparency ( self,
maskplane = None )
protected
Return the current mask transparency

Definition at line 315 of file matplotlib.py.

315 def _getMaskTransparency(self, maskplane=None):
316 """Return the current mask transparency"""
317 return self._maskTransparency[maskplane if maskplane in self._maskTransparency else None]
318

◆ _i_mtv()

lsst.display.matplotlib.matplotlib.DisplayImpl._i_mtv ( self,
data,
wcs,
title,
isMask )
protected
Internal routine to display an Image or Mask on a DS9 display

Definition at line 401 of file matplotlib.py.

401 def _i_mtv(self, data, wcs, title, isMask):
402 """Internal routine to display an Image or Mask on a DS9 display"""
403
404 title = str(title) if title else ""
405 dataArr = data.getArray()
406
407 if isMask:
408 maskPlanes = data.getMaskPlaneDict()
409 nMaskPlanes = max(maskPlanes.values()) + 1
410
411 planes = {} # build inverse dictionary
412 for key in maskPlanes:
413 planes[maskPlanes[key]] = key
414
415 planeList = range(nMaskPlanes)
416
417 maskArr = np.zeros_like(dataArr, dtype=np.int32)
418
419 colorNames = ['black']
420 colorGenerator = self.display.maskColorGenerator(omitBW=True)
421 for p in planeList:
422 color = self.display.getMaskPlaneColor(planes[p]) if p in planes else None
423
424 if not color: # none was specified
425 color = next(colorGenerator)
426 elif color.lower() == afwDisplay.IGNORE:
427 color = 'black' # we'll set alpha = 0 anyway
428
429 colorNames.append(color)
430 #
431 # Convert those colours to RGBA so we can have per-mask-plane
432 # transparency and build a colour map
433 #
434 # Pixels equal to 0 don't get set (as no bits are set), so leave
435 # them transparent and start our colours at [1] --
436 # hence "i + 1" below
437 #
438 colors = mpColors.to_rgba_array(colorNames)
439 alphaChannel = 3 # the alpha channel; the A in RGBA
440 colors[0][alphaChannel] = 0.0 # it's black anyway
441 for i, p in enumerate(planeList):
442 if colorNames[i + 1] == 'black':
443 alpha = 0.0
444 else:
445 alpha = 1 - self._getMaskTransparency(planes[p] if p in planes else None)
446
447 colors[i + 1][alphaChannel] = alpha
448
449 cmap = mpColors.ListedColormap(colors)
450 norm = mpColors.NoNorm()
451 else:
452 cmap = self._image_colormap
453 norm = self._normalize
454
455 ax = self._figure.gca()
456 bbox = data.getBBox()
457 extent = (bbox.getBeginX() - 0.5, bbox.getEndX() - 0.5,
458 bbox.getBeginY() - 0.5, bbox.getEndY() - 0.5)
459
460 with matplotlib.rc_context(dict(interactive=False)):
461 if isMask:
462 for i, p in reversed(list(enumerate(planeList))):
463 if colors[i + 1][alphaChannel] == 0: # colors[0] is reserved
464 continue
465
466 bitIsSet = (dataArr & (1 << p)) != 0
467 if bitIsSet.sum() == 0:
468 continue
469
470 maskArr[bitIsSet] = i + 1 # + 1 as we set colorNames[0] to black
471
472 if not self._fastMaskDisplay: # we draw each bitplane separately
473 ax.imshow(maskArr, origin='lower', interpolation='nearest',
474 extent=extent, cmap=cmap, norm=norm)
475 maskArr[:] = 0
476
477 if self._fastMaskDisplay: # we only draw the lowest bitplane
478 ax.imshow(maskArr, origin='lower', interpolation='nearest',
479 extent=extent, cmap=cmap, norm=norm)
480 else:
481 # If we're playing with subplots and have reset the axis
482 # the cached colorbar axis belongs to the old one, so set
483 # it to None
484 if self._mappable_ax and self._mappable_ax[1] != self._figure.gca():
485 self._colorbar_ax = None
486
487 mappable = ax.imshow(dataArr, origin='lower', interpolation='nearest',
488 extent=extent, cmap=cmap, norm=norm)
489 self._mappable_ax = (mappable, ax)
490
491 self._figure.canvas.draw_idle()
492
int max

◆ _i_scale()

lsst.display.matplotlib.matplotlib.DisplayImpl._i_scale ( self,
algorithm,
minval,
maxval,
unit,
* args,
** kwargs )
protected

Definition at line 646 of file matplotlib.py.

646 def _i_scale(self, algorithm, minval, maxval, unit, *args, **kwargs):
647
648 maskedPixels = kwargs.get("maskedPixels", [])
649 if isinstance(maskedPixels, str):
650 maskedPixels = [maskedPixels]
651 bitmask = afwImage.Mask.getPlaneBitMask(maskedPixels)
652
654 sctrl.setAndMask(bitmask)
655
656 if minval == "minmax":
657 if self._image is None:
658 raise RuntimeError("You may only use minmax if an image is loaded into the display")
659
660 mi = afwImage.makeMaskedImage(self._image, self._mask)
661 stats = afwMath.makeStatistics(mi, afwMath.MIN | afwMath.MAX, sctrl)
662 minval = stats.getValue(afwMath.MIN)
663 maxval = stats.getValue(afwMath.MAX)
664 elif minval == "zscale":
665 if bitmask:
666 print("scale(..., 'zscale', maskedPixels=...) is not yet implemented")
667
668 if algorithm is None:
669 self._normalize = None
670 elif algorithm == "asinh":
671 if minval == "zscale":
672 if self._image is None:
673 raise RuntimeError("You may only use zscale if an image is loaded into the display")
674
675 self._normalize = AsinhZScaleNormalize(image=self._image, Q=kwargs.get("Q", 8.0))
676 else:
677 self._normalize = AsinhNormalize(minimum=minval,
678 dataRange=maxval - minval, Q=kwargs.get("Q", 8.0))
679 elif algorithm == "linear":
680 if minval == "zscale":
681 if self._image is None:
682 raise RuntimeError("You may only use zscale if an image is loaded into the display")
683
684 self._normalize = ZScaleNormalize(image=self._image,
685 nSamples=kwargs.get("nSamples", 1000),
686 contrast=kwargs.get("contrast", 0.25))
687 else:
688 self._normalize = LinearNormalize(minimum=minval, maximum=maxval)
689 else:
690 raise RuntimeError("Unsupported stretch algorithm \"%s\"" % algorithm)
Pass parameters to a Statistics object.
Definition Statistics.h:83
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT > > image, typename std::shared_ptr< Mask< MaskPixelT > > mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT > > variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.
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

◆ _i_setImage()

lsst.display.matplotlib.matplotlib.DisplayImpl._i_setImage ( self,
image,
mask = None,
wcs = None )
protected
Save the current image, mask, wcs, and XY0

Definition at line 493 of file matplotlib.py.

493 def _i_setImage(self, image, mask=None, wcs=None):
494 """Save the current image, mask, wcs, and XY0"""
495 self._image = image
496 self._mask = mask
497 self._wcs = wcs
498 self._xy0 = self._image.getXY0() if self._image else (0, 0)
499
500 self._zoomfac = None
501 if self._image is None:
502 self._width, self._height = 0, 0
503 else:
504 self._width, self._height = self._image.getDimensions()
505
506 self._xcen = 0.5*self._width
507 self._ycen = 0.5*self._height
508

◆ _mtv()

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

Definition at line 319 of file matplotlib.py.

319 def _mtv(self, image, mask=None, wcs=None, title=""):
320 """Display an Image and/or Mask on a matplotlib display
321 """
322 title = str(title) if title else ""
323
324 #
325 # Save a reference to the image as it makes erase() easy and permits
326 # printing cursor values and minmax/zscale stretches. We also save XY0
327 #
328 self._i_setImage(image, mask, wcs)
329
330 # We need to know the pixel values to support e.g. 'zscale' and
331 # 'minmax', so do the scaling now
332 if self._scaleArgs.get('algorithm'): # someone called self.scale()
333 self._i_scale(self._scaleArgs['algorithm'], self._scaleArgs['minval'], self._scaleArgs['maxval'],
334 self._scaleArgs['unit'], *self._scaleArgs['args'], **self._scaleArgs['kwargs'])
335
336 ax = self._figure.gca()
337 ax.cla()
338
339 self._i_mtv(image, wcs, title, False)
340
341 if mask:
342 self._i_mtv(mask, wcs, title, True)
343
344 self.show_colorbar()
345
346 if title:
347 ax.set_title(title)
348
349 self._title = title
350
351 def format_coord(x, y, wcs=self._wcs, x0=self._xy0[0], y0=self._xy0[1],
352 origin=afwImage.PARENT, bbox=self._image.getBBox(afwImage.PARENT),
353 _useSexagesimal=self._useSexagesimal):
354
355 fmt = '(%1.2f, %1.2f)'
356 if self._mtvOrigin == afwImage.PARENT:
357 msg = fmt % (x, y)
358 else:
359 msg = (fmt + "L") % (x - x0, y - y0)
360
361 col = int(x + 0.5)
362 row = int(y + 0.5)
363 if bbox.contains(geom.PointI(col, row)):
364 if wcs is not None:
365 raDec = wcs.pixelToSky(x, y)
366 ra = raDec[0].asDegrees()
367 dec = raDec[1].asDegrees()
368
369 if _useSexagesimal[0]:
370 from astropy import units as u
371 from astropy.coordinates import Angle as apAngle
372
373 kwargs = dict(sep=':', pad=True, precision=2)
374 ra = apAngle(ra*u.deg).to_string(unit=u.hour, **kwargs)
375 dec = apAngle(dec*u.deg).to_string(unit=u.deg, **kwargs)
376 else:
377 ra = "%9.4f" % ra
378 dec = "%9.4f" % dec
379
380 msg += r" (%s, %s): (%s, %s)" % (self.__alpha, self.__delta, ra, dec)
381
382 msg += ' %1.3f' % (self._image[col, row])
383 if self._mask:
384 val = self._mask[col, row]
385 if self._interpretMaskBits:
386 msg += " [%s]" % self._mask.interpret(val)
387 else:
388 msg += " 0x%x" % val
389
390 return msg
391
392 ax.format_coord = format_coord
393 # Stop images from reporting their value as we've already
394 # printed it nicely
395 for a in ax.get_images():
396 a.get_cursor_data = lambda ev: None # disabled
397
398 # using tight_layout() is too tight and clips the axes
399 self._figure.canvas.draw_idle()
400

◆ _pan()

lsst.display.matplotlib.matplotlib.DisplayImpl._pan ( self,
colc,
rowc )
protected
Pan to (colc, rowc)

Definition at line 723 of file matplotlib.py.

723 def _pan(self, colc, rowc):
724 """Pan to (colc, rowc)"""
725
726 self._xcen = colc
727 self._ycen = rowc
728
729 self._zoom(self._zoomfac)
730

◆ _scale()

lsst.display.matplotlib.matplotlib.DisplayImpl._scale ( self,
algorithm,
minval,
maxval,
unit,
* args,
** kwargs )
protected
Set gray scale

N.b.  Supports extra arguments:
@param maskedPixels  List of names of mask bits to ignore
                     E.g. ["BAD", "INTERP"].
                     A single name is also supported

Definition at line 624 of file matplotlib.py.

624 def _scale(self, algorithm, minval, maxval, unit, *args, **kwargs):
625 """
626 Set gray scale
627
628 N.b. Supports extra arguments:
629 @param maskedPixels List of names of mask bits to ignore
630 E.g. ["BAD", "INTERP"].
631 A single name is also supported
632 """
633 self._scaleArgs['algorithm'] = algorithm
634 self._scaleArgs['minval'] = minval
635 self._scaleArgs['maxval'] = maxval
636 self._scaleArgs['unit'] = unit
637 self._scaleArgs['args'] = args
638 self._scaleArgs['kwargs'] = kwargs
639
640 try:
641 self._i_scale(algorithm, minval, maxval, unit, *args, **kwargs)
642 except (AttributeError, RuntimeError):
643 # Unable to access self._image; we'll try again when we run mtv
644 pass
645

◆ _setImageColormap()

lsst.display.matplotlib.matplotlib.DisplayImpl._setImageColormap ( self,
cmap )
protected
Set the colormap used for the image

cmap should be either the name of an attribute of matplotlib.cm or an
mpColors.Colormap (e.g. "gray" or matplotlib.cm.gray)

Definition at line 509 of file matplotlib.py.

509 def _setImageColormap(self, cmap):
510 """Set the colormap used for the image
511
512 cmap should be either the name of an attribute of matplotlib.cm or an
513 mpColors.Colormap (e.g. "gray" or matplotlib.cm.gray)
514
515 """
516 if not isinstance(cmap, mpColors.Colormap):
517 cmap = matplotlib.colormaps[cmap]
518
519 self._image_colormap = cmap
520

◆ _setMaskTransparency()

lsst.display.matplotlib.matplotlib.DisplayImpl._setMaskTransparency ( self,
transparency,
maskplane )
protected
Specify mask transparency (percent)

Definition at line 310 of file matplotlib.py.

310 def _setMaskTransparency(self, transparency, maskplane):
311 """Specify mask transparency (percent)"""
312
313 self._maskTransparency[maskplane] = 0.01*transparency
314

◆ _show()

lsst.display.matplotlib.matplotlib.DisplayImpl._show ( self)
protected
Put the plot at the top of the window stacking order

Definition at line 183 of file matplotlib.py.

183 def _show(self):
184 """Put the plot at the top of the window stacking order"""
185
186 try:
187 self._figure.canvas._tkcanvas._root().lift() # tk
188 except AttributeError:
189 pass
190
191 try:
192 self._figure.canvas.manager.window.raise_() # os/x
193 except AttributeError:
194 pass
195
196 try:
197 self._figure.canvas.raise_() # qt[45]
198 except AttributeError:
199 pass
200

◆ _zoom()

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

Definition at line 695 of file matplotlib.py.

695 def _zoom(self, zoomfac):
696 """Zoom by specified amount"""
697
698 self._zoomfac = zoomfac
699
700 if zoomfac is None:
701 return
702
703 x0, y0 = self._xy0
704
705 size = min(self._width, self._height)
706 if size < self._zoomfac: # avoid min == max
707 size = self._zoomfac
708 xmin, xmax = self._xcen + x0 + size/self._zoomfac*np.array([-1, 1])
709 ymin, ymax = self._ycen + y0 + size/self._zoomfac*np.array([-1, 1])
710
711 ax = self._figure.gca()
712
713 tb = self._figure.canvas.toolbar
714 if tb is not None: # It's None for e.g. %matplotlib inline in jupyter
715 tb.push_current() # save the current zoom in the view stack
716
717 ax.set_xlim(xmin, xmax)
718 ax.set_ylim(ymin, ymax)
719 ax.set_aspect('equal', 'datalim')
720
721 self._figure.canvas.draw_idle()
722
int min

◆ savefig()

lsst.display.matplotlib.matplotlib.DisplayImpl.savefig ( self,
* args,
** kwargs )
Defer to figure.savefig()

Parameters
----------
args : `list`
  Passed through to figure.savefig()
kwargs : `dict`
  Passed through to figure.savefig()

Definition at line 204 of file matplotlib.py.

204 def savefig(self, *args, **kwargs):
205 """Defer to figure.savefig()
206
207 Parameters
208 ----------
209 args : `list`
210 Passed through to figure.savefig()
211 kwargs : `dict`
212 Passed through to figure.savefig()
213 """
214 self._figure.savefig(*args, **kwargs)
215

◆ show_colorbar()

lsst.display.matplotlib.matplotlib.DisplayImpl.show_colorbar ( self,
show = True,
where = "right",
axSize = "5%",
axPad = None,
** kwargs )
Show (or hide) the colour bar

Parameters
----------
show : `bool`
  Should I show the colour bar?
where : `str`
  Location of colour bar: "right" or "bottom"
axSize : `float` or `str`
  Size of axes to hold the colour bar; fraction of current x-size
axPad : `float` or `str`
  Padding between axes and colour bar; fraction of current x-size
args : `list`
  Passed through to colorbar()
kwargs : `dict`
  Passed through to colorbar()

We set the default padding to put the colourbar in a reasonable
place for roughly square plots, but you may need to fiddle for
plots with extreme axis ratios.

You can only configure the colorbar when it isn't yet visible, but
as you can easily remove it this is not in practice a difficulty.

Definition at line 216 of file matplotlib.py.

216 def show_colorbar(self, show=True, where="right", axSize="5%", axPad=None, **kwargs):
217 """Show (or hide) the colour bar
218
219 Parameters
220 ----------
221 show : `bool`
222 Should I show the colour bar?
223 where : `str`
224 Location of colour bar: "right" or "bottom"
225 axSize : `float` or `str`
226 Size of axes to hold the colour bar; fraction of current x-size
227 axPad : `float` or `str`
228 Padding between axes and colour bar; fraction of current x-size
229 args : `list`
230 Passed through to colorbar()
231 kwargs : `dict`
232 Passed through to colorbar()
233
234 We set the default padding to put the colourbar in a reasonable
235 place for roughly square plots, but you may need to fiddle for
236 plots with extreme axis ratios.
237
238 You can only configure the colorbar when it isn't yet visible, but
239 as you can easily remove it this is not in practice a difficulty.
240 """
241 if show:
242 if self._mappable_ax:
243 if self._colorbar_ax is None:
244 orientationDict = dict(right="vertical", bottom="horizontal")
245
246 mappable, ax = self._mappable_ax
247
248 if where in orientationDict:
249 orientation = orientationDict[where]
250 else:
251 print(f"Unknown location {where}; "
252 f"please use one of {', '.join(orientationDict.keys())}")
253
254 if axPad is None:
255 axPad = 0.1 if orientation == "vertical" else 0.3
256
257 divider = make_axes_locatable(ax)
258 self._colorbar_ax = divider.append_axes(where, size=axSize, pad=axPad)
259
260 self._figure.colorbar(mappable, cax=self._colorbar_ax, orientation=orientation, **kwargs)
261 self._figure.sca(ax)
262
263 else:
264 if self._colorbar_ax is not None:
265 self._colorbar_ax.remove()
266 self._colorbar_ax = None
267

◆ useSexagesimal()

lsst.display.matplotlib.matplotlib.DisplayImpl.useSexagesimal ( self,
useSexagesimal )
Control the formatting coordinates as HH:MM:SS.ss

Parameters
----------
useSexagesimal : `bool`
   Print coordinates as e.g. HH:MM:SS.ss iff True

N.b. can also be set in Display's ctor
Are we formatting coordinates as HH:MM:SS.ss?

Definition at line 268 of file matplotlib.py.

268 def useSexagesimal(self, useSexagesimal):
269 """Control the formatting coordinates as HH:MM:SS.ss
270
271 Parameters
272 ----------
273 useSexagesimal : `bool`
274 Print coordinates as e.g. HH:MM:SS.ss iff True
275
276 N.b. can also be set in Display's ctor
277 """
278
279 """Are we formatting coordinates as HH:MM:SS.ss?"""
280 self._useSexagesimal[0] = useSexagesimal
281

◆ wait()

lsst.display.matplotlib.matplotlib.DisplayImpl.wait ( self,
prompt = "[c(ontinue) p(db)] :",
allowPdb = True )
Wait for keyboard input

Parameters
----------
prompt : `str`
   The prompt string.
allowPdb : `bool`
   If true, entering a 'p' or 'pdb' puts you into pdb

Returns the string you entered

Useful when plotting from a programme that exits such as a processCcd
Any key except 'p' continues; 'p' puts you into pdb (unless
allowPdb is False)

Definition at line 282 of file matplotlib.py.

282 def wait(self, prompt="[c(ontinue) p(db)] :", allowPdb=True):
283 """Wait for keyboard input
284
285 Parameters
286 ----------
287 prompt : `str`
288 The prompt string.
289 allowPdb : `bool`
290 If true, entering a 'p' or 'pdb' puts you into pdb
291
292 Returns the string you entered
293
294 Useful when plotting from a programme that exits such as a processCcd
295 Any key except 'p' continues; 'p' puts you into pdb (unless
296 allowPdb is False)
297 """
298 while True:
299 s = input(prompt)
300 if allowPdb and s in ("p", "pdb"):
301 import pdb
302 pdb.set_trace()
303 continue
304
305 return s

Member Data Documentation

◆ _colorbar_ax

lsst.display.matplotlib.matplotlib.DisplayImpl._colorbar_ax
protected

Definition at line 160 of file matplotlib.py.

◆ _display

lsst.display.matplotlib.matplotlib.DisplayImpl._display
protected

Definition at line 153 of file matplotlib.py.

◆ _fastMaskDisplay

lsst.display.matplotlib.matplotlib.DisplayImpl._fastMaskDisplay
protected

Definition at line 156 of file matplotlib.py.

◆ _figure

lsst.display.matplotlib.matplotlib.DisplayImpl._figure
protected

Definition at line 147 of file matplotlib.py.

◆ _height

lsst.display.matplotlib.matplotlib.DisplayImpl._height
protected

Definition at line 502 of file matplotlib.py.

◆ _image

lsst.display.matplotlib.matplotlib.DisplayImpl._image
protected

Definition at line 178 of file matplotlib.py.

◆ _image_colormap

lsst.display.matplotlib.matplotlib.DisplayImpl._image_colormap
protected

Definition at line 161 of file matplotlib.py.

◆ _interpretMaskBits

lsst.display.matplotlib.matplotlib.DisplayImpl._interpretMaskBits
protected

Definition at line 155 of file matplotlib.py.

◆ _mappable_ax

lsst.display.matplotlib.matplotlib.DisplayImpl._mappable_ax
protected

Definition at line 159 of file matplotlib.py.

◆ _mask

lsst.display.matplotlib.matplotlib.DisplayImpl._mask
protected

Definition at line 179 of file matplotlib.py.

◆ _maskTransparency

lsst.display.matplotlib.matplotlib.DisplayImpl._maskTransparency
protected

Definition at line 154 of file matplotlib.py.

◆ _mtvOrigin

lsst.display.matplotlib.matplotlib.DisplayImpl._mtvOrigin
protected

Definition at line 158 of file matplotlib.py.

◆ _normalize

lsst.display.matplotlib.matplotlib.DisplayImpl._normalize
protected

Definition at line 169 of file matplotlib.py.

◆ _scaleArgs

lsst.display.matplotlib.matplotlib.DisplayImpl._scaleArgs
protected

Definition at line 168 of file matplotlib.py.

◆ _title

lsst.display.matplotlib.matplotlib.DisplayImpl._title
protected

Definition at line 349 of file matplotlib.py.

◆ _useSexagesimal

lsst.display.matplotlib.matplotlib.DisplayImpl._useSexagesimal
protected

Definition at line 157 of file matplotlib.py.

◆ _wcs

lsst.display.matplotlib.matplotlib.DisplayImpl._wcs
protected

Definition at line 180 of file matplotlib.py.

◆ _width

lsst.display.matplotlib.matplotlib.DisplayImpl._width
protected

Definition at line 502 of file matplotlib.py.

◆ _xcen

lsst.display.matplotlib.matplotlib.DisplayImpl._xcen
protected

Definition at line 506 of file matplotlib.py.

◆ _xy0

lsst.display.matplotlib.matplotlib.DisplayImpl._xy0
protected

Definition at line 498 of file matplotlib.py.

◆ _ycen

lsst.display.matplotlib.matplotlib.DisplayImpl._ycen
protected

Definition at line 507 of file matplotlib.py.

◆ _zoomfac

lsst.display.matplotlib.matplotlib.DisplayImpl._zoomfac
protected

Definition at line 500 of file matplotlib.py.


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