Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALSimulation 6.2.0.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
test_phenomT.py
Go to the documentation of this file.
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2020 Hector Estelles (adapted from test_phenomX.py of Cecilio García Quiros)
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#Simple test to see if the PhenomT family models have changed: IMRPhenomT, IMRPhenomTHM, IMRPhenomTP and IMRPhenomTPHM.
19
20import sys
21import pytest
22import lal
23import lalsimulation
24import numpy as np
25
26# -- utility functions ---------------------
27
29 amp = np.abs(h)
30 phase = np.unwrap(np.angle(h))
31 return amp, phase
32
33def sum_sqr_diff(x, y):
34 return np.sqrt( np.sum( (x-y)**2 ) )
35
36def gen_test_data(spin1x, approximant, mode_array, PV, FS):
37 """
38 compute the difference between two waveforms
39 and compare to expected value
40 """
41 lalparams = lal.CreateDict()
42
43 if(mode_array!=None):
44 ModeArray = lalsimulation.SimInspiralCreateModeArray()
45 for mode in mode_array:
46 lalsimulation.SimInspiralModeArrayActivateMode(ModeArray, mode[0], mode[1])
47 lalsimulation.SimInspiralWaveformParamsInsertModeArray(lalparams, ModeArray)
48
49 if PV!=None:
50 lalsimulation.SimInspiralWaveformParamsInsertPhenomXPrecVersion(lalparams, PV)
51 if FS!=None:
52 lalsimulation.SimInspiralWaveformParamsInsertPhenomXPFinalSpinMod(lalparams, FS)
53
54 common_pars=dict(
55 m1=50*lal.MSUN_SI,
56 m2=30*lal.MSUN_SI,
57 s1x=spin1x,
58 s1y=0.,
59 s1z=0.,
60 s2x=0.,
61 s2y=0.,
62 s2z=0.,
63 distance=1,
64 inclination=np.pi/3.,
65 phiRef=0.,
66 longAscNodes=0.,
67 eccentricity=0.,
68 meanPerAno=0.,
69 deltaT=1./4096.,
70 f_min=30.,
71 f_ref=30.,
72 params=lalparams,
73 approximant=approximant
74 )
75
76 pars1=common_pars.copy()
77
78 pars2=common_pars.copy()
79 pars2.update({"inclination":0.17})
80 pars2.update({"phiRef":0.5})
81
82 hp1, hc1 = lalsimulation.SimInspiralChooseTDWaveform(**pars1)
83 hp2, hc2 = lalsimulation.SimInspiralChooseTDWaveform(**pars2)
84
85 # compute amp and phase
86 h1_amp, h1_phase = get_amp_phase(hp1.data.data - 1j * hc1.data.data)
87
88 h2_amp, h2_phase = get_amp_phase(hp2.data.data - 1j * hc2.data.data)
89
90 h_amp_diff = sum_sqr_diff(h1_amp, h2_amp)
91 h_phase_diff = sum_sqr_diff(h1_phase, h2_phase)
92
93 return h_amp_diff, h_phase_diff
94
95
96# -- test functions ---------------------
97
98def test_IMRPhenomT():
99 """
100 This test checks that IMRPhenomT hasn't changed.
101 It does this by generating two PhenomT waveforms and computing
102 their difference (according to their amplitude and phases)
103 and compares them to pre-computed values.
104
105 these pre-computed values were computed using the following line:
106
107 `expected_result = np.array(gen_test_data(0., lalsimulation.IMRPhenomT))`
108
109 """
110
111 expected_result = np.array([170742.89185874866, 38.13925592958284])
112
113 new_result = np.array(gen_test_data(0., lalsimulation.IMRPhenomT, None, None, None))
114
115 np.testing.assert_allclose(new_result, expected_result, rtol=1e-6, err_msg="IMRPhenomT test failed")
116
118 """
119 This test checks that IMRPhenomTHM hasn't changed.
120 It does this by generating two PhenomTHM waveforms and computing
121 their difference (according to their amplitude and phases)
122 and compares them to pre-computed values.
123
124 these pre-computed values were computed using the following line:
125
126 `expected_result = np.array(gen_test_data(0., lalsimulation.IMRPhenomTHM))`
127
128 """
129
130 expected_result = np.array([170645.95870333136, 200.68861022453908])
131
132 new_result = np.array(gen_test_data(0., lalsimulation.IMRPhenomTHM, None, None, None))
133
134 np.testing.assert_allclose(new_result, expected_result, rtol=1e-6, err_msg="IMRPhenomTHM test failed")
135
136def test_IMRPhenomTP():
137 """
138 This test checks that IMRPhenomTPHM hasn't changed.
139 It does this by generating two PhenomTHM waveforms and computing
140 their difference (according to their amplitude and phases)
141 and compares them to pre-computed values.
142
143 these pre-computed values were computed using the following line:
144
145 `expected_result = np.array(gen_test_data(0.5, lalsimulation.IMRPhenomTP, None, PV, FS))`
146
147 """
148
149 stored_resultsTP={None: {None: (188638.18910822965, 32.420295013783644)}}
150
151 PVs = stored_resultsTP.keys()
152
153 for PV in PVs:
154 FSs = stored_resultsTP[PV].keys()
155
156 for FS in FSs:
157 expected_result = stored_resultsTP[PV][FS]
158
159 new_result = np.array(gen_test_data(0.5, lalsimulation.IMRPhenomTP, None, PV, FS))
160
161 np.testing.assert_allclose(new_result, expected_result, rtol=2e-3, err_msg="IMRPhenomTP test failed")
162
163
165 """
166 This test checks that IMRPhenomTPHM hasn't changed.
167 It does this by generating two PhenomTHM waveforms and computing
168 their difference (according to their amplitude and phases)
169 and compares them to pre-computed values.
170
171 these pre-computed values were computed using the following line:
172
173 `expected_result = np.array(gen_test_data(0.5, lalsimulation.IMRPhenomTPHM, None, PV, FS))`
174
175 """
176
177 stored_resultsTPHM={None: {None: (189109.04099927619, 207.74817055168765)}}
178
179 PVs = stored_resultsTPHM.keys()
180
181 for PV in PVs:
182 FSs = stored_resultsTPHM[PV].keys()
183
184 for FS in FSs:
185 expected_result = stored_resultsTPHM[PV][FS]
186
187 new_result = np.array(gen_test_data(0.5, lalsimulation.IMRPhenomTPHM, None, PV, FS))
188
189 np.testing.assert_allclose(new_result, expected_result, rtol=1e-4, err_msg="IMRPhenomTPHM test failed")
190
191
192if __name__ == '__main__':
193 args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-phenomT.xml"]
194 sys.exit(pytest.main(args=[__file__] + args))
def test_IMRPhenomT()
This test checks that IMRPhenomT hasn't changed.
def get_amp_phase(h)
Definition: test_phenomT.py:28
def sum_sqr_diff(x, y)
Definition: test_phenomT.py:33
def test_IMRPhenomTP()
This test checks that IMRPhenomTPHM hasn't changed.
def gen_test_data(spin1x, approximant, mode_array, PV, FS)
compute the difference between two waveforms and compare to expected value
Definition: test_phenomT.py:40
def test_IMRPhenomTPHM()
This test checks that IMRPhenomTPHM hasn't changed.
def test_IMRPhenomTHM()
This test checks that IMRPhenomTHM hasn't changed.