Skip to content

bilby/gw/detector/calibration.py: optimize spline interpolation of calibration uncertainties

Soichiro Morisaki requested to merge soichiro/bilby:rapid_spline_cal into master

Optimize spline interpolation of calibration uncertainties utilizing formula applicable when spline nodes are evenly spaced. This is similar to the improvement made for ROQ weights in !971 (merged).

Below is a test script used for testing this change:

from bilby.gw.detector.calibration import CubicSpline
import numpy as np

n_points = 10
flow, fhigh = 20., 2048.
prefix = "recalib_H1_"

frequencies = np.linspace(flow, fhigh, 100)

parameters = {}
for i in range(n_points):
    parameters[f"{prefix}amplitude_{i}"] = np.random.uniform(-0.1, 0.1)
    parameters[f"{prefix}phase_{i}"] = np.random.uniform(-0.1 * np.pi, 0.1 * np.pi)

calobj1 = CubicSpline(prefix, flow, fhigh, n_points)
calobj2 = CubicSplineNew(prefix, flow, fhigh, n_points)

Below are results:

In:
np.max(np.abs(
    calobj1.get_calibration_factor(frequencies, **parameters) -
    calobj2.get_calibration_factor(frequencies, **parameters)
))

Out:
3.619316683849706e-15  

In: 
%%timeit -n 100
calobj1.get_calibration_factor(frequencies, **parameters)  

Out: 
585 µs ± 106 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)  

In:
%%timeit -n 100
calobj2.get_calibration_factor(frequencies, **parameters)  

Out:  
101 µs ± 23.5 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)  
Edited by Soichiro Morisaki

Merge request reports