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_spintaylor_evolveorbit.py
Go to the documentation of this file.
1# Copyright (C) 2021 Riccardo Sturani
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http: //www.gnu.org/licenses/>.
15
16"""Regression tests for the SimInspiralSpinTaylorOrbitalDriver() function of
17lalsimulation/src/LALSimInspiralSpinTaylor.c.
18"""
19
20import sys
21
22from pathlib import Path
23
24import numpy as np
25
26import pytest
27
28import lal
29import lalsimulation as lalsim
30
31DEFAULT_FILE = Path(__file__).parent / 'reviewed_evolveorbit.ini'
32NEW_DATA_STR = '######### NEW DATASET #############'
33
34
35def _format_dataset(dataset):
36 parameters = dataset['parameters']
37 spindata = dataset['spin-data']
38 dataset = (
39 parameters,
40 (spindata["spin1x"], spindata["spin1y"], spindata["spin1z"]),
41 (spindata["spin2x"], spindata["spin2y"], spindata["spin2z"]),
42 )
43 try:
44 return pytest.param(*dataset, id=parameters['approximant'])
45 except AttributeError: # pytest < 3.1.0
46 return dataset
47
49 with open(str(filename), "r") as file:
50 dataset = {}
51 for line in map(str.strip, file):
52 if not line:
53 continue
54 if line == NEW_DATA_STR:
55 if dataset: # emit the dataset
56 yield _format_dataset(dataset)
57 dataset = {}
58 # parse new section header
59 elif line.startswith("["):
60 section = line.strip("[]")
61 dataset[section] = {}
62 # parse data
63 else:
64 (key, val) = map(str.strip, line.split('=', 1))
65 if section == "spin-data":
66 val = np.fromstring(val, dtype=float, sep=" ")
67 dataset[section][key] = val
68 # emit the last dataset
69 yield _format_dataset(dataset)
70
71
72@pytest.mark.parametrize(
73 ("pars", "S1", "S2"),
74 iter_datasets_from_config(DEFAULT_FILE),
75)
76def test_spintaylor_pnevolveorbit(pars, S1, S2):
77 """Regression test for lalsim.SimInspiralSpinTaylorPNEvolveOrbit.
78 """
79 # Fixed parameters read from reviewed_evolveorbit.ini generated by GenerateOrbitalReference.py
80 lal_pars = lal.CreateDict()
81 lalsim.SimInspiralWaveformParamsInsertPNPhaseOrder(lal_pars, int(pars["phaseO"]))
82 lalsim.SimInspiralWaveformParamsInsertPNSpinOrder(lal_pars, int(pars["spinO"]))
83 lalsim.SimInspiralWaveformParamsInsertPNTidalOrder(lal_pars, int(pars["tidalO"]))
84
85 approx = lalsim.SimInspiralGetApproximantFromString(pars['approximant'])
86 out = lalsim.SimInspiralSpinTaylorOrbitalDriver(
87 float(pars['phiref']),
88 float(pars['deltaT']),
89 float(pars['m1']) * lal.MSUN_SI,
90 float(pars['m2']) * lal.MSUN_SI,
91 float(pars['fstart']),
92 float(pars['fref']),
93 float(pars['s1x']),
94 float(pars['s1y']),
95 float(pars['s1z']),
96 float(pars['s2x']),
97 float(pars['s2y']),
98 float(pars['s2z']),
99 float(pars['lnhatx']),
100 float(pars['lnhaty']),
101 float(pars['lnhatz']),
102 float(pars['e1x']),
103 float(pars['e1y']),
104 float(pars['e1z']),
105 lal_pars,
106 approx,
107 )
108 spin1out = out[2:5]
109 spin2out = out[5:8]
110
111 for spinin, spinout in (
112 (S1, spin1out),
113 (S2, spin2out),
114 ):
115 for i in range(3):
116 np.testing.assert_allclose(
117 spinout[i].data.data,
118 spinin[i],
119 err_msg="{} test failed.".format(approx),
120 rtol=1e-7,
121 )
122
123
124if __name__ == '__main__':
125 args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-spintaylor-evolveorbit.xml"]
126 sys.exit(pytest.main(args=[__file__] + args))
def test_spintaylor_pnevolveorbit(pars, S1, S2)
Regression test for lalsim.SimInspiralSpinTaylorPNEvolveOrbit.