Skip to content
Snippets Groups Projects
Commit 59a48307 authored by Moritz Huebner's avatar Moritz Huebner
Browse files

Merge branch 'faster_roq_interpolation' into 'master'

bilby/gw/likelihood.py: speed up the spline interpolation in ROQ

See merge request !971
parents 006775f7 0cf53d21
No related branches found
No related tags found
1 merge request!971bilby/gw/likelihood.py: speed up the spline interpolation in ROQ
Pipeline #249909 failed
......@@ -1366,9 +1366,8 @@ class ROQGravitationalWaveTransient(GravitationalWaveTransient):
'i,ji->j', np.conjugate(h_plus_linear + h_cross_linear),
self.weights[interferometer.name + '_linear'][indices])
d_inner_h = interp1d(
self.weights['time_samples'][indices],
d_inner_h_tc_array, kind='cubic', assume_sorted=True)(ifo_time)
d_inner_h = self._interp_five_samples(
self.weights['time_samples'][indices], d_inner_h_tc_array, ifo_time)
optimal_snr_squared = \
np.vdot(np.abs(h_plus_quadratic + h_cross_quadratic)**2,
......@@ -1404,11 +1403,39 @@ class ROQGravitationalWaveTransient(GravitationalWaveTransient):
in_bounds: bool
Whether the indices are for valid times
"""
closest = np.argmin(abs(samples - time))
closest = int((time - samples[0]) / (samples[1] - samples[0]))
indices = [closest + ii for ii in [-2, -1, 0, 1, 2]]
in_bounds = (indices[0] >= 0) & (indices[-1] < samples.size)
return indices, in_bounds
@staticmethod
def _interp_five_samples(time_samples, values, time):
"""
Interpolate a function of time with its values at the closest five times.
The algorithm is explained in https://dcc.ligo.org/T2100224.
Parameters
==========
time_samples: array-like
Closest 5 times
values: array-like
The values of the function at closest 5 times
time: float
Time at which the function is calculated
Returns
=======
value: float
The value of the function at the input time
"""
r1 = (-values[0] + 8. * values[1] - 14. * values[2] + 8. * values[3] - values[4]) / 4.
r2 = values[2] - 2. * values[3] + values[4]
a = (time_samples[3] - time) / (time_samples[1] - time_samples[0])
b = 1. - a
c = (a**3. - a) / 6.
d = (b**3. - b) / 6.
return a * values[2] + b * values[3] + c * r1 + d * r2
def perform_roq_params_check(self, ifo=None):
""" Perform checking that the prior and data are valid for the ROQ
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment