Note
Go to the end 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 = "PyFstatExampleInjectionIntoNoiseSFTs"
19 outdir = os.path.join("PyFstat_example_data", label)
20 logger = pyfstat.set_up_logger(label=label, outdir=outdir)
21
22 tstart = 1269734418
23 duration_Tsft = 100
24 Tsft = 1800
25 randSeed = 69420
26 IFO = "H1"
27 h0 = 1000
28 cosi = 0
29 F0 = 30
30 Alpha = 0
31 Delta = 0
32
33 Band = 2.0
34
35 # create sfts with a strong signal in them
36 # window options are optional here
37 noise_and_signal_writer = pyfstat.Writer(
38 label="PyFstatTestSFTsNoiseAndSignal",
39 outdir=outdir,
40 h0=h0,
41 cosi=cosi,
42 F0=F0,
43 Alpha=Alpha,
44 Delta=Delta,
45 tstart=tstart,
46 duration=duration_Tsft * Tsft,
47 Tsft=Tsft,
48 Band=Band,
49 detectors=IFO,
50 randSeed=randSeed,
51 SFTWindowType="tukey",
52 SFTWindowParam=0.001,
53 )
54 noise_and_signal_writer.make_data()
55
56 # compute Fstat
57 coherent_search = pyfstat.ComputeFstat(
58 tref=noise_and_signal_writer.tref,
59 sftfilepattern=noise_and_signal_writer.sftfilepath,
60 minCoverFreq=-0.5,
61 maxCoverFreq=-0.5,
62 )
63 FS_1 = coherent_search.get_fullycoherent_twoF(
64 noise_and_signal_writer.F0,
65 noise_and_signal_writer.F1,
66 noise_and_signal_writer.F2,
67 noise_and_signal_writer.Alpha,
68 noise_and_signal_writer.Delta,
69 )
70
71 # create noise sfts
72 # window options are again optional for this step
73 noise_writer = pyfstat.Writer(
74 label="PyFstatTestSFTsOnlyNoise",
75 outdir=outdir,
76 h0=0,
77 F0=F0,
78 tstart=tstart,
79 duration=duration_Tsft * Tsft,
80 Tsft=Tsft,
81 Band=Band,
82 detectors=IFO,
83 randSeed=randSeed,
84 SFTWindowType="tukey",
85 SFTWindowParam=0.001,
86 )
87 noise_writer.make_data()
88
89 # then inject a strong signal
90 # window options *must* match those previously used for the noiseSFTs
91 add_signal_writer = pyfstat.Writer(
92 label="PyFstatTestSFTsWithAddedSignal",
93 outdir=outdir,
94 F0=F0,
95 Alpha=Alpha,
96 Delta=Delta,
97 h0=h0,
98 cosi=cosi,
99 tstart=tstart,
100 duration=duration_Tsft * Tsft,
101 Tsft=Tsft,
102 Band=Band,
103 detectors=IFO,
104 sqrtSX=0,
105 noiseSFTs=noise_writer.sftfilepath,
106 SFTWindowType="tukey",
107 SFTWindowParam=0.001,
108 )
109 add_signal_writer.make_data()
110
111 # compute Fstat
112 coherent_search = pyfstat.ComputeFstat(
113 tref=add_signal_writer.tref,
114 sftfilepattern=add_signal_writer.sftfilepath,
115 minCoverFreq=-0.5,
116 maxCoverFreq=-0.5,
117 )
118 FS_2 = coherent_search.get_fullycoherent_twoF(
119 add_signal_writer.F0,
120 add_signal_writer.F1,
121 add_signal_writer.F2,
122 add_signal_writer.Alpha,
123 add_signal_writer.Delta,
124 )
125
126 logger.info("Base case Fstat: {}".format(FS_1))
127 logger.info("Noise + Signal Fstat: {}".format(FS_2))
128 logger.info("Relative Difference: {}".format(np.abs(FS_2 - FS_1) / FS_1))