LALPulsar 7.1.1.1-eeff03c
test_ReadSFDB.py
Go to the documentation of this file.
1# Copyright (C) 2020 Pep Covas, David Keitel, Rodrigo Tenorio
2#
3# This program is free software; you can redistribute it and/or modify it
4# under the terms of the GNU General Public License as published by the
5# Free Software Foundation; either version 2 of the License, or (at your
6# option) any later version.
7#
8# This program is distributed in the hope that it will be useful, but
9# WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11# Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc.,
15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17import sys
18import pytest
19import lalpulsar
20import numpy as np
21import os
22
23try:
24 from pathlib import Path
25except ImportError as exc: # probably macports
26 import warnings
27
28 warnings.warn(str(exc))
29 sys.exit(77)
30
31
33 # reference parameters of the test data file
34 testfilename = "V1_mfdv5_20191114_043831.SFDB09"
35 Tsft = 1024
36 startTime = 1257741529
37 SFToverlap = 512
38 IFOs = ["V1"]
39 fmin = 49
40 fmax = 51
41 signal_freq = 50
42
43 # find reference SFDB file in a portable way
44 TEST_PATH = Path(os.getenv("LAL_TEST_SRCDIR", Path(__file__).parent)).absolute()
45 sfdb_file = str(TEST_PATH / testfilename)
46
47 # read SFTs from SFDB
48 multi_sfts_from_sfdb = lalpulsar.ReadSFDB(
49 f_min=fmin,
50 f_max=fmax,
51 file_pattern=sfdb_file,
52 timeStampsStarting=None,
53 timeStampsFinishing=None,
54 )
55 print("Got SFTs for {:d} detectors from SFDBs.".format(multi_sfts_from_sfdb.length))
56 assert multi_sfts_from_sfdb.length == len(IFOs)
57 sfts_from_sfdb = multi_sfts_from_sfdb.data[0]
58 nSFTs = sfts_from_sfdb.length
59 print(
60 "Got {:d} SFTs for {:s} from SFDBs.".format(nSFTs, sfts_from_sfdb.data[0].name)
61 )
62 assert nSFTs == 3
63 for k, sft in enumerate(sfts_from_sfdb.data):
64 print("SFT {:d}/{:d}: epoch={:d}".format(k, nSFTs, sft.epoch.gpsSeconds))
65 f0 = sft.f0
66 deltaF = sft.deltaF
67 nBins = sft.data.length
68 absval = np.abs(sft.data.data)
69 maxabs = np.max(absval)
70 maxbin = np.argmax(absval)
71 maxfreq = f0 + deltaF * maxbin
72
73 # simple sanity checks of returned properties
74 print("f0 SFDB: {}".format(f0)) # Starting frequency
75 print("df SFDB: {}".format(deltaF)) # Frequency spacing between bins
76 print("nBins SFDB: {}".format(nBins)) # Number of frequency bins in one SFT
77 print(
78 "max abs value {:.4e} at freq[{:d}]={:.6f} (expected signal frequency: {:.6f})".format(
79 maxabs, maxbin, maxfreq, signal_freq
80 )
81 )
82 if k == 0:
83 maxbin0 = maxbin
84 maxabs0 = maxabs
85 assert sft.name == IFOs[0]
86 assert f0 == fmin
87 assert abs(deltaF - 1.0 / Tsft) < 1e-16
88 assert nBins == 2 * Tsft + 1
89 assert maxbin == maxbin0
90 assert abs(maxfreq - signal_freq) < 4 * deltaF
91
92
93if __name__ == "__main__":
94 args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-ReadSFDB.xml"]
95 sys.exit(pytest.main(args=[__file__] + args))
def test_ReadSFDB()