-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwferrors.py
More file actions
325 lines (285 loc) · 14.2 KB
/
wferrors.py
File metadata and controls
325 lines (285 loc) · 14.2 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import pycbc
import numpy
from pycbc import waveform
from scipy.interpolate import CubicSpline
def amplitude_phase_modification_fd(**kwds):
"""
This function applies the Amplitude-Phase modification, described in
Kumar, Melching, Ohme (2025), to the base waveform approximant in
frequency domain.
Input in kwds:
error_in_phase: 'relative' or 'absolute'
This argument specify the type of errors to be
applied.
baseline_approximant: FD approximant of the reference waveform model to
modified.
modification_type: 'cubic_spline', 'cubic_spline_nodes', or 'constant_shift'
'cubic_spline': If this option is passed, the dictionary should
includes array of delta_amplitude, delta_phase, and nodal_points
'cubic_spline_nodes': When we specify this modification_type, the lower
and upper limits of the frequency should be given along with number
of nodal points to use.
'constant_shift': This option is for the simplest case where there is no
frequency dependence of the parameters delta_amplitue and delta_phase.
We apply same delta_amplitude and delta_phase for all the frequencies.
Output:
h_plus, h_cross
"""
if kwds['error_in_phase'] not in ['relative', 'absolute']:
raise ValueError(
'Only two types of errors are supported, `\'relative\' and `\'absolute\'`.'
)
# Baseline WF parameters
baseline_wf_params = kwds.copy()
baseline_wf_params['approximant'] = kwds['baseline_approximant']
hp, hc = waveform.get_fd_waveform(baseline_wf_params)
dict_waveform_modification = kwds
if dict_waveform_modification['modification_type'] == 'cubic_spline':
wf_nodal_points = dict_waveform_modification['nodal_points']
delta_amplitude_arr = dict_waveform_modification['delta_amplitude']
delta_phase_arr = dict_waveform_modification['delta_phase']
delta_amplitude_interp = CubicSpline(wf_nodal_points, delta_amplitude_arr)
delta_phase_interp = CubicSpline(wf_nodal_points, delta_phase_arr)
# Calculating amplitude and phase in base WF model and modifying
# Plus and Cross Polarization
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (
1 + delta_amplitude_interp(hp.sample_frequencies)
)
Am_cross = waveform.amplitude_from_frequencyseries(hc) * (
1 + delta_amplitude_interp(hc.sample_frequencies)
)
if dict_waveform_modification['error_in_phase'] == 'relative':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) * (1 + delta_phase_interp(hp.sample_frequencies))
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) * (1 + delta_phase_interp(hc.sample_frequencies))
elif dict_waveform_modification['error_in_phase'] == 'absolute':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) + delta_phase_interp(hp.sample_frequencies)
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) + delta_phase_interp(hc.sample_frequencies)
elif dict_waveform_modification['modification_type'] == 'constant_shift':
delta_amplitude = dict_waveform_modification['delta_amplitude']
delta_phase = dict_waveform_modification['delta_phase']
# Calculating amplitude and phase in base WF model and modifying
# Plus and Cross Polarization
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (1 + delta_amplitude)
Am_cross = waveform.amplitude_from_frequencyseries(hc) * (1 + delta_amplitude)
if dict_waveform_modification['error_in_phase'] == 'relative':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) * (1 + delta_phase)
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) * (1 + delta_phase)
elif dict_waveform_modification['error_in_phase'] == 'absolute':
Ph_plus = (
waveform.phase_from_frequencyseries(hp, remove_start_phase=False)
+ delta_phase
)
Ph_cross = (
waveform.phase_from_frequencyseries(hc, remove_start_phase=False)
+ delta_phase
)
elif dict_waveform_modification['modification_type'] == 'cubic_spline_nodes':
f_lower = dict_waveform_modification.get(
'f_lower_wferror', default=dict_waveform_modification['f_lower']
)
f_high_wferror = dict_waveform_modification['f_high_wferror']
n_nodes_wferror = int(dict_waveform_modification['n_nodes_wferror'])
wf_nodal_points = numpy.logspace(
numpy.log10(f_lower), numpy.log10(f_high_wferror), n_nodes_wferror
)
delta_amplitude_arr = numpy.hstack(
[
dict_waveform_modification['wferror_amplitude_{}'.format(i)]
for i in range(len(wf_nodal_points))
]
)
delta_phase_arr = numpy.hstack(
[
dict_waveform_modification['wferror_phase_{}'.format(i)]
for i in range(len(wf_nodal_points))
]
)
delta_amplitude_interp = CubicSpline(wf_nodal_points, delta_amplitude_arr)
delta_phase_interp = CubicSpline(wf_nodal_points, delta_phase_arr)
# Calculating amplitude and phase in base WF model and modifying
# Plus and Cross Polarization
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (
1 + delta_amplitude_interp(hp.sample_frequencies)
)
Am_cross = waveform.amplitude_from_frequencyseries(hc) * (
1 + delta_amplitude_interp(hc.sample_frequencies)
)
if dict_waveform_modification['error_in_phase'] == 'relative':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) * (1 + delta_phase_interp(hp.sample_frequencies))
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) * (1 + delta_phase_interp(hc.sample_frequencies))
elif dict_waveform_modification['error_in_phase'] == 'absolute':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) + delta_phase_interp(hp.sample_frequencies)
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) + delta_phase_interp(hc.sample_frequencies)
else:
raise TypeError("Currently, No other modification are supported")
# Applying the correction in base model.
hp.data = numpy.vectorize(complex)(
Am_plus * numpy.cos(Ph_plus), Am_plus * numpy.sin(Ph_plus)
)
hc.data = numpy.vectorize(complex)(
Am_cross * numpy.cos(Ph_cross), Am_cross * numpy.sin(Ph_cross)
)
return hp, hc
def amplitude_phase_modification_both_polarization_fd(**kwds):
"""Modify amplitude and phase of waveform polarizations in frequency domain."""
# Baseline waveform parameters
baseline_wf_params = kwds.copy()
baseline_wf_params['approximant'] = kwds['baseline_approximant']
hp, hc = waveform.get_fd_waveform(baseline_wf_params)
dict_waveform_modification = kwds.copy()
modification_type = dict_waveform_modification['modification_type']
if modification_type == 'cubic_spline':
wf_nodal_points = dict_waveform_modification['nodal_points']
delta_amplitude_plus_arr = dict_waveform_modification['delta_amplitude_plus']
delta_phase_plus_arr = dict_waveform_modification['delta_phase_plus']
delta_amplitude_plus_interp = CubicSpline(
wf_nodal_points, delta_amplitude_plus_arr
)
delta_phase_plus_interp = CubicSpline(wf_nodal_points, delta_phase_plus_arr)
delta_amplitude_cross_arr = dict_waveform_modification['delta_amplitude_cross']
delta_phase_cross_arr = dict_waveform_modification['delta_phase_cross']
delta_amplitude_cross_interp = CubicSpline(
wf_nodal_points, delta_amplitude_cross_arr
)
delta_phase_cross_interp = CubicSpline(wf_nodal_points, delta_phase_cross_arr)
# Modify amplitude and phase for Plus and Cross polarization
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (
1 + delta_amplitude_plus_interp(hp.sample_frequencies)
)
Am_cross = waveform.amplitude_from_frequencyseries(hc) * (
1 + delta_amplitude_cross_interp(hc.sample_frequencies)
)
if dict_waveform_modification['error_in_phase'] == 'relative':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) * (1 + delta_phase_plus_interp(hp.sample_frequencies))
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) * (1 + delta_phase_cross_interp(hc.sample_frequencies))
elif dict_waveform_modification['error_in_phase'] == 'absolute':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) + delta_phase_plus_interp(hp.sample_frequencies)
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) + delta_phase_cross_interp(hc.sample_frequencies)
elif modification_type == 'constant_shift':
delta_amplitude_plus = dict_waveform_modification['delta_amplitude_plus']
delta_phase_plus = dict_waveform_modification['delta_phase_plus']
delta_amplitude_cross = dict_waveform_modification['delta_amplitude_cross']
delta_phase_cross = dict_waveform_modification['delta_phase_cross']
# Modify amplitude and phase for Plus and Cross polarization
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (
1 + delta_amplitude_plus
)
Am_cross = waveform.amplitude_from_frequencyseries(hc) * (
1 + delta_amplitude_cross
)
if dict_waveform_modification['error_in_phase'] == 'relative':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) * (1 + delta_phase_plus)
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) * (1 + delta_phase_cross)
elif dict_waveform_modification['error_in_phase'] == 'absolute':
Ph_plus = (
waveform.phase_from_frequencyseries(hp, remove_start_phase=False)
+ delta_phase_plus
)
Ph_cross = (
waveform.phase_from_frequencyseries(hc, remove_start_phase=False)
+ delta_phase_cross
)
elif modification_type == 'cubic_spline_nodes':
f_lower = dict_waveform_modification.get(
'f_lower_wferror', default=dict_waveform_modification['f_lower']
)
f_high_wferror = dict_waveform_modification['f_high_wferror']
n_nodes_wferror = int(dict_waveform_modification['n_nodes_wferror'])
wf_nodal_points = numpy.logspace(
numpy.log10(f_lower), numpy.log10(f_high_wferror), n_nodes_wferror
)
delta_amplitude_plus_arr = numpy.hstack(
[
dict_waveform_modification[f'wferror_amplitude_plus_{i}']
for i in range(len(wf_nodal_points))
]
)
delta_phase_plus_arr = numpy.hstack(
[
dict_waveform_modification[f'wferror_phase_plus_{i}']
for i in range(len(wf_nodal_points))
]
)
delta_amplitude_cross_arr = numpy.hstack(
[
dict_waveform_modification[f'wferror_amplitude_cross_{i}']
for i in range(len(wf_nodal_points))
]
)
delta_phase_cross_arr = numpy.hstack(
[
dict_waveform_modification[f'wferror_phase_cross_{i}']
for i in range(len(wf_nodal_points))
]
)
delta_amplitude_plus_interp = CubicSpline(
wf_nodal_points, delta_amplitude_plus_arr
)
delta_phase_plus_interp = CubicSpline(wf_nodal_points, delta_phase_plus_arr)
delta_amplitude_cross_interp = CubicSpline(
wf_nodal_points, delta_amplitude_cross_arr
)
delta_phase_cross_interp = CubicSpline(wf_nodal_points, delta_phase_cross_arr)
# Modify amplitude and phase for Plus and Cross polarization
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (
1 + delta_amplitude_plus_interp(hp.sample_frequencies)
)
Am_cross = waveform.amplitude_from_frequencyseries(hc) * (
1 + delta_amplitude_cross_interp(hc.sample_frequencies)
)
if dict_waveform_modification['error_in_phase'] == 'relative':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) * (1 + delta_phase_plus_interp(hp.sample_frequencies))
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) * (1 + delta_phase_cross_interp(hc.sample_frequencies))
elif dict_waveform_modification['error_in_phase'] == 'absolute':
Ph_plus = waveform.phase_from_frequencyseries(
hp, remove_start_phase=False
) + delta_phase_plus_interp(hp.sample_frequencies)
Ph_cross = waveform.phase_from_frequencyseries(
hc, remove_start_phase=False
) + delta_phase_cross_interp(hc.sample_frequencies)
else:
raise TypeError("Currently, no other modification are supported")
# Apply the correction to the base model
hp.data = numpy.vectorize(complex)(
Am_plus * numpy.cos(Ph_plus), Am_plus * numpy.sin(Ph_plus)
)
hc.data = numpy.vectorize(complex)(
Am_cross * numpy.cos(Ph_cross), Am_cross * numpy.sin(Ph_cross)
)
return hp, hc