Commit 35a44aad authored by weichangfeng's avatar weichangfeng
Browse files

Upload New File

parent 09bb24a9
Loading
Loading
Loading
Loading
+97 −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.
ref_geocent_time  = 1126259642.5
# 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=81.9, mass_2=70.91, a_1=0., a_2=0., tilt_1=0., tilt_2=0.,
        phi_12=0., phi_jl=0., luminosity_distance=1931.77, theta_jn=1.51, psi=1.54,
        phase=0., geocent_time=1126259642.5+0.22, ra=3.89, dec=-0.94)

# Fixed arguments passed into the source model
waveform_arguments = dict(waveform_approximant='IMRPhenomPv2',
                          reference_frequency=20., 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,
    start_time=ref_geocent_time - 0.5)

# 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=ref_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=ref_geocent_time + 0.15,
    maximum=ref_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,priors=priors,time_marginalization=True)

# Run sampler.  In this case we're going to use the `dynesty` sampler
result = bilby.run_sampler(
    likelihood=likelihood, priors=priors, injection_parameters=injection_parameters, label=label,outdir=outdir,sampler='dynesty', 
    nlive=2500, sample='rwalk',walks =100,nact=50,check_point_delta_t=1800,check_point_plot=True,maxmcmc=20000)

# Make a corner plot.
result.plot_corner()
+94 −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.
ref_geocent_time = 1126259642.5
# 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=81.9, mass_2=70.91, a_1=0., a_2=0., tilt_1=0., tilt_2=0.,
        phi_12=0., phi_jl=0., luminosity_distance=1931.77, theta_jn=1.51, psi=1.54,
        phase=0., geocent_time=1126259642.5+0.22, ra=3.89, dec=-0.94) 
# Fixed arguments passed into the source model
waveform_arguments = dict(waveform_approximant='IMRPhenomPv2',
                          reference_frequency=20., 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,
    start_time=ref_geocent_time - 0.5)

# 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=ref_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=ref_geocent_time + 0.15,
    maximum=ref_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,priors=priors,phase_marginalization=True, time_marginalization=True)

# Run sampler.  In this case we're going to use the `dynesty` sampler
result = bilby.run_sampler(
    likelihood=likelihood, priors=priors, injection_parameters=injection_parameters, label=label,outdir=outdir,sampler='dynesty', 
    nlive=2500, sample='rwalk',walks =100,nact=50,check_point_delta_t=1800,check_point_plot=True,maxmcmc=20000)

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

File added.

Preview size limit exceeded, changes collapsed.

