forked from gwastro/pycbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_waveform.py
executable file
·149 lines (130 loc) · 7.48 KB
/
test_waveform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Copyright (C) 2012 Alex Nitz, Josh Willis
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# =============================================================================
#
# Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.waveform module
"""
import sys
import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
from pycbc.filter import *
from pycbc.waveform import *
import pycbc.fft
import numpy
from numpy import sqrt, cos, sin
from utils import parse_args_all_schemes, simple_exit
_scheme, _context = parse_args_all_schemes("Waveform")
failing_wfs = ['PhenSpinTaylor', 'PhenSpinTaylorRD', 'EccentricTD',
'SpinDominatedWf', 'EOBNRv2HM_ROM', 'EOBNRv2_ROM', 'EccentricFD',
'NR_hdf5']
class TestWaveform(unittest.TestCase):
def setUp(self,*args):
self.context = _context
self.scheme = _scheme
def test_generation(self):
with self.context:
for waveform in td_approximants():
if waveform in failing_wfs:
continue
print waveform
hc,hp = get_td_waveform(approximant=waveform,mass1=20,mass2=20,delta_t=1.0/4096,f_lower=40)
self.assertTrue(len(hc)> 0)
for waveform in fd_approximants():
if waveform in failing_wfs:
continue
print waveform
htilde, g = get_fd_waveform(approximant=waveform,mass1=20,mass2=20,delta_f=1.0/256,f_lower=40)
self.assertTrue(len(htilde)> 0)
def test_spintaylorf2GPU(self):
print type(self.context)
if isinstance(self.context, CPUScheme):
return
fl = 25
delta_f = 1.0 / 256
for m1 in [3, 5, 15]:
for m2 in [1., 2., 3.]:
for s1 in [0.001, 1.0, 10]:
for s1Ctheta in [-1.,0.,0.5,1.]:
for s1phi in [0,2.09,4.18]:
for inclination in [0.2,1.2]:
s1x = s1 * sqrt(1-s1Ctheta**2) * cos(s1phi)
s1y = s1 * sqrt(1-s1Ctheta**2) * sin(s1phi)
s1z = s1 * s1Ctheta
# Generate SpinTaylorF2 from lalsimulation
hpLAL,hcLAL = get_fd_waveform( mass1=m1, mass2=m2, spin1x=s1x, spin1y=s1y,spin1z=s1z, delta_f=delta_f, f_lower=fl,approximant="SpinTaylorF2", amplitude_order=0, phase_order=7, inclination=inclination )
#Generate SpinTaylorF2 from SpinTaylorF2.py
with self.context:
hp,hc = get_fd_waveform( mass1=m1, mass2=m2, spin1x=s1x, spin1y=s1y,spin1z=s1z, delta_f=delta_f, f_lower=fl,approximant="SpinTaylorF2", amplitude_order=0, phase_order=7, inclination=inclination )
o = overlap(hpLAL, hp)
self.assertAlmostEqual(1.0, o, places=4)
o = overlap(hcLAL, hc)
self.assertAlmostEqual(1.0, o, places=4)
ampPLAL=numpy.abs(hpLAL.data)
ampP=numpy.abs(hp.data)
phasePLAL=numpy.unwrap(numpy.angle(hpLAL.data))
phaseP=numpy.unwrap(numpy.angle(hp.data))
ampCLAL=numpy.abs(hcLAL.data)
ampC=numpy.abs(hc.data)
phaseCLAL=numpy.unwrap(numpy.angle(hcLAL.data))
phaseC=numpy.unwrap(numpy.angle(hc.data))
indexampP=numpy.where( ampPLAL!= 0)
indexphaseP=numpy.where( phasePLAL!= 0)
indexampC=numpy.where( ampCLAL!= 0)
indexphaseC=numpy.where( phaseCLAL!= 0)
AmpDiffP = max(abs ( (ampP[indexampP]-ampPLAL[indexampP]) / ampPLAL[indexampP] ) )
PhaseDiffP = max(abs ( (phaseP[indexphaseP] - phasePLAL[indexphaseP]) / phasePLAL[indexphaseP] ) )
AmpDiffC = max(abs ( (ampC[indexampP]-ampCLAL[indexampP]) / ampCLAL[indexampP] ) )
PhaseDiffC = max(abs ( (phaseC[indexphaseP] - phaseCLAL[indexphaseP]) / phaseCLAL[indexphaseP] ) )
self.assertTrue(AmpDiffP < 0.00001)
self.assertTrue(PhaseDiffP < 0.00001)
self.assertTrue(AmpDiffC < 0.00001)
self.assertTrue(PhaseDiffC < 0.00001)
print "..checked m1: %s m2:: %s s1x: %s s1y: %s s1z: %s Inclination: %s" % (m1, m2, s1x, s1y, s1z, inclination)
def test_errors(self):
func = get_fd_waveform
self.assertRaises(ValueError,func,approximant="BLAH")
self.assertRaises(ValueError,func,approximant="SpinTaylorF2",mass1=3)
self.assertRaises(ValueError,func,approximant="SpinTaylorF2",mass1=3,mass2=3)
self.assertRaises(ValueError,func,approximant="SpinTaylorF2",mass1=3,mass2=3,phase_order=7)
self.assertRaises(ValueError,func,approximant="SpinTaylorF2",mass1=3,mass2=3,phase_order=7)
self.assertRaises(ValueError,func,approximant="SpinTaylorF2",mass1=3)
func = get_fd_waveform
self.assertRaises(ValueError,func,approximant="BLAH")
self.assertRaises(ValueError,func,approximant="TaylorF2",mass1=3)
self.assertRaises(ValueError,func,approximant="TaylorF2",mass1=3,mass2=3)
self.assertRaises(ValueError,func,approximant="TaylorF2",mass1=3,mass2=3,phase_order=7)
self.assertRaises(ValueError,func,approximant="TaylorF2",mass1=3,mass2=3,phase_order=7)
self.assertRaises(ValueError,func,approximant="TaylorF2",mass1=3)
for func in [get_fd_waveform,get_td_waveform]:
self.assertRaises(ValueError,func,approximant="BLAH")
self.assertRaises(ValueError,func,approximant="IMRPhenomB",mass1=3)
self.assertRaises(ValueError,func,approximant="IMRPhenomB",mass1=3,mass2=3)
self.assertRaises(ValueError,func,approximant="IMRPhenomB",mass1=3,mass2=3,phase_order=7)
self.assertRaises(ValueError,func,approximant="IMRPhenomB",mass1=3,mass2=3,phase_order=7)
self.assertRaises(ValueError,func,approximant="IMRPhenomB",mass1=3)
suite = unittest.TestSuite()
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestWaveform))
if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)