Commit a2acfcff authored by Reinhard Prix's avatar Reinhard Prix

apply 'black' coding style (stricter subset of PEP8)

- supply consistent flake8 settings in setup.cfg
parent 96e1046c
......@@ -4,7 +4,7 @@ import numpy as np
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
duration = 100*86400
duration = 100 * 86400
tend = tstart + duration
# Properties of the signal
......@@ -13,39 +13,46 @@ F1 = -1e-10
F2 = 0
Alpha = np.radians(83.6292)
Delta = np.radians(22.0144)
tref = .5*(tstart+tend)
tref = 0.5 * (tstart + tend)
depth = 10
h0 = sqrtSX / depth
label = 'fully_coherent_search_using_MCMC'
outdir = 'data'
label = "fully_coherent_search_using_MCMC"
outdir = "data"
data = pyfstat.Writer(
label=label, outdir=outdir, tref=tref,
tstart=tstart, F0=F0, F1=F1, F2=F2, duration=duration, Alpha=Alpha,
Delta=Delta, h0=h0, sqrtSX=sqrtSX)
label=label,
outdir=outdir,
tref=tref,
tstart=tstart,
F0=F0,
F1=F1,
F2=F2,
duration=duration,
Alpha=Alpha,
Delta=Delta,
h0=h0,
sqrtSX=sqrtSX,
)
data.make_data()
# The predicted twoF, given by lalapps_predictFstat can be accessed by
twoF = data.predict_fstat()
print('Predicted twoF value: {}\n'.format(twoF))
print("Predicted twoF value: {}\n".format(twoF))
DeltaF0 = 1e-7
DeltaF1 = 1e-13
VF0 = (np.pi * duration * DeltaF0)**2 / 3.0
VF1 = (np.pi * duration**2 * DeltaF1)**2 * 4/45.
print('\nV={:1.2e}, VF0={:1.2e}, VF1={:1.2e}\n'.format(VF0*VF1, VF0, VF1))
VF0 = (np.pi * duration * DeltaF0) ** 2 / 3.0
VF1 = (np.pi * duration ** 2 * DeltaF1) ** 2 * 4 / 45.0
print("\nV={:1.2e}, VF0={:1.2e}, VF1={:1.2e}\n".format(VF0 * VF1, VF0, VF1))
theta_prior = {'F0': {'type': 'unif',
'lower': F0-DeltaF0/2.,
'upper': F0+DeltaF0/2.},
'F1': {'type': 'unif',
'lower': F1-DeltaF1/2.,
'upper': F1+DeltaF1/2.},
'F2': F2,
'Alpha': Alpha,
'Delta': Delta
}
theta_prior = {
"F0": {"type": "unif", "lower": F0 - DeltaF0 / 2.0, "upper": F0 + DeltaF0 / 2.0},
"F1": {"type": "unif", "lower": F1 - DeltaF1 / 2.0, "upper": F1 + DeltaF1 / 2.0},
"F2": F2,
"Alpha": Alpha,
"Delta": Delta,
}
ntemps = 2
log10beta_min = -0.5
......@@ -53,13 +60,22 @@ nwalkers = 100
nsteps = [300, 300]
mcmc = pyfstat.MCMCSearch(
label=label, outdir=outdir,
sftfilepattern='{}/*{}*sft'.format(outdir, label), theta_prior=theta_prior,
tref=tref, minStartTime=tstart, maxStartTime=tend, nsteps=nsteps,
nwalkers=nwalkers, ntemps=ntemps, log10beta_min=log10beta_min)
label=label,
outdir=outdir,
sftfilepattern="{}/*{}*sft".format(outdir, label),
theta_prior=theta_prior,
tref=tref,
minStartTime=tstart,
maxStartTime=tend,
nsteps=nsteps,
nwalkers=nwalkers,
ntemps=ntemps,
log10beta_min=log10beta_min,
)
mcmc.transform_dictionary = dict(
F0=dict(subtractor=F0, symbol='$f-f^\mathrm{s}$'),
F1=dict(subtractor=F1, symbol='$\dot{f}-\dot{f}^\mathrm{s}$'))
F0=dict(subtractor=F0, symbol="$f-f^\mathrm{s}$"),
F1=dict(subtractor=F1, symbol="$\dot{f}-\dot{f}^\mathrm{s}$"),
)
mcmc.run()
mcmc.plot_corner(add_prior=True)
mcmc.print_summary()
......@@ -4,7 +4,7 @@ import numpy as np
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
duration = 100*86400
duration = 100 * 86400
tend = tstart + duration
# Properties of the signal
......@@ -13,39 +13,46 @@ F1 = -1e-10
F2 = 0
Alpha = np.radians(83.6292)
Delta = np.radians(22.0144)
tref = .5*(tstart+tend)
tref = 0.5 * (tstart + tend)
depth = 10
h0 = sqrtSX / depth
label = 'semicoherent_search_using_MCMC'
outdir = 'data'
label = "semicoherent_search_using_MCMC"
outdir = "data"
data = pyfstat.Writer(
label=label, outdir=outdir, tref=tref,
tstart=tstart, F0=F0, F1=F1, F2=F2, duration=duration, Alpha=Alpha,
Delta=Delta, h0=h0, sqrtSX=sqrtSX)
label=label,
outdir=outdir,
tref=tref,
tstart=tstart,
F0=F0,
F1=F1,
F2=F2,
duration=duration,
Alpha=Alpha,
Delta=Delta,
h0=h0,
sqrtSX=sqrtSX,
)
data.make_data()
# The predicted twoF, given by lalapps_predictFstat can be accessed by
twoF = data.predict_fstat()
print('Predicted twoF value: {}\n'.format(twoF))
print("Predicted twoF value: {}\n".format(twoF))
DeltaF0 = 1e-7
DeltaF1 = 1e-13
VF0 = (np.pi * duration * DeltaF0)**2 / 3.0
VF1 = (np.pi * duration**2 * DeltaF1)**2 * 4/45.
print('\nV={:1.2e}, VF0={:1.2e}, VF1={:1.2e}\n'.format(VF0*VF1, VF0, VF1))
VF0 = (np.pi * duration * DeltaF0) ** 2 / 3.0
VF1 = (np.pi * duration ** 2 * DeltaF1) ** 2 * 4 / 45.0
print("\nV={:1.2e}, VF0={:1.2e}, VF1={:1.2e}\n".format(VF0 * VF1, VF0, VF1))
theta_prior = {'F0': {'type': 'unif',
'lower': F0-DeltaF0/2.,
'upper': F0+DeltaF0/2.},
'F1': {'type': 'unif',
'lower': F1-DeltaF1/2.,
'upper': F1+DeltaF1/2.},
'F2': F2,
'Alpha': Alpha,
'Delta': Delta
}
theta_prior = {
"F0": {"type": "unif", "lower": F0 - DeltaF0 / 2.0, "upper": F0 + DeltaF0 / 2.0},
"F1": {"type": "unif", "lower": F1 - DeltaF1 / 2.0, "upper": F1 + DeltaF1 / 2.0},
"F2": F2,
"Alpha": Alpha,
"Delta": Delta,
}
ntemps = 1
log10beta_min = -1
......@@ -53,14 +60,23 @@ nwalkers = 100
nsteps = [300, 300]
mcmc = pyfstat.MCMCSemiCoherentSearch(
label=label, outdir=outdir, nsegs=10,
sftfilepattern='{}/*{}*sft'.format(outdir, label),
theta_prior=theta_prior, tref=tref, minStartTime=tstart, maxStartTime=tend,
nsteps=nsteps, nwalkers=nwalkers, ntemps=ntemps,
log10beta_min=log10beta_min)
label=label,
outdir=outdir,
nsegs=10,
sftfilepattern="{}/*{}*sft".format(outdir, label),
theta_prior=theta_prior,
tref=tref,
minStartTime=tstart,
maxStartTime=tend,
nsteps=nsteps,
nwalkers=nwalkers,
ntemps=ntemps,
log10beta_min=log10beta_min,
)
mcmc.transform_dictionary = dict(
F0=dict(subtractor=F0, symbol='$f-f^\mathrm{s}$'),
F1=dict(subtractor=F1, symbol='$\dot{f}-\dot{f}^\mathrm{s}$'))
F0=dict(subtractor=F0, symbol="$f-f^\mathrm{s}$"),
F1=dict(subtractor=F1, symbol="$\dot{f}-\dot{f}^\mathrm{s}$"),
)
mcmc.run()
mcmc.plot_corner(add_prior=True)
mcmc.print_summary()
......@@ -11,39 +11,47 @@ Delta = np.radians(22.0144)
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
duration = 100*86400
tend = tstart+duration
tref = .5*(tstart+tend)
duration = 100 * 86400
tend = tstart + duration
tref = 0.5 * (tstart + tend)
depth = 40
label = 'semicoherent_directed_follow_up'
outdir = 'data'
label = "semicoherent_directed_follow_up"
outdir = "data"
h0 = sqrtSX / depth
data = pyfstat.Writer(
label=label, outdir=outdir, tref=tref, tstart=tstart, F0=F0, F1=F1,
F2=F2, duration=duration, Alpha=Alpha, Delta=Delta, h0=h0, sqrtSX=sqrtSX)
label=label,
outdir=outdir,
tref=tref,
tstart=tstart,
F0=F0,
F1=F1,
F2=F2,
duration=duration,
Alpha=Alpha,
Delta=Delta,
h0=h0,
sqrtSX=sqrtSX,
)
data.make_data()
# The predicted twoF, given by lalapps_predictFstat can be accessed by
twoF = data.predict_fstat()
print('Predicted twoF value: {}\n'.format(twoF))
print("Predicted twoF value: {}\n".format(twoF))
# Search
VF0 = VF1 = 1e5
DeltaF0 = np.sqrt(VF0) * np.sqrt(3)/(np.pi*duration)
DeltaF1 = np.sqrt(VF1) * np.sqrt(180)/(np.pi*duration**2)
theta_prior = {'F0': {'type': 'unif',
'lower': F0-DeltaF0/2.,
'upper': F0+DeltaF0/2},
'F1': {'type': 'unif',
'lower': F1-DeltaF1/2.,
'upper': F1+DeltaF1/2},
'F2': F2,
'Alpha': Alpha,
'Delta': Delta
}
DeltaF0 = np.sqrt(VF0) * np.sqrt(3) / (np.pi * duration)
DeltaF1 = np.sqrt(VF1) * np.sqrt(180) / (np.pi * duration ** 2)
theta_prior = {
"F0": {"type": "unif", "lower": F0 - DeltaF0 / 2.0, "upper": F0 + DeltaF0 / 2},
"F1": {"type": "unif", "lower": F1 - DeltaF1 / 2.0, "upper": F1 + DeltaF1 / 2},
"F2": F2,
"Alpha": Alpha,
"Delta": Delta,
}
ntemps = 3
log10beta_min = -0.5
......@@ -51,23 +59,35 @@ nwalkers = 100
nsteps = [100, 100]
mcmc = pyfstat.MCMCFollowUpSearch(
label=label, outdir=outdir,
sftfilepattern='{}/*{}*sft'.format(outdir, label),
theta_prior=theta_prior, tref=tref, minStartTime=tstart, maxStartTime=tend,
nwalkers=nwalkers, nsteps=nsteps, ntemps=ntemps,
log10beta_min=log10beta_min)
label=label,
outdir=outdir,
sftfilepattern="{}/*{}*sft".format(outdir, label),
theta_prior=theta_prior,
tref=tref,
minStartTime=tstart,
maxStartTime=tend,
nwalkers=nwalkers,
nsteps=nsteps,
ntemps=ntemps,
log10beta_min=log10beta_min,
)
NstarMax = 1000
Nsegs0 = 100
fig, axes = plt.subplots(nrows=2, figsize=(3.4, 3.5))
fig, axes = mcmc.run(
NstarMax=NstarMax, Nsegs0=Nsegs0, labelpad=0.01,
plot_det_stat=False, return_fig=True, fig=fig,
axes=axes)
NstarMax=NstarMax,
Nsegs0=Nsegs0,
labelpad=0.01,
plot_det_stat=False,
return_fig=True,
fig=fig,
axes=axes,
)
for ax in axes:
ax.grid()
ax.set_xticks(np.arange(0, 600, 100))
ax.set_xticklabels([str(s) for s in np.arange(0, 700, 100)])
axes[-1].set_xlabel(r'$\textrm{Number of steps}$', labelpad=0.1)
axes[-1].set_xlabel(r"$\textrm{Number of steps}$", labelpad=0.1)
fig.tight_layout()
fig.savefig('{}/{}_walkers.png'.format(mcmc.outdir, mcmc.label), dpi=400)
fig.savefig("{}/{}_walkers.png".format(mcmc.outdir, mcmc.label), dpi=400)
from pyfstat import Writer, GlitchWriter
import numpy as np
outdir = 'data'
outdir = "data"
# First, we generate data with a reasonably strong smooth signal
# Define parameters of the Crab pulsar as an example
......@@ -17,37 +17,75 @@ h0 = 5e-24
# Properties of the GW data
sqrtSX = 1e-22
tstart = 1000000000
duration = 50*86400
tend = tstart+duration
tref = tstart + 0.5*duration
duration = 50 * 86400
tend = tstart + duration
tref = tstart + 0.5 * duration
data = Writer(
label='0_glitch', outdir=outdir, tref=tref, tstart=tstart, F0=F0, F1=F1,
F2=F2, duration=duration, Alpha=Alpha, Delta=Delta, h0=h0, sqrtSX=sqrtSX)
label="0_glitch",
outdir=outdir,
tref=tref,
tstart=tstart,
F0=F0,
F1=F1,
F2=F2,
duration=duration,
Alpha=Alpha,
Delta=Delta,
h0=h0,
sqrtSX=sqrtSX,
)
data.make_data()
# Next, taking the same signal parameters, we include a glitch half way through
dtglitch = duration/2.0
dtglitch = duration / 2.0
delta_F0 = 5e-6
delta_F1 = 0
glitch_data = GlitchWriter(
label='1_glitch', outdir=outdir, tref=tref, tstart=tstart, F0=F0, F1=F1,
F2=F2, duration=duration, Alpha=Alpha, Delta=Delta, h0=h0, sqrtSX=sqrtSX,
dtglitch=dtglitch, delta_F0=delta_F0, delta_F1=delta_F1)
label="1_glitch",
outdir=outdir,
tref=tref,
tstart=tstart,
F0=F0,
F1=F1,
F2=F2,
duration=duration,
Alpha=Alpha,
Delta=Delta,
h0=h0,
sqrtSX=sqrtSX,
dtglitch=dtglitch,
delta_F0=delta_F0,
delta_F1=delta_F1,
)
glitch_data.make_data()
# Making data with two glitches
dtglitch_2 = [duration/4.0, 4*duration/5.0]
dtglitch_2 = [duration / 4.0, 4 * duration / 5.0]
delta_phi_2 = [0, 0]
delta_F0_2 = [4e-6, 3e-7]
delta_F1_2 = [0, 0]
delta_F2_2 = [0, 0]
two_glitch_data = GlitchWriter(
label='2_glitch', outdir=outdir, tref=tref, tstart=tstart, F0=F0, F1=F1,
F2=F2, duration=duration, Alpha=Alpha, Delta=Delta, h0=h0, sqrtSX=sqrtSX,
dtglitch=dtglitch_2, delta_phi=delta_phi_2, delta_F0=delta_F0_2,
delta_F1=delta_F1_2, delta_F2=delta_F2_2)
label="2_glitch",
outdir=outdir,
tref=tref,
tstart=tstart,
F0=F0,
F1=F1,
F2=F2,
duration=duration,
Alpha=Alpha,
Delta=Delta,
h0=h0,
sqrtSX=sqrtSX,
dtglitch=dtglitch_2,
delta_phi=delta_phi_2,
delta_F0=delta_F0_2,
delta_F1=delta_F1_2,
delta_F2=delta_F2_2,
)
two_glitch_data.make_data()
......@@ -3,34 +3,42 @@ import matplotlib.pyplot as plt
import pyfstat
import gridcorner
import time
from make_simulated_data import tstart, duration, tref, F0, F1, F2, Alpha, Delta, delta_F0, dtglitch, outdir
from make_simulated_data import (
tstart,
duration,
tref,
F0,
F1,
F2,
Alpha,
Delta,
delta_F0,
dtglitch,
outdir,
)
plt.style.use('./paper.mplstyle')
plt.style.use("./paper.mplstyle")
label = 'semicoherent_glitch_robust_directed_MCMC_search_on_1_glitch'
label = "semicoherent_glitch_robust_directed_MCMC_search_on_1_glitch"
Nstar = 1000
F0_width = np.sqrt(Nstar)*np.sqrt(12)/(np.pi*duration)
F1_width = np.sqrt(Nstar)*np.sqrt(180)/(np.pi*duration**2)
F0_width = np.sqrt(Nstar) * np.sqrt(12) / (np.pi * duration)
F1_width = np.sqrt(Nstar) * np.sqrt(180) / (np.pi * duration ** 2)
theta_prior = {
'F0': {'type': 'unif',
'lower': F0-F0_width/2.,
'upper': F0+F0_width/2.},
'F1': {'type': 'unif',
'lower': F1-F1_width/2.,
'upper': F1+F1_width/2.},
'F2': F2,
'delta_F0': {'type': 'unif',
'lower': 0,
'upper': 1e-5},
'delta_F1': 0,
'tglitch': {'type': 'unif',
'lower': tstart+0.1*duration,
'upper': tstart+0.9*duration},
'Alpha': Alpha,
'Delta': Delta,
}
"F0": {"type": "unif", "lower": F0 - F0_width / 2.0, "upper": F0 + F0_width / 2.0},
"F1": {"type": "unif", "lower": F1 - F1_width / 2.0, "upper": F1 + F1_width / 2.0},
"F2": F2,
"delta_F0": {"type": "unif", "lower": 0, "upper": 1e-5},
"delta_F1": 0,
"tglitch": {
"type": "unif",
"lower": tstart + 0.1 * duration,
"upper": tstart + 0.9 * duration,
},
"Alpha": Alpha,
"Delta": Delta,
}
ntemps = 3
log10beta_min = -0.5
......@@ -38,33 +46,49 @@ nwalkers = 100
nsteps = [250, 250]
mcmc = pyfstat.MCMCGlitchSearch(
label=label, sftfilepattern='data/*1_glitch*sft', theta_prior=theta_prior,
tref=tref, minStartTime=tstart, maxStartTime=tstart+duration,
nsteps=nsteps, nwalkers=nwalkers, ntemps=ntemps,
log10beta_min=log10beta_min, nglitch=1)
mcmc.transform_dictionary['F0'] = dict(
subtractor=F0, multiplier=1e6, symbol='$f-f_\mathrm{s}$')
mcmc.unit_dictionary['F0'] = '$\mu$Hz'
mcmc.transform_dictionary['F1'] = dict(
subtractor=F1, multiplier=1e12, symbol='$\dot{f}-\dot{f}_\mathrm{s}$')
mcmc.unit_dictionary['F1'] = '$p$Hz/s'
mcmc.transform_dictionary['delta_F0'] = dict(
multiplier=1e6, subtractor=delta_F0,
symbol='$\delta f-\delta f_\mathrm{s}$')
mcmc.unit_dictionary['delta_F0'] = '$\mu$Hz/s'
mcmc.transform_dictionary['tglitch']['subtractor'] = tstart + dtglitch
mcmc.transform_dictionary['tglitch']['label'] ='$t^\mathrm{g}-t^\mathrm{g}_\mathrm{s}$\n[d]'
label=label,
sftfilepattern="data/*1_glitch*sft",
theta_prior=theta_prior,
tref=tref,
minStartTime=tstart,
maxStartTime=tstart + duration,
nsteps=nsteps,
nwalkers=nwalkers,
ntemps=ntemps,
log10beta_min=log10beta_min,
nglitch=1,
)
mcmc.transform_dictionary["F0"] = dict(
subtractor=F0, multiplier=1e6, symbol="$f-f_\mathrm{s}$"
)
mcmc.unit_dictionary["F0"] = "$\mu$Hz"
mcmc.transform_dictionary["F1"] = dict(
subtractor=F1, multiplier=1e12, symbol="$\dot{f}-\dot{f}_\mathrm{s}$"
)
mcmc.unit_dictionary["F1"] = "$p$Hz/s"
mcmc.transform_dictionary["delta_F0"] = dict(
multiplier=1e6, subtractor=delta_F0, symbol="$\delta f-\delta f_\mathrm{s}$"
)
mcmc.unit_dictionary["delta_F0"] = "$\mu$Hz/s"
mcmc.transform_dictionary["tglitch"]["subtractor"] = tstart + dtglitch
mcmc.transform_dictionary["tglitch"][
"label"
] = "$t^\mathrm{g}-t^\mathrm{g}_\mathrm{s}$\n[d]"
t1 = time.time()
mcmc.run()
dT = time.time() - t1
fig_and_axes = gridcorner._get_fig_and_axes(4, 2, 0.05)
mcmc.plot_corner(label_offset=0.25, truths=[0, 0, 0, 0],
fig_and_axes=fig_and_axes, quantiles=(0.16, 0.84),
hist_kwargs=dict(lw=1.5, zorder=-1),
truth_color='C3')
mcmc.plot_corner(
label_offset=0.25,
truths=[0, 0, 0, 0],
fig_and_axes=fig_and_axes,
quantiles=(0.16, 0.84),
hist_kwargs=dict(lw=1.5, zorder=-1),
truth_color="C3",
)
mcmc.print_summary()
print(('Prior widths =', F0_width, F1_width))
print(("Prior widths =", F0_width, F1_width))
print(("Actual run time = {}".format(dT)))
import pyfstat
import numpy as np
import matplotlib.pyplot as plt
from make_simulated_data import tstart, duration, tref, F0, F1, F2, Alpha, Delta, delta_F0, outdir, dtglitch
from make_simulated_data import (
tstart,
duration,
tref,
F0,
F1,
F2,
Alpha,
Delta,
delta_F0,
outdir,
dtglitch,
)
import time
try:
......@@ -9,34 +21,46 @@ try:
except ImportError:
raise ImportError(
"Python module 'gridcorner' not found, please install from "
"https://gitlab.aei.uni-hannover.de/GregAshton/gridcorner")
"https://gitlab.aei.uni-hannover.de/GregAshton/gridcorner"
)