change_sampled_parameters.py 2.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/bin/python
"""
Tutorial to demonstrate running parameter estimation sampling in non-standard parameters for an injected signal.

This example estimates the masses using a uniform prior in chirp mass and mass ratio and distance using a uniform in
comoving volume prior on luminosity distance between luminosity distances of 100Mpc and 5Gpc, the cosmology is WMAP7.
"""
from __future__ import division, print_function
import tupak
import numpy as np

tupak.utils.setup_logger(log_level="info")

time_duration = 4.
sampling_frequency = 2048.
outdir = 'outdir'

Colm Talbot's avatar
Colm Talbot committed
18
np.random.seed(151226)
19 20

injection_parameters = dict(mass_1=36., mass_2=29., a_1=0.4, a_2=0.3, tilt_1=0.5, tilt_2=1.0, phi_12=1.7, phi_jl=0.3,
Colm Talbot's avatar
Colm Talbot committed
21
                            luminosity_distance=3000., iota=0.4, psi=2.659, phase=1.3, geocent_time=1126259642.413,
22 23 24 25 26 27
                            waveform_approximant='IMRPhenomPv2', reference_frequency=50., ra=1.375, dec=-1.2108)

# Create the waveform_generator using a LAL BinaryBlackHole source function
waveform_generator = tupak.waveform_generator.WaveformGenerator(
    sampling_frequency=sampling_frequency, time_duration=time_duration,
    frequency_domain_source_model=tupak.source.lal_binary_black_hole,
Colm Talbot's avatar
Colm Talbot committed
28
    parameter_conversion=tupak.conversion.convert_to_lal_binary_black_hole_parameters,
29
    non_standard_sampling_parameter_keys=['chirp_mass', 'mass_ratio', 'cos_iota'],
30 31 32 33 34 35 36 37 38 39 40
    parameters=injection_parameters)
hf_signal = waveform_generator.frequency_domain_strain()

# Set up interferometers.
IFOs = [tupak.detector.get_interferometer_with_fake_noise_and_injection(
    name, injection_polarizations=hf_signal, injection_parameters=injection_parameters, time_duration=time_duration,
    sampling_frequency=sampling_frequency, outdir=outdir) for name in ['H1', 'L1', 'V1']]

# Set up prior
priors = dict()
# These parameters will not be sampled
Colm Talbot's avatar
Colm Talbot committed
41
for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'phase', 'psi', 'ra', 'dec', 'geocent_time']:
42 43 44 45 46 47 48
    priors[key] = injection_parameters[key]
priors['luminosity_distance'] = tupak.prior.create_default_prior(name='luminosity_distance')

# Initialise Likelihood
likelihood = tupak.likelihood.Likelihood(interferometers=IFOs, waveform_generator=waveform_generator)

# Run sampler
Colm Talbot's avatar
Colm Talbot committed
49
result = tupak.sampler.run_sampler(likelihood=likelihood, priors=priors, sampler='dynesty',
Colm Talbot's avatar
Colm Talbot committed
50
                                   injection_parameters=injection_parameters, label='DifferentParameters',
51
                                   outdir=outdir, conversion_function=tupak.conversion.generate_all_bbh_parameters)
52 53 54 55
result.plot_corner()
result.plot_walks()
result.plot_distributions()
print(result)