Note
Click here to download the full example code
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 label = "PyFstat_example_spectrogram"
20 outdir = os.path.join("PyFstat_example_data", label)
21
22 depth = 5
23
24 data_parameters = {
25 "sqrtSX": 1e-23,
26 "tstart": 1000000000,
27 "duration": 2 * 365 * 86400,
28 "detectors": "H1",
29 "Tsft": 1800,
30 }
31
32 signal_parameters = {
33 "F0": 100.0,
34 "F1": 0,
35 "F2": 0,
36 "Alpha": 0.0,
37 "Delta": 0.5,
38 "tp": data_parameters["tstart"],
39 "asini": 25.0,
40 "period": 50 * 86400,
41 "tref": data_parameters["tstart"],
42 "h0": data_parameters["sqrtSX"] / depth,
43 "cosi": 1.0,
44 }
45
46 # making data
47 data = pyfstat.BinaryModulatedWriter(
48 label=label, outdir=outdir, **data_parameters, **signal_parameters
49 )
50 data.make_data()
51
52 print("Loading SFT data and computing normalized power...")
53 times, freqs, sft_data = pyfstat.helper_functions.get_sft_array(data.sftfilepath)
54 normalized_power = (
55 2 * sft_data ** 2 / (data_parameters["Tsft"] * data_parameters["sqrtSX"] ** 2)
56 )
57
58 plotfile = os.path.join(outdir, label + ".png")
59 print(f"Plotting to file: {plotfile}")
60 fig, ax = plt.subplots(figsize=(0.8 * 16, 0.8 * 9))
61 ax.grid(which="both")
62 ax.set(xlabel="Time [days]", ylabel="Frequency [Hz]", ylim=(99.98, 100.02))
63 c = ax.pcolormesh(
64 (times - times[0]) / 86400,
65 freqs,
66 normalized_power,
67 cmap="inferno_r",
68 shading="nearest",
69 )
70 fig.colorbar(c, label="Normalized Power")
71 plt.tight_layout()
72 fig.savefig(plotfile)
Total running time of the script: ( 0 minutes 0.000 seconds)