-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtests.py
132 lines (102 loc) · 3.53 KB
/
tests.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
import numpy as np
from pycbc.waveform import (
get_fd_det_waveform,
get_fd_det_waveform_sequence,
get_waveform_filter_length_in_time,
)
import pytest
@pytest.fixture(params=["BBHX_PhenomD", "BBHX_PhenomHM"])
def approximant(request):
return request.param
@pytest.fixture(params=["LISA", "SSB"])
def ref_frame(request):
return request.param
@pytest.fixture(params=["1.5", "2.0"])
def tdi(request):
return request.param
@pytest.fixture()
def params():
params = {}
params["approximant"] = "BBHX_PhenomHM"
params["tdi"] = 1.5
params["ref_frame"] = "LISA"
params["ifos"] = ["LISA_A", "LISA_E", "LISA_T"]
params["coa_phase"] = 0.0
params["mass1"] = 1e6
params["mass2"] = 8e5
params["spin1z"] = 0.0
params["spin2z"] = 0.0
params["distance"] = 410
params["inclination"] = np.pi / 2
params["t_obs_start"] = 31536000
params["delta_f"] = 1.0 / params["t_obs_start"]
params["f_lower"] = 1e-4
params["f_ref"] = 8e-4
params["f_final"] = 0.1
params["delta_t"] = 1 / 0.2
params["t_offset"] = 9206958.120016199
params["tc"] = 4799624.274911478
params["eclipticlongitude"] = 0.5
params["eclipticlatitude"] = 0.23
params["polarization"] = 0.1
return params
def test_get_fd_det_waveform(params, ref_frame, approximant, tdi):
params["tdi"] = tdi
params["ref_frame"] = ref_frame
params["approximant"] = approximant
wf = get_fd_det_waveform(**params)
# Check all 3 ifos are returned
assert len(wf) == 3
def test_get_fd_det_waveform_sequence(params, approximant, tdi):
params["ifos"] = "LISA_A"
params["tdi"] = tdi
params["approximant"] = approximant
freqs = np.array([1-4, 1e-3, 1e-2])
wf = get_fd_det_waveform_sequence(sample_points=freqs, **params)
# Check all 3 ifos are returned
assert len(wf) == 1
assert len(wf["LISA_A"]) == len(freqs)
@pytest.mark.parametrize("mode_array", [None, [(3, 3)], [(2, 2), (3, 3)]])
def test_phenomhm_mode_array(params, mode_array):
params["approximant"] = "BBHX_PhenomHM"
params["mode_array"] = mode_array
wf = get_fd_det_waveform(**params)
assert len(wf) == 3
@pytest.mark.parametrize("cache_generator", [False, True])
def test_cache_generator(params, cache_generator):
from BBHX_Phenom import cached_get_waveform_genner
# Clear cache for these tests
cached_get_waveform_genner.cache_clear()
params["approximant"] = "BBHX_PhenomD"
params["cache_generator"] = cache_generator
params["mf_min"] = None
# Build cache if using it
get_fd_det_waveform(**params)
n_calls = 2
for _ in range(n_calls):
get_fd_det_waveform(**params)
cache_info = cached_get_waveform_genner.cache_info()
if cache_generator:
assert cache_info.hits == n_calls
else:
assert cache_info.hits == 0
def test_cache_generator_mf_min(params):
from BBHX_Phenom import cached_get_waveform_genner
# Clear cache for these tests
cached_get_waveform_genner.cache_clear()
params["approximant"] = "BBHX_PhenomD"
params["cache_generator"] = True
params["mf_min"] = 1e-4
masses = [2e6, 3e6]
# Build cache
get_fd_det_waveform(**params)
for m in masses:
params["mass1"] = m
get_fd_det_waveform(**params)
cache_info = cached_get_waveform_genner.cache_info()
assert cache_info.hits == len(masses)
def test_length_in_time(params, approximant):
params["approximant"] = approximant
# print(params)
duration = get_waveform_filter_length_in_time(**params)
assert duration > 0