LALSimulation  5.4.0.1-89842e6
test_SEOBNRv4HM_PA.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2022 Serguei Ossokine and Deyan Mihaylov
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 
19 import sys
20 import lal
21 import numpy as np
22 import pytest
23 import lalsimulation as lalsim
24 
25 np.set_printoptions(precision=17)
26 
27 
28 
29 def get_stored_data():
30  """
31  Pre-computed data for different waveform modes,
32  in geometric units.
33  Used in the regression test of SEOBNRv4HM_PA
34 
35  Returns:
36  Dict: dictionary containing the modes
37  """
38  data = {
39  (2, 2): [
40  [
41  # 0.40689716589895747,
42  # 0.43309591538465037,
43  # 0.4721748343322336,
44  # 0.5447370783113126,
45  # 2.0023458851711906,
46  # 1.8235613978215368,
47  0.406897143874587,
48  0.43309588629164864,
49  0.4721747898690362,
50  0.5447369805430688,
51  2.0023481970562735,
52  1.8245536590453957,
53  ],
54  [
55  # -1.3969263518385833e-01,
56  # -1.5925496591368452e02,
57  # -3.3713851919667729e02,
58  # -5.4743337706169893e02,
59  # -8.7302404936234018e02,
60  # -8.7492784847230996e02,
61  -1.3968438162982541e-01,
62  -1.5925495580678407e+02,
63  -3.3713850517954216e+02,
64  -5.4743335258722220e+02,
65  -8.7301946486216650e+02,
66  -8.7492212355961533e+02,
67  ],
68  ],
69  (2, 1): [
70  [
71  # 0.0313225894843847,
72  # 0.0347815707120482,
73  # 0.04022820240989489,
74  # 0.05123839474459091,
75  # 0.7108940042712576,
76  # 0.8451123158705316,
77  0.031322421516861723,
78  0.034781337721511429,
79  0.040227835734167786,
80  0.051237617991819341,
81  0.710259630940248132,
82  0.844879838309898212,
83  ],
84  [
85  # 1.4800894807662368,
86  # -78.07974926209056,
87  # -167.0249793662184,
88  # -272.1793580797458,
89  # -435.7330365096353,
90  # -437.18207987235945,
91  1.480096232806204837e+00,
92  -7.807974106262993530e+01,
93  -1.670249682972653318e+02,
94  -2.721793395565951528e+02,
95  -4.357288791143605522e+02,
96  -4.371762545684100587e+02,
97  ],
98  ],
99  (3, 3): [
100  [
101  # 0.05111250481525122,
102  # 0.05608646181014196,
103  # 0.0637759095572762,
104  # 0.0788643477891161,
105  # 0.5769500315793753,
106  # 0.5669386351414297,
107  0.051112501745226545,
108  0.056086457627118551,
109  0.063775902886042721,
110  0.078864332055436248,
111  0.576776486652450626,
112  0.567171822083015198,
113  ],
114  [
115  # -1.7986372334622316,
116  # -240.47335889154334,
117  # -507.3014845029567,
118  # -822.7492254842681,
119  # -1311.313003009921,
120  # -1314.2554619594298,
121  -1.798624864004767732e+00,
122  -2.404733437441886679e+02,
123  -5.073014634939491430e+02,
124  -8.227491887980770571e+02,
125  -1.311305924173796029e+03,
126  -1.314246406233119387e+03
127  ],
128  ],
129  (4, 4): [
130  [
131  # 0.0094732179486535,
132  # 0.01072105034372493,
133  # 0.01272251602463651,
134  # 0.01688049604193659,
135  # 0.24798290965344766,
136  # 0.23257308477746422,
137  0.009473217127067403,
138  0.010721049156921609,
139  0.012722513984742818,
140  0.016880490682204544,
141  0.247871444279401887,
142  0.232676698120316383,
143  ],
144  [
145  # 2.84188245155912,
146  # -315.39054175943875,
147  # -671.1605084583525,
148  # -1091.7556790940084,
149  # -1743.009269177671,
150  # -1746.8685414830832,
151  2.841897673213301445e+00,
152  -3.153905230860205506e+02,
153  -6.711604824120537387e+02,
154  -1.091755633222126562e+03,
155  -1.743000212109299355e+03,
156  -1.746856853681002576e+03,
157  ],
158  ],
159  (5, 5): [
160  [
161  # 0.00189622618209567,
162  # 0.00221381745387731,
163  # 0.00274267447438163,
164  # 0.00390737715569474,
165  # 0.11379890992679738,
166  # 0.10803857266725103,
167  0.001896205803077448,
168  0.002213789075042580,
169  0.002742629541378499,
170  0.003907280821832254,
171  0.113725569203534563,
172  0.108064932141790415,
173  ],
174  [
175  # 1.1933141845843078e00,
176  # -3.9659776027206124e02,
177  # -8.4131116974703161e02,
178  # -1.3670574321591489e03,
179  # -2.1821066712187244e03,
180  # -2.1870969032147736e03,
181  1.193337715232760221e+00,
182  -3.965977315334420723e+02,
183  -8.413111302239032057e+02,
184  -1.367057364036911622e+03,
185  -2.182095223636347328e+03,
186  -2.187082823278491560e+03,
187  ],
188  ],
189  }
190  return data
191 
192 
193 rtol_amp = {(2, 2): 1e-5, (2, 1): 1e-5, (3, 3): 1e-5, (4, 4): 1e-5, (5, 5): 1e-5}
194 rtol_phase = {(2, 2): 1e-5, (2, 1): 1e-5, (3, 3): 1e-5, (4, 4): 1e-5, (5, 5): 1e-5}
195 
196 
197 def test_SEOBNRv4HMPA():
198  """
199  Test that the waveform modes of SEOBNRv4HM_PA have not changed.
200  This is done by comparing the modes directly at a set of pre-determined
201  time points that cover the inspiral, merger and RD.
202  """
203  # Note second last element is (2,2) mode peak
204 
205  # Physical params
206 
207  chi1_x, chi1_y = 0.0, 0.0
208  chi2_x, chi2_y = 0.0, 0.0
209  m1 = 8.16594601e01
210  m2 = 1.08125863e01
211  chi1_z = -7.19166988e-01
212  chi2_z = 5.67932765e-01
213  modes = [(2, 2), (2, 1), (3, 3), (4, 4), (5, 5)]
214 
215  # Note second last element is (2,2) mode peak
216  indices = [0, 54291, 108582, 162873, 217164, 217214]
217  phi_c = 0.3
218  f_start22 = 7.3 # Frequency of the 22 mode at which the signal starts
219  distance = 10000 # Irrelevant
220 
221  deltaT = 1.0 / 16384.0
222  approx = lalsim.SEOBNRv4HM_PA
223  lmax = 5
224  lal_params = lal.CreateDict()
225  # Generate the modes
226  hlm = lalsim.SimInspiralChooseTDModes(
227  phi_c,
228  deltaT,
229  m1 * lal.MSUN_SI,
230  m2 * lal.MSUN_SI,
231  chi1_x,
232  chi1_y,
233  chi1_z,
234  chi2_x,
235  chi2_y,
236  chi2_z,
237  f_start22,
238  f_start22,
239  distance,
240  lal_params,
241  lmax,
242  approx,
243  )
244  time_hI = lalsim.SphHarmTimeSeriesGetMode(hlm, 2, 2).deltaT * np.arange(
245  len(lalsim.SphHarmTimeSeriesGetMode(hlm, 2, 2).data.data)
246  )
247  hI = {}
248 
249  for lm in modes:
250  hI[lm] = lalsim.SphHarmTimeSeriesGetMode(hlm, lm[0], lm[1]).data.data
251 
252  # Compare stored to current data
253 
254  data = get_stored_data()
255 
256  for mode in modes:
257  amp = np.abs(hI[mode])[indices]
258  phase = np.unwrap(np.angle(hI[mode]))[indices]
259  amp_stored, phase_stored = data[mode]
260  # print(',\n'.join([f"{x:.18f}" for x in amp]))
261  # print(',\n'.join([f"{x:.18e}" for x in phase]))
262  np.testing.assert_allclose(amp, amp_stored, atol=0, rtol=rtol_amp[mode])
263  np.testing.assert_allclose(phase, phase_stored, atol=0, rtol=rtol_phase[mode])
264 
265 
266 if __name__ == "__main__":
267  args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-SEOBNRv4HMPA.xml"]
268  sys.exit(pytest.main(args=[__file__] + args))
def test_SEOBNRv4HMPA()
Test that the waveform modes of SEOBNRv4HM_PA have not changed.
def get_stored_data()
Pre-computed data for different waveform modes, in geometric units.