LSSTApplications  19.0.0-14-gb0260a2+599893a4c6,20.0.0+126303c00d,20.0.0+2f3d0e5c40,20.0.0+36ef800059,20.0.0+5ac7adcc0c,20.0.0+693a64958a,20.0.0+bebc1f60e8,20.0.0+cad136aba6,20.0.0+e2e26847c2,20.0.0+e69b5d60e7,20.0.0-1-g10df615+11b215b765,20.0.0-1-g253301a+36ef800059,20.0.0-1-g2b7511a+bebc1f60e8,20.0.0-1-g4d801e7+aeeb640673,20.0.0-1-g5b95a8c+f111d5f02f,20.0.0-1-g660595b+f45b7d88f4,20.0.0-1-gc96f8cb+e3b38461e6,20.0.0-1-gd1c87d7+85c46248f3,20.0.0-1-gedffbd8+d0b27f8bcb,20.0.0-16-g111fe95+e3b38461e6,20.0.0-16-g18096c8+d1a4df0137,20.0.0-16-g233ea98+a4df35922d,20.0.0-17-ga9337b4+41f27cfd54,20.0.0-2-g4dae9ad+e3b38461e6,20.0.0-2-g7818986+85c46248f3,20.0.0-2-gec03fae+ff10c6d78d,20.0.0-28-g282f9e7e+feda6aebd8,20.0.0-3-g4cc78c6+63636aeed8,20.0.0-3-g6a8623c+d1a4df0137,20.0.0-3-g750bffe+f5427621ce,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-5-g357b56b+f45b7d88f4,20.0.0-5-gfcebe35+e2b15ed341,20.0.0-52-g73d9071+9bf1eb8e0a,20.0.0-7-gcda7bf1+773ba852cb,20.0.0-8-g4540fe2a+952f6d3c43,20.0.0-9-g61a2a9a3d+14f89e4eca,w.2020.40
LSSTDataManagementBasePackage
makeBlendedCat.py
Go to the documentation of this file.
1 """Make a catalog of fakes that are highly blended."""
2 
3 import os
4 import random
5 import argparse
6 
7 import numpy as np
8 from astropy.table import Table, Column
9 
10 
11 def disturbRaDec(num, mu=0.6, sigma=0.6):
12  """Disturb the coordinate a little bit."""
13  return (np.random.normal(mu, sigma, num) / 3600.0)
14 
15 
16 def makeBlendedCat(fakeCat, realCat, raCol='ra', decCol='dec',
17  sigma=0.6, mu=0.6):
18  """Make a highly blended version of fake catalog."""
19  # Fake catalog
20  if not os.path.isfile(fakeCat):
21  raise Exception('# Can not find input fake catalog : %s' % fakeCat)
22  else:
23  fakeTab = Table.read(fakeCat, format='fits')
24  nFake = len(fakeTab)
25  print("# There are %d fake galaxies in the catalog" % nFake)
26  # Name of the output catalog
27  blendTab = fakeCat.replace('.fits', '_highb.fits')
28 
29  # Real catalog
30  if not os.path.isfile(realCat):
31  raise Exception('# Can not find input real catalog : %s' % realCat)
32  else:
33  realTab = Table.read(realCat, format='fits')
34  nReal = len(realTab)
35  print("# There are %d real galaxies in the catalog" % nReal)
36 
37  # Randomly select nFake galaxies from the realCat
38  indices = random.sample(list(range(nReal)), nFake)
39 
40  # Replace the RA, DEC with a small shift
41  fakeTab.add_column(Column(realTab[indices][raCol], name='RA_ori'))
42  fakeTab.add_column(Column(realTab[indices][decCol], name='Dec_ori'))
43 
44  fakeTab['RA'] = (realTab[indices][raCol] + disturbRaDec(nFake,
45  mu=mu,
46  sigma=sigma))
47  fakeTab['Dec'] = (realTab[indices][decCol] + disturbRaDec(nFake,
48  mu=mu,
49  sigma=sigma))
50 
51  # Save the new catalog
52  fakeTab.write(blendTab, format='fits', overwrite=True)
53 
54  return fakeTab
55 
56 
57 if __name__ == '__main__':
58 
59  parser = argparse.ArgumentParser()
60  parser.add_argument("fakeCat", help="Input catalog of fake objects")
61  parser.add_argument("realCat", help="Catalog of real objects")
62  parser.add_argument('--ra', '--raCol', dest='raCol',
63  help='Column for RA in realCat',
64  default='ra')
65  parser.add_argument('--dec', '--decCol', dest='decCol',
66  help='Column for DEC in realCat',
67  default='dec')
68  parser.add_argument('--mu', dest='mu',
69  help='mu of a normal distribution',
70  default=0.6, type=float)
71  parser.add_argument('--sigma', dest='sigma',
72  help='sigma of a normal distribution',
73  default=0.6, type=float)
74 
75  args = parser.parse_args()
76 
77  makeBlendedCat(args.fakeCat, args.realCat,
78  raCol=args.raCol, decCol=args.decCol,
79  sigma=args.sigma, mu=args.mu)
lsst.synpipe.makeBlendedCat.disturbRaDec
def disturbRaDec(num, mu=0.6, sigma=0.6)
Definition: makeBlendedCat.py:11
list
daf::base::PropertyList * list
Definition: fits.cc:913
lsst.synpipe.makeBlendedCat.makeBlendedCat
def makeBlendedCat(fakeCat, realCat, raCol='ra', decCol='dec', sigma=0.6, mu=0.6)
Definition: makeBlendedCat.py:16