Sample release for GW190412

This notebook serves as a basic introduction to loading and viewing data released in associaton with the publication titled GW190412: Observation of a Binary-Black-Hole Coalescence with Asymmetric Masses avaliable through DCC.

The data used in these tutorials can be downloaded from the same DCC page.

Note: This notebook has been prepared for the released samples that are available since DCC version 12. Preliminary samples were distributed with preprint versions of the paper. The samples initially released with the published paper contained a minor bug that only affected the calculation of the network matched-filter SNR. This bug has been fixed with the current release.

The released data file can be read in using the PESummary or h5py libraries. For this notebook we'll start with simple stuff using h5py. Then we'll use PESummary v0.9.1 to read the data files as well as for plotting. For general instructions on how to manipulate the data file and/or read this data file with h5py, see the PESummary docs.

In [1]:
# import useful python packages
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import h5py
import scipy
In [2]:
# There is a known incompatibility between some older versions of numpy/scipy and seaborn. 
# Make sure you have an up-to-date version of scipy installed.
# This notebook has been tested with the following versions
for name, package in zip(('numpy', 'scipy', 'seaborn', 'h5py'), (np, scipy, sns, h5py)):
    print('{} version: {}'.format(name, package.__version__))
numpy version: 1.17.3
scipy version: 1.3.2
seaborn version: 0.9.0
h5py version: 2.10.0

Some simple stuff with "vanilla" h5py

In [3]:
# read in the data
fn = 'GW190412_posterior_samples_v3.h5'
data = h5py.File(fn,'r')

# print out parametrized waveform family names ("approximants" in LIGO jargon).
print('approximants:',data.keys())

# print out top-level data structures for one approximant. Here fore example we use the combined samples
# between IMRPhenomPv3HM and SEOBNRv4PHM. The data structure is the same for all approximants.
print('Top-level data structures:',data['combined'].keys())

# extract posterior samples for one of the approximants
posterior_samples = data['combined']['posterior_samples']
print('data structures in posterior_samples:',posterior_samples.dtype)
pnames = [item for item in posterior_samples.dtype.names]
print('parameter names:',pnames)

# get samples for one of the parameters
dL = posterior_samples['luminosity_distance']
print('dL shape, mean, std =',dL.shape,dL.mean(),dL.std())

# smooth it
from scipy.stats.kde import gaussian_kde
hs = gaussian_kde(dL)

# histogram, and overlay the smoothed PDF
plt.figure()
h, b, o = plt.hist(dL,bins=100)
hsmoothed = hs(b)*len(dL)*(b[1]-b[0])
plt.plot(b,hsmoothed)
plt.xlabel('luminosity distance')
plt.ylabel('posterior PDF')
plt.show()

