LALPulsar 7.1.1.1-eeff03c
test_metric_utils.py
Go to the documentation of this file.
1# Copyright (C) 2024 Karl Wette
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
19
20import numpy as np
21from numpy.testing import assert_allclose
22
23
25 from lalpulsar.metric_utils import mismatch_ellipse
26
27 mu_max = 0.1
28
29 with pytest.raises(AssertionError):
30 g = np.ones((3, 2))
31 xx, yy = mismatch_ellipse(g, mu_max)
32
33 g = np.array([[7, 1], [1, 1]])
34
35 with pytest.raises(AssertionError):
36 xx, yy = mismatch_ellipse(g, 0.0)
37
38 xx, yy = mismatch_ellipse(g, mu_max)
39
40 assert len(xx) == len(yy)
41
42 mu = []
43 for i in range(len(xx)):
44 xy = np.array([xx[i], yy[i]])
45 mu.append(xy @ g @ xy)
46
47 assert len(mu) == len(xx)
48
49 assert_allclose(mu, mu_max, rtol=1e-5)
50
51
52if __name__ == "__main__":
53 args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-metric_utils.xml"]
54 sys.exit(pytest.main(args=[__file__] + args))
def mismatch_ellipse(g, mu_max, tol=0.001)
Return points plotting the mismatch ellipse of a metric.
Definition: metric_utils.py:32