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.helper_functions 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 tstart = data.tstart
29 duration = data.duration
30
31 inj = {
32 "tref": data.tstart,
33 "F0": data.F0,
34 "F1": data.F1,
35 "F2": data.F2,
36 "Alpha": data.Alpha,
37 "Delta": data.Delta,
38 "transient_tstart": data.transient_tstart,
39 "transient_duration": data.transient_duration,
40 }
41
42 DeltaF0 = 6e-7
43 DeltaF1 = 1e-13
44
45 # to make the search cheaper, we exactly target the transientStartTime
46 # to the injected value and only search over TransientTau
47 theta_prior = {
48 "F0": {
49 "type": "unif",
50 "lower": inj["F0"] - DeltaF0 / 2.0,
51 "upper": inj["F0"] + DeltaF0 / 2.0,
52 },
53 "F1": {
54 "type": "unif",
55 "lower": inj["F1"] - DeltaF1 / 2.0,
56 "upper": inj["F1"] + DeltaF1 / 2.0,
57 },
58 "F2": inj["F2"],
59 "Alpha": inj["Alpha"],
60 "Delta": inj["Delta"],
61 "transient_tstart": tstart + 0.25 * duration,
62 "transient_duration": {
63 "type": "halfnorm",
64 "loc": 0.001 * duration,
65 "scale": 0.5 * duration,
66 },
67 }
68
69 ntemps = 2
70 log10beta_min = -1
71 nwalkers = 100
72 nsteps = [100, 100]
73
74 transientWindowType = "rect"
75 BSGL = False
76 BtSG = False
77
78 mcmc = pyfstat.MCMCTransientSearch(
79 label="transient_search" + ("_BSGL" if BSGL else "") + ("_BtSG" if BtSG else ""),
80 outdir=data.outdir,
81 sftfilepattern=os.path.join(data.outdir, "*simulated_transient_signal*sft"),
82 theta_prior=theta_prior,
83 tref=inj["tref"],
84 nsteps=nsteps,
85 nwalkers=nwalkers,
86 ntemps=ntemps,
87 log10beta_min=log10beta_min,
88 transientWindowType=transientWindowType,
89 BSGL=BSGL,
90 BtSG=BtSG,
91 )
92 mcmc.run(walker_plot_args={"plot_det_stat": True, "injection_parameters": inj})
93 mcmc.print_summary()
94 mcmc.plot_corner(add_prior=True, truths=inj)
95 mcmc.plot_prior_posterior(injection_parameters=inj)
96
97 # plot cumulative 2F, first building a dict as required for PredictFStat
98 d, maxtwoF = mcmc.get_max_twoF()
99 for key, val in mcmc.theta_prior.items():
100 if key not in d:
101 d[key] = val
102 d["h0"] = data.h0
103 d["cosi"] = data.cosi
104 d["psi"] = data.psi
105 PFS_input = get_predict_fstat_parameters_from_dict(
106 d, transientWindowType=transientWindowType
107 )
108 mcmc.plot_cumulative_max(PFS_input=PFS_input)
Total running time of the script: ( 0 minutes 0.000 seconds)