LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
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="")
 
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 70 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 120 of file utils.py.

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

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 134 of file utils.py.

134  def append(self, image, label=None, ctype=None):
135  """Add an image to the list of images to be mosaiced
136 
137  Returns
138  -------
139  index
140  the index of this image (may be passed to `getBBox()`)
141 
142  Notes
143  -----
144  Set may be cleared with ``Mosaic.reset()``
145  """
146  if not self.xsize:
147  self.xsize = image.getWidth()
148  self.ysize = image.getHeight()
149 
150  self.images.append(image)
151  self.labels.append((label, ctype))
152 
153  return len(self.images)
154 
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 303 of file utils.py.

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

◆ 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 285 of file utils.py.

285  def getBBox(self, ix, iy=None):
286  """Get the BBox for a panel
287 
288  Parameters
289  ----------
290  ix : `int`
291  If ``iy`` is not `None`, this is the x coordinate of the panel.
292  If ``iy`` is `None`, this is the number of the panel.
293  iy : `int`, optional
294  The y coordinate of the panel.
295  """
296 
297  if iy is None:
298  ix, iy = ix % self.nx, ix//self.nx
299 
300  return lsst.geom.Box2I(lsst.geom.PointI(ix*(self.xsize + self.gutter), iy*(self.ysize + self.gutter)),
301  lsst.geom.ExtentI(self.xsize, self.ysize))
302 
An integer coordinate rectangle.
Definition: Box.h:55

◆ makeMosaic()

def lsst.afw.display.utils.Mosaic.makeMosaic (   self,
  images = None,
  display = "deferToFrame",
  mode = None,
  background = None,
  title = "" 
)
Return a mosaic of all the images provided.

If none are specified, use the list accumulated with `Mosaic.append()`.

If display is specified, display the mosaic

Definition at line 155 of file utils.py.

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

◆ nImage()

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

Definition at line 340 of file utils.py.

340  def nImage(self):
341  """Number of images
342  """
343  return len(self.images)
344 
345 

◆ reset()

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

Definition at line 129 of file utils.py.

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

◆ setBackground()

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

Definition at line 259 of file utils.py.

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

◆ setGutter()

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

Definition at line 254 of file utils.py.

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

◆ 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 264 of file utils.py.

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

Member Data Documentation

◆ background

lsst.afw.display.utils.Mosaic.background

Definition at line 122 of file utils.py.

◆ gutter

lsst.afw.display.utils.Mosaic.gutter

Definition at line 121 of file utils.py.

◆ images

lsst.afw.display.utils.Mosaic.images

Definition at line 131 of file utils.py.

◆ labels

lsst.afw.display.utils.Mosaic.labels

Definition at line 132 of file utils.py.

◆ mode

lsst.afw.display.utils.Mosaic.mode

Definition at line 283 of file utils.py.

◆ nImage

lsst.afw.display.utils.Mosaic.nImage

Definition at line 178 of file utils.py.

◆ ny

lsst.afw.display.utils.Mosaic.ny

Definition at line 221 of file utils.py.

◆ xsize

lsst.afw.display.utils.Mosaic.xsize

Definition at line 124 of file utils.py.

◆ ysize

lsst.afw.display.utils.Mosaic.ysize

Definition at line 125 of file utils.py.


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