import lsst.afw.image as afwImage
import lsst.afw.display as afwDisplay
afwDisplay.setDefaultBackend("ds9")
afwDisplay.delDisplay('all')
exp = afwImage.ExposureF("data/HSC-0908120-056-small.fits")
display0 = afwDisplay.getDisplay(frame=0, backend="ds9", verbose=True)
The workhorse "display my image" routine
display0.mtv(exp, title="parent")
Configure the mask plane transparency (alpha); in percent and draw the CROSSTALK plane in orange
display0.setMaskTransparency(50)
display0.setMaskPlaneColor("CROSSTALK", "orange")
Now redisplay that image with some of the mask planes disabled
for frame in (0, 1):
disp = afwDisplay.getDisplay(frame, verbose=True)
disp.setMaskTransparency(50)
if frame == 1:
disp.setMaskPlaneColor("CROSSTALK", "ignore")
disp.mtv(exp, title="parent")
disp.erase()
disp.dot('o', 205, 180, size=6, ctype=afwDisplay.RED)
Zoom and pan works too
display0.pan(205, 180)
display0.zoom(4)
afwDisplay.getDisplay(1).zoom(4, 205, 180)
Now overlay something, in this case symbols and lines
display0.show() # Un-iconise and raise the display to the top of the stacking order if appropriate
display0.erase()
with display0.Buffering():
display0.dot('o', 200, 220)
vertices = [(200, 220), (210, 230), (224, 230), (214, 220), (200, 220)]
display0.line(vertices, ctype=afwDisplay.CYAN)
display0.line(vertices[:-1], symbs="+x+x", size=3)
Now control the stretch.
display0.show()
display0.scaleLimits("zscale")
display0.scaleType("linear")
Demonstrate the utility routine to generate mask plane colours (used by e.g. the ds9 implementation of _mtv)
colorGenerator = display0.maskColorGenerator(omitBW=True)
for i in range(10):
print i, next(colorGenerator),
Now the make-an-image-mosaic code. Start by creating a set of 30x30 images with labels
images = []
labels = []
for i in range(1, 4):
im = afwImage.ImageF(30, 30); im[:] = 100*i
images.append(im)
labels.append("Label %d" % i)
import lsst.afw.display.utils as dispUtils
m = dispUtils.Mosaic()
mosaic = m.makeMosaic(images)
disp = afwDisplay.getDisplay(frame=2)
disp.mtv(mosaic)
m.drawLabels(labels, display=disp)
m = dispUtils.Mosaic()
m.setGutter(5)
m.setBackground(10)
m.setMode("x")
for im, lab in zip(images, labels):
m.append(im, lab)
mos = m.makeMosaic(frame=3) # it's really better to pass a Display object