Note
Go to the end 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
11 import matplotlib.pyplot as plt
12 import numpy as np
13
14 import pyfstat
15
16 # not github-action compatible
17 # plt.rcParams["font.family"] = "serif"
18 # plt.rcParams["font.size"] = 18
19 # plt.rcParams["text.usetex"] = True
20
21 # workaround deprecation warning
22 # see https://github.com/matplotlib/matplotlib/issues/21723
23 plt.rcParams["axes.grid"] = False
24
25 label = "PyFstatExampleSpectrogramNormPower"
26 outdir = os.path.join("PyFstat_example_data", label)
27 logger = pyfstat.set_up_logger(label=label, outdir=outdir)
28
29 depth = 5
30
31 gap_duration = 10 * 86400
32 Tsft = 1800
33
34 segments = [ # Define the tstart and duration of each segment of data
35 {"tstart": 1000000000, "duration": 120 * 86400},
36 {"tstart": 1000000000 + 120 * 86400 + gap_duration, "duration": 300 * 86400},
37 {"tstart": 1000000000 + 420 * 86400 + 2 * gap_duration, "duration": 120 * 86400},
38 ]
39
40 timestamps = {
41 "H1": np.concatenate(
42 [ # Generate timestamps for each segment and concatenate them
43 segment["tstart"] + Tsft * np.arange(segment["duration"] // Tsft)
44 for segment in segments
45 ]
46 )
47 }
48
49 data_parameters = {
50 "sqrtSX": 1e-23,
51 "timestamps": timestamps,
52 "detectors": "H1",
53 "Tsft": 1800,
54 }
55
56 signal_parameters = {
57 "F0": 100.0,
58 "F1": 0,
59 "F2": 0,
60 "Alpha": 0.0,
61 "Delta": 0.5,
62 "tp": segments[0]["tstart"],
63 "asini": 25.0,
64 "period": 50 * 86400,
65 "tref": segments[0]["tstart"],
66 "h0": data_parameters["sqrtSX"] / depth,
67 "cosi": 1.0,
68 }
69
70 # making data
71 data = pyfstat.BinaryModulatedWriter(
72 label=label, outdir=outdir, **data_parameters, **signal_parameters
73 )
74 data.make_data()
75
76 ax = pyfstat.utils.plot_spectrogram(
77 sftfilepattern=data.sftfilepath,
78 detector=data_parameters["detectors"],
79 sqrtSX=data_parameters["sqrtSX"],
80 quantity="normpower",
81 savefig=True,
82 outdir=outdir,
83 label=label,
84 )