Note
Click here to download the full example code
Software injection into pre-existing data files
Add a software injection into a set of SFTs.
In this case, the set of SFTs is generated using Makefakedata_v5, but the same procedure can be applied to any other set of SFTs (including real detector data).
12 import os
13
14 import numpy as np
15
16 import pyfstat
17
18 label = "PyFstat_example_injection_into_noise_sfts"
19 outdir = os.path.join("PyFstat_example_data", label)
20
21 tstart = 1269734418
22 duration_Tsft = 100
23 Tsft = 1800
24 randSeed = 69420
25 IFO = "H1"
26 h0 = 1000
27 cosi = 0
28 F0 = 30
29 Alpha = 0
30 Delta = 0
31
32 Band = 2.0
33
34 # create sfts with a strong signal in them
35 # window options are optional here
36 noise_and_signal_writer = pyfstat.Writer(
37 label="test_noiseSFTs_noise_and_signal",
38 outdir=outdir,
39 h0=h0,
40 cosi=cosi,
41 F0=F0,
42 Alpha=Alpha,
43 Delta=Delta,
44 tstart=tstart,
45 duration=duration_Tsft * Tsft,
46 Tsft=Tsft,
47 Band=Band,
48 detectors=IFO,
49 randSeed=randSeed,
50 SFTWindowType="tukey",
51 SFTWindowBeta=0.001,
52 )
53 sftfilepattern = os.path.join(
54 noise_and_signal_writer.outdir,
55 "*{}*{}*sft".format(duration_Tsft, noise_and_signal_writer.label),
56 )
57
58 noise_and_signal_writer.make_data()
59
60 # compute Fstat
61 coherent_search = pyfstat.ComputeFstat(
62 tref=noise_and_signal_writer.tref,
63 sftfilepattern=sftfilepattern,
64 minCoverFreq=-0.5,
65 maxCoverFreq=-0.5,
66 )
67 FS_1 = coherent_search.get_fullycoherent_twoF(
68 noise_and_signal_writer.F0,
69 noise_and_signal_writer.F1,
70 noise_and_signal_writer.F2,
71 noise_and_signal_writer.Alpha,
72 noise_and_signal_writer.Delta,
73 )
74
75 # create noise sfts
76 # window options are again optional for this step
77 noise_writer = pyfstat.Writer(
78 label="test_noiseSFTs_only_noise",
79 outdir=outdir,
80 h0=0,
81 F0=F0,
82 tstart=tstart,
83 duration=duration_Tsft * Tsft,
84 Tsft=Tsft,
85 Band=Band,
86 detectors=IFO,
87 randSeed=randSeed,
88 SFTWindowType="tukey",
89 SFTWindowBeta=0.001,
90 )
91 noise_writer.make_data()
92
93 # then inject a strong signal
94 # window options *must* match those previously used for the noiseSFTs
95 add_signal_writer = pyfstat.Writer(
96 label="test_noiseSFTs_add_signal",
97 outdir=outdir,
98 F0=F0,
99 Alpha=Alpha,
100 Delta=Delta,
101 h0=h0,
102 cosi=cosi,
103 tstart=tstart,
104 duration=duration_Tsft * Tsft,
105 Tsft=Tsft,
106 Band=Band,
107 detectors=IFO,
108 sqrtSX=0,
109 noiseSFTs=os.path.join(
110 noise_writer.outdir, "*{}*{}*sft".format(duration_Tsft, noise_writer.label)
111 ),
112 SFTWindowType="tukey",
113 SFTWindowBeta=0.001,
114 )
115 sftfilepattern = os.path.join(
116 add_signal_writer.outdir,
117 "*{}*{}*sft".format(duration_Tsft, add_signal_writer.label),
118 )
119 add_signal_writer.make_data()
120
121 # compute Fstat
122 coherent_search = pyfstat.ComputeFstat(
123 tref=add_signal_writer.tref,
124 sftfilepattern=sftfilepattern,
125 minCoverFreq=-0.5,
126 maxCoverFreq=-0.5,
127 )
128 FS_2 = coherent_search.get_fullycoherent_twoF(
129 add_signal_writer.F0,
130 add_signal_writer.F1,
131 add_signal_writer.F2,
132 add_signal_writer.Alpha,
133 add_signal_writer.Delta,
134 )
135
136 print("Base case Fstat: {}".format(FS_1))
137 print("Noise + Signal Fstat: {}".format(FS_2))
138 print("Relative Difference: {}".format(np.abs(FS_2 - FS_1) / FS_1))
Total running time of the script: ( 0 minutes 0.000 seconds)