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

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

Gallery generated by Sphinx-Gallery