Note
Click here to download the full example code
Short transient MCMC search
MCMC search for a Short transient CW signal.
8 import os
9
10 import numpy as np
11 import PyFstat_example_make_data_for_short_transient_search as data
12
13 import pyfstat
14 from pyfstat.helper_functions import get_predict_fstat_parameters_from_dict
15
16 if __name__ == "__main__":
17
18 if not os.path.isdir(data.outdir) or not np.any(
19 [f.endswith(".sft") for f in os.listdir(data.outdir)]
20 ):
21 raise RuntimeError(
22 "Please first run PyFstat_example_make_data_for_short_transient_search.py !"
23 )
24
25 inj = {
26 "tref": data.tstart,
27 "F0": data.F0,
28 "F1": data.F1,
29 "F2": data.F2,
30 "Alpha": data.Alpha,
31 "Delta": data.Delta,
32 "transient_tstart": data.transient_tstart,
33 "transient_duration": data.transient_duration,
34 }
35
36 DeltaF0 = 1e-2
37 DeltaF1 = 1e-9
38
39 theta_prior = {
40 "F0": {
41 "type": "unif",
42 "lower": inj["F0"] - DeltaF0 / 2.0,
43 "upper": inj["F0"] + DeltaF0 / 2.0,
44 },
45 "F1": {
46 "type": "unif",
47 "lower": inj["F1"] - DeltaF1 / 2.0,
48 "upper": inj["F1"] + DeltaF1 / 2.0,
49 },
50 "F2": inj["F2"],
51 "Alpha": inj["Alpha"],
52 "Delta": inj["Delta"],
53 "transient_tstart": {
54 "type": "unif",
55 "lower": data.tstart,
56 "upper": data.tstart + data.duration - 2 * data.Tsft,
57 },
58 "transient_duration": {
59 "type": "unif",
60 "lower": 2 * data.Tsft,
61 "upper": data.duration - 2 * data.Tsft,
62 },
63 }
64
65 ntemps = 2
66 log10beta_min = -1
67 nwalkers = 100
68 nsteps = [200, 200]
69
70 BSGL = False
71 transientWindowType = "rect"
72
73 mcmc = pyfstat.MCMCTransientSearch(
74 label="transient_search" + ("_BSGL" if BSGL else ""),
75 outdir=data.outdir,
76 sftfilepattern=os.path.join(data.outdir, "*simulated_transient_signal*sft"),
77 theta_prior=theta_prior,
78 tref=inj["tref"],
79 nsteps=nsteps,
80 nwalkers=nwalkers,
81 ntemps=ntemps,
82 log10beta_min=log10beta_min,
83 transientWindowType=transientWindowType,
84 BSGL=BSGL,
85 )
86 mcmc.run(walker_plot_args={"plot_det_stat": True, "injection_parameters": inj})
87 mcmc.print_summary()
88 mcmc.plot_corner(add_prior=True, truths=inj)
89 mcmc.plot_prior_posterior(injection_parameters=inj)
90
91 # plot cumulative 2F, first building a dict as required for PredictFStat
92 d, maxtwoF = mcmc.get_max_twoF()
93 for key, val in mcmc.theta_prior.items():
94 if key not in d:
95 d[key] = val
96 d["h0"] = data.h0
97 d["cosi"] = data.cosi
98 d["psi"] = data.psi
99 PFS_input = get_predict_fstat_parameters_from_dict(
100 d, transientWindowType=transientWindowType
101 )
102 mcmc.plot_cumulative_max(PFS_input=PFS_input)
Total running time of the script: ( 0 minutes 0.000 seconds)