Skip to content
Snippets Groups Projects
Commit 274059a7 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Remove old paper directory

parent afbb9815
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 1066 deletions
import pyfstat
import numpy as np
import os
import sys
import time
ID = sys.argv[1]
outdir = sys.argv[2]
label = 'run_{}'.format(ID)
data_label = '{}_data'.format(label)
results_file_name = '{}/NoiseOnlyMCResults_{}.txt'.format(outdir, ID)
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
Tspan = 100*86400
tend = tstart + Tspan
# Fixed properties of the signal
F0_center = 30
F1_center = -1e-10
F2 = 0
Alpha = np.radians(83.6292)
Delta = np.radians(22.0144)
tref = .5*(tstart+tend)
VF0 = VF1 = 100
DeltaF0 = VF0 * np.sqrt(3)/(np.pi*Tspan)
DeltaF1 = VF1 * np.sqrt(45/4.)/(np.pi*Tspan**2)
nsteps = 25
run_setup = [((nsteps, 0), 20, False),
((nsteps, 0), 7, False),
((nsteps, 0), 2, False),
((nsteps, nsteps), 1, False)]
h0 = 0
F0 = F0_center + np.random.uniform(-0.5, 0.5)*DeltaF0
F1 = F1_center + np.random.uniform(-0.5, 0.5)*DeltaF1
psi = np.random.uniform(-np.pi/4, np.pi/4)
phi = np.random.uniform(0, 2*np.pi)
cosi = np.random.uniform(-1, 1)
data = pyfstat.Writer(
label=data_label, outdir=outdir, tref=tref,
tstart=tstart, F0=F0, F1=F1, F2=F2, duration=Tspan, Alpha=Alpha,
Delta=Delta, h0=h0, sqrtSX=sqrtSX, psi=psi, phi=phi, cosi=cosi,
detector='H1,L1')
data.make_data()
startTime = time.time()
theta_prior = {'F0': {'type': 'unif',
'lower': F0_center-DeltaF0,
'upper': F0_center+DeltaF0},
'F1': {'type': 'unif',
'lower': F1_center-DeltaF1,
'upper': F1_center+DeltaF1},
'F2': F2,
'Alpha': Alpha,
'Delta': Delta
}
ntemps = 2
log10temperature_min = -1
nwalkers = 100
mcmc = pyfstat.MCMCFollowUpSearch(
label=label, outdir=outdir,
sftfilepath='{}/*{}*sft'.format(outdir, data_label),
theta_prior=theta_prior,
tref=tref, minStartTime=tstart, maxStartTime=tend,
nwalkers=nwalkers, ntemps=ntemps,
log10temperature_min=log10temperature_min)
mcmc.run(run_setup=run_setup, create_plots=False, log_table=False,
gen_tex_table=False)
mcmc.print_summary()
d, maxtwoF = mcmc.get_max_twoF()
dF0 = F0 - d['F0']
dF1 = F1 - d['F1']
runTime = time.time() - startTime
with open(results_file_name, 'a') as f:
f.write('{:1.8e} {:1.8e} {:1.8e} {}\n'
.format(dF0, dF1, maxtwoF, runTime))
os.system('rm {}/*{}*'.format(outdir, label))
import pyfstat
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import os
from tqdm import tqdm
from oct2py import octave
import glob
from scipy.stats import rv_continuous, chi2
filenames = glob.glob("CollectedOutput/*.txt")
plt.style.use('paper')
Tspan = 100 * 86400
class maxtwoFinNoise_gen(rv_continuous):
def _pdf(self, twoF, Ntrials):
F = twoF/2.0
alpha = (1 + F)*np.exp(-F)
a = Ntrials/2.0*F*np.exp(-F)
b = (1 - alpha)**(Ntrials-1)
return a*b
df_list = []
for fn in filenames:
df = pd.read_csv(
fn, sep=' ', names=['dF0', 'dF1', 'twoF', 'runTime'])
df['CLUSTER_ID'] = fn.split('_')[1]
df_list.append(df)
df = pd.concat(df_list)
print 'Number of samples = ', len(df)
fig, ax = plt.subplots()
ax.hist(df.twoF, bins=50, histtype='step', color='k', normed=True, linewidth=1,
label='Monte-Carlo histogram')
maxtwoFinNoise = maxtwoFinNoise_gen(a=0)
Ntrials_effective, loc, scale = maxtwoFinNoise.fit(df.twoF.values, floc=0, fscale=1)
print 'Ntrials effective = {:1.2e}'.format(Ntrials_effective)
twoFsmooth = np.linspace(0, df.twoF.max(), 1000)
best_fit_pdf = maxtwoFinNoise.pdf(twoFsmooth, Ntrials_effective)
ax.plot(twoFsmooth, best_fit_pdf, '-r',
label=r'$p(2\mathcal{{F}}_{{\rm max}})$ for {} $N_{{\rm trials}}$'
.format(pyfstat.texify_float(Ntrials_effective, d=2)))
pval = 1e-6
twoFsmooth_HD = np.linspace(
twoFsmooth[np.argmax(best_fit_pdf)], df.twoF.max(), 100000)
best_fit_pdf_HD = maxtwoFinNoise.pdf(twoFsmooth_HD, Ntrials_effective)
spacing = twoFsmooth_HD[1]-twoFsmooth_HD[0]
print twoFsmooth_HD[np.argmin(np.abs(best_fit_pdf_HD - pval))], spacing
ax.set_xlabel('$\widetilde{2\mathcal{F}}$')
ax.set_xlim(0, 60)
ax.legend(frameon=False, fontsize=6)
fig.tight_layout()
fig.savefig('directed_noise_twoF_histogram.png')
from latex_macro_generator import write_to_macro
write_to_macro('DirectedMCNoiseOnlyMaximum', '{:1.1f}'.format(np.max(df.twoF)),
'../macros.tex')
write_to_macro('DirectedMCNoiseN', len(df), '../macros.tex')
Executable= DirectedMCNoiseOnly_repeat.sh
Arguments= $(Cluster)_$(Process)
Universe=vanilla
Input=/dev/null
accounting_group = ligo.dev.o2.cw.explore.test
Output=CollectedOutput/out.$(Cluster).$(Process)
Error=CollectedOutput/err.$(Cluster).$(Process)
Log=CollectedOutput/log.$(Cluster).$(Process)
request_cpus = 1
request_memory = 16 GB
Queue 1
frequency_grid_files = grided_frequency_search_1D.png
fully_coherent_files = fully_coherent_search_using_MCMC_walkers.png
follow_up_files = follow_up_run_setup.tex follow_up_walkers.png
transient_files = transient_search_initial_stage_twoFcumulative.png transient_search_corner.png
glitch_files = single_glitch_F0F1_grid_2D.png single_glitch_glitchSearch_corner.png
all_files = $(frequency_grid_files) $(fully_coherent_files) $(follow_up_files) $(transient_files) $(glitch_files)
copyfiles:
cd data; cp $(all_files) ../../
import pyfstat
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
F0 = 30.0
F1 = -1e-10
F2 = 0
Alpha = 1.0
Delta = 0.5
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
duration = 100*86400
tend = tstart+duration
tref = .5*(tstart+tend)
depth = 50
data_label = 'follow_up'
h0 = sqrtSX / depth
data = pyfstat.Writer(
label=data_label, outdir='data', 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)
# Search
VF0 = VF1 = 500
DeltaF0 = VF0 * np.sqrt(3)/(np.pi*duration)
DeltaF1 = VF1 * np.sqrt(45/4.)/(np.pi*duration**2)
DeltaAlpha = 1e-1
DeltaDelta = 1e-1
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': {'type': 'unif', 'lower': Alpha-DeltaAlpha,
'upper': Alpha+DeltaAlpha},
'Delta': {'type': 'unif', 'lower': Delta-DeltaDelta,
'upper': Delta+DeltaDelta},
}
ntemps = 3
log10temperature_min = -0.5
nwalkers = 100
scatter_val = 1e-10
nsteps = [200, 200]
mcmc = pyfstat.MCMCFollowUpSearch(
label='follow_up', outdir='data',
sftfilepath='data/*'+data_label+'*sft', theta_prior=theta_prior, tref=tref,
minStartTime=tstart, maxStartTime=tend, nwalkers=nwalkers, nsteps=nsteps,
ntemps=ntemps, log10temperature_min=log10temperature_min,
scatter_val=scatter_val)
fig, axes = plt.subplots(nrows=2, ncols=2)
fig, axes = mcmc.run(
R=10, Nsegs0=100, subtractions=[F0, F1, Alpha, Delta], labelpad=0.01,
fig=fig, axes=axes, plot_det_stat=False, return_fig=True)
axes[3].set_xlabel(r'$\textrm{Number of steps}$', labelpad=0.1)
for ax in axes:
ax.set_xlim(0, axes[0].get_xlim()[-1])
ax.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(5))
fig.tight_layout()
fig.savefig('{}/{}_walkers.png'.format(mcmc.outdir, mcmc.label), dpi=400)
mcmc.plot_corner(add_prior=True)
mcmc.print_summary()
import pyfstat
import numpy as np
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
duration = 100*86400
tend = tstart + duration
# Properties of the signal
F0 = 30.0
F1 = -1e-10
F2 = 0
Alpha = 5e-3
Delta = 6e-2
tref = .5*(tstart+tend)
depth = 10
h0 = sqrtSX / depth
data_label = 'fully_coherent_search_using_MCMC'
data = pyfstat.Writer(
label=data_label, outdir='data', 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)
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)
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
}
ntemps = 1
log10temperature_min = -1
nwalkers = 1000
nsteps = [50, 50]
mcmc = pyfstat.MCMCSearch(
label='fully_coherent_search_using_MCMC', outdir='data',
sftfilepath='data/*'+data_label+'-*sft', theta_prior=theta_prior, tref=tref,
minStartTime=tstart, maxStartTime=tend, nsteps=nsteps, nwalkers=nwalkers,
ntemps=ntemps, log10temperature_min=log10temperature_min)
mcmc.run(context='paper', subtractions=[30, -1e-10])
mcmc.plot_corner(add_prior=True)
mcmc.print_summary()
from latex_macro_generator import write_to_macro
write_to_macro('BasicExampleF0', '{:1.0f}'.format(F0), '../macros.tex')
write_to_macro('BasicExampleF1', F1, '../macros.tex')
write_to_macro('BasicExampleh0', h0, '../macros.tex')
write_to_macro('BasicExampleSqrtSn', sqrtSX, '../macros.tex')
write_to_macro('BasicExampleDepth', depth, '../macros.tex')
write_to_macro('BasicExampleDeltaF0', DeltaF0, '../macros.tex')
write_to_macro('BasicExampleDeltaF1', DeltaF1, '../macros.tex')
write_to_macro('BasicExampleVF0', VF0, '../macros.tex')
write_to_macro('BasicExampleVF1', VF1, '../macros.tex')
write_to_macro('BasicExampleV', VF0*VF1, '../macros.tex')
write_to_macro('BasicExamplenburn', nsteps[0], '../macros.tex')
write_to_macro('BasicExamplenprod', nsteps[1], '../macros.tex')
import pyfstat
import numpy as np
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
duration = 100*86400
tend = tstart + duration
# Properties of the signal
F0 = 30.0
F1 = -1e-10
F2 = 0
Alpha = 5e-3
Delta = 6e-2
tref = .5*(tstart+tend)
depth = 10
h0 = sqrtSX / depth
data_label = 'fully_coherent_search_using_MCMC_convergence'
data = pyfstat.Writer(
label=data_label, outdir='data', 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)
DeltaF0 = 5e-7
DeltaF1 = 1e-12
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)
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
}
ntemps = 1
log10temperature_min = -1
nwalkers = 100
nsteps = [900, 100]
mcmc = pyfstat.MCMCSearch(
label='fully_coherent_search_using_MCMC_convergence', outdir='data',
sftfilepath='data/*'+data_label+'*sft', theta_prior=theta_prior, tref=tref,
minStartTime=tstart, maxStartTime=tend, nsteps=nsteps, nwalkers=nwalkers,
ntemps=ntemps, log10temperature_min=log10temperature_min)
mcmc.setup_convergence_testing(
convergence_threshold_number=5, convergence_plot_upper_lim=10,
convergence_burnin_fraction=0.1)
mcmc.run(context='paper', subtractions=[30, -1e-10])
mcmc.plot_corner(add_prior=True)
mcmc.print_summary()
import pyfstat
import numpy as np
import matplotlib.pyplot as plt
from latex_macro_generator import write_to_macro
plt.style.use('paper')
F0 = 100.0
F1 = 0
F2 = 0
Alpha = 5.98
Delta = -0.1
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
duration = 30 * 60 * 60
tend = tstart+duration
tref = .5*(tstart+tend)
psi = 2.25
phi = 0.2
cosi = 0.5
depth = 2
data_label = 'grided_frequency_depth_{:1.0f}'.format(depth)
h0 = sqrtSX / depth
data = pyfstat.Writer(
label=data_label, outdir='data', tref=tref,
tstart=tstart, F0=F0, F1=F1, F2=F2, duration=duration, Alpha=Alpha,
Delta=Delta, h0=h0, sqrtSX=sqrtSX, detectors='H1', cosi=cosi, phi=phi,
psi=psi)
data.make_data()
DeltaF0 = 1.5e-4
F0s = [F0-DeltaF0/2., F0+DeltaF0/2., DeltaF0/2000]
F1s = [F1]
F2s = [F2]
Alphas = [Alpha]
Deltas = [Delta]
search = pyfstat.GridSearch(
'grided_frequency_search', 'data', 'data/*'+data_label+'-*.sft', F0s, F1s,
F2s, Alphas, Deltas, tref, tstart, tend)
search.run()
fig, ax = plt.subplots()
xidx = search.keys.index('F0')
frequencies = np.unique(search.data[:, xidx])
twoF = search.data[:, -1]
#mismatch = np.sign(x-F0)*(duration * np.pi * (x - F0))**2 / 12.0
ax.plot(frequencies-F0, twoF, 'k', lw=0.5)
DeltaF = frequencies - F0
ax.set_ylabel('$\widetilde{2\mathcal{F}}$')
ax.set_xlabel('Template frequency')
dF0 = np.sqrt(12*1)/(np.pi*duration)
xticks = [-4/86400., -3/86400., -2/86400., -86400, 0,
1/86400., 2/86400., 3/86400., 4/86400.]
#ax.set_xticks(xticks)
#xticklabels = [r'$f_0 {-} \frac{4}{1\textrm{-day}}$', '$f_0$',
# r'$f_0 {+} \frac{4}{1\textrm{-day}}$']
#ax.set_xticklabels(xticklabels)
ax.grid(linewidth=0.1)
plt.tight_layout()
fig.savefig('{}/{}_1D.png'.format(search.outdir, search.label), dpi=300)
write_to_macro('GridedFrequencySqrtSx', '{}'.format(
pyfstat.helper_functions.texify_float(sqrtSX)),
'../macros.tex')
write_to_macro('GridedFrequencyh0', '{}'.format(
pyfstat.helper_functions.texify_float(h0)),
'../macros.tex')
write_to_macro('GridedFrequencyT', '{}'.format(int(duration/86400)),
'../macros.tex')
figure.figsize: 3.4, 2.5
figure.facecolor: w
axes.labelsize: 6
axes.titlesize: 6
xtick.labelsize: 4
ytick.labelsize: 4
legend.fontsize: 6
font.size: 6
grid.linewidth: 0.8
lines.linewidth: 1.0
patch.linewidth: 0.24
lines.markersize: 3.6
lines.markeredgewidth: 0
xtick.major.size: 2.0
ytick.major.size: 2.0
xtick.minor.size: 1.5
xtick.minor.visible: True
ytick.minor.size: 1.5
ytick.minor.visible: True
xtick.major.pad: 2.5
ytick.major.pad: 2.5
pdf.compression: 9
savefig.format: png
savefig.dpi: 300
font.family: serif
font.serif: Computer Modern
text.usetex: True
axes.formatter.use_mathtext: True
axes.formatter.useoffset: False
axes.formatter.limits : -3, 4
import pyfstat
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
sqrtSX = 1e-22
tstart = 1000000000
duration = 100*86400
tend = tstart+duration
# Define parameters of the Crab pulsar as an example
tref = .5*(tstart + tend)
F0 = 30.0
F1 = -1e-10
F2 = 0
Alpha = np.radians(83.6292)
Delta = np.radians(22.0144)
# Signal strength
depth = 10
h0 = sqrtSX / depth
VF0 = VF1 = 200
dF0 = np.sqrt(3)/(np.pi*duration)
dF1 = np.sqrt(45/4.)/(np.pi*duration**2)
DeltaF0 = VF0 * dF0
DeltaF1 = VF1 * dF1
# Next, taking the same signal parameters, we include a glitch half way through
R = 0.5
dtglitch = R*duration
delta_F0 = 0.25*DeltaF0
delta_F1 = -0.1*DeltaF1
glitch_data = pyfstat.Writer(
label='single_glitch', outdir='data', 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()
FCtwoFPM = glitch_data.predict_fstat()
F0s = [F0-DeltaF0/2., F0+DeltaF0/2., 1*dF0]
F1s = [F1-DeltaF1/2., F1+DeltaF1/2., 1*dF1]
F2s = [F2]
Alphas = [Alpha]
Deltas = [Delta]
search = pyfstat.GridSearch(
'single_glitch_F0F1_grid', 'data', 'data/*single_glitch*sft', F0s, F1s,
F2s, Alphas, Deltas, tref, tstart, tend)
search.run()
ax = search.plot_2D('F0', 'F1', save=False)
ax.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(6))
plt.tight_layout()
plt.savefig('data/single_glitch_F0F1_grid_2D.png', dpi=500)
FCtwoF = search.get_max_twoF()['twoF']
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.,
'upper': F0+DeltaF0/2},
'F1': {'type': 'unif', 'lower': F1-DeltaF1/2.,
'upper': F1+DeltaF1/2},
'F2': F2,
'Alpha': Alpha,
'Delta': Delta,
'tglitch': {'type': 'unif', 'lower': tstart+0.1*duration,
'upper': tend-0.1*duration},
'delta_F0': {'type': 'halfnorm', 'loc': 0, 'scale': 1e-7*F0},
'delta_F1': {'type': 'norm', 'loc': 0, 'scale': abs(1e-3*F1)},
}
ntemps = 3
log10temperature_min = -0.1
nwalkers = 100
nsteps = [1000, 1000]
glitch_mcmc = pyfstat.MCMCGlitchSearch(
'single_glitch_glitchSearch', 'data',
sftfilepath='data/*_single_glitch*.sft', theta_prior=theta_prior,
tref=tref, minStartTime=tstart, maxStartTime=tend, nsteps=nsteps,
nwalkers=nwalkers, ntemps=ntemps,
log10temperature_min=log10temperature_min)
glitch_mcmc.write_prior_table()
glitch_mcmc.run()
glitch_mcmc.plot_corner(figsize=(6, 6))
glitch_mcmc.print_summary()
GlitchtwoF = glitch_mcmc.get_max_twoF()[1]
from latex_macro_generator import write_to_macro
write_to_macro('SingleGlitchTspan', '{:1.1f}'.format(duration/86400),
'../macros.tex')
write_to_macro('SingleGlitchR', '{:1.1f}'.format(R), '../macros.tex')
write_to_macro('SingleGlitchDepth',
'{}'.format(pyfstat.texify_float(sqrtSX/h0)), '../macros.tex')
write_to_macro('SingleGlitchF0', '{}'.format(F0), '../macros.tex')
write_to_macro('SingleGlitchF1', '{}'.format(F1), '../macros.tex')
write_to_macro('SingleGlitchdeltaF0',
'{}'.format(pyfstat.texify_float(delta_F0)), '../macros.tex')
write_to_macro('SingleGlitchdeltaF1',
'{}'.format(pyfstat.texify_float(delta_F1)), '../macros.tex')
write_to_macro('SingleGlitchFCtwoFPM', '{:1.1f}'.format(FCtwoFPM),
'../macros.tex')
write_to_macro('SingleGlitchFCtwoF', '{:1.1f}'.format(FCtwoF),
'../macros.tex')
write_to_macro('SingleGlitch_FCMismatch',
'{:1.1f}'.format((FCtwoFPM-FCtwoF)/FCtwoFPM), '../macros.tex')
write_to_macro('SingleGlitchGlitchtwoF', '{:1.1f}'.format(GlitchtwoF),
'../macros.tex')
import pyfstat
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('thesis')
F0 = 30.0
F1 = -1e-10
F2 = 0
Alpha = 5e-3
Delta = 6e-2
tstart = 1000000000
duration = 100*86400
data_tstart = tstart - duration
data_tend = data_tstart + 3*duration
tref = .5*(data_tstart+data_tend)
h0 = 4e-24
sqrtSX = 1e-22
transient = pyfstat.Writer(
label='transient', outdir='data', tref=tref, tstart=tstart, F0=F0, F1=F1,
F2=F2, duration=duration, Alpha=Alpha, Delta=Delta, h0=h0, sqrtSX=sqrtSX,
minStartTime=data_tstart, maxStartTime=data_tend)
transient.make_data()
print transient.predict_fstat()
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)
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
}
ntemps = 3
log10temperature_min = -1
nwalkers = 100
nsteps = [100, 100]
mcmc = pyfstat.MCMCSearch(
label='transient_search_initial_stage', outdir='data',
sftfilepath='data/*transient*sft', theta_prior=theta_prior, tref=tref,
minStartTime=data_tstart, maxStartTime=data_tend, nsteps=nsteps,
nwalkers=nwalkers, ntemps=ntemps,
log10temperature_min=log10temperature_min)
mcmc.run()
fig, ax = plt.subplots()
mcmc.write_par()
mcmc.generate_loudest()
mcmc.plot_cumulative_max(ax=ax)
ax.set_xlabel('Days from $t_\mathrm{start}$')
ax.legend_.remove()
fig.savefig('data/transient_search_initial_stage_twoFcumulative')
mcmc.print_summary()
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,
'transient_tstart': {'type': 'unif',
'lower': data_tstart,
'upper': data_tend-0.2*duration},
'transient_duration': {'type': 'halfnorm',
'loc': 0.01*duration,
'scale': 0.5*duration}
}
nwalkers = 500
nsteps = [200, 200]
mcmc = pyfstat.MCMCTransientSearch(
label='transient_search', outdir='data',
sftfilepath='data/*transient*sft', theta_prior=theta_prior, tref=tref,
minStartTime=data_tstart, maxStartTime=data_tend, nsteps=nsteps,
nwalkers=nwalkers, ntemps=ntemps,
log10temperature_min=log10temperature_min)
mcmc.run()
mcmc.plot_corner()
mcmc.print_summary()
#!/bin/bash
. /home/gregory.ashton/lalsuite-install/etc/lalapps-user-env.sh
export PATH="/home/gregory.ashton/anaconda2/bin:$PATH"
export MPLCONFIGDIR=/home/gregory.ashton/.config/matplotlib
for ((n=0;n<5;n++))
do
/home/gregory.ashton/anaconda2/bin/python generate_data.py "$1" /local/user/gregory.ashton --no-interactive
done
cp /local/user/gregory.ashton/NoiseOnlyMCResults_"$1".txt $(pwd)/CollectedOutput
import pyfstat
import numpy as np
import os
import sys
import time
nglitch = 2
ID = sys.argv[1]
outdir = sys.argv[2]
label = 'run_{}'.format(ID)
data_label = '{}_data'.format(label)
results_file_name = '{}/NoiseOnlyMCResults_{}.txt'.format(outdir, ID)
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
Tspan = 100*86400
tend = tstart + Tspan
# Fixed properties of the signal
F0_center = 30
F1_center = -1e-10
F2 = 0
Alpha = np.radians(83.6292)
Delta = np.radians(22.0144)
tref = .5*(tstart+tend)
VF0 = VF1 = 200
dF0 = np.sqrt(3)/(np.pi*Tspan)
dF1 = np.sqrt(45/4.)/(np.pi*Tspan**2)
DeltaF0 = VF0 * dF0
DeltaF1 = VF1 * dF1
nsteps = 25
run_setup = [((nsteps, 0), 20, False),
((nsteps, 0), 7, False),
((nsteps, 0), 2, False),
((nsteps, nsteps), 1, False)]
h0 = 0
F0 = F0_center + np.random.uniform(-0.5, 0.5)*DeltaF0
F1 = F1_center + np.random.uniform(-0.5, 0.5)*DeltaF1
psi = np.random.uniform(-np.pi/4, np.pi/4)
phi = np.random.uniform(0, 2*np.pi)
cosi = np.random.uniform(-1, 1)
# Next, taking the same signal parameters, we include a glitch half way through
dtglitch = Tspan/2.0
delta_F0 = 0.25*DeltaF0
delta_F1 = -0.1*DeltaF1
glitch_data = pyfstat.Writer(
label=data_label, outdir=outdir, tref=tref, tstart=tstart, F0=F0,
F1=F1, F2=F2, duration=Tspan, Alpha=Alpha, Delta=Delta, h0=h0,
sqrtSX=sqrtSX, dtglitch=dtglitch, delta_F0=delta_F0, delta_F1=delta_F1)
glitch_data.make_data()
startTime = time.time()
theta_prior = {'F0': {'type': 'unif', 'lower': F0-DeltaF0/2., # PROBLEM
'upper': F0+DeltaF0/2},
'F1': {'type': 'unif', 'lower': F1-DeltaF1/2.,
'upper': F1+DeltaF1/2},
'F2': F2,
'Alpha': Alpha,
'Delta': Delta,
'tglitch': {'type': 'unif', 'lower': tstart+0.1*Tspan,
'upper': tend-0.1*Tspan},
'delta_F0': {'type': 'halfnorm', 'loc': 0, 'scale': DeltaF0},
'delta_F1': {'type': 'norm', 'loc': 0, 'scale': DeltaF1},
}
ntemps = 2
log10temperature_min = -0.1
nwalkers = 100
nsteps = [500, 500]
glitch_mcmc = pyfstat.MCMCGlitchSearch(
label=label, outdir=outdir,
sftfilepath='{}/*{}*sft'.format(outdir, data_label),
theta_prior=theta_prior,
tref=tref, minStartTime=tstart, maxStartTime=tend, nsteps=nsteps,
nwalkers=nwalkers, ntemps=ntemps, nglitch=nglitch,
log10temperature_min=log10temperature_min)
glitch_mcmc.run(run_setup=run_setup, create_plots=False, log_table=False,
gen_tex_table=False)
glitch_mcmc.print_summary()
d, maxtwoF = glitch_mcmc.get_max_twoF()
dF0 = F0 - d['F0']
dF1 = F1 - d['F1']
#tglitch = d['tglitch']
#R = (tglitch - tstart) / Tspan
#delta_F0 = d['delta_F0']
#delta_F1 = d['delta_F1']
runTime = time.time() - startTime
with open(results_file_name, 'a') as f:
f.write('{} {:1.8e} {:1.8e} {:1.8e} {:1.1f}\n'
.format(nglitch, dF0, dF1, maxtwoF, runTime))
os.system('rm {}/*{}*'.format(outdir, label))
import pyfstat
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import os
from tqdm import tqdm
from oct2py import octave
import glob
from scipy.stats import rv_continuous, chi2
from scipy.special import gammaincc
from latex_macro_generator import write_to_macro
def CF_twoFmax_integrand(theta, twoFmax, Nt):
Fmax = twoFmax/2.0
return np.exp(1j*theta*twoFmax)*Nt/2.0*Fmax*np.exp(-Fmax)*(1-(1+Fmax)*np.exp(-Fmax))**(Nt-1.)
def pdf_twoFhat(twoFhat, Ng, Nts, twoFtildemax=100, dtwoF=0.05):
if np.ndim(Nts) == 0:
Nts = np.zeros(Ng+1) + Nts
twoFtildemax_int = np.arange(0, twoFtildemax, dtwoF)
theta_int = np.arange(-1./dtwoF, 1./dtwoF, 1./twoFtildemax)
CF_twoFtildemax_theta = np.array(
[[np.trapz(CF_twoFmax_integrand(t, twoFtildemax_int, Nt), twoFtildemax_int)
for t in theta_int]
for Nt in Nts])
CF_twoFhat_theta = np.prod(CF_twoFtildemax_theta, axis=0)
print CF_twoFhat_theta.shape, theta_int.shape
pdf = (1/(2*np.pi)) * np.array(
[np.trapz(np.exp(-1j*theta_int*twoFhat_val)*CF_twoFhat_theta,
theta_int) for twoFhat_val in twoFhat])
print np.trapz(pdf.real, x=twoFhat)
return pdf
filenames = glob.glob("CollectedOutput/*.txt")
plt.style.use('paper')
Tspan = 100 * 86400
df_list = []
for fn in filenames:
df = pd.read_csv(
fn, sep=' ', names=['nglitches', 'dF0', 'dF1', 'twoF', 'runTime'])
df['CLUSTER_ID'] = fn.split('_')[1]
df_list.append(df)
df = pd.concat(df_list)
colors = ['C0', 'C1']
fig, ax = plt.subplots()
handles = []
labels = []
for ng, c in zip(np.unique(df.nglitches.values), colors):
print 'ng={}'.format(ng)
df_temp = df[df.nglitches == ng]
#df_temp = df_temp[[str(x).isalpha() for x in df_temp.CLUSTER_ID.values]]
print df_temp.tail()
Nsamples = len(df_temp)
MaxtwoF = df_temp.twoF.max()
print 'Number of samples = ', Nsamples
print 'Max twoF', MaxtwoF
print np.any(np.isnan(df_temp.twoF.values))
ax.hist(df_temp.twoF, bins=40, histtype='stepfilled',
normed=True, align='mid', alpha=0.5,
linewidth=1, label='$N_\mathrm{{glitches}}={}$'.format(ng),
color=c)
write_to_macro('DirectedMC{}GlitchNoiseOnlyMaximum'.format(ng),
'{:1.1f}'.format(MaxtwoF), '../macros.tex')
write_to_macro('DirectedMC{}GlitchNoiseN'.format(ng),
'{:1.0f}'.format(Nsamples), '../macros.tex')
twoFmax = np.linspace(0, 100, 200)
ax.plot(twoFmax, pdf_twoFhat(twoFmax, ng, Nsamples,
twoFtildemax=2*MaxtwoF, dtwoF=0.1),
color=c, label='$N_\mathrm{{glitches}}={}$ predicted'.format(ng))
ax.set_xlabel('$\widehat{2\mathcal{F}}$')
ax.set_xlim(0, 90)
handles, labels = ax.get_legend_handles_labels()
idxs = np.argsort(labels)
ax.legend(np.array(handles)[idxs], np.array(labels)[idxs], frameon=False,
fontsize=6)
fig.tight_layout()
fig.savefig('glitch_noise_twoF_histogram.png')
Executable= SingleGlitchMCNoiseOnly.sh
Arguments= $(Cluster)_$(Process)
Universe=vanilla
Input=/dev/null
accounting_group=ligo.dev.o1.cw.directedisolatedother.semicoherent
Output=CollectedOutput/out.$(Cluster).$(Process)
Error=CollectedOutput/err.$(Cluster).$(Process)
Log=CollectedOutput/log.$(Cluster).$(Process)
request_cpus = 1
request_memory = 16 GB
Queue 1806
SHELL = /bin/bash
main = paper_cw_mcmc.pdf
.PHONY : main clean figclean arxiv jones
main : $(main)
git_tag.tex :
./git-tag.sh $@
$(main): *.tex git_tag.tex
pdflatex ${@:.pdf=} && bibtex ${@:.pdf=} && pdflatex ${@:.pdf=} && pdflatex ${@:.pdf=}
clean :
rm -f git_tag.tex $(main:.pdf=){.aux,.bbl,.blg,.log,.out,.pdf,Notes.bib} $(texfigs) $(texonlyfigs)
arxiv :
rm -f $(main)
rm -f git_tag.tex
tar -cvf arxiv_submission.tar *tex *bib bibliography.bib *pdf *.bbl
- Add macros for the directed MC results
- Add macros for the all-sky MC results
- Adds macros for the examples values
- Investigate cause of all-sky losses again
- Run the transient search for a weaker signal
- Add results from Messenger et al for the transient - is there a fit?
- Weaken basyes factor definitions since they are not used, just put it in the context
Paper/VolumeConvergenceInvestigation.png

