Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
17## \defgroup lalpulsar_py_metric_utils Parameter Space Metric Utilities
18## \ingroup lalpulsar_python
19"""
20Utilities for working with parameter space metrics.
21"""
22
23import numpy as np
24
25
26def mismatch_ellipse(g, mu_max, tol=0.001):
27 """Return points plotting the mismatch ellipse of a metric.
28
29 :param g: Metric.
30 :param mu_max: Maximum mismatch.
31 :param tol: Tolerance in generating points to plot.
32 """
33 assert g.shape == (2, 2)
34 assert mu_max > 0
35 assert tol > 0
36
37 # starting point
38 zz = [0]
39 x = np.cos(zz[-1])
40 y = np.sin(zz[-1])
41 rr = [
42 np.sqrt(
43 mu_max / (g[0, 0] * x**2 + (g[0, 1] + g[1, 0]) * x * y + g[1, 1] * y**2)
44 )
45 ]
46 dz = 2 * np.pi / 1000
47
48 # until ellipse is complete
49 while zz[-1] < 2 * np.pi:
50
51 # next point
52 z = zz[-1] + dz
53 x = np.cos(z)
54 y = np.sin(z)
55 r = np.sqrt(
56 mu_max / (g[0, 0] * x**2 + (g[0, 1] + g[1, 0]) * x * y + g[1, 1] * y**2)
57 )
58
59 # decide if next point is well-spaced from previous point
60 e = abs(r - rr[-1]) / rr[-1]
61 if e < 0.1 * tol and 2 * np.pi / dz > 1000:
62 dz *= 1.5
63 elif e > tol:
64 dz /= 3
65 else:
66
67 # store new point
68 zz.append(z)
69 rr.append(r)
70
71 # finish back at the starting point
72 zz[-1] = zz[0]
73 rr[-1] = rr[0]
74
75 xx = rr * np.cos(zz)
76 yy = rr * np.sin(zz)
77
78 return xx, yy
def mismatch_ellipse(g, mu_max, tol=0.001)
Return points plotting the mismatch ellipse of a metric.
Definition: metric_utils.py:32