Coverage for pesummary/tests/calibration_test.py: 39.5%
38 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-12-09 22:34 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-12-09 22:34 +0000
1# Licensed under an MIT style license -- see LICENSE.md
3from pesummary.gw.file.calibration import CalibrationDict, Calibration
4import numpy as np
5import os
6import shutil
7import tempfile
9tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name
11__author__ = ["Charlie Hoy <charlie.hoy@ligo.org>"]
14class TestCalibrationDict(object):
15 """Test that the CalibrationDict works as expected
16 """
17 def setup_method(self):
18 """Setup the testing class
19 """
20 self.calibration_data = {
21 "H1": [[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
22 [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6]],
23 "L1": [[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
24 [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6]],
25 }
27 def test_initiate(self):
28 """Test that the PSDDict class can be initalized correctly
29 """
30 cal_dict = CalibrationDict(
31 self.calibration_data.keys(), self.calibration_data.values()
32 )
33 assert sorted(list(cal_dict.detectors)) == ["H1", "L1"]
34 assert isinstance(cal_dict["H1"], Calibration)
35 np.testing.assert_almost_equal(
36 cal_dict["H1"].frequencies, [0, 0.0]
37 )
38 np.testing.assert_almost_equal(
39 cal_dict["L1"].phase_upper, [0.6, 0.6]
40 )
42 cal_dict = CalibrationDict(self.calibration_data)
43 assert sorted(list(cal_dict.detectors)) == ["H1", "L1"]
44 assert isinstance(cal_dict["H1"], Calibration)
45 np.testing.assert_almost_equal(
46 cal_dict["H1"].frequencies, [0, 0.0]
47 )
48 np.testing.assert_almost_equal(
49 cal_dict["L1"].phase_upper, [0.6, 0.6]
50 )
53class TestCalibration(object):
54 """Test the Calibration class
55 """
56 def setup_method(self):
57 """Setup the testing class
58 """
59 self.obj = Calibration([[1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7]])
60 if not os.path.isdir(tmpdir):
61 os.mkdir(tmpdir)
63 def teardown_method(self):
64 """Remove all files and directories created from this class
65 """
66 if os.path.isdir(tmpdir):
67 shutil.rmtree(tmpdir)
69 def test_save_to_file(self):
70 """Test the save to file method
71 """
72 self.obj.save_to_file("{}/test.dat".format(tmpdir))
73 data = np.genfromtxt("{}/test.dat".format(tmpdir))
74 np.testing.assert_almost_equal(data.T[0], [1, 1])
75 np.testing.assert_almost_equal(data.T[1], [2, 2])
77 def test_invalid_input(self):
78 """Test that the appropiate error is raised if the input is wrong
79 """
80 import pytest
82 with pytest.raises(IndexError):
83 obj = Calibration([10, 10])