15       "# Users should not usually set the default backend in a script.\n",
 
   17       "# If you want to explicitly set the backend (the default is \"ds9\" \n",
 
   18       "# if you've setup display_ds9, or \"virtualDevice\" otherwise), put \n",
 
   19       "# something like this in your $PYTHONSTARTUP file\n",
 
   22       "    import lsst.afw.display as afwDisplay\n",
 
   23       "except ImportError:\n",
 
   24       "    afwDisplay = None\n",
 
   28       "        afwDisplay.setDefaultBackend(\"ds9\" if True else \"virtualDevice\")\n",
 
   29       "    except RuntimeError as e:\n",
 
   32       "    afwDisplay.setDefaultMaskTransparency(75)"
 
   40      "cell_type": "markdown",
 
   43       "You don't usually need to do this, but if we have changed the defaultBackend we need a clean slate of displays"
 
   50       "afwDisplay.delAllDisplays()"
 
   61       "import lsst.afw.image as afwImage\n",
 
   63       "fileName = \"../tests/data/HSC-0908120-056-small.fits\"\n",
 
   64       "exp = afwImage.ExposureF(fileName)"
 
   75       "display0 = afwDisplay.getDisplay() # frame=0, verbose=True)"
 
   83      "cell_type": "markdown",
 
   86       "The workhorse \"display my image\" routine"
 
   93       "display0.mtv(exp, title=\"parent\")"
 
  101      "cell_type": "markdown",
 
  104       "Configure the mask plane transparency (alpha); in percent and draw the CROSSTALK plane in orange"
 
  111       "display0.setMaskTransparency(50)\n",
 
  112       "display0.setMaskPlaneColor(\"CROSSTALK\", \"orange\")"
 
  114      "language": "python",
 
  120      "cell_type": "markdown",
 
  123       "Now redisplay that image with some of the mask planes disabled"
 
  130       "for frame in (0, 1):\n",
 
  131       "    disp = afwDisplay.getDisplay(frame, verbose=True)\n",
 
  133       "    disp.setMaskTransparency(50)\n",
 
  136       "        disp.setMaskPlaneColor(\"CROSSTALK\", \"ignore\")\n",
 
  137       "    disp.mtv(exp, title=\"parent\")\n",
 
  140       "    disp.dot('o', 205, 180, size=6, ctype=afwDisplay.RED)"
 
  142      "language": "python",
 
  148      "cell_type": "markdown",
 
  151       "Zoom and pan works too"
 
  158       "display0.pan(205, 180)\n",
 
  159       "display0.zoom(4)\n",
 
  161       "afwDisplay.getDisplay(1).zoom(4, 205, 180)"
 
  163      "language": "python",
 
  169      "cell_type": "markdown",
 
  172       "Now overlay something, in this case symbols and lines"
 
  179       "display0.show()  # Un-iconise and raise the display to the top of the stacking order if appropriate\n",
 
  181       "display0.erase()\n",
 
  183       "with display0.Buffering():\n",
 
  184       "    display0.dot('o', 200, 220)\n",
 
  185       "    vertices = [(200, 220), (210, 230), (224, 230), (214, 220), (200, 220)]\n",
 
  186       "    display0.line(vertices, ctype=afwDisplay.CYAN)\n",
 
  187       "    display0.line(vertices[:-1], symbs=\"+x+x\", size=3)"
 
  189      "language": "python",
 
  195      "cell_type": "markdown",
 
  198       "Now control the stretch."
 
  207       "display0.scale(\"linear\", \"zscale\")"
 
  209      "language": "python",
 
  215      "cell_type": "markdown",
 
  218       "Demonstrate the utility routine to generate mask plane colours (used by e.g. the ds9 implementation of _mtv)"
 
  225       "colorGenerator = display0.maskColorGenerator(omitBW=True)\n",
 
  226       "for i in range(10):\n",
 
  227       "    print i, next(colorGenerator),"
 
  229      "language": "python",
 
  233        "output_type": "stream",
 
  236         "0 red 1 green 2 blue 3 cyan 4 magenta 5 yellow 6 red 7 green 8 blue 9 cyan\n"
 
  243      "cell_type": "markdown",
 
  246       "Check that we can display a range of types of image"
 
  253       "dummy = afwDisplay.getDisplay(\"dummy\", \"virtualDevice\")\n",
 
  255       "for imageType in [afwImage.DecoratedImageF,\n",
 
  256       "                  afwImage.ExposureF,\n",
 
  257       "                  afwImage.ImageU, \n",
 
  258       "                  afwImage.ImageI,\n",
 
  259       "                  afwImage.ImageF,\n",
 
  260       "                  afwImage.MaskedImageF,\n",
 
  262       "    im = imageType(fileName)\n",
 
  265       "im = afwImage.MaskU(fileName, 3)\n",
 
  268      "language": "python",
 
  274      "cell_type": "markdown",
 
  277       "Now the make-an-image-mosaic code.  Start by creating a set of 30x30 images with labels"
 
  286       "for i in range(1, 4):\n",
 
  287       "    im = afwImage.ImageF(30, 30); im[:] = 100*i\n",
 
  288       "    images.append(im)\n",
 
  289       "    labels.append(\"Label %d\" % i)"
 
  291      "language": "python",
 
  300       "m = afwDisplay.Mosaic()\n",
 
  302       "mosaic = m.makeMosaic(images)\n",
 
  303       "disp = afwDisplay.getDisplay(frame=2)\n",
 
  304       "disp.mtv(mosaic)\n",
 
  305       "m.drawLabels(labels, display=disp)"
 
  307      "language": "python",
 
  316       "m = afwDisplay.Mosaic()\n",
 
  319       "m.setBackground(10)\n",
 
  320       "m.setMode(\"x\")\n",
 
  322       "for im, lab in zip(images, labels):\n",
 
  323       "    m.append(im, lab)\n",
 
  325       "mos = m.makeMosaic(frame=3)        # it's really better to pass a Display object"
 
  327      "language": "python",