Skip to content
Snippets Groups Projects
Commit e2601cbc authored by Colm Talbot's avatar Colm Talbot
Browse files

flake examples

parent de0704cf
No related branches found
No related tags found
1 merge request!228Update examples
Pipeline #33244 failed
Showing
with 26 additions and 52 deletions
......@@ -50,7 +50,7 @@ waveform_generator = bilby.gw.WaveformGenerator(
ifos = bilby.gw.detector.InterferometerList(['H1', 'L1'])
ifos.set_strain_data_from_power_spectral_densities(
sampling_frequency=sampling_frequency, duration=duration,
start_time=injection_parameters['geocent_time']-3)
start_time=injection_parameters['geocent_time'] - 3)
ifos.inject_signal(waveform_generator=waveform_generator,
parameters=injection_parameters)
......@@ -85,4 +85,3 @@ result = bilby.run_sampler(
# Make a corner plot.
result.plot_corner()
......@@ -25,7 +25,7 @@ np.random.seed(88170235)
# We are going to inject a binary neutron star 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_1,a_2) , etc.
# spins of both black holes (a_1, a_2), etc.
injection_parameters = dict(
mass_1=1.5, mass_2=1.3, a_1=0.0, a_2=0.0, luminosity_distance=50.,
iota=0.4, psi=2.659, phase=1.3, geocent_time=1126259642.413,
......@@ -35,7 +35,7 @@ injection_parameters = dict(
# to inject the signal into. For the
# TaylorF2 waveform, we cut the signal close to the isco frequency
duration = 8
sampling_frequency = 2*1570.
sampling_frequency = 2 * 1570.
start_time = injection_parameters['geocent_time'] + 2 - duration
# Fixed arguments passed into the source model. The analysis starts at 40 Hz.
......@@ -64,7 +64,7 @@ priors = bilby.gw.prior.BNSPriorSet()
for key in ['a_1', 'a_2', 'psi', 'geocent_time', 'ra', 'dec',
'iota', 'luminosity_distance', 'phase']:
priors[key] = injection_parameters[key]
# Initialise the likelihood by passing in the interferometer data (IFOs)
# and the waveoform generator
likelihood = bilby.gw.GravitationalWaveTransient(
......@@ -78,4 +78,3 @@ result = bilby.run_sampler(
injection_parameters=injection_parameters, outdir=outdir, label=label)
result.plot_corner()
......@@ -39,7 +39,7 @@ waveform_arguments = dict(waveform_approximant='IMRPhenomPv2',
waveform_generator = bilby.gw.WaveformGenerator(
duration=duration, sampling_frequency=sampling_frequency,
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
parameters=injection_parameters,waveform_arguments=waveform_arguments)
parameters=injection_parameters, waveform_arguments=waveform_arguments)
# Set up interferometers. In this case we'll use three interferometers
# (LIGO-Hanford (H1), LIGO-Livingston (L1), and Virgo (V1)).
......@@ -83,4 +83,3 @@ result = bilby.run_sampler(
# make some plots of the outputs
result.plot_corner()
......@@ -34,15 +34,14 @@ waveform_arguments = dict(waveform_approximant='IMRPhenomPv2',
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,
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', 'K1'])
ifos.set_strain_data_from_power_spectral_densities(
sampling_frequency=sampling_frequency, duration=duration,
start_time=injection_parameters['geocent_time']-3)
start_time=injection_parameters['geocent_time'] - 3)
ifos.inject_signal(waveform_generator=waveform_generator,
parameters=injection_parameters)
......@@ -80,4 +79,3 @@ result = bilby.core.sampler.run_sampler(
injection_parameters=injection_parameters, label='DifferentParameters',
conversion_function=bilby.gw.conversion.generate_all_bbh_parameters)
result.plot_corner()
......@@ -16,9 +16,9 @@ duration = 1
# Here we define out source model - this is the sine-Gaussian model in the
# frequency domain.
def sine_gaussian(f, A, f0, tau, phi0, geocent_time, ra, dec, psi):
arg = -(np.pi * tau * (f-f0))**2 + 1j * phi0
arg = -(np.pi * tau * (f - f0))**2 + 1j * phi0
plus = np.sqrt(np.pi) * A * tau * np.exp(arg) / 2.
cross = plus * np.exp(1j*np.pi/2)
cross = plus * np.exp(1j * np.pi / 2)
return {'plus': plus, 'cross': cross}
......@@ -52,4 +52,3 @@ result = bilby.core.sampler.run_sampler(
likelihood, prior, sampler='dynesty', outdir=outdir, label=label,
resume=False, sample='unif', injection_parameters=injection_parameters)
result.plot_corner()
......@@ -62,4 +62,3 @@ result = bilby.core.sampler.run_sampler(
injection_parameters=injection_parameters, outdir=outdir, label=label)
result.plot_corner()
......@@ -88,4 +88,3 @@ result = bilby.run_sampler(
# And finally we make some plots of the output posteriors.
result.plot_corner()
......@@ -72,4 +72,3 @@ result = bilby.run_sampler(
likelihood=likelihood, priors=priors, sampler='dynesty', outdir=outdir,
injection_parameters=injection_parameters, label='specify_prior')
result.plot_corner()
......@@ -58,4 +58,3 @@ result = bilby.run_sampler(
likelihood=likelihood, priors=priors, sampler='dynesty',
injection_parameters=injection_parameters, outdir=outdir, label=label)
result.plot_corner()
......@@ -57,7 +57,7 @@ waveform_generator =\
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)
start_time=injection_parameters['geocent_time'] - 3)
ifos.inject_signal(waveform_generator=waveform_generator,
parameters=injection_parameters)
......
......@@ -38,7 +38,7 @@ waveform_generator = bilby.gw.waveform_generator.WaveformGenerator(
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)
start_time=injection_parameters['geocent_time'] - 3)
ifos.inject_signal(waveform_generator=waveform_generator,
parameters=injection_parameters)
......@@ -63,15 +63,3 @@ result = bilby.core.sampler.run_sampler(
# make some plots of the outputs
result.plot_corner()
......@@ -91,4 +91,3 @@ result = bilby.run_sampler(
likelihood=likelihood, priors=priors, sampler='dynesty', npoints=500,
label=label)
result.plot_corner()
......@@ -11,11 +11,11 @@ class Likelihood(bilby.Likelihood):
self.parameters = dict(x=None, y=None)
def log_likelihood(self):
return -1/(self.interp(self.parameters['x'], self.parameters['y'])[0])
return -1 / (self.interp(self.parameters['x'], self.parameters['y'])[0])
for letter in ['t', 'u', 'p', 'a', 'k']:
img = 1-io.imread('{}.jpg'.format(letter), as_grey=True)[::-1, :]
img = 1 - io.imread('{}.jpg'.format(letter), as_grey=True)[::-1, :]
x = np.arange(img.shape[0])
y = np.arange(img.shape[1])
interp = si.interpolate.interp2d(x, y, img.T)
......
......@@ -51,4 +51,3 @@ likelihood = bilby.gw.likelihood.GravitationalWaveTransient(
result = bilby.run_sampler(likelihood, prior, sampler='dynesty',
outdir=outdir, label=label)
result.plot_corner()
......@@ -17,14 +17,14 @@ injection_parameters = dict(m=0.5, c=0.2)
sigma = 1
sampling_frequency = 10
time_duration = 10
time = np.arange(0, time_duration, 1/sampling_frequency)
time = np.arange(0, time_duration, 1 / sampling_frequency)
N = len(time)
data = model(time, **injection_parameters) + np.random.normal(0, sigma, N)
likelihood = bilby.core.likelihood.GaussianLikelihood(
time, data, model, sigma=sigma)
priors = {}
priors = dict()
priors['m'] = bilby.core.prior.Uniform(0, 1, 'm')
priors['c'] = bilby.core.prior.Uniform(-2, 2, 'c')
......@@ -40,5 +40,3 @@ resultA.plot_walkers()
result = resultA + resultB
result.plot_corner()
print(result)
......@@ -39,8 +39,8 @@ class SimpleGaussianLikelihood(bilby.Likelihood):
mu = self.parameters['mu']
sigma = self.parameters['sigma']
res = self.data - mu
return -0.5 * (np.sum((res / sigma)**2)
+ self.N*np.log(2*np.pi*sigma**2))
return -0.5 * (np.sum((res / sigma)**2) +
self.N * np.log(2 * np.pi * sigma**2))
likelihood = SimpleGaussianLikelihood(data)
......
#!/usr/bin/env python
""" Helper script to faciliate downloading data from LOSC
Usage: To download the GW150914 data from https://losc.ligo.org/events/
Usage: To download the GW150914 data from https://losc.ligo.org/events/
$ python get_LOSC_event_data -e GW150914
......@@ -52,7 +52,7 @@ for det, in ['H', 'L']:
event, detector, sampling_frequency, starttime, duration))
os.remove(filename)
time = np.arange(0, int(duration), 1/int(sampling_frequency)) + int(starttime)
time = np.arange(0, int(duration), 1 / int(sampling_frequency)) + int(starttime)
arr = [time] + data
outfile = '{}/{}_strain_data.npy'.format(args.outdir, args.event)
......
......@@ -15,7 +15,7 @@ outdir = 'outdir'
# Define a model to fit to each data set
def model(x, c0, c1):
return c0 + c1*x
return c0 + c1 * x
N = 10
......@@ -64,8 +64,8 @@ fig2.savefig('outdir/hyper_parameter_combined_posteriors.png')
def hyper_prior(data, mu, sigma):
return np.exp(- (data['c0'] - mu)**2 / (2 * sigma**2))\
/ (2 * np.pi * sigma**2)**0.5
return np.exp(- (data['c0'] - mu)**2 / (2 * sigma**2)) /\
(2 * np.pi * sigma**2)**0.5
def run_prior(data):
......
......@@ -9,7 +9,6 @@ from __future__ import division
import bilby
import numpy as np
import matplotlib.pyplot as plt
import inspect
from bilby.core.likelihood import GaussianLikelihood
......@@ -34,7 +33,7 @@ sigma = 1
# contents of the injection_paramsters when calling the model function.
sampling_frequency = 10
time_duration = 10
time = np.arange(0, time_duration, 1/sampling_frequency)
time = np.arange(0, time_duration, 1 / sampling_frequency)
N = len(time)
data = model(time, **injection_parameters) + np.random.normal(0, sigma, N)
......
......@@ -36,7 +36,7 @@ sigma = 1
# contents of the injection_paramsters when calling the model function.
sampling_frequency = 10
time_duration = 10
time = np.arange(0, time_duration, 1/sampling_frequency)
time = np.arange(0, time_duration, 1 / sampling_frequency)
N = len(time)
data = model(time, **injection_parameters) + np.random.normal(0, sigma, N)
......@@ -139,9 +139,10 @@ class PriorPyMC3(bilby.core.prior.Prior):
return pm.Uniform(self.name, lower=self.minimum,
upper=self.maximum)
# From hereon, the syntax is exactly equivalent to other bilby examples
# We make a prior
priors = {}
priors = dict()
priors['m'] = bilby.core.prior.Uniform(0, 5, 'm')
priors['c'] = PriorPyMC3(-2, 2, 'c')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment