Commit 6c484298 authored by weichangfeng's avatar weichangfeng
Browse files

Upload New File

parent 8f6a7271
Loading
Loading
Loading
Loading
+95 −0
Original line number Diff line number Diff line
#!/usr/bin/env python
"""
Tutorial to demonstrate running parameter estimation on a reduced parameter
space for an injected signal.

This example estimates the masses using a uniform prior in both component masses
and distance using a uniform in comoving volume prior on luminosity distance
between luminosity distances of 100Mpc and 5Gpc, the cosmology is Planck15.
"""

import numpy as np
import bilby

# Set the duration and sampling frequency of the data segment that we're
# going to inject the signal into
duration = 1.
sampling_frequency = 256.

# Specify the output directory and the name of the simulation.
outdir = 'outdir'
label = 'bbh_in_bilby_and_vitamin_0605'
bilby.core.utils.setup_logger(outdir=outdir, label=label)

# Set up a random seed for result reproducibility.  This is optional!
np.random.seed(88170235)

# We are going to inject a binary black hole waveform.  We first establish a
# dictionary of parameters that includes all of the different waveform
# parameters, including masses of the two black holes (mass_1, mass_2),
# spins of both black holes (a, tilt, phi), etc.
injection_parameters = dict(
    mass_1=86., mass_2=69., a_1=0.4, a_2=0.3, tilt_1=0.5, tilt_2=1.0,
    phi_12=1.7, phi_jl=0.3, luminosity_distance=2000., theta_jn=0.4, psi=2.659,
    phase=1.3, geocent_time=1126259642.5+0.22, ra=1.375, dec=-1.2108)

# Fixed arguments passed into the source model
waveform_arguments = dict(waveform_approximant='IMRPhenomPv2',
                          reference_frequency=50., minimum_frequency=20.)

# Create the waveform_generator using a LAL BinaryBlackHole source function
waveform_generator = bilby.gw.WaveformGenerator(
    duration=duration, sampling_frequency=sampling_frequency,
    frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
    parameter_conversion=bilby.gw.conversion.convert_to_lal_binary_black_hole_parameters,
    waveform_arguments=waveform_arguments)

# Set up interferometers.  In this case we'll use two interferometers
# (LIGO-Hanford (H1), LIGO-Livingston (L1). These default to their design
# sensitivity
ifos = bilby.gw.detector.InterferometerList(['H1', 'L1', 'V1'])
ifos.set_strain_data_from_power_spectral_densities(
    sampling_frequency=sampling_frequency, duration=duration,
    start_time=injection_parameters['geocent_time'] - 0.5)
ifos.inject_signal(waveform_generator=waveform_generator,
                   parameters=injection_parameters)

# Set up a PriorDict, which inherits from dict.
# By default we will sample all terms in the signal models.  However, this will
# take a long time for the calculation, so for this example we will set almost
# all of the priors to be equall to their injected values.  This implies the
# prior is a delta function at the true, injected value.  In reality, the
# sampler implementation is smart enough to not sample any parameter that has
# a delta-function prior.
# The above list does *not* include mass_1, mass_2, theta_jn and luminosity
# distance, which means those are the parameters that will be included in the
# sampler.  If we do nothing, then the default priors get used.
priors = bilby.gw.prior.BBHPriorDict()
priors.pop('chirp_mass')
priors.pop('mass_ratio')

priors['mass_1'] = bilby.core.prior.Uniform(name='mass_1', minimum=30, maximum=160, unit='$M_{\\odot}$')
priors['mass_2'] = bilby.core.prior.Uniform(name='mass_2', minimum=30, maximum=160, unit='$M_{\\odot}$')
priors['luminosity_distance'] = bilby.prior.Uniform(minimum=1000, maximum=3000, name='luminosity_distance', latex_label='luminosity_distance')   


priors['geocent_time'] = bilby.core.prior.Uniform(
    minimum=injection_parameters['geocent_time'] + 0.15,
    maximum=injection_parameters['geocent_time'] + 0.35,
    name='geocent_time', latex_label='$t_c$', unit='$s$')
for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 
            'phase']:
    priors[key] = injection_parameters[key]

# Initialise the likelihood by passing in the interferometer data (ifos) and
# the waveform generator
likelihood = bilby.gw.GravitationalWaveTransient(
    interferometers=ifos, waveform_generator=waveform_generator)

