Extract information from a pesummary TGR file
When the summarytgr executable is used, all
data is stored in the output h5
file (by default called
tgr_samples.h5). Here, we give details about how to extract the information
stored.
Loading the file
The tgr_samples.h5 file can be loaded with the universal read function. For example:
>>> from pesummary.io import read
>>> f = read('tgr_samples.h5')
>>> type(f)
<class 'pesummary.gw.file.formats.pesummary.TGRPESummary'>
IMRCT data
The purpose of the IMRCT test is to calculate a PDF for the final mass and final spin deviation parameters, see Ghosh et al 2018 for details. If only one analysis is stored in the tgr_samples.h5 file, the PDF can be extracted with the following code snippet:
>>> deviation = f.imrct_deviation["final_mass_final_spin_deviations"]
>>> type(deviation)
<class 'pesummary.utils.pdf.DiscretePDF2D'>
If more than one analysis is stored, we need to specify which analysis we wish to load:
>>> interested = "analysis_1"
>>> deviation = f.imrct_deviation[interested]["final_mass_final_spin_deviations"]
>>> type(deviation)
<class 'pesummary.utils.pdf.DiscretePDF2D'>
The PDF is stored as a ProbabilityDict2D class. This only stores the 2D PDF. However, we can generate the marginalized PDF for both the final mass deviation and final spin deviation at once with the following:
>>> full = deviation.marginalize()
>>> type(full)
<class 'pesummary.utils.pdf.DiscretePDF2Dplus1D'>
The output is the a DiscretePDF2Dplus1D class. We may then use the input class methods to extract the PDF for the final mass deviation:
>>> final_mass_deviation = full.probs_x.x
>>> final_mass_deviation_pdf = full.probs_x.probs
We may extract the final spin deviation PDF using similar code to above but
changing x
to y
. For example:
>>> final_spin_deviation = full.probs_y.x
>>> final_spin_deviation_pdf = full.probs_y.probs
These PDFs are dependent on a set of posterior samples which were generated from an inspiral only and postinspiral only analysis. These posterior samples are also stored in the tgr_samples.h5 file. These posterior samples are accessed in the same way as other files. For example,
>>> pe_samples = f.samples_dict
>>> type(pe_samples)
<class 'pesummary.utils.samples_dict.MultiAnalysisSamplesDict'>
>>> type(pe_samples["inspiral"])
<class 'pesummary.utils.samples_dict.SamplesDict'>
This returns a MultiAnalysisSamplesDict class which stores both the inspiral and postinspiral samples. The individual inspiral and postinspiral analyses are stored as a SamplesDict class.
All additional information is stored in the meta data. We can extract the meta data with the following:
>>> kwargs = f.extra_kwargs
If only one analysis is stored, the kwargs are stored under the label primary. If multiple analyses are stored, we use the labels which were provided from the command line,
>>> interested = "primary"
>>> print(kwargs[interested])
{'GR Quantile (%)': X, 'N_bins': Y, 'Time (seconds)': Z, 'evolve_spins': array([b'False', b'False'], dtype='|S5'), 'inspiral approximant': 'approximant', 'inspiral maximum frequency (Hz)': 'frequency', 'postinspiral approximant': 'approximant', 'postinspiral minimum frequency (Hz)': 'frequency'}
Where we are using place holders (X
, Y
, Z
,
'approximant'
, …) for the above code snippet.