Compute a spectrogram

Compute the spectrogram of a set of SFTs. This is useful to produce visualizations of the Doppler modulation of a CW signal.

 9 import os
10
11 import matplotlib.pyplot as plt
12
13 import pyfstat
14
15 # not github-action compatible
16 # plt.rcParams["font.family"] = "serif"
17 # plt.rcParams["font.size"] = 18
18 # plt.rcParams["text.usetex"] = True
19
20 # workaround deprecation warning
21 # see https://github.com/matplotlib/matplotlib/issues/21723
22 plt.rcParams["axes.grid"] = False
23
24 label = "PyFstat_example_spectrogram"
25 outdir = os.path.join("PyFstat_example_data", label)
26
27 depth = 5
28
29 data_parameters = {
30     "sqrtSX": 1e-23,
31     "tstart": 1000000000,
32     "duration": 2 * 365 * 86400,
33     "detectors": "H1",
34     "Tsft": 1800,
35 }
36
37 signal_parameters = {
38     "F0": 100.0,
39     "F1": 0,
40     "F2": 0,
41     "Alpha": 0.0,
42     "Delta": 0.5,
43     "tp": data_parameters["tstart"],
44     "asini": 25.0,
45     "period": 50 * 86400,
46     "tref": data_parameters["tstart"],
47     "h0": data_parameters["sqrtSX"] / depth,
48     "cosi": 1.0,
49 }
50
51 # making data
52 data = pyfstat.BinaryModulatedWriter(
53     label=label, outdir=outdir, **data_parameters, **signal_parameters
54 )
55 data.make_data()
56
57 print("Loading SFT data and computing normalized power...")
58 freqs, times, sft_data = pyfstat.helper_functions.get_sft_as_arrays(data.sftfilepath)
59 sft_power = sft_data["H1"].real ** 2 + sft_data["H1"].imag ** 2
60 normalized_power = (
61     2 * sft_power / (data_parameters["Tsft"] * data_parameters["sqrtSX"] ** 2)
62 )
63
64 plotfile = os.path.join(outdir, label + ".png")
65 print(f"Plotting to file: {plotfile}")
66 fig, ax = plt.subplots(figsize=(0.8 * 16, 0.8 * 9))
67 ax.set(xlabel="Time [days]", ylabel="Frequency [Hz]", ylim=(99.98, 100.02))
68 c = ax.pcolormesh(
69     (times["H1"] - times["H1"][0]) / 86400,
70     freqs,
71     normalized_power,
72     cmap="inferno_r",
73     shading="nearest",
74 )
75 fig.colorbar(c, label="Normalized Power")
76 plt.tight_layout()
77 fig.savefig(plotfile)

Total running time of the script: ( 0 minutes 0.000 seconds)

Gallery generated by Sphinx-Gallery