diff --git a/examples/injection_examples/basic_tutorial.py b/examples/injection_examples/basic_tutorial.py index e22d3805685244a36b49d304d23fe9f043f153a8..9fde009d64725aaa429c7c5131243951814ed2d1 100644 --- a/examples/injection_examples/basic_tutorial.py +++ b/examples/injection_examples/basic_tutorial.py @@ -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() - diff --git a/examples/injection_examples/binary_neutron_star_example.py b/examples/injection_examples/binary_neutron_star_example.py index 4f826a060037129c891286c28e2a022d626a6edd..4b3b9b848fdc790bc424cecd788c765327386f31 100644 --- a/examples/injection_examples/binary_neutron_star_example.py +++ b/examples/injection_examples/binary_neutron_star_example.py @@ -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() - diff --git a/examples/injection_examples/calibration_example.py b/examples/injection_examples/calibration_example.py index 9f2052ffb55d019aa1509ae251aa6f57d4bc9c14..ec3f3491e9ad61fda38512557d91a5345cf68f2d 100644 --- a/examples/injection_examples/calibration_example.py +++ b/examples/injection_examples/calibration_example.py @@ -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() - diff --git a/examples/injection_examples/change_sampled_parameters.py b/examples/injection_examples/change_sampled_parameters.py index aabcbfebcef8307957c285350b3731b9756d630d..06dfa174033d12e53b02bb0f033eceeb64609da7 100644 --- a/examples/injection_examples/change_sampled_parameters.py +++ b/examples/injection_examples/change_sampled_parameters.py @@ -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() - diff --git a/examples/injection_examples/create_your_own_source_model.py b/examples/injection_examples/create_your_own_source_model.py index 4e0ab71da47eed96df2d8dd6f6a1c2a716154cfe..ded59e157ee098bd7c765dae01e0b5b55790d408 100644 --- a/examples/injection_examples/create_your_own_source_model.py +++ b/examples/injection_examples/create_your_own_source_model.py @@ -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() - diff --git a/examples/injection_examples/create_your_own_time_domain_source_model.py b/examples/injection_examples/create_your_own_time_domain_source_model.py index 28bae69525026fa7255e07247493f61c0e8be51a..82ca24d187775fb8213910498fa2dddd940b24e7 100644 --- a/examples/injection_examples/create_your_own_time_domain_source_model.py +++ b/examples/injection_examples/create_your_own_time_domain_source_model.py @@ -62,4 +62,3 @@ result = bilby.core.sampler.run_sampler( injection_parameters=injection_parameters, outdir=outdir, label=label) result.plot_corner() - diff --git a/examples/injection_examples/eccentric_inspiral.py b/examples/injection_examples/eccentric_inspiral.py index 2034df2b57b3419ac4dbf1c65b4f20e0d12fe660..2709220fc7b07e91af9597bff6872178447c7a43 100644 --- a/examples/injection_examples/eccentric_inspiral.py +++ b/examples/injection_examples/eccentric_inspiral.py @@ -88,4 +88,3 @@ result = bilby.run_sampler( # And finally we make some plots of the output posteriors. result.plot_corner() - diff --git a/examples/injection_examples/how_to_specify_the_prior.py b/examples/injection_examples/how_to_specify_the_prior.py index 4c9b80635f2900d91b740971098ee4dbb7710b21..6a5eb033729cb1d3cb7f442c594084e8decd27f9 100644 --- a/examples/injection_examples/how_to_specify_the_prior.py +++ b/examples/injection_examples/how_to_specify_the_prior.py @@ -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() - diff --git a/examples/injection_examples/marginalized_likelihood.py b/examples/injection_examples/marginalized_likelihood.py index 29eae13c6221d76493716ae9dfafbec54e75bcdb..05c1def463d2ddad61bbff15997e49c50f0233ec 100644 --- a/examples/injection_examples/marginalized_likelihood.py +++ b/examples/injection_examples/marginalized_likelihood.py @@ -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() - diff --git a/examples/injection_examples/non_tensor.py b/examples/injection_examples/non_tensor.py index 6b5bc8e298d26822871c4ed6d71866bc2f7b0c56..c75fcf0dbcaad9eb589e700f8baccdb393818a89 100644 --- a/examples/injection_examples/non_tensor.py +++ b/examples/injection_examples/non_tensor.py @@ -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) diff --git a/examples/injection_examples/sine_gaussian_example.py b/examples/injection_examples/sine_gaussian_example.py index 2f0d1a127250037999a46a9dc0a3884f8c7db157..07ac1ff0b2a12f1fe446e3f08e1fc85f70783c1f 100644 --- a/examples/injection_examples/sine_gaussian_example.py +++ b/examples/injection_examples/sine_gaussian_example.py @@ -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() - - - - - - - - - - - - diff --git a/examples/injection_examples/using_gwin.py b/examples/injection_examples/using_gwin.py index dc312ddd8d2285edb5de82fb898ad4b0fb2b26e8..1539195e60cf0e68f1b3d565f35161e91fbce84b 100644 --- a/examples/injection_examples/using_gwin.py +++ b/examples/injection_examples/using_gwin.py @@ -91,4 +91,3 @@ result = bilby.run_sampler( likelihood=likelihood, priors=priors, sampler='dynesty', npoints=500, label=label) result.plot_corner() - diff --git a/examples/logo/sample_logo.py b/examples/logo/sample_logo.py index b82733ebe78f7cfd582a3af0901f69144f728d4b..59153aeeffeecc1fb4780d0ffccf5535c69d02e6 100644 --- a/examples/logo/sample_logo.py +++ b/examples/logo/sample_logo.py @@ -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) diff --git a/examples/open_data_examples/GW150914.py b/examples/open_data_examples/GW150914.py index aa5ca44af19f6575feb8ed7e8b4e373b001bec0a..f44c9dd1cb4c82867f8880e612bf2cf0b1c711d2 100644 --- a/examples/open_data_examples/GW150914.py +++ b/examples/open_data_examples/GW150914.py @@ -51,4 +51,3 @@ likelihood = bilby.gw.likelihood.GravitationalWaveTransient( result = bilby.run_sampler(likelihood, prior, sampler='dynesty', outdir=outdir, label=label) result.plot_corner() - diff --git a/examples/other_examples/add_multiple_results.py b/examples/other_examples/add_multiple_results.py index f4c565555ad6250390622cd71fd1f433a7599c64..83f57b1a62ca15b16735bd6677e11e96a3bb260c 100644 --- a/examples/other_examples/add_multiple_results.py +++ b/examples/other_examples/add_multiple_results.py @@ -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) - - diff --git a/examples/other_examples/gaussian_example.py b/examples/other_examples/gaussian_example.py index bf7730286f12ddc70ac9bfe647e6e637fd4004ac..2d9e51938dbcc1c871f4d44ef46f3df12366cc5c 100644 --- a/examples/other_examples/gaussian_example.py +++ b/examples/other_examples/gaussian_example.py @@ -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) diff --git a/examples/other_examples/get_LOSC_event_data.py b/examples/other_examples/get_LOSC_event_data.py index 6197426eb6e02869fb73e18b349d8dde92ca1fc5..9c7b314797480aa4f4f6df5b767144490a84ca19 100644 --- a/examples/other_examples/get_LOSC_event_data.py +++ b/examples/other_examples/get_LOSC_event_data.py @@ -1,7 +1,7 @@ #!/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) diff --git a/examples/other_examples/hyper_parameter_example.py b/examples/other_examples/hyper_parameter_example.py index 21ad6c24dcba6937ab79d3732dfbe7f198644290..ef04e98400a5759bf02484d97bd49a9494d4b1b2 100644 --- a/examples/other_examples/hyper_parameter_example.py +++ b/examples/other_examples/hyper_parameter_example.py @@ -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): diff --git a/examples/other_examples/linear_regression_pymc3.py b/examples/other_examples/linear_regression_pymc3.py index df98e5a5bf8ba2d1dc5dca7451b232d0abcf35ab..eb98be1edd7a7092dec74fd4b2eaa4dc32997bbe 100644 --- a/examples/other_examples/linear_regression_pymc3.py +++ b/examples/other_examples/linear_regression_pymc3.py @@ -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) diff --git a/examples/other_examples/linear_regression_pymc3_custom_likelihood.py b/examples/other_examples/linear_regression_pymc3_custom_likelihood.py index f62b187acd00b296b74cf4952a9d60cea325782e..4270e696891056c9638a6fd2084b0c99fc3daf58 100644 --- a/examples/other_examples/linear_regression_pymc3_custom_likelihood.py +++ b/examples/other_examples/linear_regression_pymc3_custom_likelihood.py @@ -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') diff --git a/examples/other_examples/linear_regression_unknown_noise.py b/examples/other_examples/linear_regression_unknown_noise.py index be44d994f0ffea88fa91666d850cfbd31a03879b..e4427c9e0b062a880327527dbfbdf7541a962261 100644 --- a/examples/other_examples/linear_regression_unknown_noise.py +++ b/examples/other_examples/linear_regression_unknown_noise.py @@ -31,7 +31,7 @@ sigma = 1 # contents of the injection_parameters 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) diff --git a/examples/other_examples/occam_factor_example.py b/examples/other_examples/occam_factor_example.py index b977eaeadf53086326ca4047a8a9aa64bb607b0c..7785a540f956db8886311dc67b308e0ab390b98d 100644 --- a/examples/other_examples/occam_factor_example.py +++ b/examples/other_examples/occam_factor_example.py @@ -84,8 +84,8 @@ class Polynomial(bilby.Likelihood): def log_likelihood(self): res = self.y - self.polynomial(self.x, self.parameters) - return -0.5 * (np.sum((res / self.sigma)**2) - + self.N*np.log(2*np.pi*self.sigma**2)) + return -0.5 * (np.sum((res / self.sigma)**2) + + self.N * np.log(2 * np.pi * self.sigma**2)) def fit(n): diff --git a/examples/other_examples/radioactive_decay.py b/examples/other_examples/radioactive_decay.py index b59fad8a96e318ec85a4a661b9703d8a5989cfcd..aceabd156ff1a68bdbb4bf500d0718e6167241ee 100644 --- a/examples/other_examples/radioactive_decay.py +++ b/examples/other_examples/radioactive_decay.py @@ -45,8 +45,8 @@ def decay_rate(delta_t, halflife, n_init): n_atoms = n_init * atto * n_avogadro - rates = (np.exp(-np.log(2) * (times[:-1] / halflife)) - - np.exp(- np.log(2) * (times[1:] / halflife))) * n_atoms / delta_t + rates = (np.exp(-np.log(2) * (times[:-1] / halflife)) - + np.exp(- np.log(2) * (times[1:] / halflife))) * n_atoms / delta_t return rates diff --git a/examples/supernova_example/supernova_example.py b/examples/supernova_example/supernova_example.py index 05b2eebcdbf4538e9aa8d492020a0dbc9de2d5c2..507c4e4ed1c4c4907b7b9f153649d0634897c953 100644 --- a/examples/supernova_example/supernova_example.py +++ b/examples/supernova_example/supernova_example.py @@ -45,7 +45,7 @@ waveform_generator = bilby.gw.waveform_generator.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)