gstlal-inspiral  1.9.2
 All Classes Namespaces Files Functions
gstlal_inspiral_add_dt_dphi_snr_ratio_pdfs
1 #!/usr/bin/env python3
2 #
3 # Copyright (C) 2018, 2019 Chad Hanna
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19 import sys
20 import numpy
21 import h5py
22 from gstlal.stats.inspiral_extrinsics import TimePhaseSNR
23 
24 # Read in and combine all of the input files
25 h5_covmat = h5py.File(sys.argv[1])
26 kwargs = {"SNR":h5_covmat["SNR"], "psd_fname":h5_covmat["psd"]}
27 h5_covmat.close()
28 files = sys.argv[2:]
29 TPS = TimePhaseSNR.from_hdf5(files[0], files[1:], **kwargs)
30 
31 # compute the normalization
32 time, phase, deff = TimePhaseSNR.tile(NSIDE = 8, NANGLE = 17)
33 # This actually doesn't matter it is just needed to map from eff distance to
34 # snr, but the TimePhaseSNR code actually undoes this...
35 h = {"H1":1., "L1":1., "V1":1., "K1":1.}
36 
37 # set the norm to 1
38 combos = TPS.combos + (("H1",),("L1",),("V1",),("K1",))
39 norm = dict((frozenset(k), 1.) for k in combos)
40 TPS.norm = norm
41 
42 def extract_dict(DICT, keys):
43  return dict((k,v) for k,v in DICT.items() if k in keys)
44 
45 norm = dict((frozenset(k), 0.) for k in combos)
46 for i in range(len(time["H1"])):
47  t = dict((k, v[i]) for k, v in time.items())
48  p = dict((k, v[i]) for k, v in phase.items())
49  s = dict((k, h[k] / v[i]) for k, v in deff.items())
50 
51  for ifos in combos:
52  t2 = extract_dict(t, ifos)
53  p2 = extract_dict(p, ifos)
54  s2 = extract_dict(s, ifos)
55  h2 = extract_dict(h, ifos)
56  norm[frozenset(ifos)] += TPS(t2,p2,s2,h2) * (sum(x**2 for x in s2.values())**.5)**4 / len(time["H1"]) * 1. / (16. * numpy.pi**2)
57 
58 TPS.norm = norm
59 
60 # write the result to disk
61 TPS.to_hdf5("inspiral_dtdphi_pdf.h5")