LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
visualization.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from builtins import zip
3 from builtins import range
4 #
5 # LSST Data Management System
6 # Copyright 2008, 2009, 2010, 2011, 2012 LSST Corporation.
7 #
8 # This product includes software developed by the
9 # LSST Project (http://www.lsst.org/).
10 #
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the LSST License Statement and
22 # the GNU General Public License along with this program. If not,
23 # see <http://www.lsstcorp.org/LegalNotices/>.
24 #
25 
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]
86  task = lsst.pipe.tasks.mocks.MockCoaddTask()
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
A floating-point coordinate rectangle geometry.
Definition: Box.h:271