# release memory for the data
#del data
approximants: <KeysViewHDF5 ['IMRPhenomD', 'IMRPhenomHM', 'IMRPhenomPv3', 'IMRPhenomPv3HM', 'NRHybSur3dq8', 'SEOBNRv4HM_ROM', 'SEOBNRv4P', 'SEOBNRv4PHM', 'SEOBNRv4_ROM', 'combined', 'history', 'version']>
Top-level data structures: <KeysViewHDF5 ['approximant', 'calibration_envelope', 'config_file', 'injection_data', 'meta_data', 'posterior_samples', 'priors', 'psds', 'version']>
data structures in posterior_samples: [('recalib_V1_amplitude_0', '<f8'), ('chi_eff', '<f8'), ('phi_12', '<f8'), ('phi_1', '<f8'), ('iota', '<f8'), ('recalib_V1_phase_4', '<f8'), ('tilt_2', '<f8'), ('H1_matched_filter_snr_angle', '<f8'), ('recalib_L1_frequency_9', '<f8'), ('recalib_H1_frequency_3', '<f8'), ('recalib_L1_phase_5', '<f8'), ('recalib_V1_phase_1', '<f8'), ('recalib_H1_amplitude_5', '<f8'), ('recalib_H1_frequency_2', '<f8'), ('V1_matched_filter_snr_angle', '<f8'), ('recalib_L1_amplitude_6', '<f8'), ('L1_matched_filter_snr_angle', '<f8'), ('recalib_L1_frequency_0', '<f8'), ('recalib_L1_frequency_4', '<f8'), ('recalib_V1_amplitude_6', '<f8'), ('cos_tilt_2', '<f8'), ('recalib_V1_amplitude_8', '<f8'), ('recalib_H1_amplitude_9', '<f8'), ('recalib_V1_amplitude_5', '<f8'), ('recalib_V1_phase_2', '<f8'), ('recalib_V1_frequency_6', '<f8'), ('recalib_H1_frequency_7', '<f8'), ('recalib_V1_amplitude_7', '<f8'), ('recalib_L1_frequency_7', '<f8'), ('L1_matched_filter_snr', '<f8'), ('recalib_H1_frequency_6', '<f8'), ('cos_theta_jn', '<f8'), ('luminosity_distance', '<f8'), ('recalib_H1_phase_6', '<f8'), ('H1_matched_filter_abs_snr', '<f8'), ('a_1', '<f8'), ('recalib_L1_frequency_5', '<f8'), ('phi_2', '<f8'), ('network_optimal_snr', '<f8'), ('recalib_L1_amplitude_8', '<f8'), ('recalib_H1_phase_2', '<f8'), ('recalib_L1_frequency_3', '<f8'), ('recalib_H1_amplitude_0', '<f8'), ('recalib_V1_frequency_8', '<f8'), ('recalib_V1_frequency_1', '<f8'), ('recalib_V1_phase_9', '<f8'), ('recalib_H1_amplitude_7', '<f8'), ('recalib_H1_phase_5', '<f8'), ('tilt_1', '<f8'), ('recalib_V1_amplitude_9', '<f8'), ('spin_2z', '<f8'), ('phase', '<f8'), ('recalib_V1_amplitude_2', '<f8'), ('recalib_V1_frequency_3', '<f8'), ('recalib_H1_amplitude_2', '<f8'), ('recalib_H1_phase_9', '<f8'), ('spin_2x', '<f8'), ('chi_p', '<f8'), ('recalib_H1_phase_3', '<f8'), ('recalib_V1_phase_6', '<f8'), ('recalib_H1_phase_7', '<f8'), ('recalib_L1_phase_0', '<f8'), ('recalib_V1_frequency_5', '<f8'), ('mass_1', '<f8'), ('recalib_V1_phase_3', '<f8'), ('recalib_V1_phase_8', '<f8'), ('V1_optimal_snr', '<f8'), ('recalib_H1_amplitude_3', '<f8'), ('spin_1z', '<f8'), ('recalib_H1_phase_8', '<f8'), ('recalib_H1_frequency_5', '<f8'), ('recalib_L1_amplitude_2', '<f8'), ('recalib_H1_amplitude_6', '<f8'), ('recalib_H1_frequency_4', '<f8'), ('recalib_V1_amplitude_1', '<f8'), ('recalib_V1_frequency_2', '<f8'), ('recalib_L1_amplitude_9', '<f8'), ('recalib_H1_frequency_0', '<f8'), ('spin_1y', '<f8'), ('inverted_mass_ratio', '<f8'), ('peak_luminosity', '<f8'), ('psi', '<f8'), ('H1_matched_filter_snr', '<f8'), ('recalib_L1_frequency_8', '<f8'), ('recalib_L1_amplitude_5', '<f8'), ('recalib_L1_phase_7', '<f8'), ('recalib_L1_phase_3', '<f8'), ('theta_jn', '<f8'), ('recalib_L1_amplitude_1', '<f8'), ('recalib_H1_frequency_8', '<f8'), ('V1_matched_filter_snr', '<f8'), ('cos_iota', '<f8'), ('V1_matched_filter_abs_snr', '<f8'), ('phi_jl', '<f8'), ('a_2', '<f8'), ('recalib_L1_phase_6', '<f8'), ('final_mass', '<f8'), ('symmetric_mass_ratio', '<f8'), ('recalib_H1_frequency_1', '<f8'), ('time_jitter', '<f8'), ('geocent_time', '<f8'), ('recalib_V1_amplitude_4', '<f8'), ('H1_optimal_snr', '<f8'), ('recalib_H1_phase_0', '<f8'), ('recalib_H1_phase_4', '<f8'), ('recalib_L1_frequency_2', '<f8'), ('recalib_L1_amplitude_7', '<f8'), ('ra', '<f8'), ('recalib_L1_phase_2', '<f8'), ('recalib_V1_phase_7', '<f8'), ('recalib_H1_amplitude_4', '<f8'), ('spin_1x', '<f8'), ('recalib_V1_phase_5', '<f8'), ('recalib_L1_phase_8', '<f8'), ('cos_tilt_1', '<f8'), ('recalib_V1_amplitude_3', '<f8'), ('recalib_H1_amplitude_1', '<f8'), ('recalib_L1_phase_4', '<f8'), ('total_mass', '<f8'), ('recalib_V1_frequency_9', '<f8'), ('recalib_L1_phase_1', '<f8'), ('recalib_H1_phase_1', '<f8'), ('log_likelihood', '<f8'), ('chirp_mass', '<f8'), ('recalib_H1_frequency_9', '<f8'), ('recalib_V1_frequency_0', '<f8'), ('mass_2', '<f8'), ('recalib_V1_frequency_7', '<f8'), ('spin_2y', '<f8'), ('chi_2_in_plane', '<f8'), ('dec', '<f8'), ('comoving_distance', '<f8'), ('recalib_L1_frequency_1', '<f8'), ('recalib_L1_amplitude_4', '<f8'), ('final_spin', '<f8'), ('recalib_V1_phase_0', '<f8'), ('recalib_L1_frequency_6', '<f8'), ('recalib_H1_amplitude_8', '<f8'), ('L1_optimal_snr', '<f8'), ('mass_ratio', '<f8'), ('recalib_V1_frequency_4', '<f8'), ('recalib_L1_amplitude_0', '<f8'), ('L1_matched_filter_abs_snr', '<f8'), ('chi_1_in_plane', '<f8'), ('recalib_L1_amplitude_3', '<f8'), ('recalib_L1_phase_9', '<f8'), ('redshift', '<f8'), ('mass_1_source', '<f8'), ('mass_2_source', '<f8'), ('total_mass_source', '<f8'), ('chirp_mass_source', '<f8'), ('final_mass_source', '<f8'), ('radiated_energy', '<f8'), ('V1_time', '<f8'), ('H1_time', '<f8'), ('L1_time', '<f8'), ('network_matched_filter_snr', '<f8')]
parameter names: ['recalib_V1_amplitude_0', 'chi_eff', 'phi_12', 'phi_1', 'iota', 'recalib_V1_phase_4', 'tilt_2', 'H1_matched_filter_snr_angle', 'recalib_L1_frequency_9', 'recalib_H1_frequency_3', 'recalib_L1_phase_5', 'recalib_V1_phase_1', 'recalib_H1_amplitude_5', 'recalib_H1_frequency_2', 'V1_matched_filter_snr_angle', 'recalib_L1_amplitude_6', 'L1_matched_filter_snr_angle', 'recalib_L1_frequency_0', 'recalib_L1_frequency_4', 'recalib_V1_amplitude_6', 'cos_tilt_2', 'recalib_V1_amplitude_8', 'recalib_H1_amplitude_9', 'recalib_V1_amplitude_5', 'recalib_V1_phase_2', 'recalib_V1_frequency_6', 'recalib_H1_frequency_7', 'recalib_V1_amplitude_7', 'recalib_L1_frequency_7', 'L1_matched_filter_snr', 'recalib_H1_frequency_6', 'cos_theta_jn', 'luminosity_distance', 'recalib_H1_phase_6', 'H1_matched_filter_abs_snr', 'a_1', 'recalib_L1_frequency_5', 'phi_2', 'network_optimal_snr', 'recalib_L1_amplitude_8', 'recalib_H1_phase_2', 'recalib_L1_frequency_3', 'recalib_H1_amplitude_0', 'recalib_V1_frequency_8', 'recalib_V1_frequency_1', 'recalib_V1_phase_9', 'recalib_H1_amplitude_7', 'recalib_H1_phase_5', 'tilt_1', 'recalib_V1_amplitude_9', 'spin_2z', 'phase', 'recalib_V1_amplitude_2', 'recalib_V1_frequency_3', 'recalib_H1_amplitude_2', 'recalib_H1_phase_9', 'spin_2x', 'chi_p', 'recalib_H1_phase_3', 'recalib_V1_phase_6', 'recalib_H1_phase_7', 'recalib_L1_phase_0', 'recalib_V1_frequency_5', 'mass_1', 'recalib_V1_phase_3', 'recalib_V1_phase_8', 'V1_optimal_snr', 'recalib_H1_amplitude_3', 'spin_1z', 'recalib_H1_phase_8', 'recalib_H1_frequency_5', 'recalib_L1_amplitude_2', 'recalib_H1_amplitude_6', 'recalib_H1_frequency_4', 'recalib_V1_amplitude_1', 'recalib_V1_frequency_2', 'recalib_L1_amplitude_9', 'recalib_H1_frequency_0', 'spin_1y', 'inverted_mass_ratio', 'peak_luminosity', 'psi', 'H1_matched_filter_snr', 'recalib_L1_frequency_8', 'recalib_L1_amplitude_5', 'recalib_L1_phase_7', 'recalib_L1_phase_3', 'theta_jn', 'recalib_L1_amplitude_1', 'recalib_H1_frequency_8', 'V1_matched_filter_snr', 'cos_iota', 'V1_matched_filter_abs_snr', 'phi_jl', 'a_2', 'recalib_L1_phase_6', 'final_mass', 'symmetric_mass_ratio', 'recalib_H1_frequency_1', 'time_jitter', 'geocent_time', 'recalib_V1_amplitude_4', 'H1_optimal_snr', 'recalib_H1_phase_0', 'recalib_H1_phase_4', 'recalib_L1_frequency_2', 'recalib_L1_amplitude_7', 'ra', 'recalib_L1_phase_2', 'recalib_V1_phase_7', 'recalib_H1_amplitude_4', 'spin_1x', 'recalib_V1_phase_5', 'recalib_L1_phase_8', 'cos_tilt_1', 'recalib_V1_amplitude_3', 'recalib_H1_amplitude_1', 'recalib_L1_phase_4', 'total_mass', 'recalib_V1_frequency_9', 'recalib_L1_phase_1', 'recalib_H1_phase_1', 'log_likelihood', 'chirp_mass', 'recalib_H1_frequency_9', 'recalib_V1_frequency_0', 'mass_2', 'recalib_V1_frequency_7', 'spin_2y', 'chi_2_in_plane', 'dec', 'comoving_distance', 'recalib_L1_frequency_1', 'recalib_L1_amplitude_4', 'final_spin', 'recalib_V1_phase_0', 'recalib_L1_frequency_6', 'recalib_H1_amplitude_8', 'L1_optimal_snr', 'mass_ratio', 'recalib_V1_frequency_4', 'recalib_L1_amplitude_0', 'L1_matched_filter_abs_snr', 'chi_1_in_plane', 'recalib_L1_amplitude_3', 'recalib_L1_phase_9', 'redshift', 'mass_1_source', 'mass_2_source', 'total_mass_source', 'chirp_mass_source', 'final_mass_source', 'radiated_energy', 'V1_time', 'H1_time', 'L1_time', 'network_matched_filter_snr']
dL shape, mean, std = (23984,) 736.6247989688214 89.0194377498277

Now use PESummary v0.9.1 to read the data files as well as for plotting.

In [4]:
# import ligo-specific python packages. 
# pesummary is a ligo-specific python package for reading and plotting the results of Bayesian parameter estimation.
# Install with "pip install pesummary" , and make sure you have version >= 0.3.0.
import pesummary
from pesummary.gw.file.read import read
print(pesummary.__version__)
0.9.1

There are 9 different approximants that were used to analyze GW190412 plus the combined samples of IMRPhenomPv3HM and SEOBNRv4PHM. They are all stored in the data file.

In [5]:
fn = 'GW190412_posterior_samples_v3.h5'
data = read(fn)
labels = data.labels
print(labels)
['IMRPhenomD', 'IMRPhenomHM', 'IMRPhenomPv3', 'IMRPhenomPv3HM', 'NRHybSur3dq8', 'SEOBNRv4HM_ROM', 'SEOBNRv4P', 'SEOBNRv4PHM', 'SEOBNRv4_ROM', 'combined']

To illustrate the data structure we pick the combined posteriors and plot the respective data.

In [6]:
samples_dict = data.samples_dict
posterior_samples = samples_dict["combined"]
prior_samples = data.priors["samples"]["combined"]
parameters = posterior_samples.keys()
print(parameters)
dict_keys(['recalib_V1_amplitude_0', 'chi_eff', 'phi_12', 'phi_1', 'iota', 'recalib_V1_phase_4', 'tilt_2', 'H1_matched_filter_snr_angle', 'recalib_L1_frequency_9', 'recalib_H1_frequency_3', 'recalib_L1_phase_5', 'recalib_V1_phase_1', 'recalib_H1_amplitude_5', 'recalib_H1_frequency_2', 'V1_matched_filter_snr_angle', 'recalib_L1_amplitude_6', 'L1_matched_filter_snr_angle', 'recalib_L1_frequency_0', 'recalib_L1_frequency_4', 'recalib_V1_amplitude_6', 'cos_tilt_2', 'recalib_V1_amplitude_8', 'recalib_H1_amplitude_9', 'recalib_V1_amplitude_5', 'recalib_V1_phase_2', 'recalib_V1_frequency_6', 'recalib_H1_frequency_7', 'recalib_V1_amplitude_7', 'recalib_L1_frequency_7', 'L1_matched_filter_snr', 'recalib_H1_frequency_6', 'cos_theta_jn', 'luminosity_distance', 'recalib_H1_phase_6', 'H1_matched_filter_abs_snr', 'a_1', 'recalib_L1_frequency_5', 'phi_2', 'network_optimal_snr', 'recalib_L1_amplitude_8', 'recalib_H1_phase_2', 'recalib_L1_frequency_3', 'recalib_H1_amplitude_0', 'recalib_V1_frequency_8', 'recalib_V1_frequency_1', 'recalib_V1_phase_9', 'recalib_H1_amplitude_7', 'recalib_H1_phase_5', 'tilt_1', 'recalib_V1_amplitude_9', 'spin_2z', 'phase', 'recalib_V1_amplitude_2', 'recalib_V1_frequency_3', 'recalib_H1_amplitude_2', 'recalib_H1_phase_9', 'spin_2x', 'chi_p', 'recalib_H1_phase_3', 'recalib_V1_phase_6', 'recalib_H1_phase_7', 'recalib_L1_phase_0', 'recalib_V1_frequency_5', 'mass_1', 'recalib_V1_phase_3', 'recalib_V1_phase_8', 'V1_optimal_snr', 'recalib_H1_amplitude_3', 'spin_1z', 'recalib_H1_phase_8', 'recalib_H1_frequency_5', 'recalib_L1_amplitude_2', 'recalib_H1_amplitude_6', 'recalib_H1_frequency_4', 'recalib_V1_amplitude_1', 'recalib_V1_frequency_2', 'recalib_L1_amplitude_9', 'recalib_H1_frequency_0', 'spin_1y', 'inverted_mass_ratio', 'peak_luminosity', 'psi', 'H1_matched_filter_snr', 'recalib_L1_frequency_8', 'recalib_L1_amplitude_5', 'recalib_L1_phase_7', 'recalib_L1_phase_3', 'theta_jn', 'recalib_L1_amplitude_1', 'recalib_H1_frequency_8', 'V1_matched_filter_snr', 'cos_iota', 'V1_matched_filter_abs_snr', 'phi_jl', 'a_2', 'recalib_L1_phase_6', 'final_mass', 'symmetric_mass_ratio', 'recalib_H1_frequency_1', 'time_jitter', 'geocent_time', 'recalib_V1_amplitude_4', 'H1_optimal_snr', 'recalib_H1_phase_0', 'recalib_H1_phase_4', 'recalib_L1_frequency_2', 'recalib_L1_amplitude_7', 'ra', 'recalib_L1_phase_2', 'recalib_V1_phase_7', 'recalib_H1_amplitude_4', 'spin_1x', 'recalib_V1_phase_5', 'recalib_L1_phase_8', 'cos_tilt_1', 'recalib_V1_amplitude_3', 'recalib_H1_amplitude_1', 'recalib_L1_phase_4', 'total_mass', 'recalib_V1_frequency_9', 'recalib_L1_phase_1', 'recalib_H1_phase_1', 'log_likelihood', 'chirp_mass', 'recalib_H1_frequency_9', 'recalib_V1_frequency_0', 'mass_2', 'recalib_V1_frequency_7', 'spin_2y', 'chi_2_in_plane', 'dec', 'comoving_distance', 'recalib_L1_frequency_1', 'recalib_L1_amplitude_4', 'final_spin', 'recalib_V1_phase_0', 'recalib_L1_frequency_6', 'recalib_H1_amplitude_8', 'L1_optimal_snr', 'mass_ratio', 'recalib_V1_frequency_4', 'recalib_L1_amplitude_0', 'L1_matched_filter_abs_snr', 'chi_1_in_plane', 'recalib_L1_amplitude_3', 'recalib_L1_phase_9', 'redshift', 'mass_1_source', 'mass_2_source', 'total_mass_source', 'chirp_mass_source', 'final_mass_source', 'radiated_energy', 'V1_time', 'H1_time', 'L1_time', 'network_matched_filter_snr'])

