Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bilby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lscsoft
bilby
Commits
aacd56a8
Commit
aacd56a8
authored
6 years ago
by
Colm Talbot
Browse files
Options
Downloads
Patches
Plain Diff
update basic_tutorial
parent
eec3327b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!222
Resolve "BNS: ability to sample in and convert to \tilde{Lambda} and \delta\tilde{\Lambda}"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/injection_examples/basic_tutorial.py
+41
-27
41 additions, 27 deletions
examples/injection_examples/basic_tutorial.py
with
41 additions
and
27 deletions
examples/injection_examples/basic_tutorial.py
+
41
−
27
View file @
aacd56a8
#!/bin/python
"""
Tutorial to demonstrate running parameter estimation on a reduced parameter space for an injected signal.
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 WMAP7.
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 WMAP7.
"""
from
__future__
import
division
,
print_function
...
...
@@ -11,7 +14,8 @@ 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
# Set the duration and sampling frequency of the data segment that we're going
# to inject the signal into
duration
=
4.
sampling_frequency
=
2048.
...
...
@@ -24,12 +28,14 @@ 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),
# 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
=
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
,
luminosity_distance
=
2000.
,
iota
=
0.4
,
psi
=
2.659
,
phase
=
1.3
,
geocent_time
=
1126259642.413
,
ra
=
1.375
,
dec
=-
1.2108
)
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
,
luminosity_distance
=
4000.
,
iota
=
0.4
,
psi
=
2.659
,
phase
=
1.3
,
geocent_time
=
1126259642.413
,
ra
=
1.375
,
dec
=-
1.2108
)
# Fixed arguments passed into the source model
waveform_arguments
=
dict
(
waveform_approximant
=
'
IMRPhenomPv2
'
,
...
...
@@ -51,29 +57,37 @@ ifos.set_strain_data_from_power_spectral_densities(
ifos
.
inject_signal
(
waveform_generator
=
waveform_generator
,
parameters
=
injection_parameters
)
# Set up prior, which is a dictionary
# 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, iota 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.
# Set up PriorSet, 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 equal 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, iota
# 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
.
BBHPriorSet
()
priors
[
'
geocent_time
'
]
=
bilby
.
core
.
prior
.
Uniform
(
minimum
=
injection_parameters
[
'
geocent_time
'
]
-
1
,
maximum
=
injection_parameters
[
'
geocent_time
'
]
+
1
,
name
=
'
geocent_time
'
,
latex_label
=
'
$t_c$
'
,
unit
=
'
$s$
'
)
for
key
in
[
'
a_1
'
,
'
a_2
'
,
'
tilt_1
'
,
'
tilt_2
'
,
'
phi_12
'
,
'
phi_jl
'
,
'
psi
'
,
'
ra
'
,
'
dec
'
,
'
geocent_time
'
,
'
phase
'
]:
# priors['geocent_time'] = bilby.core.prior.Uniform(
# minimum=injection_parameters['geocent_time'] - 1,
# maximum=injection_parameters['geocent_time'] + 1,
# name='geocent_time', latex_label='$t_c$', unit='$s$')
for
key
in
[
'
a_1
'
,
'
a_2
'
,
'
tilt_1
'
,
'
tilt_2
'
,
'
phi_12
'
,
'
phi_jl
'
,
'
psi
'
,
'
ra
'
,
'
dec
'
,
'
geocent_time
'
,
'
phase
'
]:
priors
[
key
]
=
injection_parameters
[
key
]
# Initialise the likelihood by passing in the interferometer data (IFOs) and the waveoform generator
likelihood
=
bilby
.
gw
.
GravitationalWaveTransient
(
interferometers
=
ifos
,
waveform_generator
=
waveform_generator
,
time_marginalization
=
False
,
phase_marginalization
=
False
,
distance_marginalization
=
False
,
prior
=
priors
)
# Initialise the likelihood by passing in the interferometer data (IFOs)
# and the waveoform generator
likelihood
=
bilby
.
gw
.
GravitationalWaveTransient
(
interferometers
=
ifos
,
waveform_generator
=
waveform_generator
,
time_marginalization
=
False
,
phase_marginalization
=
False
,
distance_marginalization
=
False
,
prior
=
priors
)
# Run sampler. In this case we're going to use the `dynesty` sampler
result
=
bilby
.
run_sampler
(
likelihood
=
likelihood
,
priors
=
priors
,
sampler
=
'
dynesty
'
,
npoints
=
1000
,
injection_parameters
=
injection_parameters
,
outdir
=
outdir
,
label
=
label
)
result
=
bilby
.
run_sampler
(
likelihood
=
likelihood
,
priors
=
priors
,
sampler
=
'
nestle
'
,
npoints
=
1000
,
injection_parameters
=
injection_parameters
,
outdir
=
outdir
,
label
=
label
,
conversion_function
=
bilby
.
gw
.
conversion
.
generate_all_bbh_parameters
)
# make some plots of the outputs
result
.
plot_corner
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment