lsst.pipe.tasks  14.0-39-g03bf09b5
visualization.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010, 2011, 2012 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 from __future__ import absolute_import, division, print_function
24 from builtins import zip
25 from builtins import range
26 from matplotlib import pyplot
27 
28 import lsst.afw.geom
29 
30 
31 def plotObservations(catalog, wcs):
32  """Plot the bounding boxes of an observation catalog (see MockCoaddTask.buildObservationCatalog)
33  using matplotlib, in the coordinates defined by the given Wcs (usually a skymap Wcs).
34  """
35  for record in catalog:
36  box = lsst.afw.geom.Box2D(record.getBBox())
37  x = []
38  y = []
39  iWcs = record.getWcs()
40  for xi, yi in box.getCorners():
41  try:
42  coord = iWcs.pixelToSky(xi, yi)
43  xo, yo = wcs.skyToPixel(coord)
44  x.append(xo)
45  y.append(yo)
46  except:
47  print("WARNING: point %d, %d failed" % (xi, yi))
48  pyplot.fill(x, y, facecolor='r', alpha=0.1, edgecolor=None)
49 
50 
51 def plotPatches(tractInfo):
52  """Plot the patches in a skymap tract using matplotlib.
53  """
54  nPatchX, nPatchY = tractInfo.getNumPatches()
55  for iPatchX in range(nPatchX):
56  for iPatchY in range(nPatchY):
57  patchInfo = tractInfo.getPatchInfo((iPatchX, iPatchY))
58  xp1, yp1 = list(zip(*patchInfo.getOuterBBox().getCorners()))
59  xp2, yp2 = list(zip(*patchInfo.getInnerBBox().getCorners()))
60  pyplot.fill(xp1, yp1, fill=False, edgecolor='g', linestyle='dashed')
61  pyplot.fill(xp2, yp2, fill=False, edgecolor='g')
62 
63 
64 def plotTruth(catalog, wcs):
65  """Plot the objects in a truth catalog as dots using matplotlib, in the coordinate
66  system defined by the given Wcs.
67  """
68  xp = []
69  yp = []
70  for record in catalog:
71  x, y = wcs.skyToPixel(record.getCoord())
72  xp.append(x)
73  yp.append(y)
74  pyplot.plot(xp, yp, 'k+')
75 
76 
77 def displayImages(root):
78  """Display coadd images with DS9 in different frames, with the bounding boxes of the
79  observations that went into them overlayed.
80  """
83  butler = lsst.daf.persistence.Butler(root=root)
84  skyMap = butler.get("deepCoadd_skyMap")
85  tractInfo = skyMap[0]
87  coadds = [patchRef.get("deepCoadd", immediate=True)
88  for patchRef in task.iterPatchRefs(butler, tractInfo)]
89  for n, coadd in enumerate(coadds):
90  lsst.afw.display.ds9.mtv(coadd, frame=n+1)
91  for n, coadd in enumerate(coadds):
93  return butler
94 
95 
96 def makePlots(root):
97  """Convenience function to make all matplotlib plots.
98  """
100  import lsst.daf.persistence
101  butler = lsst.daf.persistence.Butler(root=root)
102  skyMap = butler.get("deepCoadd_skyMap")
103  observations = butler.get("observations", tract=0)
104  truth = butler.get("truth", tract=0)
105  tractInfo = skyMap[0]
106  plotPatches(tractInfo)
107  plotObservations(observations, tractInfo.getWcs())
108  plotTruth(truth, tractInfo.getWcs())
109  pyplot.axis("scaled")
110  pyplot.show()
111  return butler
def drawCoaddInputs(exposure, frame=None, ctype=None, bin=1, display="deferToFrame")
def mtv(data, frame=None, title="", wcs=None, args, kwargs)