31 "drawBBox",
"drawFootprint",
"drawCoaddInputs",
35 def _getDisplayFromDisplayOrFrame(display, frame=None):
36 """Return an `lsst.afw.display.Display` given either a display or a frame ID. 40 If the two arguments are consistent, return the desired display; if they are not, 41 raise a `RuntimeError` exception. 43 If the desired display is `None`, return `None`; 44 if ``(display, frame) == ("deferToFrame", None)``, return the default display 50 if display
in (
"deferToFrame",
None):
51 if display
is None and frame
is None:
57 if display
and not hasattr(display,
"frame"):
58 raise RuntimeError(
"display == %s doesn't support .frame" % display)
60 if frame
and display
and display.frame != frame:
61 raise RuntimeError(
"Please specify display *or* frame")
66 display = afwDisplay.getDisplay(frame, create=
True)
72 """A class to handle mosaics of one or more identically-sized images 73 (or `~lsst.afw.image.Mask` or `~lsst.afw.image.MaskedImage`) 77 Note that this mosaic is a patchwork of the input images; if you want to 78 make a mosaic of a set images of the sky, you probably want to use the coadd code 88 m.setMode("square") # the default; other options are "x" or "y" 90 mosaic = m.makeMosaic(im1, im2, im3) # build the mosaic 91 display = afwDisplay.getDisplay() 92 display.mtv(mosaic) # display it 93 m.drawLabels(["Label 1", "Label 2", "Label 3"], display) # label the panels 95 # alternative way to build a mosaic 96 images = [im1, im2, im3] 97 labels = ["Label 1", "Label 2", "Label 3"] 99 mosaic = m.makeMosaic(images) 101 m.drawLabels(labels, display) 103 # Yet another way to build a mosaic (no need to build the images/labels lists) 104 for i in range(len(images)): 105 m.append(images[i], labels[i]) 106 # You may optionally include a colour, e.g. afwDisplay.YELLOW, as a third argument 108 mosaic = m.makeMosaic() 110 m.drawLabels(display=display) 116 mosaic = m.makeMosaic(display=display) 118 You can return the (ix, iy)th (or nth) bounding box (in pixels) with `getBBox()` 121 def __init__(self, gutter=3, background=0, mode="square"):
131 """Reset the list of images to be mosaiced""" 135 def append(self, image, label=None, ctype=None):
136 """Add an image to the list of images to be mosaiced 141 the index of this image (may be passed to `getBBox()`) 145 Set may be cleared with ``Mosaic.reset()`` 148 self.
xsize = image.getWidth()
149 self.
ysize = image.getHeight()
156 def makeMosaic(self, images=None, display="deferToFrame", mode=None,
157 background=None, title=""):
158 """Return a mosaic of all the images provided. 160 If none are specified, use the list accumulated with `Mosaic.append()`. 162 If display is specified, display the mosaic 168 "You have already appended %d images to this Mosaic" % len(self.
images))
180 raise RuntimeError(
"You must provide at least one image")
184 w, h = im.getWidth(), im.getHeight()
190 if background
is None:
197 while nx*im.getWidth() < ny*im.getHeight():
209 assert(nx*ny >= self.
nImage)
214 elif isinstance(mode, int):
220 raise RuntimeError(
"Unknown mosaicing mode: %s" % mode)
222 self.nx, self.
ny = nx, ny
230 except AttributeError:
231 raise RuntimeError(
"Attempt to mosaic images of type %s which don't support set" %
234 for i
in range(len(images)):
235 smosaic = mosaic.Factory(
236 mosaic, self.
getBBox(i%nx, i//nx), afwImage.LOCAL)
239 if smosaic.getDimensions() != im.getDimensions():
241 (smosaic.getHeight() - im.getHeight())//2)
243 llc, im.getDimensions()), afwImage.LOCAL)
247 display = _getDisplayFromDisplayOrFrame(display)
249 display.mtv(mosaic, title=title)
257 """Set the number of pixels between panels in a mosaic 262 """Set the value in the gutters 267 """Set mosaicing mode. 271 mode : {"square", "x", "y"} 275 Make mosaic as square as possible 277 Make mosaic one image high 279 Make mosaic one image wide 282 if mode
not in (
"square",
"x",
"y"):
283 raise RuntimeError(
"Unknown mosaicing mode: %s" % mode)
288 """Get the BBox for a panel 293 If ``iy`` is not `None`, this is the x coordinate of the panel. 294 If ``iy`` is `None`, this is the number of the panel. 296 The y coordinate of the panel. 300 ix, iy = ix % self.nx, ix//self.nx
305 def drawLabels(self, labels=None, display="deferToFrame", frame=None):
306 """Draw the list labels at the corners of each panel. 310 If labels is None, use the ones specified by ``Mosaic.append()`` 319 if len(labels) != self.
nImage:
320 raise RuntimeError(
"You provided %d labels for %d panels" % (
321 len(labels), self.
nImage))
323 display = _getDisplayFromDisplayOrFrame(display, frame)
327 with display.Buffering():
328 for i
in range(len(labels)):
330 label, ctype = labels[i],
None 339 display.dot(str(label), self.
getBBox(i).getMinX(),
340 self.
getBBox(i).getMinY(), ctype=ctype)
349 def drawBBox(bbox, borderWidth=0.0, origin=None, display="deferToFrame", ctype=None, bin=1, frame=None):
350 """Draw a bounding box on a display frame with the specified ctype. 354 bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D` 356 borderWidth : `float` 357 Include this many pixels 359 If specified, the box is shifted by ``origin`` 362 The desired color, either e.g. `lsst.afw.display.RED` or a color name known to X11 364 All BBox coordinates are divided by bin, as is right and proper for overlaying on a binned image 367 x0, y0 = bbox.getMinX(), bbox.getMinY()
368 x1, y1 = bbox.getMaxX(), bbox.getMaxY()
382 display = _getDisplayFromDisplayOrFrame(display, frame)
383 display.line([(x0 - borderWidth, y0 - borderWidth),
384 (x0 - borderWidth, y1 + borderWidth),
385 (x1 + borderWidth, y1 + borderWidth),
386 (x1 + borderWidth, y0 - borderWidth),
387 (x0 - borderWidth, y0 - borderWidth),
391 def drawFootprint(foot, borderWidth=0.5, origin=None, XY0=None, frame=None, ctype=None, bin=1,
392 peaks=False, symb="+", size=0.4, ctypePeak=None, display="deferToFrame"):
393 """Draw an `lsst.afw.detection.Footprint` on a display frame with the specified ctype. 397 foot : `lsst.afw.detection.Footprint` 398 borderWidth : `float` 399 Include an extra borderWidth pixels 401 If ``origin`` is present, it's arithmetically added to the Footprint 403 if ``XY0`` is present is subtracted from the Footprint 406 The desired color, either e.g. `lsst.afw.display.RED` or a color name known to X11 408 All Footprint coordinates are divided by bin, as is right and proper 409 for overlaying on a binned image 411 If peaks is `True`, also show the object's Peaks using the specified 412 ``symb`` and ``size`` and ``ctypePeak`` 416 The desired color for peaks, either e.g. `lsst.afw.display.RED` or a color name known to X11 422 raise RuntimeError(
"You may not specify both origin and XY0")
423 origin = (-XY0[0], -XY0[1])
425 display = _getDisplayFromDisplayOrFrame(display, frame)
426 with display.Buffering():
428 for s
in foot.getSpans():
429 y, x0, x1 = s.getY(), s.getX0(), s.getX1()
440 display.line([(x0 - borderWidth, y - borderWidth),
441 (x0 - borderWidth, y + borderWidth),
442 (x1 + borderWidth, y + borderWidth),
443 (x1 + borderWidth, y - borderWidth),
444 (x0 - borderWidth, y - borderWidth),
448 for p
in foot.getPeaks():
449 x, y = p.getIx(), p.getIy()
458 display.dot(symb, x, y, size=size, ctype=ctypePeak)
462 """Draw the bounding boxes of input exposures to a coadd on a display 463 frame with the specified ctype, assuming ``display.mtv()`` has already been 464 called on the given exposure on this frame. 466 All coordinates are divided by ``bin``, as is right and proper for overlaying on a binned image 468 coaddWcs = exposure.getWcs()
469 catalog = exposure.getInfo().getCoaddInputs().ccds
473 display = _getDisplayFromDisplayOrFrame(display, frame)
475 with display.Buffering():
476 for record
in catalog:
478 ccdCorners = ccdBox.getCorners()
479 coaddCorners = [coaddWcs.skyToPixel(record.getWcs().pixelToSky(point)) + offset
480 for point
in ccdCorners]
481 display.line([(coaddCorners[i].getX()/bin, coaddCorners[i].getY()/bin)
482 for i
in range(-1, 4)], ctype=ctype)
def drawCoaddInputs(exposure, frame=None, ctype=None, bin=1, display="deferToFrame")
def setBackground(self, background)
A floating-point coordinate rectangle geometry.
def drawFootprint(foot, borderWidth=0.5, origin=None, XY0=None, frame=None, ctype=None, bin=1, peaks=False, symb="+", size=0.4, ctypePeak=None, display="deferToFrame")
def getBBox(self, ix, iy=None)
def drawLabels(self, labels=None, display="deferToFrame", frame=None)
def append(self, image, label=None, ctype=None)
def setGutter(self, gutter)
def __init__(self, gutter=3, background=0, mode="square")
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
def makeMosaic(self, images=None, display="deferToFrame", mode=None, background=None, title="")
An integer coordinate rectangle.
def drawBBox(bbox, borderWidth=0.0, origin=None, display="deferToFrame", ctype=None, bin=1, frame=None)