lsst.synpipe  15.0-3-g11fe1a0+10
showFootprints.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """
3 function to show a list of src footprints in a mosaic
4 """
5 from __future__ import absolute_import
6 
7 from builtins import str
8 from builtins import range
9 import argparse
10 
11 import lsst.afw.image
13 import lsst.afw.display.ds9 as ds9
15 
16 from . import matchFakes
17 
18 import numpy.random
19 
20 
21 def getMosaic(sources, exposure, idname):
22  """
23  make a ds9 mosaic for the given source list from the given exposure
24 
25  stolen from psfMosaic.py on the sphinx documentation
26  """
27  img = exposure.getMaskedImage().getImage()
28  subImages = []
29  labels = []
30  for src in sources:
31  footBBox = src.getFootprint().getBBox()
32  subimg = lsst.afw.image.ImageF(img, footBBox,
33  lsst.afw.image.PARENT, True)
34  footMask = lsst.afw.image.ImageU(footBBox)
35  src.getFootprint().insertIntoImage(footMask, 1, footBBox)
36  subimg *= footMask.convertF()
37  subImages.append(subimg)
38  labels.append('ID=%s' % str(src.get(idname)))
39 
41  m.setGutter(2)
42  m.setBackground(0)
43  m.setMode("square")
44 
45  # create the mosaic
46  for img in subImages:
47  m.append(img)
48  mosaic = m.makeMosaic()
49 
50  # display it with labels in ds9
51  ds9.mtv(mosaic)
52  m.drawLabels(labels)
53 
54 
55 def main(root, visit, ccd, fakes=None, blends=False, listobj=16, filt=None):
56 
57  butler = lsst.daf.persistence.Butler(root)
58  dataId = {'visit': visit,
59  'ccd': int(ccd)} if filt is None else {'tract': visit,
60  'patch': ccd,
61  'filter': filt}
62 
63  if fakes is not None:
64  src = matchFakes.getFakeSources(butler, dataId,
65  extraCols=('zeropoint'),
66  radecMatch=fakes)
67  else:
68  src = butler.get('src' if filt is None else 'deepCoadd-src', dataId)
69  if not blends:
70  src = [s for s in src if ((s.get('deblend.nchild') == 0) &
71  (s.get('parent') == 0))]
72  else:
73  src = [s for s in src if (s.get('deblend.nchild') == 0)]
74 
75  exposure = butler.get('calexp' if filt is None else 'deepCoadd', dataId)
76 
77  if type(listobj) is int:
78  listobj = numpy.random.choice(list(range(len(src))), listobj, False)
79 
80  srcList = [src[i] for i in listobj]
81 
82  getMosaic(srcList, exposure, 'fakeId' if fakes else 'id')
83 
84 
85 if __name__ == '__main__':
86  parser = argparse.ArgumentParser()
87  parser.add_argument('root', help="Root directory of data repository")
88  parser.add_argument("visit", type=int, help="Visit or tract")
89  parser.add_argument("ccd", type=str, help="CCD or patch")
90  parser.add_argument('-d', '--band', default=None,
91  help='HSC filter, used with tract/patch')
92  parser.add_argument('-f', '--fake', default=None,
93  help='show fake sources, using -f as catalog')
94  parser.add_argument('-n', '--number', dest='num',
95  help='number of objects to show',
96  default=16, type=int)
97  parser.add_argument('-b', '--blends', action='store_true',
98  default=False, help='show blended systems')
99 
100  args = parser.parse_args()
101 
102  main(args.root, args.visit, args.ccd,
103  fakes=args.fake, listobj=args.num,
104  blends=args.blends, filt=args.band)
def getMosaic(sources, exposure, idname)
def main(root, visit, ccd, fakes=None, blends=False, listobj=16, filt=None)