gstlal-inspiral  1.9.3
 All Classes Namespaces Files Functions
gstlal_inspiral_add_mass_models
1 #!/usr/bin/env python3
2 #
3 # Copyright (C) 2017,2018 Heather Fong and 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 h5py
20 import argparse
21 import numpy
22 
23 parser = argparse.ArgumentParser(description = "Add mass models for prior weighting of templates")
24 parser.add_argument("--output", metavar='name', type=str, help='The output file name', default = "inspiral_mass_model.h5")
25 parser.add_argument("modelfiles", nargs = "+")
26 options = parser.parse_args()
27 
28 SNRshape = (0,)
29 coeffshape = (1,1,0)
30 
31 for fname in options.modelfiles:
32  f = h5py.File(fname, "r")
33  if f["SNR"].shape[0] > SNRshape[0]:
34  SNRshape = f["SNR"].shape
35  if f["coefficients"].shape[2] > coeffshape[2]:
36  coeffshape = f["coefficients"].shape
37  f.close()
38 
39 coefficients = numpy.zeros(coeffshape)
40 SNR = numpy.zeros(SNRshape)
41 
42 for fname in options.modelfiles:
43  f = h5py.File(fname, "r")
44  SNR += f["SNR"]
45  coefficients[:,:,:f["coefficients"].shape[2]] += f["coefficients"]
46  f.close()
47 
48 f = h5py.File(options.output, "w")
49 f.create_dataset("SNR", data = SNR)
50 f.create_dataset("coefficients", data = coefficients)