Note
Click here to download the full example code
Long transient MCMC search
MCMC search for a long transient CW signal.
7 import pyfstat
8 import os
9 import numpy as np
10 import PyFstat_example_make_data_for_long_transient_search as data
11 from pyfstat.helper_functions import get_predict_fstat_parameters_from_dict
12
13 if not os.path.isdir(data.outdir) or not np.any(
14 [f.endswith(".sft") for f in os.listdir(data.outdir)]
15 ):
16 raise RuntimeError(
17 "Please first run PyFstat_example_make_data_for_long_transient_search.py !"
18 )
19
20 tstart = data.tstart
21 duration = data.duration
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 = 6e-7
35 DeltaF1 = 1e-13
36
37 # to make the search cheaper, we exactly target the transientStartTime
38 # to the injected value and only search over TransientTau
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": tstart + 0.25 * duration,
54 "transient_duration": {
55 "type": "halfnorm",
56 "loc": 0.001 * duration,
57 "scale": 0.5 * duration,
58 },
59 }
60
61 ntemps = 2
62 log10beta_min = -1
63 nwalkers = 100
64 nsteps = [100, 100]
65
66 transientWindowType = "rect"
67
68 mcmc = pyfstat.MCMCTransientSearch(
69 label="transient_search",
70 outdir=data.outdir,
71 sftfilepattern=os.path.join(data.outdir, "*simulated_transient_signal*sft"),
72 theta_prior=theta_prior,
73 tref=inj["tref"],
74 nsteps=nsteps,
75 nwalkers=nwalkers,
76 ntemps=ntemps,
77 log10beta_min=log10beta_min,
78 transientWindowType=transientWindowType,
79 )
80 mcmc.run(walker_plot_args={"plot_det_stat": True, "injection_parameters": inj})
81 mcmc.print_summary()
82 mcmc.plot_corner(add_prior=True, truths=inj)
83 mcmc.plot_prior_posterior(injection_parameters=inj)
84
85 # plot cumulative 2F, first building a dict as required for PredictFStat
86 d, maxtwoF = mcmc.get_max_twoF()
87 for key, val in mcmc.theta_prior.items():
88 if key not in d:
89 d[key] = val
90 d["h0"] = data.h0
91 d["cosi"] = data.cosi
92 d["psi"] = data.psi
93 PFS_input = get_predict_fstat_parameters_from_dict(
94 d, transientWindowType=transientWindowType
95 )
96 mcmc.plot_cumulative_max(PFS_input=PFS_input)
Total running time of the script: ( 0 minutes 0.000 seconds)