bilby/gw/detector/calibration.py: optimize spline interpolation of calibration uncertainties
Compare changes
+ 39
− 11
@@ -181,6 +181,26 @@ class CubicSpline(Recalibrate):
@@ -208,18 +228,26 @@ class CubicSpline(Recalibrate):
Maintenance will be performed on git.ligo.org, containers.ligo.org, and docs.ligo.org on Tuesday 1 April 2025 starting at approximately 9am PDT. It is expected to take around 30 minutes and there will be several periods of downtime throughout the maintenance. Please address any comments, concerns, or questions to the helpdesk.
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)