121 KiB

#!/bin/bash
. /home/gregory.ashton/lalsuite-install/etc/lalapps-user-env.sh
export PATH="/home/gregory.ashton/anaconda2/bin:$PATH"
export MPLCONFIGDIR=/home/gregory.ashton/.config/matplotlib
for ((n=0;n<1;n++))
do
/home/gregory.ashton/anaconda2/bin/python generate_data.py "$1" /local/user/gregory.ashton --no-template-counting --no-interactive
done
mv /local/user/gregory.ashton/VolumeConvergenceResults_"$1".txt $(pwd)/CollectedOutput
import pyfstat
import numpy as np
import os
import sys
import time
ID = sys.argv[1]
outdir = sys.argv[2]
label = 'VCrun_{}'.format(ID)
data_label = 'VCrunData_{}_'.format(ID)
results_file_name = '{}/VolumeConvergenceResults_{}.txt'.format(outdir, ID)
# Properties of the GW data
sqrtSX = 1e-23
tstart = 1000000000
Tspan = 100*86400
tend = tstart + Tspan
# Fixed properties of the signal
F0 = 30
F1 = -1e-10
F2 = 0
Alpha = np.radians(83.6292)
Delta = np.radians(22.0144)
tref = .5*(tstart+tend)
depth = 100
h0 = sqrtSX / float(depth)
psi = np.random.uniform(-np.pi/4, np.pi/4)
phi = np.random.uniform(0, 2*np.pi)
cosi = np.random.uniform(-1, 1)
data = pyfstat.Writer(
label=data_label, outdir=outdir, tref=tref,
tstart=tstart, F0=F0, F1=F1, F2=F2, duration=Tspan, Alpha=Alpha,
Delta=Delta, h0=h0, sqrtSX=sqrtSX, psi=psi, phi=phi, cosi=cosi,
detectors='L1')
data.make_data()
twoF_PM = data.predict_fstat()
nsteps = [500, 500]
Vs = np.arange(50, 550, 50)
Vs = [50, 150, 200, 250, 350, 400, 450]
for V in Vs:
DeltaF0 = V * np.sqrt(3)/(np.pi*Tspan)
DeltaF1 = V * np.sqrt(45/4.)/(np.pi*Tspan**2)
startTime = time.time()
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 = 3
log10temperature_min = -0.5
nwalkers = 100
mcmc = pyfstat.MCMCSearch(
label=label, outdir=outdir, nsteps=nsteps,
sftfilepath='{}/*{}*sft'.format(outdir, data_label),
theta_prior=theta_prior,
tref=tref, minStartTime=tstart, maxStartTime=tend,
nwalkers=nwalkers, ntemps=ntemps,
log10temperature_min=log10temperature_min)
mcmc.setup_convergence_testing(
convergence_period=10, convergence_length=10,
convergence_burnin_fraction=0.1, convergence_threshold_number=5,
convergence_threshold=1.1, convergence_early_stopping=False)
mcmc.run(create_plots=False,
log_table=False, gen_tex_table=False
)
mcmc.print_summary()
cdF0, cdF1 = mcmc.convergence_diagnostic[-1]
d, maxtwoF = mcmc.get_max_twoF()
d_med_std = mcmc.get_median_stds()
dF0 = F0 - d['F0']
dF1 = F1 - d['F1']
F0_std = d_med_std['F0_std']
F1_std = d_med_std['F1_std']
runTime = time.time() - startTime
with open(results_file_name, 'a') as f:
f.write('{} {:1.8e} {:1.8e} {:1.8e} {:1.8e} {:1.8e} {:1.8e} {:1.8e} {:1.8e} {:1.5e} {:1.5e} {}\n'
.format(V, dF0, dF1, F0_std, F1_std, DeltaF0, DeltaF1, maxtwoF, twoF_PM, cdF0, cdF1,
runTime))
os.system('rm {}/*{}*'.format(outdir, label))
os.system('rm {}/*{}*'.format(outdir, data_label))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment