31 "drawBBox",
"drawFootprint",
"drawCoaddInputs",
35 def _getDisplayFromDisplayOrFrame(display, frame=None):
36 """!Return an afwDisplay.Display given either a display or a frame ID. 38 If the two arguments are consistent, return the desired display; if they are not, 39 raise a RuntimeError exception. 41 If the desired display is None, return None; 42 if (display, frame) == ("deferToFrame", None), return the default display""" 47 if display
in (
"deferToFrame",
None):
48 if display
is None and frame
is None:
54 if display
and not hasattr(display,
"frame"):
55 raise RuntimeError(
"display == %s doesn't support .frame" % display)
57 if frame
and display
and display.frame != frame:
58 raise RuntimeError(
"Please specify display *or* frame")
63 display = afwDisplay.getDisplay(frame, create=
True)
69 """A class to handle mosaics of one or more identically-sized images (or Masks or MaskedImages) 74 m.setMode("square") # the default; other options are "x" or "y" 76 mosaic = m.makeMosaic(im1, im2, im3) # build the mosaic 77 display = afwDisplay.getDisplay() 78 display.mtv(mosaic) # display it 79 m.drawLabels(["Label 1", "Label 2", "Label 3"], display) # label the panels 81 # alternative way to build a mosaic 82 images = [im1, im2, im3] 83 labels = ["Label 1", "Label 2", "Label 3"] 85 mosaic = m.makeMosaic(images) 87 m.drawLabels(labels, display) 89 # Yet another way to build a mosaic (no need to build the images/labels lists) 90 for i in range(len(images)): 91 m.append(images[i], labels[i]) 92 # You may optionally include a colour, e.g. afwDisplay.YELLOW, as a third argument 94 mosaic = m.makeMosaic() 96 m.drawLabels(display=display) 99 mosaic = m.makeMosaic(display=display) 101 You can return the (ix, iy)th (or nth) bounding box (in pixels) with getBBox() 104 def __init__(self, gutter=3, background=0, mode="square"):
114 """Reset the list of images to be mosaiced""" 118 def append(self, image, label=None, ctype=None):
119 """Add an image to the list of images to be mosaiced 120 Set may be cleared with Mosaic.reset() 122 Returns the index of this image (may be passed to getBBox()) 125 self.
xsize = image.getWidth()
126 self.
ysize = image.getHeight()
133 def makeMosaic(self, images=None, display="deferToFrame", mode=None,
134 background=None, title="", frame=None):
135 """Return a mosaic of all the images provided; if none are specified, 136 use the list accumulated with Mosaic.append(). 138 Note that this mosaic is a patchwork of the input images; if you want to 139 make a mosaic of a set images of the sky, you probably want to use the coadd code 141 If display or frame (deprecated) is specified, display the mosaic 147 "You have already appended %d images to this Mosaic" % len(self.
images))
159 raise RuntimeError(
"You must provide at least one image")
163 w, h = im.getWidth(), im.getHeight()
169 if background
is None:
176 while nx*im.getWidth() < ny*im.getHeight():
188 assert(nx*ny >= self.
nImage)
193 elif isinstance(mode, int):
199 raise RuntimeError(
"Unknown mosaicing mode: %s" % mode)
201 self.nx, self.
ny = nx, ny
209 except AttributeError:
210 raise RuntimeError(
"Attempt to mosaic images of type %s which don't support set" %
213 for i
in range(len(images)):
214 smosaic = mosaic.Factory(
215 mosaic, self.
getBBox(i%nx, i//nx), afwImage.LOCAL)
218 if smosaic.getDimensions() != im.getDimensions():
220 (smosaic.getHeight() - im.getHeight())//2)
222 llc, im.getDimensions()), afwImage.LOCAL)
226 display = _getDisplayFromDisplayOrFrame(display, frame)
228 display.mtv(mosaic, title=title)
236 """Set the number of pixels between panels in a mosaic""" 240 """Set the value in the gutters""" 244 """Set mosaicing mode. Valid options: 245 square Make mosaic as square as possible 246 x Make mosaic one image high 247 y Make mosaic one image wide 250 if mode
not in (
"square",
"x",
"y"):
251 raise RuntimeError(
"Unknown mosaicing mode: %s" % mode)
256 """Get the BBox for the nth or (ix, iy)the panel""" 259 ix, iy = ix % self.nx, ix//self.nx
264 def drawLabels(self, labels=None, display="deferToFrame", frame=None):
265 """Draw the list labels at the corners of each panel. If labels is None, use the ones 266 specified by Mosaic.append()""" 274 if len(labels) != self.
nImage:
275 raise RuntimeError(
"You provided %d labels for %d panels" % (
276 len(labels), self.
nImage))
278 display = _getDisplayFromDisplayOrFrame(display, frame)
282 with display.Buffering():
283 for i
in range(len(labels)):
285 label, ctype = labels[i],
None 294 display.dot(
str(label), self.
getBBox(i).getMinX(),
295 self.
getBBox(i).getMinY(), ctype=ctype)
299 """Number of images""" 303 def drawBBox(bbox, borderWidth=0.0, origin=None, display="deferToFrame", ctype=None, bin=1, frame=None):
304 """Draw an afwImage::BBox on a display frame with the specified ctype. Include an extra borderWidth pixels 305 If origin is present, it's Added to the BBox 307 All BBox coordinates are divided by bin, as is right and proper for overlaying on a binned image 309 x0, y0 = bbox.getMinX(), bbox.getMinY()
310 x1, y1 = bbox.getMaxX(), bbox.getMaxY()
324 display = _getDisplayFromDisplayOrFrame(display, frame)
325 display.line([(x0 - borderWidth, y0 - borderWidth),
326 (x0 - borderWidth, y1 + borderWidth),
327 (x1 + borderWidth, y1 + borderWidth),
328 (x1 + borderWidth, y0 - borderWidth),
329 (x0 - borderWidth, y0 - borderWidth),
333 def drawFootprint(foot, borderWidth=0.5, origin=None, XY0=None, frame=None, ctype=None, bin=1,
334 peaks=False, symb="+", size=0.4, ctypePeak=None, display="deferToFrame"):
335 """Draw an afwDetection::Footprint on a display frame with the specified ctype. Include an extra borderWidth 336 pixels If origin is present, it's Added to the Footprint; if XY0 is present is Subtracted from the Footprint 338 If peaks is True, also show the object's Peaks using the specified symbol and size and ctypePeak 340 All Footprint coordinates are divided by bin, as is right and proper for overlaying on a binned image 345 raise RuntimeError(
"You may not specify both origin and XY0")
346 origin = (-XY0[0], -XY0[1])
348 display = _getDisplayFromDisplayOrFrame(display, frame)
349 with display.Buffering():
351 for s
in foot.getSpans():
352 y, x0, x1 = s.getY(), s.getX0(), s.getX1()
363 display.line([(x0 - borderWidth, y - borderWidth),
364 (x0 - borderWidth, y + borderWidth),
365 (x1 + borderWidth, y + borderWidth),
366 (x1 + borderWidth, y - borderWidth),
367 (x0 - borderWidth, y - borderWidth),
371 for p
in foot.getPeaks():
372 x, y = p.getIx(), p.getIy()
381 display.dot(symb, x, y, size=size, ctype=ctypePeak)
385 """Draw the bounding boxes of input exposures to a coadd on a display frame with the specified ctype, 386 assuming display.mtv() has already been called on the given exposure on this frame. 389 All coordinates are divided by bin, as is right and proper for overlaying on a binned image 391 coaddWcs = exposure.getWcs()
392 catalog = exposure.getInfo().getCoaddInputs().ccds
396 display = _getDisplayFromDisplayOrFrame(display, frame)
398 with display.Buffering():
399 for record
in catalog:
401 ccdCorners = ccdBox.getCorners()
402 coaddCorners = [coaddWcs.skyToPixel(record.getWcs().pixelToSky(point)) + offset
403 for point
in ccdCorners]
404 display.line([(coaddCorners[i].getX()/bin, coaddCorners[i].getY()/bin)
405 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 makeMosaic(self, images=None, display="deferToFrame", mode=None, background=None, title="", frame=None)
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")
An integer coordinate rectangle.
def drawBBox(bbox, borderWidth=0.0, origin=None, display="deferToFrame", ctype=None, bin=1, frame=None)