plot_data.py 2.69 KB
Newer Older
1
2
3
4
5
6
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import os
from tqdm import tqdm
from oct2py import octave
7
8
9
import glob

filenames = glob.glob("CollectedOutput/*.txt")
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

plt.style.use('paper')

Tspan = 100 * 86400


def Recovery(Tspan, Depth, twoFstar=60, detectors='H1,L1'):
    numDetectors = len(detectors.split(','))
    cmd = ("DetectionProbabilityStackSlide('Nseg', 1, 'Tdata', {},"
           "'misHist', createDeltaHist(0), 'avg2Fth', {}, 'detectors', '{}',"
           "'Depth', {})"
           ).format(numDetectors*Tspan, twoFstar, detectors, Depth)
    return octave.eval(cmd, verbose=False)


def binomialConfidenceInterval(N, K, confidence=0.95):
    cmd = '[fLow, fUpper] = binomialConfidenceInterval({}, {}, {})'.format(
        N, K, confidence)
    [l, u] =  octave.eval(cmd, verbose=False, return_both=True)[0].split('\n')
    return float(l.split('=')[1]), float(u.split('=')[1])

31
32
33
df_list = []
for fn in filenames:
    df = pd.read_csv(
Gregory Ashton's avatar
Gregory Ashton committed
34
        fn, sep=' ', names=['depth', 'h0', 'dF0', 'dF1', 'twoF', 'runTime'])
35
36
37
    df['CLUSTER_ID'] = fn.split('_')[1]
    df_list.append(df)
df = pd.concat(df_list)
38

39
twoFstar = 70
40
41
42
43
44
45
46
47
48
49
50
51
52
53
depths = np.unique(df.depth.values)
recovery_fraction = []
recovery_fraction_CI = []
for d in depths:
    twoFs = df[df.depth == d].twoF.values
    N = len(twoFs)
    K = np.sum(twoFs > twoFstar)
    print d, N, K
    recovery_fraction.append(K/float(N))
    [fLower, fUpper] = binomialConfidenceInterval(N, K)
    recovery_fraction_CI.append([fLower, fUpper])

yerr = np.abs(recovery_fraction - np.array(recovery_fraction_CI).T)
fig, ax = plt.subplots()
Gregory Ashton's avatar
Gregory Ashton committed
54
ax.errorbar(depths, recovery_fraction, yerr=yerr, fmt='sr', marker='s', ms=2,
55
            capsize=1, capthick=0.5, elinewidth=0.5,
Gregory Ashton's avatar
Gregory Ashton committed
56
            label='Monte-Carlo result', zorder=10)
57

58
fname = 'analytic_data_{}.txt'.format(twoFstar)
59
60
61
62
63
64
65
66
67
68
69
70
71
72
if os.path.isfile(fname):
    depths_smooth, recovery_analytic = np.loadtxt(fname)
else:
    depths_smooth = np.linspace(10, 550, 100)
    recovery_analytic = []
    for d in tqdm(depths_smooth):
        recovery_analytic.append(Recovery(Tspan, d, twoFstar))
    np.savetxt(fname, np.array([depths_smooth, recovery_analytic]))
depths_smooth = np.concatenate(([0], depths_smooth))
recovery_analytic = np.concatenate(([1], recovery_analytic))
ax.plot(depths_smooth, recovery_analytic, '-k', label='Theoretical maximum')


ax.set_ylim(0, 1.05)
73
ax.set_xlabel(r'Sensitivity depth', size=10)
74
75
76
77
78
ax.set_ylabel(r'Recovered fraction', size=10)
ax.legend(loc=1, frameon=False)

fig.tight_layout()
fig.savefig('allsky_recovery.png')
79
80


Gregory Ashton's avatar
Gregory Ashton committed
81
total_number_steps = 6 * 50.
82
fig, ax = plt.subplots()
Gregory Ashton's avatar
Gregory Ashton committed
83
84
85
ax.hist(df.runTime/total_number_steps, bins=50)
ax.set_xlabel('run-time per step [s]')
fig.tight_layout()
86
87
fig.savefig('runTimeHist.png')