LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | List of all members
lsst.afw.display.utils.Mosaic Class Reference

Public Member Functions

def __init__ (self, gutter=3, background=0, mode="square")
 
def reset (self)
 
def append (self, image, label=None, ctype=None)
 
def makeMosaic (self, images=None, display="deferToFrame", mode=None, background=None, title="", frame=None)
 
def setGutter (self, gutter)
 
def setBackground (self, background)
 
def setMode (self, mode)
 
def getBBox (self, ix, iy=None)
 
def drawLabels (self, labels=None, display="deferToFrame", frame=None)
 
def nImage (self)
 

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 `~lsst.afw.image.Mask` or `~lsst.afw.image.MaskedImage`)

Notes
-----
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

Examples
--------

.. code-block:: py

   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:

.. code-block:: py

   mosaic = m.makeMosaic(display=display)

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

Definition at line 71 of file utils.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 121 of file utils.py.

121  def __init__(self, gutter=3, background=0, mode="square"):
122  self.gutter = gutter # number of pixels between panels in a mosaic
123  self.background = background # value in gutters
124  self.setMode(mode) # mosaicing mode
125  self.xsize = 0 # column size of panels
126  self.ysize = 0 # row size of panels
127 
128  self.reset()
129 
def __init__(self, minimum, dataRange, Q)

Member Function Documentation

◆ append()

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

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

Notes
-----
Set may be cleared with ``Mosaic.reset()``

Definition at line 135 of file utils.py.

135  def append(self, image, label=None, ctype=None):
136  """Add an image to the list of images to be mosaiced
137 
138  Returns
139  -------
140  index
141  the index of this image (may be passed to `getBBox()`)
142 
143  Notes
144  -----
145  Set may be cleared with ``Mosaic.reset()``
146  """
147  if not self.xsize:
148  self.xsize = image.getWidth()
149  self.ysize = image.getHeight()
150 
151  self.images.append(image)
152  self.labels.append((label, ctype))
153 
154  return len(self.images)
155 
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33

◆ drawLabels()

def lsst.afw.display.utils.Mosaic.drawLabels (   self,
  labels = None,
  display = "deferToFrame",
  frame = None 
)
Draw the list labels at the corners of each panel.

Notes
-----
If labels is None, use the ones specified by ``Mosaic.append()``

Definition at line 305 of file utils.py.

305  def drawLabels(self, labels=None, display="deferToFrame", frame=None):
306  """Draw the list labels at the corners of each panel.
307 
308  Notes
309  -----
310  If labels is None, use the ones specified by ``Mosaic.append()``
311  """
312 
313  if not labels:
314  labels = self.labels
315 
316  if not labels:
317  return
318 
319  if len(labels) != self.nImage:
320  raise RuntimeError("You provided %d labels for %d panels" % (
321  len(labels), self.nImage))
322 
323  display = _getDisplayFromDisplayOrFrame(display, frame)
324  if not display:
325  return
326 
327  with display.Buffering():
328  for i in range(len(labels)):
329  if labels[i]:
330  label, ctype = labels[i], None
331  try:
332  label, ctype = label
333  except Exception:
334  pass
335 
336  if not label:
337  continue
338 
339  display.dot(str(label), self.getBBox(i).getMinX(),
340  self.getBBox(i).getMinY(), ctype=ctype)
341 

◆ getBBox()

def lsst.afw.display.utils.Mosaic.getBBox (   self,
  ix,
  iy = None 
)
Get the BBox for a panel

Parameters
----------
ix : `int`
    If ``iy`` is not `None`, this is the x coordinate of the panel.
    If ``iy`` is `None`, this is the number of the panel.
iy : `int`, optional
    The y coordinate of the panel.

Definition at line 287 of file utils.py.

287  def getBBox(self, ix, iy=None):
288  """Get the BBox for a panel
289 
290  Parameters
291  ----------
292  ix : `int`
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.
295  iy : `int`, optional
296  The y coordinate of the panel.
297  """
298 
299  if iy is None:
300  ix, iy = ix % self.nx, ix//self.nx
301 
302  return lsst.geom.Box2I(lsst.geom.PointI(ix*(self.xsize + self.gutter), iy*(self.ysize + self.gutter)),
303  lsst.geom.ExtentI(self.xsize, self.ysize))
304 
An integer coordinate rectangle.
Definition: Box.h:54

