Note
Click here to download the full example code
Short transient grid search¶
An example grid-based search for a short transient signal. By default, the standard persistent-CW 2F-statistic and the transient max2F statistic are compared.
You can turn on either BSGL = True or BtSG = True (not both!) to test alternative statistics.
This is also ready to use on a GPU, if you have one available and pycuda installed. Just change to tCWFstatMapVersion = “pycuda”.
17 import os
18
19 import numpy as np
20 import PyFstat_example_make_data_for_short_transient_search as data
21
22 import pyfstat
23
24 tCWFstatMapVersion = "lal"
25
26 if __name__ == "__main__":
27 logger = pyfstat.set_up_logger(
28 label="short_transient_grid_search", outdir=data.outdir
29 )
30 if not os.path.isdir(data.outdir) or not np.any(
31 [f.endswith(".sft") for f in os.listdir(data.outdir)]
32 ):
33 raise RuntimeError(
34 "Please first run PyFstat_example_make_data_for_short_transient_search.py !"
35 )
36
37 maxStartTime = data.tstart + data.duration
38
39 m = 0.001
40 dF0 = np.sqrt(12 * m) / (np.pi * data.duration)
41 DeltaF0 = 100 * dF0
42 F0s = [data.F0 - DeltaF0 / 2.0, data.F0 + DeltaF0 / 2.0, dF0]
43 F1s = [data.F1]
44 F2s = [data.F2]
45 Alphas = [data.Alpha]
46 Deltas = [data.Delta]
47
48 BSGL = False
49 BtSG = False
50
51 logger.info("Standard CW search:")
52 search1 = pyfstat.GridSearch(
53 label=f"CW{'_BSGL' if BSGL else ''}",
54 outdir=data.outdir,
55 sftfilepattern=os.path.join(data.outdir, "*simulated_transient_signal*sft"),
56 F0s=F0s,
57 F1s=F1s,
58 F2s=F2s,
59 Alphas=Alphas,
60 Deltas=Deltas,
61 tref=data.tref,
62 BSGL=BSGL,
63 )
64 search1.run()
65 search1.print_max_twoF()
66 search1.plot_1D(
67 xkey="F0", xlabel="freq [Hz]", ylabel=search1.tex_labels[search1.detstat]
68 )
69
70 logger.info("with t0,tau bands:")
71 label = f"tCW{'_BSGL' if BSGL else ''}{'_BtSG' if BtSG else ''}_FstatMap_{tCWFstatMapVersion}"
72 search2 = pyfstat.TransientGridSearch(
73 label=label,
74 outdir=data.outdir,
75 sftfilepattern=os.path.join(data.outdir, "*simulated_transient_signal*sft"),
76 F0s=F0s,
77 F1s=F1s,
78 F2s=F2s,
79 Alphas=Alphas,
80 Deltas=Deltas,
81 tref=data.tref,
82 transientWindowType="rect",
83 t0Band=data.duration - 2 * data.Tsft,
84 tauBand=data.duration,
85 outputTransientFstatMap=True,
86 tCWFstatMapVersion=tCWFstatMapVersion,
87 BSGL=BSGL,
88 BtSG=BtSG,
89 )
90 search2.run()
91 search2.print_max_twoF()
92 search2.plot_1D(
93 xkey="F0", xlabel="freq [Hz]", ylabel=search2.tex_labels[search2.detstat]
94 )
Total running time of the script: ( 0 minutes 0.000 seconds)