As an example, we'll show the different posterior distributions derived from the combined (precession + higher multipoles) data and the posterior distribution derived using the different approximants for the luminosity_distance parameter.

In [7]:
from pesummary.gw.plots.latex_labels import GWlatex_labels

parameter = "luminosity_distance"
latex_label = GWlatex_labels[parameter]

fig = posterior_samples.plot(parameter, type="hist", kde=False, prior=prior_samples[parameter])
fig.set_size_inches(12, 8)
plt.show()
In [8]:
from pesummary.core.plots.plot import _1d_comparison_histogram_plot

samples = []
for label in labels:
    samples.append(samples_dict[label][parameter])


colors = ['b', 'r', 'k', 'y', 'orange', 'g','purple','cyan','grey','violet']
fig = _1d_comparison_histogram_plot(parameter, samples, colors, latex_label, labels, kde=True)
fig.set_size_inches(12, 8)
plt.show()

Below is another examples for the mass ratio of the combined data set.

In [9]:
parameter = "mass_ratio"
latex_label = GWlatex_labels[parameter]

fig = posterior_samples.plot(parameter, type="hist", kde=True, prior=prior_samples[parameter])
fig.set_size_inches(12, 8)
plt.show()

Make a corner plot:

In [10]:
from pesummary.gw.plots.plot import _make_corner_plot

fig = _make_corner_plot(posterior_samples, GWlatex_labels, corner_parameters=['mass_1_source', 'mass_2_source', 'luminosity_distance', 'theta_jn', 'chi_eff', 'chi_p'])
plt.show()

The psds that were used for each analysis can also be extracted from this file and plotted

In [11]:
psd = data.psd["combined"]
fig = psd.plot(fmin=20.0)
fig.set_size_inches(12, 8)
plt.show()