◆ makeMosaic()

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()`.

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

Definition at line 157 of file utils.py.

157  background=None, title="", frame=None):
158  """Return a mosaic of all the images provided.
159 
160  If none are specified, use the list accumulated with `Mosaic.append()`.
161 
162  If display or frame (deprecated) is specified, display the mosaic
163  """
164 
165  if images:
166  if self.images:
167  raise RuntimeError(
168  "You have already appended %d images to this Mosaic" % len(self.images))
169 
170  try:
171  len(images) # check that it quacks like a list
172  except TypeError:
173  images = [images]
174 
175  self.images = images
176  else:
177  images = self.images
178 
179  if self.nImage == 0:
180  raise RuntimeError("You must provide at least one image")
181 
182  self.xsize, self.ysize = 0, 0
183  for im in images:
184  w, h = im.getWidth(), im.getHeight()
185  if w > self.xsize:
186  self.xsize = w
187  if h > self.ysize:
188  self.ysize = h
189 
190  if background is None:
191  background = self.background
192  if mode is None:
193  mode = self.mode
194 
195  if mode == "square":
196  nx, ny = 1, self.nImage
197  while nx*im.getWidth() < ny*im.getHeight():
198  nx += 1
199  ny = self.nImage//nx
200 
201  if nx*ny < self.nImage:
202  ny += 1
203  if nx*ny < self.nImage:
204  nx += 1
205 
206  if nx > self.nImage:
207  nx = self.nImage
208 
209  assert(nx*ny >= self.nImage)
210  elif mode == "x":
211  nx, ny = self.nImage, 1
212  elif mode == "y":
213  nx, ny = 1, self.nImage
214  elif isinstance(mode, int):
215  nx = mode
216  ny = self.nImage//nx
217  if nx*ny < self.nImage:
218  ny += 1
219  else:
220  raise RuntimeError("Unknown mosaicing mode: %s" % mode)
221 
222  self.nx, self.ny = nx, ny
223 
224  mosaic = images[0].Factory(
225  lsst.geom.Extent2I(nx*self.xsize + (nx - 1)*self.gutter,
226  ny*self.ysize + (ny - 1)*self.gutter)
227  )
228  try:
229  mosaic.set(self.background)
230  except AttributeError:
231  raise RuntimeError("Attempt to mosaic images of type %s which don't support set" %
232  type(mosaic))
233 
234  for i in range(len(images)):
235  smosaic = mosaic.Factory(
236  mosaic, self.getBBox(i%nx, i//nx), afwImage.LOCAL)
237  im = images[i]
238 
239  if smosaic.getDimensions() != im.getDimensions(): # im is smaller than smosaic
240  llc = lsst.geom.PointI((smosaic.getWidth() - im.getWidth())//2,
241  (smosaic.getHeight() - im.getHeight())//2)
242  smosaic = smosaic.Factory(smosaic, lsst.geom.Box2I(
243  llc, im.getDimensions()), afwImage.LOCAL)
244 
245  smosaic[:] = im
246 
247  display = _getDisplayFromDisplayOrFrame(display, frame)
248  if display:
249  display.mtv(mosaic, title=title)
250 
251  if images == self.images:
252  self.drawLabels(display=display)
253 
254  return mosaic
255 
table::Key< int > type
Definition: Detector.cc:167
An integer coordinate rectangle.
Definition: Box.h:54

◆ nImage()

def lsst.afw.display.utils.Mosaic.nImage (   self)
Number of images

Definition at line 343 of file utils.py.

343  def nImage(self):
344  """Number of images
345  """
346  return len(self.images)
347 
348 

◆ reset()

def lsst.afw.display.utils.Mosaic.reset (   self)
Reset the list of images to be mosaiced

Definition at line 130 of file utils.py.

130  def reset(self):
131  """Reset the list of images to be mosaiced"""
132  self.images = [] # images to mosaic together
133  self.labels = [] # labels for images
134 

◆ setBackground()

def lsst.afw.display.utils.Mosaic.setBackground (   self,
  background 
)
Set the value in the gutters

Definition at line 261 of file utils.py.

261  def setBackground(self, background):
262  """Set the value in the gutters
263  """
264  self.background = background
265 

◆ setGutter()

def lsst.afw.display.utils.Mosaic.setGutter (   self,
  gutter 
)
Set the number of pixels between panels in a mosaic

Definition at line 256 of file utils.py.

256  def setGutter(self, gutter):
257  """Set the number of pixels between panels in a mosaic
258  """
259  self.gutter = gutter
260 

◆ setMode()

def lsst.afw.display.utils.Mosaic.setMode (   self,
  mode 
)
Set mosaicing mode.

Parameters
----------
mode : {"square", "x", "y"}
    Valid options:

    square
Make mosaic as square as possible
    x
Make mosaic one image high
    y
Make mosaic one image wide

Definition at line 266 of file utils.py.

266  def setMode(self, mode):
267  """Set mosaicing mode.
268 
269  Parameters
270  ----------
271  mode : {"square", "x", "y"}
272  Valid options:
273 
274  square
275  Make mosaic as square as possible
276  x
277  Make mosaic one image high
278  y
279  Make mosaic one image wide
280  """
281 
282  if mode not in ("square", "x", "y"):
283  raise RuntimeError("Unknown mosaicing mode: %s" % mode)
284 
285  self.mode = mode
286 

Member Data Documentation

◆ background

lsst.afw.display.utils.Mosaic.background

Definition at line 123 of file utils.py.

◆ gutter

lsst.afw.display.utils.Mosaic.gutter

Definition at line 122 of file utils.py.

◆ images

lsst.afw.display.utils.Mosaic.images

Definition at line 132 of file utils.py.

◆ labels

lsst.afw.display.utils.Mosaic.labels

Definition at line 133 of file utils.py.

◆ mode

lsst.afw.display.utils.Mosaic.mode

Definition at line 285 of file utils.py.

◆ nImage

lsst.afw.display.utils.Mosaic.nImage

Definition at line 179 of file utils.py.

◆ ny

lsst.afw.display.utils.Mosaic.ny

Definition at line 222 of file utils.py.

◆ xsize

lsst.afw.display.utils.Mosaic.xsize

Definition at line 125 of file utils.py.

◆ ysize

lsst.afw.display.utils.Mosaic.ysize

Definition at line 126 of file utils.py.


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