Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALFrame 3.0.7.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
test_frread.py
Go to the documentation of this file.
1# Copyright (C) 2019 Duncan Macleod
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
17"""Tests for lalframe.frread
18"""
19
20import sys
21import os
22try:
23 from pathlib import Path
24except ImportError as exc: # probably macports
25 import warnings
26 warnings.warn(str(exc))
27 sys.exit(77)
28
29import pytest
30
31import lal
32from lal.utils.cache import CacheEntry
33
34from lalframe import frread
35
36try:
37 from glue.lal import Cache
38except ImportError:
39 Cache = None
40else:
41 Cache.entry_class = CacheEntry
42
43# find test GWF file
44TEST_PATH = Path(os.getenv(
45 "LAL_TEST_SRCDIR",
46 Path(__file__).parent,
47)).absolute().parent
48TEST_GWF = TEST_PATH / "F-TEST-600000060-60.gwf"
49
50# parametrize sources
51SOURCES = [
52 str(TEST_GWF),
53 lal.CacheGlob(str(TEST_GWF.parent), TEST_GWF.name),
54]
55if Cache is not None:
56 SOURCES.append(Cache([CacheEntry.from_T050017(str(TEST_GWF))]))
57
58
59@pytest.mark.parametrize("source", SOURCES)
61 ts = frread.read_timeseries(
62 source,
63 "H1:LSC-AS_Q",
64 )
65 assert ts.name == "H1:LSC-AS_Q"
66 assert ts.data.length == 16384 * 60
67 assert ts.deltaT == 6.103515625e-05
68
69
70@pytest.mark.parametrize("instart, induration, outstart, outduration", [
71 (None, None, 600000060, 60),
72 (600000061, None, 600000061, 59),
73 (None, 30, 600000060, 30),
74 (600000061, 1, 600000061, 1),
75])
77 instart,
78 induration,
79 outstart,
80 outduration,
81):
82 ts = frread.read_timeseries(
83 str(TEST_GWF),
84 "H1:LSC-AS_Q",
85 start=instart,
86 duration=induration,
87 )
88 assert ts.epoch == outstart
89 assert ts.data.length * ts.deltaT == outduration
90
91
92@pytest.mark.parametrize("inputs, message", [
93 (("does-not-exist.gwf", "channel"),
94 "Internal function call failed: I/O error"),
95 ((str(TEST_GWF), "bad-channel"), "Wrong name"),
96])
97def test_read_timeseries_error(inputs, message):
98 with pytest.raises(RuntimeError) as exc:
99 frread.read_timeseries(*inputs)
100 assert str(exc.value) == message
101
102
103if __name__ == '__main__':
104 args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-frread.xml"]
105 sys.exit(pytest.main(args=[__file__] + args))
def test_read_timeseries(source)
Definition: test_frread.py:60
def test_read_timeseries_start_duration(instart, induration, outstart, outduration)
Definition: test_frread.py:81
def test_read_timeseries_error(inputs, message)
Definition: test_frread.py:97