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