generate_data.py 3.14 KB
Newer Older
1
2
3
4
import pyfstat
import numpy as np
import os
import sys
5
import time
6
7
8
9
10
11
12
13
14

ID = sys.argv[1]
outdir = sys.argv[2]

label = 'run_{}'.format(ID)
data_label = '{}_data'.format(label)
results_file_name = '{}/MCResults_{}.txt'.format(outdir, ID)

# Properties of the GW data
Gregory Ashton's avatar
Gregory Ashton committed
15
sqrtSX = 1e-23
16
17
18
19
20
21
tstart = 1000000000
Tspan = 100*86400
tend = tstart + Tspan

# Fixed properties of the signal
F0_center = 30
Gregory Ashton's avatar
Gregory Ashton committed
22
F1_center = -1e-10
23
24
25
26
27
28
29
30
F2 = 0
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)

31
32
33
DeltaAlpha = 0.02
DeltaDelta = 0.02

Gregory Ashton's avatar
Gregory Ashton committed
34
depths = np.linspace(100, 400, 9)
35

36
37
38
39
40
41
nsteps = 50
run_setup = [((nsteps, 0), 20, False),
             ((nsteps, 0), 11, False),
             ((nsteps, 0), 6, False),
             ((nsteps, 0), 3, False),
             ((nsteps, nsteps), 1, False)]
42
43
44
45


for depth in depths:
    h0 = sqrtSX / float(depth)
46
47
    F0 = F0_center + np.random.uniform(-0.5, 0.5)*DeltaF0
    F1 = F1_center + np.random.uniform(-0.5, 0.5)*DeltaF1
Gregory Ashton's avatar
Gregory Ashton committed
48
    Alpha_center = np.random.uniform(DeltaAlpha, 2*np.pi-DeltaAlpha)
49
50
51
    Delta_center = np.arccos(2*np.random.uniform(0, 1)-1)-np.pi/2
    Alpha = Alpha_center + np.random.uniform(-0.5, 0.5)*DeltaAlpha
    Delta = Delta_center + np.random.uniform(-0.5, 0.5)*DeltaDelta
52
53
54
55
56
57
58
59
60
61
62
    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()

63
    startTime = time.time()
64
    theta_prior = {'F0': {'type': 'unif',
65
66
                          'lower': F0_center-DeltaF0,
                          'upper': F0_center+DeltaF0},
67
                   'F1': {'type': 'unif',
68
69
                          'lower': F1_center-DeltaF1,
                          'upper': F1_center+DeltaF1},
70
71
                   'F2': F2,
                   'Alpha': {'type': 'unif',
72
73
                             'lower': Alpha_center-DeltaAlpha,
                             'upper': Alpha_center+DeltaAlpha},
74
                   'Delta': {'type': 'unif',
75
76
                             'lower': Delta_center-DeltaDelta,
                             'upper': Delta_center+DeltaDelta},
77
78
                   }

79
    ntemps = 2
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    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)
    d, maxtwoF = mcmc.get_max_twoF()
    dF0 = F0 - d['F0']
    dF1 = F1 - d['F1']
95
    runTime = time.time() - startTime
96
    with open(results_file_name, 'a') as f:
Gregory Ashton's avatar
Gregory Ashton committed
97
98
        f.write('{} {:1.8e} {:1.8e} {:1.8e} {:1.8e} {}\n'
                .format(depth, h0, dF0, dF1, maxtwoF, runTime))
99
    os.system('rm {}/*{}*'.format(outdir, label))