+91 −0
Original line number Diff line number Diff line
14:37 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
14:37 INFO    : Injected signal in H1:
14:37 INFO    :   optimal SNR = 13.17
14:37 INFO    :   matched filter SNR = 14.09-0.75j
14:37 INFO    :   mass_1 = 81.9
14:37 INFO    :   mass_2 = 70.91
14:37 INFO    :   a_1 = 0.0
14:37 INFO    :   a_2 = 0.0
14:37 INFO    :   tilt_1 = 0.0
14:37 INFO    :   tilt_2 = 0.0
14:37 INFO    :   phi_12 = 0.0
14:37 INFO    :   phi_jl = 0.0
14:37 INFO    :   luminosity_distance = 1931.77
14:37 INFO    :   theta_jn = 1.51
14:37 INFO    :   psi = 1.54
14:37 INFO    :   phase = 0.0
14:37 INFO    :   geocent_time = 1126259642.72
14:37 INFO    :   ra = 3.89
14:37 INFO    :   dec = -0.94
14:37 INFO    : Injected signal in L1:
14:37 INFO    :   optimal SNR = 11.18
14:37 INFO    :   matched filter SNR = 11.85-0.15j
14:37 INFO    :   mass_1 = 81.9
14:37 INFO    :   mass_2 = 70.91
14:37 INFO    :   a_1 = 0.0
14:37 INFO    :   a_2 = 0.0
14:37 INFO    :   tilt_1 = 0.0
14:37 INFO    :   tilt_2 = 0.0
14:37 INFO    :   phi_12 = 0.0
14:37 INFO    :   phi_jl = 0.0
14:37 INFO    :   luminosity_distance = 1931.77
14:37 INFO    :   theta_jn = 1.51
14:37 INFO    :   psi = 1.54
14:37 INFO    :   phase = 0.0
14:37 INFO    :   geocent_time = 1126259642.72
14:37 INFO    :   ra = 3.89
14:37 INFO    :   dec = -0.94
14:37 INFO    : Injected signal in V1:
14:37 INFO    :   optimal SNR = 5.26
14:37 INFO    :   matched filter SNR = 4.62+0.10j
14:37 INFO    :   mass_1 = 81.9
14:37 INFO    :   mass_2 = 70.91
14:37 INFO    :   a_1 = 0.0
14:37 INFO    :   a_2 = 0.0
14:37 INFO    :   tilt_1 = 0.0
14:37 INFO    :   tilt_2 = 0.0
14:37 INFO    :   phi_12 = 0.0
14:37 INFO    :   phi_jl = 0.0
14:37 INFO    :   luminosity_distance = 1931.77
14:37 INFO    :   theta_jn = 1.51
14:37 INFO    :   psi = 1.54
14:37 INFO    :   phase = 0.0
14:37 INFO    :   geocent_time = 1126259642.72
14:37 INFO    :   ra = 3.89
14:37 INFO    :   dec = -0.94
14:37 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.
14:37 INFO    : Running for label 'bbh_in_bilby_and_vitamin_0605', output will be saved to 'outdir'
14:37 INFO    : Using lal version 7.1.2
14:37 INFO    : Using lal git version Branch: None;Tag: lalsuite-v6.82;Id: cf792129c2473f42ce6c6ee21d8234254cefd337;;Builder: Unknown User <>;Repository status: UNCLEAN: Modified working tree
14:37 INFO    : Using lalsimulation version 2.5.1
14:37 INFO    : Using lalsimulation git version Branch: None;Tag: lalsuite-v6.82;Id: cf792129c2473f42ce6c6ee21d8234254cefd337;;Builder: Unknown User <>;Repository status: UNCLEAN: Modified working tree
14:37 INFO    : Search parameters:
14:37 INFO    :   mass_1 = Uniform(minimum=30, maximum=160, name='mass_1', latex_label='$m_1$', unit='$M_{\\odot}$', boundary=None)
14:37 INFO    :   mass_2 = Uniform(minimum=30, maximum=160, name='mass_2', latex_label='$m_2$', unit='$M_{\\odot}$', boundary=None)
14:37 INFO    :   luminosity_distance = Uniform(minimum=1000, maximum=3000, name='luminosity_distance', latex_label='luminosity_distance', unit=None, boundary=None)
14:37 INFO    :   dec = Cosine(minimum=-1.5707963267948966, maximum=1.5707963267948966, name='dec', latex_label='$\\mathrm{DEC}$', unit=None, boundary=None)
14:37 INFO    :   ra = Uniform(minimum=0, maximum=6.283185307179586, name='ra', latex_label='$\\mathrm{RA}$', unit=None, boundary='periodic')
14:37 INFO    :   theta_jn = Sine(minimum=0, maximum=3.141592653589793, name='theta_jn', latex_label='$\\theta_{JN}$', unit=None, boundary=None)
14:37 INFO    :   psi = Uniform(minimum=0, maximum=3.141592653589793, name='psi', latex_label='$\\psi$', unit=None, boundary='periodic')
14:37 INFO    :   time_jitter = Uniform(minimum=-0.00390625, maximum=0.00390625, name='time_jitter', latex_label='$t_j$', unit=None, boundary='periodic')
14:37 INFO    :   phase = 0.0
14:37 INFO    :   a_1 = 0.0
14:37 INFO    :   a_2 = 0.0
14:37 INFO    :   tilt_1 = 0.0
14:37 INFO    :   tilt_2 = 0.0
14:37 INFO    :   phi_12 = 0.0
14:37 INFO    :   phi_jl = 0.0
14:37 INFO    :   geocent_time = 1126259642.0
14:37 INFO    : Single likelihood evaluation took 1.840e-03 s
14:37 INFO    : Using sampler Dynesty with kwargs {'bound': 'multi', 'sample': 'rwalk', 'verbose': True, 'periodic': None, 'reflective': None, 'check_point_delta_t': 1800, 'nlive': 2500, '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': 1500, 'print_func': <bound method Dynesty._print_func of <bilby.core.sampler.dynesty.Dynesty object at 0x7f53e23e7b20>>, 'dlogz': 0.1, 'maxiter': None, 'maxcall': None, 'logl_max': inf, 'add_live': True, 'print_progress': True, 'save_bounds': False, 'n_effective': None, 'maxmcmc': 20000, 'nact': 50}
14:37 INFO    : Checkpoint every check_point_delta_t = 1800s
14:37 INFO    : Using dynesty version 1.0.1
14:37 INFO    : Using the bilby-implemented rwalk sample method with ACT estimated walks
14:37 INFO    : Resume file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle does not exist.
14:37 INFO    : Generating initial points from the prior
15:08 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
15:38 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
16:11 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
Loading