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