Commit b1954017 authored by weichangfeng's avatar weichangfeng
Browse files

Upload New File

parent 6c484298
Loading
Loading
Loading
Loading
+96 −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=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=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=2000)

# 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=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=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=2000)

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

File added.

Preview size limit exceeded, changes collapsed.

+117 −0
Original line number Diff line number Diff line
02:11 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
02:11 INFO    : Injected signal in H1:
02:11 INFO    :   optimal SNR = 22.37
02:11 INFO    :   matched filter SNR = 23.13-0.53j
02:11 INFO    :   mass_1 = 86.0
02:11 INFO    :   mass_2 = 69.0
02:11 INFO    :   a_1 = 0.4
02:11 INFO    :   a_2 = 0.3
02:11 INFO    :   tilt_1 = 0.5
02:11 INFO    :   tilt_2 = 1.0
02:11 INFO    :   phi_12 = 1.7
02:11 INFO    :   phi_jl = 0.3
02:11 INFO    :   luminosity_distance = 2000.0
02:11 INFO    :   theta_jn = 0.4
02:11 INFO    :   psi = 2.659
02:11 INFO    :   phase = 1.3
02:11 INFO    :   geocent_time = 1126259642.72
02:11 INFO    :   ra = 1.375
02:11 INFO    :   dec = -1.2108
02:11 INFO    : Injected signal in L1:
02:11 INFO    :   optimal SNR = 18.10
02:11 INFO    :   matched filter SNR = 18.24+0.80j
02:11 INFO    :   mass_1 = 86.0
02:11 INFO    :   mass_2 = 69.0
02:11 INFO    :   a_1 = 0.4
02:11 INFO    :   a_2 = 0.3
02:11 INFO    :   tilt_1 = 0.5
02:11 INFO    :   tilt_2 = 1.0
02:11 INFO    :   phi_12 = 1.7
02:11 INFO    :   phi_jl = 0.3
02:11 INFO    :   luminosity_distance = 2000.0
02:11 INFO    :   theta_jn = 0.4
02:11 INFO    :   psi = 2.659
02:11 INFO    :   phase = 1.3
02:11 INFO    :   geocent_time = 1126259642.72
02:11 INFO    :   ra = 1.375
02:11 INFO    :   dec = -1.2108
02:11 INFO    : Injected signal in V1:
02:11 INFO    :   optimal SNR = 18.33
02:11 INFO    :   matched filter SNR = 17.33-0.51j
02:11 INFO    :   mass_1 = 86.0
02:11 INFO    :   mass_2 = 69.0
02:11 INFO    :   a_1 = 0.4
02:11 INFO    :   a_2 = 0.3
02:11 INFO    :   tilt_1 = 0.5
02:11 INFO    :   tilt_2 = 1.0
02:11 INFO    :   phi_12 = 1.7
02:11 INFO    :   phi_jl = 0.3
02:11 INFO    :   luminosity_distance = 2000.0
02:11 INFO    :   theta_jn = 0.4
02:11 INFO    :   psi = 2.659
02:11 INFO    :   phase = 1.3
02:11 INFO    :   geocent_time = 1126259642.72
02:11 INFO    :   ra = 1.375
02:11 INFO    :   dec = -1.2108
02:11 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.
02:11 INFO    : Running for label 'bbh_in_bilby_and_vitamin_0605', output will be saved to 'outdir'
02:11 INFO    : Using lal version 7.1.2
02:11 INFO    : Using lal git version Branch: None;Tag: lalsuite-v6.82;Id: cf792129c2473f42ce6c6ee21d8234254cefd337;;Builder: Unknown User <>;Repository status: UNCLEAN: Modified working tree
02:11 INFO    : Using lalsimulation version 2.5.1
02:11 INFO    : Using lalsimulation git version Branch: None;Tag: lalsuite-v6.82;Id: cf792129c2473f42ce6c6ee21d8234254cefd337;;Builder: Unknown User <>;Repository status: UNCLEAN: Modified working tree
02:11 INFO    : Search parameters:
02:11 INFO    :   mass_1 = Uniform(minimum=30, maximum=160, name='mass_1', latex_label='$m_1$', unit='$M_{\\odot}$', boundary=None)
02:11 INFO    :   mass_2 = Uniform(minimum=30, maximum=160, name='mass_2', latex_label='$m_2$', unit='$M_{\\odot}$', boundary=None)
02:11 INFO    :   luminosity_distance = Uniform(minimum=1000, maximum=3000, name='luminosity_distance', latex_label='luminosity_distance', unit=None, boundary=None)
02:11 INFO    :   dec = Cosine(minimum=-1.5707963267948966, maximum=1.5707963267948966, name='dec', latex_label='$\\mathrm{DEC}$', unit=None, boundary=None)
02:11 INFO    :   ra = Uniform(minimum=0, maximum=6.283185307179586, name='ra', latex_label='$\\mathrm{RA}$', unit=None, boundary='periodic')
02:11 INFO    :   theta_jn = Sine(minimum=0, maximum=3.141592653589793, name='theta_jn', latex_label='$\\theta_{JN}$', unit=None, boundary=None)
02:11 INFO    :   psi = Uniform(minimum=0, maximum=3.141592653589793, name='psi', latex_label='$\\psi$', unit=None, boundary='periodic')
02:11 INFO    :   time_jitter = Uniform(minimum=-0.00390625, maximum=0.00390625, name='time_jitter', latex_label='$t_j$', unit=None, boundary='periodic')
02:11 INFO    :   phase = 1.3
02:11 INFO    :   a_1 = 0.4
02:11 INFO    :   a_2 = 0.3
02:11 INFO    :   tilt_1 = 0.5
02:11 INFO    :   tilt_2 = 1.0
02:11 INFO    :   phi_12 = 1.7
02:11 INFO    :   phi_jl = 0.3
02:11 INFO    :   geocent_time = 1126259642.0
02:11 INFO    : Single likelihood evaluation took 1.164e-03 s
02:11 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 0x7f27acf70520>>, 'dlogz': 0.1, 'maxiter': None, 'maxcall': None, 'logl_max': inf, 'add_live': True, 'print_progress': True, 'save_bounds': False, 'n_effective': None, 'maxmcmc': 2000, 'nact': 50}
02:11 INFO    : Checkpoint every check_point_delta_t = 1800s
02:11 INFO    : Using dynesty version 1.0.1
02:11 INFO    : Using the bilby-implemented rwalk sample method with ACT estimated walks
02:11 INFO    : Resume file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle does not exist.
02:11 INFO    : Generating initial points from the prior
02:42 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
03:12 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
03:42 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
03:42 WARNING : singular matrix
03:42 WARNING : Failed to create dynesty state plot at checkpoint
03:42 WARNING : singular matrix
03:42 WARNING : Failed to create dynesty run plot at checkpoint
04:12 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
04:45 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
05:16 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
05:46 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
06:16 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
06:46 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
07:17 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
07:47 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
08:17 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
09:42 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
11:48 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
12:18 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
13:01 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
13:31 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
13:31 WARNING : singular matrix
13:31 WARNING : Failed to create dynesty state plot at checkpoint
14:01 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
15:23 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
15:54 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
16:24 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
17:11 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
18:11 INFO    : Written checkpoint file outdir/bbh_in_bilby_and_vitamin_0605_resume.pickle
+63.1 KiB
Loading image diff...
Loading