Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALSimulation 6.2.0.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
test_TEOBResumS.py
Go to the documentation of this file.
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2020 Michalis Agathos
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http: //www.gnu.org/licenses/>.
17
18# define required parameters for time domain and frequency domain
19# as well as their default values
20
21"""Simple test to see if TEOBResumS has changed
22
23Some functions copied from test_phenomPv3HM.py.
24"""
25
26import sys
27import pytest
28import lal
29import lalsimulation
30import numpy as np
31
32# -- utility functions ---------------------
33
35 amp = np.abs(h)
36 phase = np.unwrap(np.angle(h))
37 return amp, phase
38
39def sum_sqr_diff(x, y):
40 return np.sqrt( np.sum( (x-y)**2 ) )
41
42def gen_test_data():
43 """
44 compute the difference between two waveforms
45 and compare to expected value
46 """
47
48 common_pars=dict(
49 m1=50*lal.MSUN_SI,
50 m2=30*lal.MSUN_SI,
51 s1x=0,
52 s1y=0,
53 s1z=-0.45,
54 s2x=0,
55 s2y=0,
56 s2z=0.98,
57 distance=1,
58 inclination=0.,
59 phiRef=0.,
60 longAscNodes=0.,
61 eccentricity=0.,
62 meanPerAno=0.,
63 deltaT=1./4096.,
64 f_min=30.,
65 f_ref=30.,
66 params=None,
67 approximant=lalsimulation.TEOBResumS
68 )
69
70 pars1 = common_pars.copy()
71 pars2 = common_pars.copy()
72 pars2.update({"m2":20.*lal.MSUN_SI})
73
74 hp1, hc1 = lalsimulation.SimInspiralChooseTDWaveform(**pars1)
75 hp2, hc2 = lalsimulation.SimInspiralChooseTDWaveform(**pars2)
76
77 # compute amp and phase
78 hp1_amp, hp1_phase = get_amp_phase(hp1.data.data)
79 hc1_amp, hc1_phase = get_amp_phase(hc1.data.data)
80
81 hp2_amp, hp2_phase = get_amp_phase(hp2.data.data)
82 hc2_amp, hc2_phase = get_amp_phase(hc2.data.data)
83
84 npeak1 = np.argmax(hp1_amp)
85 npeak2 = np.argmax(hp2_amp)
86 ni = min(npeak1, npeak2)
87 no = min(hp1.data.length - npeak1, hp2.data.length - npeak2)
88
89 # Truncate and align waveforms in place w.r.t. peak
90 hp1_amp = hp1_amp[npeak1-ni:npeak1+no]
91 hc1_amp = hc1_amp[npeak1-ni:npeak1+no]
92 hp2_amp = hp2_amp[npeak2-ni:npeak2+no]
93 hc2_amp = hc2_amp[npeak2-ni:npeak2+no]
94 hp1_phase = hp1_phase[npeak1-ni:npeak1+no]
95 hc1_phase = hc1_phase[npeak1-ni:npeak1+no]
96 hp2_phase = hp2_phase[npeak2-ni:npeak2+no]
97 hc2_phase = hc2_phase[npeak2-ni:npeak2+no]
98
99 hp_amp_diff = sum_sqr_diff(hp1_amp, hp2_amp)
100 hp_phase_diff = sum_sqr_diff(hp1_phase, hp2_phase)
101
102 hc_amp_diff = sum_sqr_diff(hc1_amp, hc2_amp)
103 hc_phase_diff = sum_sqr_diff(hc1_phase, hc2_phase)
104
105 # since we want to compare decimals, we return the above quantities as 0.xxxxx..
106 # by dividing them for their order of magnitude +1
107 return hp_amp_diff/1e6, hp_phase_diff/1e3, hc_amp_diff/1e6, hc_phase_diff/1e3
108
109
110
111# -- test functions ---------------------
112
113def test_TEOBResumS():
114 """
115 This test checks that TEOBResumS hasn't changed.
116 It does this by generating two TEOBResumS waveforms and computing
117 their difference (according to their amplitude and phases)
118 and compares them to pre-computed values.
119
120 these pre-computed values were computed using the following line:
121
122 `expected_result = np.array(gen_test_data())`
123
124 """
125
126
127 expected_result = np.array([0.27385, 0.14397, 0.27356, 0.14324])
128 new_result = np.array(gen_test_data())
129 np.testing.assert_almost_equal(new_result, expected_result, 5, "TEOBResumS test failed")
130
131
132
133# -- run the tests ------------------------------
134
135if __name__ == '__main__':
136 sys.exit(pytest.main(args=[__file__] + sys.argv[1:] + ['-v']))
def sum_sqr_diff(x, y)
def test_TEOBResumS()
This test checks that TEOBResumS hasn't changed.
def gen_test_data()
compute the difference between two waveforms and compare to expected value