26 from __future__
import absolute_import, division, print_function
27 from builtins
import str
28 from builtins
import range
29 from builtins
import object
36 "drawBBox",
"drawFootprint",
"drawCoaddInputs",
40 def _getDisplayFromDisplayOrFrame(display, frame=None):
41 """!Return an afwDisplay.Display given either a display or a frame ID. 43 If the two arguments are consistent, return the desired display; if they are not, 44 raise a RuntimeError exception. 46 If the desired display is None, return None; 47 if (display, frame) == ("deferToFrame", None), return the default display""" 52 if display
in (
"deferToFrame",
None):
53 if display
is None and frame
is None:
59 if display
and not hasattr(display,
"frame"):
60 raise RuntimeError(
"display == %s doesn't support .frame" % display)
62 if frame
and display
and display.frame != frame:
63 raise RuntimeError(
"Please specify display *or* frame")
68 display = afwDisplay.getDisplay(frame, create=
True)
74 """A class to handle mosaics of one or more identically-sized images (or Masks or MaskedImages) 79 m.setMode("square") # the default; other options are "x" or "y" 81 mosaic = m.makeMosaic(im1, im2, im3) # build the mosaic 82 display = afwDisplay.getDisplay() 83 display.mtv(mosaic) # display it 84 m.drawLabels(["Label 1", "Label 2", "Label 3"], display) # label the panels 86 # alternative way to build a mosaic 87 images = [im1, im2, im3] 88 labels = ["Label 1", "Label 2", "Label 3"] 90 mosaic = m.makeMosaic(images) 92 m.drawLabels(labels, display) 94 # Yet another way to build a mosaic (no need to build the images/labels lists) 95 for i in range(len(images)): 96 m.append(images[i], labels[i]) 97 # You may optionally include a colour, e.g. afwDisplay.YELLOW, as a third argument 99 mosaic = m.makeMosaic() 101 m.drawLabels(display=display) 104 mosaic = m.makeMosaic(display=display) 106 You can return the (ix, iy)th (or nth) bounding box (in pixels) with getBBox() 109 def __init__(self, gutter=3, background=0, mode="square"):
119 """Reset the list of images to be mosaiced""" 123 def append(self, image, label=None, ctype=None):
124 """Add an image to the list of images to be mosaiced 125 Set may be cleared with Mosaic.reset() 127 Returns the index of this image (may be passed to getBBox()) 130 self.
xsize = image.getWidth()
131 self.
ysize = image.getHeight()
138 def makeMosaic(self, images=None, display="deferToFrame", mode=None,
139 background=None, title="", frame=None):
140 """Return a mosaic of all the images provided; if none are specified, 141 use the list accumulated with Mosaic.append(). 143 Note that this mosaic is a patchwork of the input images; if you want to 144 make a mosaic of a set images of the sky, you probably want to use the coadd code 146 If display or frame (deprecated) is specified, display the mosaic 152 "You have already appended %d images to this Mosaic" % len(self.
images))
164 raise RuntimeError(
"You must provide at least one image")
168 w, h = im.getWidth(), im.getHeight()
174 if background
is None:
181 while nx*im.getWidth() < ny*im.getHeight():
193 assert(nx*ny >= self.
nImage)
198 elif isinstance(mode, int):
204 raise RuntimeError(
"Unknown mosaicing mode: %s" % mode)
206 self.nx, self.
ny = nx, ny
214 except AttributeError:
215 raise RuntimeError(
"Attempt to mosaic images of type %s which don't support set" %
218 for i
in range(len(images)):
219 smosaic = mosaic.Factory(
220 mosaic, self.
getBBox(i%nx, i//nx), afwImage.LOCAL)
223 if smosaic.getDimensions() != im.getDimensions():
225 (smosaic.getHeight() - im.getHeight())//2)
227 llc, im.getDimensions()), afwImage.LOCAL)
231 display = _getDisplayFromDisplayOrFrame(display, frame)
233 display.mtv(mosaic, title=title)
241 """Set the number of pixels between panels in a mosaic""" 245 """Set the value in the gutters""" 249 """Set mosaicing mode. Valid options: 250 square Make mosaic as square as possible 251 x Make mosaic one image high 252 y Make mosaic one image wide 255 if mode
not in (
"square",
"x",
"y"):
256 raise RuntimeError(
"Unknown mosaicing mode: %s" % mode)
261 """Get the BBox for the nth or (ix, iy)the panel""" 264 ix, iy = ix % self.nx, ix//self.nx
269 def drawLabels(self, labels=None, display="deferToFrame", frame=None):
270 """Draw the list labels at the corners of each panel. If labels is None, use the ones 271 specified by Mosaic.append()""" 279 if len(labels) != self.
nImage:
280 raise RuntimeError(
"You provided %d labels for %d panels" % (
281 len(labels), self.
nImage))
283 display = _getDisplayFromDisplayOrFrame(display, frame)
287 with display.Buffering():
288 for i
in range(len(labels)):
290 label, ctype = labels[i],
None 299 display.dot(str(label), self.
getBBox(i).getMinX(),
300 self.
getBBox(i).getMinY(), ctype=ctype)
304 """Number of images""" 308 def drawBBox(bbox, borderWidth=0.0, origin=None, display="deferToFrame", ctype=None, bin=1, frame=None):
309 """Draw an afwImage::BBox on a display frame with the specified ctype. Include an extra borderWidth pixels 310 If origin is present, it's Added to the BBox 312 All BBox coordinates are divided by bin, as is right and proper for overlaying on a binned image 314 x0, y0 = bbox.getMinX(), bbox.getMinY()
315 x1, y1 = bbox.getMaxX(), bbox.getMaxY()
329 display = _getDisplayFromDisplayOrFrame(display, frame)
330 display.line([(x0 - borderWidth, y0 - borderWidth),
331 (x0 - borderWidth, y1 + borderWidth),
332 (x1 + borderWidth, y1 + borderWidth),
333 (x1 + borderWidth, y0 - borderWidth),
334 (x0 - borderWidth, y0 - borderWidth),
338 def drawFootprint(foot, borderWidth=0.5, origin=None, XY0=None, frame=None, ctype=None, bin=1,
339 peaks=False, symb="+", size=0.4, ctypePeak=None, display="deferToFrame"):
340 """Draw an afwDetection::Footprint on a display frame with the specified ctype. Include an extra borderWidth 341 pixels If origin is present, it's Added to the Footprint; if XY0 is present is Subtracted from the Footprint 343 If peaks is True, also show the object's Peaks using the specified symbol and size and ctypePeak 345 All Footprint coordinates are divided by bin, as is right and proper for overlaying on a binned image 350 raise RuntimeError(
"You may not specify both origin and XY0")
351 origin = (-XY0[0], -XY0[1])
353 display = _getDisplayFromDisplayOrFrame(display, frame)
354 with display.Buffering():
356 for s
in foot.getSpans():
357 y, x0, x1 = s.getY(), s.getX0(), s.getX1()
368 display.line([(x0 - borderWidth, y - borderWidth),
369 (x0 - borderWidth, y + borderWidth),
370 (x1 + borderWidth, y + borderWidth),
371 (x1 + borderWidth, y - borderWidth),
372 (x0 - borderWidth, y - borderWidth),
376 for p
in foot.getPeaks():
377 x, y = p.getIx(), p.getIy()
386 display.dot(symb, x, y, size=size, ctype=ctypePeak)
390 """Draw the bounding boxes of input exposures to a coadd on a display frame with the specified ctype, 391 assuming display.mtv() has already been called on the given exposure on this frame. 394 All coordinates are divided by bin, as is right and proper for overlaying on a binned image 396 coaddWcs = exposure.getWcs()
397 catalog = exposure.getInfo().getCoaddInputs().ccds
401 display = _getDisplayFromDisplayOrFrame(display, frame)
403 with display.Buffering():
404 for record
in catalog:
406 ccdCorners = ccdBox.getCorners()
407 coaddCorners = [coaddWcs.skyToPixel(record.getWcs().pixelToSky(point)) + offset
408 for point
in ccdCorners]
409 display.line([(coaddCorners[i].getX()/bin, coaddCorners[i].getY()/bin)
410 for i
in range(-1, 4)], ctype=ctype)
def drawCoaddInputs(exposure, frame=None, ctype=None, bin=1, display="deferToFrame")
def setBackground(self, background)
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)
An integer coordinate rectangle.
def append(self, image, label=None, ctype=None)
def setGutter(self, gutter)
def __init__(self, gutter=3, background=0, mode="square")
A floating-point coordinate rectangle geometry.
def drawBBox(bbox, borderWidth=0.0, origin=None, display="deferToFrame", ctype=None, bin=1, frame=None)