# Run sampler.  In this case we're going to use the `dynesty` sampler
result = bilby.run_sampler(
    likelihood=likelihood, priors=priors, sampler='dynesty', npoints=2000,
    injection_parameters=injection_parameters, outdir=outdir, label=label)

# Make a corner plot.
result.plot_corner()
+93 −0
Original line number Diff line number Diff line
#!/usr/bin/env python
"""
Tutorial to demonstrate running parameter estimation on a reduced parameter
space for an injected signal.

This example estimates the masses using a uniform prior in both component masses
and distance using a uniform in comoving volume prior on luminosity distance
between luminosity distances of 100Mpc and 5Gpc, the cosmology is Planck15.
"""

import numpy as np
import bilby

# Set the duration and sampling frequency of the data segment that we're
# going to inject the signal into
duration = 1.
sampling_frequency = 256.

# Specify the output directory and the name of the simulation.
outdir = 'outdir_15p'
label = 'bbh_15p_in_bilby_and_vitamin_0605'
bilby.core.utils.setup_logger(outdir=outdir, label=label)

# Set up a random seed for result reproducibility.  This is optional!
np.random.seed(88170235)

# We are going to inject a binary black hole waveform.  We first establish a
# dictionary of parameters that includes all of the different waveform
# parameters, including masses of the two black holes (mass_1, mass_2),
# spins of both black holes (a, tilt, phi), etc.
injection_parameters = dict(
    mass_1=86., mass_2=69., a_1=0.4, a_2=0.3, tilt_1=0.5, tilt_2=1.0,
    phi_12=1.7, phi_jl=0.3, luminosity_distance=2000., theta_jn=0.4, psi=2.659,
    phase=1.3, geocent_time=1126259642.5+0.22, ra=1.375, dec=-1.2108)

# Fixed arguments passed into the source model
waveform_arguments = dict(waveform_approximant='IMRPhenomPv2',
                          reference_frequency=50., minimum_frequency=20.)

# Create the waveform_generator using a LAL BinaryBlackHole source function
waveform_generator = bilby.gw.WaveformGenerator(
    duration=duration, sampling_frequency=sampling_frequency,
    frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
    parameter_conversion=bilby.gw.conversion.convert_to_lal_binary_black_hole_parameters,
    waveform_arguments=waveform_arguments)

# Set up interferometers.  In this case we'll use two interferometers
# (LIGO-Hanford (H1), LIGO-Livingston (L1). These default to their design
# sensitivity
ifos = bilby.gw.detector.InterferometerList(['H1', 'L1', 'V1'])
ifos.set_strain_data_from_power_spectral_densities(
    sampling_frequency=sampling_frequency, duration=duration,
    start_time=injection_parameters['geocent_time'] - 0.5)
ifos.inject_signal(waveform_generator=waveform_generator,
                   parameters=injection_parameters)

# Set up a PriorDict, which inherits from dict.
# By default we will sample all terms in the signal models.  However, this will
# take a long time for the calculation, so for this example we will set almost
# all of the priors to be equall to their injected values.  This implies the
# prior is a delta function at the true, injected value.  In reality, the
# sampler implementation is smart enough to not sample any parameter that has
# a delta-function prior.
# The above list does *not* include mass_1, mass_2, theta_jn and luminosity
# distance, which means those are the parameters that will be included in the
# sampler.  If we do nothing, then the default priors get used.
priors = bilby.gw.prior.BBHPriorDict()
priors.pop('chirp_mass')
priors.pop('mass_ratio')

priors['mass_1'] = bilby.core.prior.Uniform(name='mass_1', minimum=30, maximum=160, unit='$M_{\\odot}$')
priors['mass_2'] = bilby.core.prior.Uniform(name='mass_2', minimum=30, maximum=160, unit='$M_{\\odot}$')
priors['luminosity_distance'] = bilby.prior.Uniform(minimum=1000, maximum=3000, name='luminosity_distance', latex_label='luminosity_distance')   


priors['geocent_time'] = bilby.core.prior.Uniform(
    minimum=injection_parameters['geocent_time'] + 0.15,
    maximum=injection_parameters['geocent_time'] + 0.35,
    name='geocent_time', latex_label='$t_c$', unit='$s$')


# Initialise the likelihood by passing in the interferometer data (ifos) and
# the waveform generator
likelihood = bilby.gw.GravitationalWaveTransient(
    interferometers=ifos, waveform_generator=waveform_generator)

# Run sampler.  In this case we're going to use the `dynesty` sampler
result = bilby.run_sampler(
    likelihood=likelihood, priors=priors, sampler='dynesty', npoints=2000,
    injection_parameters=injection_parameters, outdir=outdir, label=label)

