Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
test_series.py
Go to the documentation of this file.
1# Copyright (C) 2019 Duncan Macleod
2# Copyright (C) 2025 Leo Singer
3#
4# This program is free software; you can redistribute it and/or modify it
5# under the terms of the GNU General Public License as published by the
6# Free Software Foundation; either version 2 of the License, or (at your
7# option) any later version.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12# Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18"""Tests for lal.series"""
19
20import io
21import sys
22
23import igwn_ligolw.ligolw
24import igwn_ligolw.utils
25import numpy as np
26import pytest
27
28import lal.series
29
30
31@pytest.mark.parametrize(
32 "scalar_type", ["REAL4", "REAL8", "COMPLEX8", "COMPLEX16"]
33)
34@pytest.mark.parametrize("domain", ["Frequency", "Time"])
35@pytest.mark.parametrize(
36 "encoding,assert_array_equal",
37 [
38 ["Text", np.testing.assert_array_almost_equal],
39 ["base64", np.testing.assert_array_equal]
40 ]
41)
42def test_build_series(scalar_type, domain, encoding, assert_array_equal):
43 class_name = f"{scalar_type}{domain}Series"
44 build_series = getattr(lal.series, f"build_{class_name}")
45 parse_series = getattr(lal.series, f"parse_{class_name}")
46 create_series = getattr(lal, f"Create{class_name}")
47
48 series = create_series(
49 "name", lal.LIGOTimeGPS(3141, 59), 42.0, 2.5, lal.KiloGramUnit, 1234)
50 series.data.data = np.random.uniform(size=series.data.data.shape)
51
52 fileobj = io.BytesIO()
53 xmldoc = igwn_ligolw.ligolw.Document()
54 xmldoc.appendChild(
55 build_series(series, comment="This is a comment", encoding=encoding))
56 igwn_ligolw.utils.write_fileobj(xmldoc, fileobj)
57 print(fileobj.getvalue())
58 xml_str = fileobj.getvalue().decode()
59 assert f'Encoding="{encoding}' in xml_str
60 assert "This is a comment" in xml_str
61
62 fileobj.seek(0)
63 xmldoc = igwn_ligolw.utils.load_fileobj(fileobj)
64 new_series = parse_series(xmldoc)
65 assert new_series.name == series.name
66 assert new_series.f0 == series.f0
67 assert_array_equal(new_series.data.data, series.data.data)
68
69
70if __name__ == '__main__':
71 args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-test-series.xml"]
72 sys.exit(pytest.main(args=[__file__] + args))
def test_build_series(scalar_type, domain, encoding, assert_array_equal)
Definition: test_series.py:42