LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | List of all members
lsst.afw.display.utils.Mosaic Class Reference
Inheritance diagram for lsst.afw.display.utils.Mosaic:

Public Member Functions

def __init__
 
def reset
 
def append
 
def makeMosaic
 
def setGutter
 
def setBackground
 
def setMode
 
def getBBox
 
def drawLabels
 

Public Attributes

 gutter
 
 background
 
 xsize
 
 ysize
 
 images
 
 labels
 
 nImage
 
 ny
 
 mode
 

Detailed Description

A class to handle mosaics of one or more identically-sized images (or Masks or MaskedImages)
E.g.
m = Mosaic()
m.setGutter(5)
m.setBackground(10)
m.setMode("square")                     # the default; other options are "x" or "y"

mosaic = m.makeMosaic(im1, im2, im3)    # build the mosaic
display = afwDisplay.getDisplay()
display.mtv(mosaic)                         # display it
m.drawLabels(["Label 1", "Label 2", "Label 3"], display) # label the panels

# alternative way to build a mosaic
images = [im1, im2, im3]               
labels = ["Label 1", "Label 2", "Label 3"]

mosaic = m.makeMosaic(images)
display.mtv(mosaic)
m.drawLabels(labels, display)

# Yet another way to build a mosaic (no need to build the images/labels lists)
for i in range(len(images)):
    m.append(images[i], labels[i])
# You may optionally include a colour, e.g. afwDisplay.YELLOW, as a third argument

mosaic = m.makeMosaic()
display.mtv(mosaic)
m.drawLabels(display=display)

Or simply:
mosaic = m.makeMosaic(display=display)

You can return the (ix, iy)th (or nth) bounding box (in pixels) with getBBox()

Definition at line 69 of file utils.py.

Constructor & Destructor Documentation

def lsst.afw.display.utils.Mosaic.__init__ (   self,
  gutter = 3,
  background = 0,
  mode = "square" 
)

Definition at line 104 of file utils.py.

105  def __init__(self, gutter=3, background=0, mode="square"):
106  self.gutter = gutter # number of pixels between panels in a mosaic
107  self.background = background # value in gutters
108  self.setMode(mode) # mosaicing mode
109  self.xsize = 0 # column size of panels
110  self.ysize = 0 # row size of panels
111 
112  self.reset()

Member Function Documentation

def lsst.afw.display.utils.Mosaic.append (   self,
  image,
  label = None,
  ctype = None 
)
Add an image to the list of images to be mosaiced
Set may be cleared with Mosaic.reset()

Returns the index of this image (may be passed to getBBox())

Definition at line 118 of file utils.py.

119  def append(self, image, label=None, ctype=None):
120  """Add an image to the list of images to be mosaiced
121  Set may be cleared with Mosaic.reset()
122 
123  Returns the index of this image (may be passed to getBBox())
124  """
125  if not self.xsize:
126  self.xsize = image.getWidth()
127  self.ysize = image.getHeight()
128 
129  self.images.append(image)
130  self.labels.append((label, ctype))
131 
132  return len(self.images)
def lsst.afw.display.utils.Mosaic.drawLabels (   self,
  labels = None,
  display = "deferToFrame",
  frame = None 
)
Draw the list labels at the corners of each panel.  If labels is None, use the ones
specified by Mosaic.append()

Definition at line 250 of file utils.py.

251  def drawLabels(self, labels=None, display="deferToFrame", frame=None):
252  """Draw the list labels at the corners of each panel. If labels is None, use the ones
253  specified by Mosaic.append()"""
254 
255  if not labels:
256  labels = self.labels
257 
258  if not labels:
259  return
260 
261  if len(labels) != self.nImage:
262  raise RuntimeError, ("You provided %d labels for %d panels" % (len(labels), self.nImage))
263 
264  display = _getDisplayFromDisplayOrFrame(display, frame)
265  if not display:
266  return
267 
268  with display.Buffering():
269  for i in range(len(labels)):
270  if labels[i]:
271  label, ctype = labels[i], None
272  try:
273  label, ctype = label
274  except:
275  pass
276 
277  if not label:
278  continue
279 
280  display.dot(str(label), self.getBBox(i).getMinX(), self.getBBox(i).getMinY(), ctype=ctype)
def _getDisplayFromDisplayOrFrame
Return an afwDisplay.Display given either a display or a frame ID.
Definition: utils.py:36
def lsst.afw.display.utils.Mosaic.getBBox (   self,
  ix,
  iy = None 
)
Get the BBox for the nth or (ix, iy)the panel

Definition at line 241 of file utils.py.

242  def getBBox(self, ix, iy=None):
243  """Get the BBox for the nth or (ix, iy)the panel"""
244 
245  if iy is None:
246  ix, iy = ix % self.nx, ix//self.nx
247 
248  return afwGeom.Box2I(afwGeom.PointI(ix*(self.xsize + self.gutter), iy*(self.ysize + self.gutter)),
249  afwGeom.ExtentI(self.xsize, self.ysize))
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.afw.display.utils.Mosaic.makeMosaic (   self,
  images = None,
  display = "deferToFrame",
  mode = None,
  background = None,
  title = "",
  frame = None 
)
Return a mosaic of all the images provided; if none are specified,
use the list accumulated with Mosaic.append().

Note that this mosaic is a patchwork of the input images;  if you want to
make a mosaic of a set images of the sky, you probably want to use the coadd code

If display or frame (deprecated) is specified, display the mosaic

Definition at line 133 of file utils.py.

134  def makeMosaic(self, images=None, display="deferToFrame", mode=None, 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().
137 
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
140 
141  If display or frame (deprecated) is specified, display the mosaic
142  """
143 
144  if not images:
145  images = self.images
147  self.nImage = len(images)
148  if self.nImage == 0:
149  raise RuntimeError, "You must provide at least one image"
150 
151  self.xsize, self.ysize = 0, 0
152  for im in images:
153  w, h = im.getWidth(), im.getHeight()
154  if w > self.xsize:
155  self.xsize = w
156  if h > self.ysize:
157  self.ysize = h
158 
159  if background is None:
160  background = self.background
161  if mode is None:
162  mode = self.mode
163 
164  if mode == "square":
165  nx, ny = 1, self.nImage
166  while nx*im.getWidth() < ny*im.getHeight():
167  nx += 1
168  ny = self.nImage//nx
169 
170  if nx*ny < self.nImage:
171  ny += 1
172  if nx*ny < self.nImage:
173  nx += 1
174 
175  if nx > self.nImage:
176  nx = self.nImage
177 
178  assert(nx*ny >= self.nImage)
179  elif mode == "x":
180  nx, ny = self.nImage, 1
181  elif mode == "y":
182  nx, ny = 1, self.nImage
183  elif isinstance(mode, int):
184  nx = mode
185  ny = self.nImage//nx
186  if nx*ny < self.nImage:
187  ny += 1
188  else:
189  raise RuntimeError, ("Unknown mosaicing mode: %s" % mode)
191  self.nx, self.ny = nx, ny
192 
193  mosaic = images[0].Factory(
194  afwGeom.Extent2I(nx*self.xsize + (nx - 1)*self.gutter, ny*self.ysize + (ny - 1)*self.gutter)
195  )
196  try:
197  mosaic.set(self.background)
198  except AttributeError:
199  raise RuntimeError("Attempt to mosaic images of type %s which don't support set" %
200  type(mosaic))
201 
202  for i in range(len(images)):
203  smosaic = mosaic.Factory(mosaic, self.getBBox(i%nx, i//nx), afwImage.LOCAL)
204  im = images[i]
205 
206  if smosaic.getDimensions() != im.getDimensions(): # im is smaller than smosaic
207  llc = afwGeom.PointI((smosaic.getWidth() - im.getWidth())//2,
208  (smosaic.getHeight() - im.getHeight())//2)
209  smosaic = smosaic.Factory(smosaic, afwGeom.Box2I(llc, im.getDimensions()), afwImage.LOCAL)
210 
211  smosaic <<= im
212 
213  display = _getDisplayFromDisplayOrFrame(display, frame)
214  if display:
215  display.mtv(mosaic, title=title)
216 
217  if images == self.images:
218  self.drawLabels(display=display)
219 
220  return mosaic
An integer coordinate rectangle.
Definition: Box.h:53
def _getDisplayFromDisplayOrFrame
Return an afwDisplay.Display given either a display or a frame ID.
Definition: utils.py:36
def lsst.afw.display.utils.Mosaic.reset (   self)
Reset the list of images to be mosaiced

Definition at line 113 of file utils.py.

114  def reset(self):
115  """Reset the list of images to be mosaiced"""
116  self.images = [] # images to mosaic together
117  self.labels = [] # labels for images
def lsst.afw.display.utils.Mosaic.setBackground (   self,
  background 
)
Set the value in the gutters

Definition at line 225 of file utils.py.

226  def setBackground(self, background):
227  """Set the value in the gutters"""
228  self.background = background
def lsst.afw.display.utils.Mosaic.setGutter (   self,
  gutter 
)
Set the number of pixels between panels in a mosaic

Definition at line 221 of file utils.py.

222  def setGutter(self, gutter):
223  """Set the number of pixels between panels in a mosaic"""
224  self.gutter = gutter
def lsst.afw.display.utils.Mosaic.setMode (   self,
  mode 
)
Set mosaicing mode.  Valid options:
   square       Make mosaic as square as possible
   x            Make mosaic one image high
   y            Make mosaic one image wide

Definition at line 229 of file utils.py.

230  def setMode(self, mode):
231  """Set mosaicing mode. Valid options:
232  square Make mosaic as square as possible
233  x Make mosaic one image high
234  y Make mosaic one image wide
235  """
236 
237  if mode not in ("square", "x", "y"):
238  raise RuntimeError, ("Unknown mosaicing mode: %s" % mode)
240  self.mode = mode

Member Data Documentation

lsst.afw.display.utils.Mosaic.background

Definition at line 106 of file utils.py.

lsst.afw.display.utils.Mosaic.gutter

Definition at line 105 of file utils.py.

lsst.afw.display.utils.Mosaic.images

Definition at line 115 of file utils.py.

lsst.afw.display.utils.Mosaic.labels

Definition at line 116 of file utils.py.

lsst.afw.display.utils.Mosaic.mode

Definition at line 239 of file utils.py.

lsst.afw.display.utils.Mosaic.nImage

Definition at line 146 of file utils.py.

lsst.afw.display.utils.Mosaic.ny

Definition at line 190 of file utils.py.

lsst.afw.display.utils.Mosaic.xsize

Definition at line 108 of file utils.py.

lsst.afw.display.utils.Mosaic.ysize

Definition at line 109 of file utils.py.


The documentation for this class was generated from the following file: