forked from gwastro/pycbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_spatmplt.py
85 lines (73 loc) · 3.41 KB
/
test_spatmplt.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
# 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")
class TestSPAtmplt(unittest.TestCase):
def setUp(self,*args):
self.context = _context
self.scheme = _scheme
def test_spatmplt(self):
fl = 25
delta_f = 1.0 / 256
for m1 in [1, 1.4, 20]:
for m2 in [1.4, 20]:
for s1 in [-2, -1, -0.5, 0, 0.5, 1, 2]:
for s2 in [-2, -1, -0.5, 0, 0.5, 1, 2]:
# Generate TaylorF2 from lalsimulation, restricting to the capabilities of spatmplt
hpr,_ = get_fd_waveform( mass1=m1, mass2=m2, spin1z=s1, spin2z=s2,
delta_f=delta_f, f_lower=fl,
approximant="TaylorF2", amplitude_order=0,
spin_order=-1, phase_order=-1)
hpr=hpr.astype(complex64)
with self.context:
# Generate the spatmplt waveform
out = zeros(len(hpr), dtype=complex64)
hp = get_waveform_filter(out, mass1=m1, mass2=m2, spin1z=s1, spin2z=s2,
delta_f=delta_f, f_lower=fl, approximant="SPAtmplt",
amplitude_order=0, spin_order=-1, phase_order=-1)
# Check the diff is sane
mag = abs(hpr).sum()
diff = abs(hp - hpr).sum() / mag
self.assertTrue(diff < 0.01)
# Point to point overlap (no phase or time maximization)
o = overlap(hp, hpr)
self.assertAlmostEqual(1.0, o, places=4)
print "checked m1: %s m2:: %s s1z: %s s2z: %s] overlap = %s, diff = %s" % (m1, m2, s1, s2, o, diff)
suite = unittest.TestSuite()
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSPAtmplt))
if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)