LSST Applications g063fba187b+fee0456c91,g0f08755f38+ea96e5a5a3,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+90257ff92a,g20f6ffc8e0+ea96e5a5a3,g217e2c1bcf+937a289c59,g28da252d5a+daa7da44eb,g2bbee38e9b+253935c60e,g2bc492864f+253935c60e,g3156d2b45e+6e55a43351,g32e5bea42b+31359a2a7a,g347aa1857d+253935c60e,g35bb328faa+a8ce1bb630,g3a166c0a6a+253935c60e,g3b1af351f3+a8ce1bb630,g3e281a1b8c+c5dd892a6c,g414038480c+416496e02f,g41af890bb2+afe91b1188,g599934f4f4+0db33f7991,g7af13505b9+e36de7bce6,g80478fca09+da231ba887,g82479be7b0+a4516e59e3,g858d7b2824+ea96e5a5a3,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+bc6ab8dfbd,gb58c049af0+d64f4d3760,gc28159a63d+253935c60e,gcab2d0539d+3f2b72788c,gcf0d15dbbd+4ea9c45075,gda6a2b7d83+4ea9c45075,gdaeeff99f8+1711a396fd,ge79ae78c31+253935c60e,gef2f8181fd+3031e3cf99,gf0baf85859+c1f95f4921,gfa517265be+ea96e5a5a3,gfa999e8aa5+17cd334064,w.2024.50
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
lsst.afw.display.utils.Mosaic Class Reference

Public Member Functions

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

Public Attributes

 gutter
 
 background
 
 xsize
 
 ysize
 
 images
 
 labels
 
 nImage
 
 nx
 
 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__()

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

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

◆ drawLabels()

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

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

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

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

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

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

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

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.

◆ nx

lsst.afw.display.utils.Mosaic.nx

Definition at line 221 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: