Note
Click here to download the full example code
Long transient MCMC searchΒΆ
MCMC search for a long transient CW 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.
13 import os
14
15 import numpy as np
16 import PyFstat_example_make_data_for_long_transient_search as data
17
18 import pyfstat
19 from pyfstat.utils import get_predict_fstat_parameters_from_dict
20
21 if not os.path.isdir(data.outdir) or not np.any(
22 [f.endswith(".sft") for f in os.listdir(data.outdir)]
23 ):
24 raise RuntimeError(
25 "Please first run PyFstat_example_make_data_for_long_transient_search.py !"
26 )
27
28 label = "PyFstatExampleLongTransientMCMCSearch"
29 logger = pyfstat.set_up_logger(label=label, outdir=data.outdir)
30
31 tstart = data.tstart
32 duration = data.duration
33
34 inj = {
35 "tref": data.tstart,
36 "F0": data.F0,
37 "F1": data.F1,
38 "F2": data.F2,
39 "Alpha": data.Alpha,
40 "Delta": data.Delta,
41 "transient_tstart": data.transient_tstart,
42 "transient_duration": data.transient_duration,
43 }
44
45 DeltaF0 = 6e-7
46 DeltaF1 = 1e-13
47
48 # to make the search cheaper, we exactly target the transientStartTime
49 # to the injected value and only search over TransientTau
50 theta_prior = {
51 "F0": {
52 "type": "unif",
53 "lower": inj["F0"] - DeltaF0 / 2.0,
54 "upper": inj["F0"] + DeltaF0 / 2.0,
55 },
56 "F1": {
57 "type": "unif",
58 "lower": inj["F1"] - DeltaF1 / 2.0,
59 "upper": inj["F1"] + DeltaF1 / 2.0,
60 },
61 "F2": inj["F2"],
62 "Alpha": inj["Alpha"],
63 "Delta": inj["Delta"],
64 "transient_tstart": tstart + 0.25 * duration,
65 "transient_duration": {
66 "type": "halfnorm",
67 "loc": 0.001 * duration,
68 "scale": 0.5 * duration,
69 },
70 }
71
72 ntemps = 2
73 log10beta_min = -1
74 nwalkers = 100
75 nsteps = [100, 100]
76
77 transientWindowType = "rect"
78 BSGL = False
79 BtSG = False
80
81 mcmc = pyfstat.MCMCTransientSearch(
82 label=label + ("BSGL" if BSGL else "") + ("BtSG" if BtSG else ""),
83 outdir=data.outdir,
84 sftfilepattern=os.path.join(data.outdir, f"*{data.label}*sft"),
85 theta_prior=theta_prior,
86 tref=inj["tref"],
87 nsteps=nsteps,
88 nwalkers=nwalkers,
89 ntemps=ntemps,
90 log10beta_min=log10beta_min,
91 transientWindowType=transientWindowType,
92 BSGL=BSGL,
93 BtSG=BtSG,
94 )
95 mcmc.run(walker_plot_args={"plot_det_stat": True, "injection_parameters": inj})
96 mcmc.print_summary()
97 mcmc.plot_corner(add_prior=True, truths=inj)
98 mcmc.plot_prior_posterior(injection_parameters=inj)
99
100 # plot cumulative 2F, first building a dict as required for PredictFStat
101 d, maxtwoF = mcmc.get_max_twoF()
102 for key, val in mcmc.theta_prior.items():
103 if key not in d:
104 d[key] = val
105 d["h0"] = data.h0
106 d["cosi"] = data.cosi
107 d["psi"] = data.psi
108 PFS_input = get_predict_fstat_parameters_from_dict(
109 d, transientWindowType=transientWindowType
110 )
111 mcmc.plot_cumulative_max(PFS_input=PFS_input)
Total running time of the script: ( 0 minutes 0.000 seconds)