-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
158 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Example of running nessai with bilby on a gravitational wave likelihood. This | ||
examples includes all 15 parameters for CBC and should take around 2 hours to | ||
run. | ||
Based on the Bilby example: https://git.ligo.org/lscsoft/bilby | ||
""" | ||
|
||
import bilby | ||
|
||
outdir = "./outdir/" | ||
label = "ins_gw_example_full" | ||
|
||
bilby.core.utils.setup_logger(outdir=outdir, label=label) | ||
|
||
duration = 4.0 | ||
sampling_frequency = 2048.0 | ||
|
||
bilby.core.utils.random.seed(151226) | ||
|
||
# Use an injection that is similar to GW150914 | ||
injection_parameters = dict( | ||
total_mass=66.0, | ||
mass_ratio=0.9, | ||
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.413, | ||
ra=1.375, | ||
dec=-1.2108, | ||
) | ||
|
||
waveform_arguments = dict( | ||
waveform_approximant="IMRPhenomPv2", reference_frequency=50.0 | ||
) | ||
|
||
# Create the waveform_generator | ||
waveform_generator = bilby.gw.waveform_generator.WaveformGenerator( | ||
sampling_frequency=sampling_frequency, | ||
duration=duration, | ||
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 | ||
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"] - 3, | ||
) | ||
ifos.inject_signal( | ||
waveform_generator=waveform_generator, parameters=injection_parameters | ||
) | ||
|
||
# Set up prior | ||
priors = bilby.gw.prior.BBHPriorDict() | ||
priors["geocent_time"] = bilby.core.prior.Uniform( | ||
minimum=injection_parameters["geocent_time"] - 0.1, | ||
maximum=injection_parameters["geocent_time"] + 0.1, | ||
name="geocent_time", | ||
latex_label="$t_c$", | ||
unit="$s$", | ||
) | ||
|
||
# Initialise the likelihood | ||
# nessai supports the marginalisation included in bilby | ||
likelihood = bilby.gw.likelihood.GravitationalWaveTransient( | ||
interferometers=ifos, | ||
waveform_generator=waveform_generator, | ||
priors=priors, | ||
phase_marginalization=True, | ||
distance_marginalization=False, | ||
) | ||
priors["chirp_mass"].maximum = 40 | ||
|
||
# for key in [ | ||
# "a_1", | ||
# "a_2", | ||
# "tilt_1", | ||
# "tilt_2", | ||
# "phi_12", | ||
# "phi_jl", | ||
# # "luminosity_distance", | ||
# "psi", | ||
# "geocent_time", | ||
# "ra", | ||
# "dec", | ||
# ]: | ||
# priors[key] = injection_parameters[key] | ||
|
||
|
||
# Run sampler | ||
|
||
# The `flow_class` should be set to `GWFlowProposal` for GW PE. This includes | ||
# specific default reparameterisations for certain parameters. For example, | ||
# it knows that theta_jn is angle with a sine prior. | ||
|
||
result = bilby.core.sampler.run_sampler( | ||
likelihood=likelihood, | ||
priors=priors, | ||
outdir=outdir, | ||
injection_parameters=injection_parameters, | ||
label=label, | ||
conversion_function=bilby.gw.conversion.generate_all_bbh_parameters, | ||
sampler="inessai", | ||
resume=False, | ||
plot=True, | ||
nlive=8000, | ||
min_samples=1000, | ||
seed=150914, | ||
flow_config=dict( | ||
n_blocks=6, | ||
n_neurons=32, | ||
batch_norm_between_layers=True, | ||
), | ||
reset_flow=4, | ||
n_pool=8, | ||
threshold_kwargs=dict(q=0.66), | ||
draw_iid_live=True, | ||
rebalance_interval=1, | ||
stopping_criterion=["ratio", "fractional_error"], | ||
check_criteria="all", | ||
tolerance=[-1, 0.1], | ||
min_iteration=5, | ||
) | ||
|
||
# Produce corner plots | ||
result.plot_corner() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters