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
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.ds9 as ds9
11 
12 from . import matchFakes
13 
14 import numpy.random
15 
16 
17 def getMosaic(sources, exposure, idname):
18  """
19  make a ds9 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 
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 in ds9
47  ds9.mtv(mosaic)
48  m.drawLabels(labels)
49 
50 
51 def main(root, visit, ccd, fakes=None, blends=False, listobj=16, filt=None):
52 
53  butler = lsst.daf.persistence.Butler(root)
54  dataId = {'visit': visit,
55  'ccd': int(ccd)} if filt is None else {'tract': visit,
56  'patch': ccd,
57  'filter': filt}
58 
59  if fakes is not None:
60  src = matchFakes.getFakeSources(butler, dataId,
61  extraCols=('zeropoint'),
62  radecMatch=fakes)
63  else:
64  src = butler.get('src' if filt is None else 'deepCoadd-src', dataId)
65  if not blends:
66  src = [s for s in src if ((s.get('deblend.nchild') == 0) &
67  (s.get('parent') == 0))]
68  else:
69  src = [s for s in src if (s.get('deblend.nchild') == 0)]
70 
71  exposure = butler.get('calexp' if filt is None else 'deepCoadd', dataId)
72 
73  if type(listobj) is int:
74  listobj = numpy.random.choice(list(range(len(src))), listobj, False)
75 
76  srcList = [src[i] for i in listobj]
77 
78  getMosaic(srcList, exposure, 'fakeId' if fakes else 'id')
79 
80 
81 if __name__ == '__main__':
82  parser = argparse.ArgumentParser()
83  parser.add_argument('root', help="Root directory of data repository")
84  parser.add_argument("visit", type=int, help="Visit or tract")
85  parser.add_argument("ccd", type=str, help="CCD or patch")
86  parser.add_argument('-d', '--band', default=None,
87  help='HSC filter, used with tract/patch')
88  parser.add_argument('-f', '--fake', default=None,
89  help='show fake sources, using -f as catalog')
90  parser.add_argument('-n', '--number', dest='num',
91  help='number of objects to show',
92  default=16, type=int)
93  parser.add_argument('-b', '--blends', action='store_true',
94  default=False, help='show blended systems')
95 
96  args = parser.parse_args()
97 
98  main(args.root, args.visit, args.ccd,
99  fakes=args.fake, listobj=args.num,
100  blends=args.blends, filt=args.band)
def getMosaic(sources, exposure, idname)
def main(root, visit, ccd, fakes=None, blends=False, listobj=16, filt=None)
daf::base::PropertyList * list
Definition: fits.cc:833