LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
LSSTDataManagementBasePackage
showFootprints.py
Go to the documentation of this file.
1 """
2 function to show a list of src footprints in a mosaic
3 """
4 
5 import argparse
6 
7 import lsst.afw.image
9 import lsst.afw.display as afwDisplay
11 
12 from . import matchFakes
13 
14 import numpy.random
15 
16 
17 def getMosaic(sources, exposure, idname):
18  """
19  make a mosaic for the given source list from the given exposure
20 
21  stolen from psfMosaic.py on the sphinx documentation
22  """
23  img = exposure.getMaskedImage().getImage()
24  subImages = []
25  labels = []
26  for src in sources:
27  footBBox = src.getFootprint().getBBox()
28  subimg = lsst.afw.image.ImageF(img, footBBox,
29  lsst.afw.image.PARENT, True)
30  footMask = lsst.afw.image.ImageU(footBBox)
31  src.getFootprint().insertIntoImage(footMask, 1, footBBox)
32  subimg *= footMask.convertF()
33  subImages.append(subimg)
34  labels.append('ID=%s' % str(src.get(idname)))
35 
36  m = afwDisplay.utils.Mosaic()
37  m.setGutter(2)
38  m.setBackground(0)
39  m.setMode("square")
40 
41  # create the mosaic
42  for img in subImages:
43  m.append(img)
44  mosaic = m.makeMosaic()
45 
46  # display it with labels
47  disp = afwDisplay.Display()
48  disp.mtv(mosaic, title="mosaic")
49  m.drawLabels(labels)
50 
51 
52 def main(root, visit, ccd, fakes=None, blends=False, listobj=16, filt=None):
53 
54  butler = lsst.daf.persistence.Butler(root)
55  dataId = {'visit': visit,
56  'ccd': int(ccd)} if filt is None else {'tract': visit,
57  'patch': ccd,
58  'filter': filt}
59 
60  if fakes is not None:
61  src = matchFakes.getFakeSources(butler, dataId,
62  extraCols=('zeropoint'),
63  radecMatch=fakes)
64  else:
65  src = butler.get('src' if filt is None else 'deepCoadd-src', dataId)
66  if not blends:
67  src = [s for s in src if ((s.get('deblend.nchild') == 0) &
68  (s.get('parent') == 0))]
69  else:
70  src = [s for s in src if (s.get('deblend.nchild') == 0)]
71 
72  exposure = butler.get('calexp' if filt is None else 'deepCoadd', dataId)
73 
74  if type(listobj) is int:
75  listobj = numpy.random.choice(list(range(len(src))), listobj, False)
76 
77  srcList = [src[i] for i in listobj]
78 
79  getMosaic(srcList, exposure, 'fakeId' if fakes else 'id')
80 
81 
82 if __name__ == '__main__':
83  parser = argparse.ArgumentParser()
84  parser.add_argument('root', help="Root directory of data repository")
85  parser.add_argument("visit", type=int, help="Visit or tract")
86  parser.add_argument("ccd", type=str, help="CCD or patch")
87  parser.add_argument('-d', '--band', default=None,
88  help='HSC filter, used with tract/patch')
89  parser.add_argument('-f', '--fake', default=None,
90  help='show fake sources, using -f as catalog')
91  parser.add_argument('-n', '--number', dest='num',
92  help='number of objects to show',
93  default=16, type=int)
94  parser.add_argument('-b', '--blends', action='store_true',
95  default=False, help='show blended systems')
96 
97  args = parser.parse_args()
98 
99  main(args.root, args.visit, args.ccd,
100  fakes=args.fake, listobj=args.num,
101  blends=args.blends, filt=args.band)
def getMosaic(sources, exposure, idname)
table::Key< int > type
Definition: Detector.cc:163
def main(root, visit, ccd, fakes=None, blends=False, listobj=16, filt=None)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
daf::base::PropertyList * list
Definition: fits.cc:903