# Make a corner plot.
result.plot_corner()
+505 −0

File added.

Preview size limit exceeded, changes collapsed.

+131 −0
Original line number Diff line number Diff line
11:21 INFO    : Waveform generator initiated with
  frequency_domain_source_model: bilby.gw.source.lal_binary_black_hole
  time_domain_source_model: None
  parameter_conversion: bilby.gw.conversion.convert_to_lal_binary_black_hole_parameters
11:21 INFO    : Injected signal in H1:
11:21 INFO    :   optimal SNR = 22.66
11:21 INFO    :   matched filter SNR = 23.25+1.54j
11:21 INFO    :   mass_1 = 86.0
11:21 INFO    :   mass_2 = 69.0
11:21 INFO    :   a_1 = 0.4
11:21 INFO    :   a_2 = 0.3
11:21 INFO    :   tilt_1 = 0.5
11:21 INFO    :   tilt_2 = 1.0
11:21 INFO    :   phi_12 = 1.7
11:21 INFO    :   phi_jl = 0.3
11:21 INFO    :   luminosity_distance = 2000.0
11:21 INFO    :   theta_jn = 0.4
11:21 INFO    :   psi = 2.659
11:21 INFO    :   phase = 1.3
11:21 INFO    :   geocent_time = 1126259642.72
11:21 INFO    :   ra = 1.375
11:21 INFO    :   dec = -1.2108
11:21 INFO    : Injected signal in L1:
11:21 INFO    :   optimal SNR = 18.35
11:21 INFO    :   matched filter SNR = 17.41-0.83j
11:21 INFO    :   mass_1 = 86.0
11:21 INFO    :   mass_2 = 69.0
11:21 INFO    :   a_1 = 0.4
11:21 INFO    :   a_2 = 0.3
11:21 INFO    :   tilt_1 = 0.5
11:21 INFO    :   tilt_2 = 1.0
11:21 INFO    :   phi_12 = 1.7
11:21 INFO    :   phi_jl = 0.3
11:21 INFO    :   luminosity_distance = 2000.0
11:21 INFO    :   theta_jn = 0.4
11:21 INFO    :   psi = 2.659
11:21 INFO    :   phase = 1.3
11:21 INFO    :   geocent_time = 1126259642.72
11:21 INFO    :   ra = 1.375
11:21 INFO    :   dec = -1.2108
11:21 INFO    : Injected signal in V1:
11:21 INFO    :   optimal SNR = 18.71
11:21 INFO    :   matched filter SNR = 16.50-0.21j
11:21 INFO    :   mass_1 = 86.0
11:21 INFO    :   mass_2 = 69.0
11:21 INFO    :   a_1 = 0.4
11:21 INFO    :   a_2 = 0.3
11:21 INFO    :   tilt_1 = 0.5
11:21 INFO    :   tilt_2 = 1.0
11:21 INFO    :   phi_12 = 1.7
11:21 INFO    :   phi_jl = 0.3
11:21 INFO    :   luminosity_distance = 2000.0
11:21 INFO    :   theta_jn = 0.4
11:21 INFO    :   psi = 2.659
11:21 INFO    :   phase = 1.3
11:21 INFO    :   geocent_time = 1126259642.72
11:21 INFO    :   ra = 1.375
11:21 INFO    :   dec = -1.2108
11:21 INFO    : No prior given, using default BBH priors in /home/weichangfeng/.local/lib/python3.8/site-packages/bilby/gw/prior_files/precessing_spins_bbh.prior.
11:21 INFO    : Running for label 'bbh_in_bilby_and_vitamin_0605', output will be saved to 'outdir'
11:21 INFO    : Using lal version 7.1.0
11:21 INFO    : Using lal git version Branch: None;Tag: lalsuite-v6.79;Id: 2439365b5a320735efaf7171b37738032dcf7b6b;;Builder: Unknown User <>;Repository status: UNCLEAN: Modified working tree
11:21 INFO    : Using lalsimulation version 2.3.0
11:21 INFO    : Using lalsimulation git version Branch: None;Tag: lalsuite-v6.79;Id: 2439365b5a320735efaf7171b37738032dcf7b6b;;Builder: Unknown User <>;Repository status: UNCLEAN: Modified working tree
11:21 INFO    : Search parameters:
11:21 INFO    :   mass_1 = Uniform(minimum=30, maximum=160, name='mass_1', latex_label='$m_1$', unit='$M_{\\odot}$', boundary=None)
11:21 INFO    :   mass_2 = Uniform(minimum=30, maximum=160, name='mass_2', latex_label='$m_2$', unit='$M_{\\odot}$', boundary=None)
11:21 INFO    :   luminosity_distance = Uniform(minimum=1000, maximum=3000, name='luminosity_distance', latex_label='luminosity_distance', unit=None, boundary=None)
11:21 INFO    :   dec = Cosine(name='dec', latex_label='$\\mathrm{DEC}$', unit=None, minimum=-1.5707963267948966, maximum=1.5707963267948966, boundary=None)
11:21 INFO    :   ra = Uniform(minimum=0, maximum=6.283185307179586, name='ra', latex_label='$\\mathrm{RA}$', unit=None, boundary='periodic')
11:21 INFO    :   theta_jn = Sine(name='theta_jn', latex_label='$\\theta_{JN}$', unit=None, minimum=0, maximum=3.141592653589793, boundary=None)
11:21 INFO    :   psi = Uniform(minimum=0, maximum=3.141592653589793, name='psi', latex_label='$\\psi$', unit=None, boundary='periodic')
11:21 INFO    :   geocent_time = Uniform(minimum=1126259642.8700001, maximum=1126259643.07, name='geocent_time', latex_label='$t_c$', unit='$s$', boundary=None)
11:21 INFO    :   phase = 1.3
11:21 INFO    :   a_1 = 0.4
11:21 INFO    :   a_2 = 0.3
11:21 INFO    :   tilt_1 = 0.5
11:21 INFO    :   tilt_2 = 1.0
11:21 INFO    :   phi_12 = 1.7
11:21 INFO    :   phi_jl = 0.3
11:21 INFO    : Single likelihood evaluation took 9.233e-04 s
11:21 INFO    : Using sampler Dynesty with kwargs {'bound': 'multi', 'sample': 'rwalk', 'verbose': True, 'periodic': None, 'reflective': None, 'check_point_delta_t': 600, 'nlive': 2000, 'first_update': None, 'walks': 100, 'npdim': None, 'rstate': None, 'queue_size': 1, 'pool': None, 'use_pool': None, 'live_points': None, 'logl_args': None, 'logl_kwargs': None, 'ptform_args': None, 'ptform_kwargs': None, 'enlarge': 1.5, 'bootstrap': None, 'vol_dec': 0.5, 'vol_check': 8.0, 'facc': 0.2, 'slices': 5, 'update_interval': 1200, 'print_func': <bound method Dynesty._print_func of <bilby.core.sampler.dynesty.Dynesty object at 0x7f61b8e5a2e0>>, 'dlogz': 0.1, 'maxiter': None, 'maxcall': None, 'logl_max': inf, 'add_live': True, 'print_progress': True, 'save_bounds': False, 'n_effective': None, 'maxmcmc': 5000, 'nact': 5}
11:21 INFO    : Checkpoint every check_point_delta_t = 600s
11:21 INFO    : Using dynesty version 1.0.1
11:21 INFO    : Using the bilby-implemented rwalk sample method with ACT estimated walks
11:21 INFO    : Resume file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle does not exist.
11:21 INFO    : Generating initial points from the prior
11:31 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
11:41 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
16:07 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
16:17 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
16:28 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
16:38 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
16:48 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
16:59 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
17:09 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
17:19 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
17:30 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
17:40 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
17:51 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
18:01 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
18:12 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
18:22 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
18:33 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
18:43 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
18:43 INFO    : Writing 106 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
18:54 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
18:54 INFO    : Writing 183 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
19:05 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
19:05 INFO    : Writing 313 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
19:15 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
19:15 INFO    : Writing 524 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
19:26 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
19:26 INFO    : Writing 926 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
19:37 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
19:37 INFO    : Writing 1197 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
19:47 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
19:47 INFO    : Writing 2706 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
19:58 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
19:58 INFO    : Writing 5969 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
20:09 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
20:09 INFO    : Writing 11780 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
20:15 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
20:15 INFO    : Writing 11814 current samples to outdir/bbh_in_bilby_and_vitamin_0605_samples.dat
20:17 INFO    : Sampling time: 8:53:32.591021
20:17 INFO    : Summary of results:
nsamples: 52514
ln_noise_evidence: -857.034
ln_evidence: -854.148 +/-  0.138
ln_bayes_factor:  2.886 +/-  0.138
Loading