3 matches fakes based on position stored in the calibrated exposure image header
16 """Get list of sources which agree in position with fake ones with tol
20 sources = butler.get(
'src', dataId)
21 cal_md = butler.get(
'calexp_md', dataId)
24 srcX, srcY = sources.getX(), sources.getY()
26 zeropoint = 2.5*np.log10(cal_md.getScalar(
"FLUXMAG0"))
28 flux, ferr = sources.getPsfFlux(), sources.getPsfFluxErr()
30 mag, merr = 2.5*np.log10(flux), 2.5/np.log(10)*(ferr/flux)
34 fakeXY = collections.defaultdict(tuple)
36 fakename = re.compile(
'FAKE([0-9]+)')
37 for card
in cal_md.names():
38 m = fakename.match(card)
40 x, y =
list(map(float, (cal_md.getScalar(card)).split(
',')))
41 fakeXY[int(m.group(1))] = (x, y)
43 srcIndex = collections.defaultdict(list)
44 for fid, fcoord
in fakeXY.items():
45 matched = ((np.abs(srcX-fcoord[0]) < tol) &
46 (np.abs(srcY-fcoord[1]) < tol))
47 srcIndex[fid] = np.where(matched)[0]
53 for s
in srcIndex.values():
56 srcPsfMag.append(mag[ss])
57 srcPsfMerr.append(merr[ss])
58 matchX.append(srcX[ss])
59 matchY.append(srcY[ss])
66 return srcIndex, fakeXY, matchX, matchY, srcPsfMag, srcPsfMerr
72 parser = argparse.ArgumentParser()
73 parser.add_argument(
'rootDir', help=
'root dir of data repo')
74 parser.add_argument(
'visit', help=
'id of visit', type=int)
75 parser.add_argument(
'ccd', help=
'id of ccd', type=int)
76 args = parser.parse_args()
78 starIndex, fakeXY, matchX, matchY, starPsfMag, starPsfMerr =
getFakeSources(args.rootDir,
83 nMatch = len(np.argwhere(starPsfMag))
84 print(
"# Number of Injected Stars : %d" % nInject)
85 print(
"# Number of Matched Stars : %d" % nMatch)
86 print(
"# Visit = %d CCD = %d" % (args.visit, args.ccd))
87 print(
"# FakeX FakeY PSFMag PSFMagErr Deblend ")
89 for i
in range(nInject):
90 if len(starIndex[i]) > 1:
92 elif starPsfMag[i] > 0:
99 print(
"%6.1d %6.1d %7.3f %6.3f %s" % (injectXY[0], injectXY[1],
100 starPsfMag[i], starPsfMerr[i], deblend))
103 if __name__ ==
'__main__':