Note
Go to the end to download the full example code.
MCMC search: Semicoherent F-statistic
Directed MCMC search for an isolated CW signal using the semicoherent F-statistic.
9 import os
10
11 import numpy as np
12
13 import pyfstat
14
15 label = "PyFstatExampleSemiCoherentMCMCSearch"
16 outdir = os.path.join("PyFstat_example_data", label)
17 logger = pyfstat.set_up_logger(label=label, outdir=outdir)
18
19 # Properties of the GW data
20 data_parameters = {
21 "sqrtSX": 1e-23,
22 "tstart": 1000000000,
23 "duration": 100 * 86400,
24 "detectors": "H1",
25 }
26 tend = data_parameters["tstart"] + data_parameters["duration"]
27 mid_time = 0.5 * (data_parameters["tstart"] + tend)
28
29 # Properties of the signal
30 depth = 10
31 signal_parameters = {
32 "F0": 30.0,
33 "F1": -1e-10,
34 "F2": 0,
35 "Alpha": np.radians(83.6292),
36 "Delta": np.radians(22.0144),
37 "tref": mid_time,
38 "h0": data_parameters["sqrtSX"] / depth,
39 "cosi": 1.0,
40 }
41
42 data = pyfstat.Writer(
43 label=label, outdir=outdir, **data_parameters, **signal_parameters
44 )
45 data.make_data()
46
47 # The predicted twoF (expectation over noise realizations) can be accessed by
48 twoF = data.predict_fstat()
49 logger.info("Predicted twoF value: {}\n".format(twoF))
50
51 DeltaF0 = 1e-7
52 DeltaF1 = 1e-13
53 VF0 = (np.pi * data_parameters["duration"] * DeltaF0) ** 2 / 3.0
54 VF1 = (np.pi * data_parameters["duration"] ** 2 * DeltaF1) ** 2 * 4 / 45.0
55 logger.info("\nV={:1.2e}, VF0={:1.2e}, VF1={:1.2e}\n".format(VF0 * VF1, VF0, VF1))
56
57 theta_prior = {
58 "F0": {
59 "type": "unif",
60 "lower": signal_parameters["F0"] - DeltaF0 / 2.0,
61 "upper": signal_parameters["F0"] + DeltaF0 / 2.0,
62 },
63 "F1": {
64 "type": "unif",
65 "lower": signal_parameters["F1"] - DeltaF1 / 2.0,
66 "upper": signal_parameters["F1"] + DeltaF1 / 2.0,
67 },
68 }
69 for key in "F2", "Alpha", "Delta":
70 theta_prior[key] = signal_parameters[key]
71
72 ntemps = 1
73 log10beta_min = -1
74 nwalkers = 100
75 nsteps = [300, 300]
76
77 mcmc = pyfstat.MCMCSemiCoherentSearch(
78 label=label,
79 outdir=outdir,
80 nsegs=10,
81 sftfilepattern=data.sftfilepath,
82 theta_prior=theta_prior,
83 tref=mid_time,
84 minStartTime=data_parameters["tstart"],
85 maxStartTime=tend,
86 nsteps=nsteps,
87 nwalkers=nwalkers,
88 ntemps=ntemps,
89 log10beta_min=log10beta_min,
90 )
91 mcmc.transform_dictionary = dict(
92 F0=dict(subtractor=signal_parameters["F0"], symbol="$f-f^\\mathrm{s}$"),
93 F1=dict(
94 subtractor=signal_parameters["F1"], symbol="$\\dot{f}-\\dot{f}^\\mathrm{s}$"
95 ),
96 )
97 mcmc.run(
98 walker_plot_args={"plot_det_stat": True, "injection_parameters": signal_parameters}
99 )
100 mcmc.print_summary()
101 mcmc.plot_corner(add_prior=True, truths=signal_parameters)
102 mcmc.plot_prior_posterior(injection_parameters=signal_parameters)
103 mcmc.plot_chainconsumer(truth=signal_parameters)
104 mcmc.plot_cumulative_max(
105 savefig=True,
106 custom_ax_kwargs={"title": "Cumulative 2F for the best MCMC candidate"},
107 )