Logo coherent WaveBurst  
Library Reference Guide
Logo
h52samples.py
Go to the documentation of this file.
1 # Copyright (C) 2020 Gabriele Vedovato
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 # extract posterior samples (model) from h5 file and save to dat file
17 # uses pesummary package
18 
19 from pesummary.io import write
20 from pesummary.gw.file.read import read
21 import numpy as np
22 import sys
23 import os
24 
25 ifile=sys.argv[1]
26 model=sys.argv[2]
27 ofile=sys.argv[3]
28 
29 def main(ifile,model,ofile):
30 
31  cwd = os.getcwd()
32 
33  print('\nPlease wait while reading file '+cwd+'/'+ifile+' ...')
34 
35  f = read(ifile)
36  print(f.labels)
37 
38  print('\nPlease wait while reading samples '+model+' from file '+cwd+'/'+ifile+' ...')
39 
40  samples_dict = f.samples_dict
41  posterior_samples = samples_dict[model]
42  parameters = sorted(list(posterior_samples.keys()))
43  print(parameters)
44 
45  print('\nPlease wait while writing samples '+model+' to file '+cwd+'/'+ofile+' ...')
46 
47  parameters = list(posterior_samples.keys())
48  samples_array = np.array([posterior_samples[param] for param in parameters]).T
49  write(parameters, samples_array, package="core", file_format="dat", filename=ofile)
50 
51 main(ifile,model,ofile)
TList * list
def main(ifile, model, ofile)
Definition: h52samples.py:29
iD print()