LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
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 from matplotlib import pyplot
23 
24 import lsst.afw.geom
25 
26 
27 def plotObservations(catalog, wcs):
28  """Plot the bounding boxes of an observation catalog (see MockCoaddTask.buildObservationCatalog)
29  using matplotlib, in the coordinates defined by the given Wcs (usually a skymap Wcs).
30  """
31  for record in catalog:
32  box = lsst.afw.geom.Box2D(record.getBBox())
33  x = []
34  y = []
35  iWcs = record.getWcs()
36  for xi, yi in box.getCorners():
37  try:
38  coord = iWcs.pixelToSky(xi, yi)
39  xo, yo = wcs.skyToPixel(coord)
40  x.append(xo)
41  y.append(yo)
42  except Exception as e:
43  print("WARNING: point %d, %d failed: error=%s" % (xi, yi, e))
44  pyplot.fill(x, y, facecolor='r', alpha=0.1, edgecolor=None)
45 
46 
47 def plotPatches(tractInfo):
48  """Plot the patches in a skymap tract using matplotlib.
49  """
50  nPatchX, nPatchY = tractInfo.getNumPatches()
51  for iPatchX in range(nPatchX):
52  for iPatchY in range(nPatchY):
53  patchInfo = tractInfo.getPatchInfo((iPatchX, iPatchY))
54  xp1, yp1 = list(zip(*patchInfo.getOuterBBox().getCorners()))
55  xp2, yp2 = list(zip(*patchInfo.getInnerBBox().getCorners()))
56  pyplot.fill(xp1, yp1, fill=False, edgecolor='g', linestyle='dashed')
57  pyplot.fill(xp2, yp2, fill=False, edgecolor='g')
58 
59 
60 def plotTruth(catalog, wcs):
61  """Plot the objects in a truth catalog as dots using matplotlib, in the coordinate
62  system defined by the given Wcs.
63  """
64  xp = []
65  yp = []
66  for record in catalog:
67  x, y = wcs.skyToPixel(record.getCoord())
68  xp.append(x)
69  yp.append(y)
70  pyplot.plot(xp, yp, 'k+')
71 
72 
73 def displayImages(root):
74  """Display coadd images with DS9 in different frames, with the bounding boxes of the
75  observations that went into them overlayed.
76  """
79  butler = lsst.daf.persistence.Butler(root=root)
80  skyMap = butler.get("deepCoadd_skyMap")
81  tractInfo = skyMap[0]
83  coadds = [patchRef.get("deepCoadd", immediate=True)
84  for patchRef in task.iterPatchRefs(butler, tractInfo)]
85  for n, coadd in enumerate(coadds):
86  lsst.afw.display.ds9.mtv(coadd, frame=n+1)
87  for n, coadd in enumerate(coadds):
89  return butler
90 
91 
92 def makePlots(root):
93  """Convenience function to make all matplotlib plots.
94  """
97  butler = lsst.daf.persistence.Butler(root=root)
98  skyMap = butler.get("deepCoadd_skyMap")
99  observations = butler.get("observations", tract=0)
100  truth = butler.get("truth", tract=0)
101  tractInfo = skyMap[0]
102  plotPatches(tractInfo)
103  plotObservations(observations, tractInfo.getWcs())
104  plotTruth(truth, tractInfo.getWcs())
105  pyplot.axis("scaled")
106  pyplot.show()
107  return butler
def drawCoaddInputs(exposure, frame=None, ctype=None, bin=1, display="deferToFrame")
Definition: utils.py:461
A floating-point coordinate rectangle geometry.
Definition: Box.h:294
def mtv(data, frame=None, title="", wcs=None, args, kwargs)
Definition: ds9.py:93
daf::base::PropertyList * list
Definition: fits.cc:833