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

Initial commit of Directed MC study

parent 08265105
No related branches found
No related tags found
No related merge requests found
import pyfstat
import numpy as np
import os
# Properties of the GW data
sqrtSX = 2e-23
tstart = 1000000000
Tspan = 100*86400
tend = tstart + Tspan
# Fixed properties of the signal
F0_center = 30
F1_center = 1e-10
F2 = 0
Alpha = 5e-3
Delta = 6e-2
tref = .5*(tstart+tend)
data_label = 'temp_data_{}'.format(os.getpid())
results_file_name = 'MCResults.txt'
VF0 = VF1 = 100
DeltaF0 = VF0 * np.sqrt(3)/(np.pi*Tspan)
DeltaF1 = VF1 * np.sqrt(45/4.)/(np.pi*Tspan**2)
depths = np.linspace(100, 250, 13)
run_setup = [((10, 0), 16, False),
((10, 0), 5, False),
((10, 10), 1, False)]
for depth in depths:
h0 = sqrtSX / float(depth)
r = np.random.uniform(0, 1)
theta = np.random.uniform(0, 2*np.pi)
F0 = F0_center + 3*np.sqrt(r)*np.cos(theta)/(np.pi**2 * Tspan**2)
F1 = F1_center + 45*np.sqrt(r)*np.sin(theta)/(4*np.pi**2 * Tspan**4)
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='data', 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()
predicted_twoF = data.predict_fstat()
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 = 50
nsteps = [50, 50]
mcmc = pyfstat.MCMCFollowUpSearch(
label='temp', 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(run_setup=run_setup, create_plots=False, log_table=False,
gen_tex_table=False)
d, maxtwoF = mcmc.get_max_twoF()
dF0 = F0 - d['F0']
dF1 = F1 - d['F1']
with open(results_file_name, 'a') as f:
f.write('{} {:1.8e} {:1.8e} {:1.8e} {:1.8e} {:1.8e}\n'
.format(depth, h0, dF0, dF1, predicted_twoF, maxtwoF))
os.system('rm data/temp*')
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import scipy.stats
Tspan = 100 * 86400
def Recovery(Tspan, Depth, twoFstar=60):
rho2 = 4*Tspan/25./Depth**2
twoF_Hs = scipy.stats.distributions.ncx2(df=4, nc=rho2)
return 1 - twoF_Hs.cdf(twoFstar)
results_file_name = 'MCResults.txt'
df = pd.read_csv(
results_file_name, sep=' ', names=['depth', 'h0', 'dF0', 'dF1',
'twoF_predicted', 'twoF'])
twoFstar = 60
depths = np.unique(df.depth.values)
recovery_fraction = []
recovery_fraction_std = []
for d in depths:
twoFs = df[df.depth == d].twoF.values
print d, len(twoFs)
n = float(len(twoFs))
rf = np.sum(twoFs > twoFstar) / n
rf_bars = [np.sum(np.concatenate((twoFs[:i-1], twoFs[i:]))>twoFstar)/(n-1)
for i in range(int(n))]
var = (n-1)/n * np.sum([(rf_bar - rf)**2 for rf_bar in rf_bars])
recovery_fraction.append(rf)
recovery_fraction_std.append(np.sqrt(var))
fig, ax = plt.subplots()
ax.errorbar(depths, recovery_fraction, yerr=recovery_fraction_std)
#ax.plot(depths, recovery_fraction)
depths_smooth = np.linspace(min(depths), max(depths), 100)
recovery_analytic = [Recovery(Tspan, d) for d in depths_smooth]
ax.plot(depths_smooth, recovery_analytic)
ax.set_xlabel(r'Signal depth', size=16)
ax.set_ylabel('Recovered fraction [%]', size=12)
fig.savefig('directed_recovery.png')
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats
def Recovery(Tspan, Depth, twoFstar=60):
rho2 = 4*Tspan/25./Depth**2
twoF_Hs = scipy.stats.distributions.ncx2(df=4, nc=rho2)
return 1 - twoF_Hs.cdf(twoFstar)
N = 500
Tspan = np.linspace(0.1, 365*86400, N)
Depth = np.linspace(10, 300, N)
X, Y = np.meshgrid(Tspan, Depth)
X = X / 86400
Z = [[Recovery(t, d) for t in Tspan] for d in Depth]
fig, ax = plt.subplots()
pax = ax.pcolormesh(X, Y, Z, cmap=plt.cm.viridis)
CS = ax.contour(X, Y, Z, [0.95])
plt.clabel(CS, inline=1, fontsize=12, fmt='%s', manual=[(200, 180)])
plt.colorbar(pax, label='Recovery fraction')
ax.set_xlabel(r'$T_{\rm span}$ [days]', size=16)
ax.set_ylabel(r'Depth=$\frac{\sqrt{S_{\rm n}}}{h_0}$', size=14)
ax.set_xlim(min(Tspan)/86400., max(Tspan)/86400.)
ax.set_ylim(min(Depth), max(Depth))
fig.savefig('recovery.png')
for ((n=0;n<100;n++))
do
echo $n
python generate_data.py --quite --no-template-counting
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment