LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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
ds9.mtv(mosaic)                         # display it
m.drawLabels(["Label 1", "Label 2", "Label 3"]) # label the panels

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

mosaic = m.makeMosaic(images)
ds9.mtv(mosaic)
m.drawLabels(labels)

# 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. ds9.YELLOW, as a third argument

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

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

Definition at line 34 of file utils.py.

Constructor & Destructor Documentation

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

Definition at line 65 of file utils.py.

65 
66  def __init__(self, gutter=3, background=0, mode="square"):
67  self.gutter = gutter # number of pixels between panels in a mosaic
68  self.background = background # value in gutters
69  self.setMode(mode) # mosaicing mode
70  self.xsize = 0 # column size of panels
71  self.ysize = 0 # row size of panels
72 
73  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 79 of file utils.py.

79 
80  def append(self, image, label=None, ctype=None):
81  """Add an image to the list of images to be mosaiced
82  Set may be cleared with Mosaic.reset()
83 
84  Returns the index of this image (may be passed to getBBox())
85  """
86  if not self.xsize:
87  self.xsize = image.getWidth()
88  self.ysize = image.getHeight()
89 
90  self.images.append(image)
91  self.labels.append((label, ctype))
92 
93  return len(self.images)
def lsst.afw.display.utils.Mosaic.drawLabels (   self,
  labels = None,
  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 210 of file utils.py.

211  def drawLabels(self, labels=None, frame=None):
212  """Draw the list labels at the corners of each panel. If labels is None, use the ones
213  specified by Mosaic.append()"""
214 
215  if frame is None:
216  return
217 
218  if not labels:
219  labels = self.labels
220 
221  if not labels:
222  return
223 
224  if len(labels) != self.nImage:
225  raise RuntimeError, ("You provided %d labels for %d panels" % (len(labels), self.nImage))
226 
227  with ds9.Buffering():
228  for i in range(len(labels)):
229  if labels[i]:
230  label, ctype = labels[i], None
231  try:
232  label, ctype = label
233  except:
234  pass
235 
236  if not label:
237  continue
238 
239  ds9.dot(str(label), self.getBBox(i).getMinX(), self.getBBox(i).getMinY(),
240  frame=frame, ctype=ctype)
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 201 of file utils.py.

202  def getBBox(self, ix, iy=None):
203  """Get the BBox for the nth or (ix, iy)the panel"""
204 
205  if iy is None:
206  ix, iy = ix % self.nx, ix/self.nx
207 
208  return afwGeom.Box2I(afwGeom.Point2I(ix*(self.xsize + self.gutter), iy*(self.ysize + self.gutter)),
209  afwGeom.Extent2I(self.xsize, self.ysize))
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.afw.display.utils.Mosaic.makeMosaic (   self,
  images = None,
  frame = None,
  mode = None,
  background = None,
  title = "" 
)
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 frame is specified, display it

Definition at line 94 of file utils.py.

94 
95  def makeMosaic(self, images=None, frame=None, mode=None, background=None, title=""):
96  """Return a mosaic of all the images provided; if none are specified,
97  use the list accumulated with Mosaic.append().
98 
99  Note that this mosaic is a patchwork of the input images; if you want to
100  make a mosaic of a set images of the sky, you probably want to use the coadd code
101 
102  If frame is specified, display it
103  """
104 
105  if not images:
106  images = self.images
108  self.nImage = len(images)
109  if self.nImage == 0:
110  raise RuntimeError, "You must provide at least one image"
111 
112  self.xsize, self.ysize = 0, 0
113  for im in images:
114  w, h = im.getWidth(), im.getHeight()
115  if w > self.xsize:
116  self.xsize = w
117  if h > self.ysize:
118  self.ysize = h
119 
120  if background is None:
121  background = self.background
122  if mode is None:
123  mode = self.mode
124 
125  if mode == "square":
126  nx, ny = 1, self.nImage
127  while nx*im.getWidth() < ny*im.getHeight():
128  nx += 1
129  ny = int(self.nImage/nx)
130 
131  if nx*ny < self.nImage:
132  ny += 1
133  if nx*ny < self.nImage:
134  nx += 1
135 
136  if nx > self.nImage:
137  nx = self.nImage
138 
139  assert(nx*ny >= self.nImage)
140  elif mode == "x":
141  nx, ny = self.nImage, 1
142  elif mode == "y":
143  nx, ny = 1, self.nImage
144  elif isinstance(mode, int):
145  nx = mode
146  ny = self.nImage//nx
147  if nx*ny < self.nImage:
148  ny += 1
149  else:
150  raise RuntimeError, ("Unknown mosaicing mode: %s" % mode)
152  self.nx, self.ny = nx, ny
153 
154  mosaic = images[0].Factory(
155  afwGeom.Extent2I(nx*self.xsize + (nx - 1)*self.gutter, ny*self.ysize + (ny - 1)*self.gutter)
156  )
157  try:
158  mosaic.set(self.background)
159  except AttributeError:
160  raise RuntimeError("Attempt to mosaic images of type %s which don't support set" %
161  type(mosaic))
162 
163  for i in range(len(images)):
164  smosaic = mosaic.Factory(mosaic, self.getBBox(i%nx, i//nx), afwImage.LOCAL)
165  im = images[i]
166 
167  if smosaic.getDimensions() != im.getDimensions(): # im is smaller than smosaic
168  llc = afwGeom.Point2I((smosaic.getWidth() - im.getWidth())//2,
169  (smosaic.getHeight() - im.getHeight())//2)
170  smosaic = smosaic.Factory(smosaic, afwGeom.Box2I(llc, im.getDimensions()), afwImage.LOCAL)
171 
172  smosaic <<= im
173 
174  if frame is not None:
175  ds9.mtv(mosaic, frame=frame, title=title)
176 
177  if images == self.images:
178  self.drawLabels(frame=frame)
179 
180  return mosaic
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.afw.display.utils.Mosaic.reset (   self)
Reset the list of images to be mosaiced

Definition at line 74 of file utils.py.

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

Definition at line 185 of file utils.py.

186  def setBackground(self, background):
187  """Set the value in the gutters"""
188  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 181 of file utils.py.

182  def setGutter(self, gutter):
183  """Set the number of pixels between panels in a mosaic"""
184  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 189 of file utils.py.

190  def setMode(self, mode):
191  """Set mosaicing mode. Valid options:
192  square Make mosaic as square as possible
193  x Make mosaic one image high
194  y Make mosaic one image wide
195  """
196 
197  if mode not in ("square", "x", "y"):
198  raise RuntimeError, ("Unknown mosaicing mode: %s" % mode)
200  self.mode = mode

Member Data Documentation

lsst.afw.display.utils.Mosaic.background

Definition at line 67 of file utils.py.

lsst.afw.display.utils.Mosaic.gutter

Definition at line 66 of file utils.py.

lsst.afw.display.utils.Mosaic.images

Definition at line 76 of file utils.py.

lsst.afw.display.utils.Mosaic.labels

Definition at line 77 of file utils.py.

lsst.afw.display.utils.Mosaic.mode

Definition at line 199 of file utils.py.

lsst.afw.display.utils.Mosaic.nImage

Definition at line 107 of file utils.py.

lsst.afw.display.utils.Mosaic.ny

Definition at line 151 of file utils.py.

lsst.afw.display.utils.Mosaic.xsize

Definition at line 69 of file utils.py.

lsst.afw.display.utils.Mosaic.ysize

Definition at line 70 of file utils.py.


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