From e2601cbc00e37de40d3f4ded25b15bcc085f1d0c Mon Sep 17 00:00:00 2001 From: Colm Talbot <colm.talbot@ligo.org> Date: Thu, 4 Oct 2018 21:31:44 +1000 Subject: [PATCH] flake examples --- examples/injection_examples/basic_tutorial.py | 3 +-- .../binary_neutron_star_example.py | 7 +++---- examples/injection_examples/calibration_example.py | 3 +-- .../change_sampled_parameters.py | 6 ++---- .../create_your_own_source_model.py | 5 ++--- .../create_your_own_time_domain_source_model.py | 1 - examples/injection_examples/eccentric_inspiral.py | 1 - .../injection_examples/how_to_specify_the_prior.py | 1 - .../injection_examples/marginalized_likelihood.py | 1 - examples/injection_examples/non_tensor.py | 2 +- .../injection_examples/sine_gaussian_example.py | 14 +------------- examples/injection_examples/using_gwin.py | 1 - examples/logo/sample_logo.py | 4 ++-- examples/open_data_examples/GW150914.py | 1 - examples/other_examples/add_multiple_results.py | 6 ++---- examples/other_examples/gaussian_example.py | 4 ++-- examples/other_examples/get_LOSC_event_data.py | 4 ++-- examples/other_examples/hyper_parameter_example.py | 6 +++--- examples/other_examples/linear_regression_pymc3.py | 3 +-- .../linear_regression_pymc3_custom_likelihood.py | 5 +++-- .../linear_regression_unknown_noise.py | 2 +- examples/other_examples/occam_factor_example.py | 4 ++-- examples/other_examples/radioactive_decay.py | 4 ++-- examples/supernova_example/supernova_example.py | 2 +- 24 files changed, 32 insertions(+), 58 deletions(-) diff --git a/examples/injection_examples/basic_tutorial.py b/examples/injection_examples/basic_tutorial.py index e22d38056..9fde009d6 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 4f826a060..4b3b9b848 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 9f2052ffb..ec3f3491e 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 aabcbfebc..06dfa1740 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 4e0ab71da..ded59e157 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 28bae6952..82ca24d18 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 2034df2b5..2709220fc 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 4c9b80635..6a5eb0337 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 29eae13c6..05c1def46 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 6b5bc8e29..c75fcf0db 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 2f0d1a127..07ac1ff0b 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 dc312ddd8..1539195e6 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 b82733ebe..59153aeef 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 aa5ca44af..f44c9dd1c 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 f4c565555..83f57b1a6 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 bf7730286..2d9e51938 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 6197426eb..9c7b31479 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 21ad6c24d..ef04e9840 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 df98e5a5b..eb98be1ed 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 f62b187ac..4270e6968 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 be44d994f..e4427c9e0 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 b977eaead..7785a540f 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 b59fad8a9..aceabd156 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 05b2eebcd..507c4e4ed 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) -- GitLab