Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALSimulation 6.2.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
test_SEOBNRv5_ROM_NRTidalv3.py
Go to the documentation of this file.
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2024 Adrian Abac
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"""
19Simple test to see if SEOBNRv5_ROM_NRTidalv3 have changed
20Adapted from test_SEOBNRv5HM_ROM.py.
21"""
22
23import sys, os
24import warnings
25try:
26 from pathlib import Path
27except ImportError as exc:
28 import warnings
29 warnings.warn(str(exc))
30 sys.exit(77)
31
32import pytest
33import lal
34import lalsimulation
35import numpy as np
36
37# -- utility functions ---------------------
38
40 amp = np.abs(h)
41 phase = np.unwrap(np.angle(h))
42 return amp, phase
43
44def sum_sqr_diff(x, y):
45 return np.sqrt( np.sum( (x-y)**2 ) )
46
47def gen_test_data(approximant):
48 """
49 compute the difference between two waveforms
50 and compare to expected value
51 """
52
53 LALparams = lal.CreateDict()
54 lambda1 = 400.0
55 lambda2 = 600.0
56 lalsimulation.SimInspiralWaveformParamsInsertTidalLambda1(LALparams, lambda1)
57 lalsimulation.SimInspiralWaveformParamsInsertTidalLambda2(LALparams, lambda2)
58 common_pars=dict(
59 m1=1.4*lal.MSUN_SI,
60 m2=1.2*lal.MSUN_SI,
61 S1x=0,
62 S1y=0,
63 S1z=-0.45,
64 S2x=0,
65 S2y=0,
66 S2z=0.98,
67 distance=1,
68 inclination=0.,
69 phiRef=0.,
70 longAscNodes=0.,
71 eccentricity=0.,
72 meanPerAno=0.,
73 deltaF=1./4.,
74 f_min=30.,
75 f_max=512.,
76 f_ref=30.,
77 LALpars=LALparams,
78 approximant=approximant
79 )
80
81 pars1 = common_pars.copy()
82
83 pars2 = common_pars.copy()
84 pars2.update({"m2":1.0*lal.MSUN_SI})
85 hp1, hc1 = lalsimulation.SimInspiralChooseFDWaveform(**pars1)
86 hp2, hc2 = lalsimulation.SimInspiralChooseFDWaveform(**pars2)
87
88 # compute amp and phase
89 hp1_amp, hp1_phase = get_amp_phase(hp1.data.data)
90 hc1_amp, hc1_phase = get_amp_phase(hc1.data.data)
91
92 hp2_amp, hp2_phase = get_amp_phase(hp2.data.data)
93 hc2_amp, hc2_phase = get_amp_phase(hc2.data.data)
94
95 hp_amp_diff = sum_sqr_diff(hp1_amp, hp2_amp)
96 hp_phase_diff = sum_sqr_diff(hp1_phase, hp2_phase)
97
98 hc_amp_diff = sum_sqr_diff(hc1_amp, hc2_amp)
99 hc_phase_diff = sum_sqr_diff(hc1_phase, hc2_phase)
100
101 return hp_amp_diff, hp_phase_diff, hc_amp_diff, hc_phase_diff
102
103
104
105# -- test functions ---------------------
106
107@pytest.mark.skipif(
108 "LAL_DATA_PATH" not in os.environ,
109 reason="LAL_DATA_PATH not found",
110)
112 """
113 This test checks that SEOBNRv5_ROM_NRTidalv3 hasn't changed.
114 It does this by generating two SEOBNRv5_ROM_NRTidalv3 waveforms and computing
115 their difference (according to their amplitude and phases)
116 and compares them to pre-computed values.
117
118 these pre-computed values were computed using the following line:
119
120 `expected_result = np.array(gen_test_data(lalsimulation.SEOBNRv5_ROM_NRTidalv3))`
121 """
122 LAL_DATA_PATH = os.environ['LAL_DATA_PATH']
123 for D in LAL_DATA_PATH.split(':'):
124 path = Path(D) / "SEOBNRv5ROM_v1.0.hdf5"
125 if path.is_file():
126 have_ROM_data_file = True
127 break
128 else:
129 pytest.skip(
130 "SEOBNRv5ROM_v1.0.hdf5 not found in $LAL_DATA_PATH:{}".format(LAL_DATA_PATH),
131 )
132
133 expected_result = np.array([35.01601891, 1112.2071495, 35.01601891, 1112.0829081])
134 new_result = np.array(gen_test_data(lalsimulation.SEOBNRv5_ROM_NRTidalv3))
135 np.testing.assert_almost_equal(new_result, expected_result, 7, "SEOBNRv5ROM_NRTidalv3 test failed")
136
137#-- run the tests ------------------------------
138
139if __name__ == '__main__':
140 if "LAL_DATA_PATH" not in os.environ:
141 warnings.warn("LAL_DATA_PATH not found, cannot execute tests")
142 sys.exit(77)
143 args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-SEOBNRv5_ROM_NRTidalv3.xml"]
144 sys.exit(pytest.main(args=[__file__] + args))
def gen_test_data(approximant)
compute the difference between two waveforms and compare to expected value
def test_SEOBNRv5_ROM_NRTidalv3()
This test checks that SEOBNRv5_ROM_NRTidalv3 hasn't changed.