From 07d5c09aa5eaab7c60c8d17401959e38e4bb5a19 Mon Sep 17 00:00:00 2001 From: owinter Date: Fri, 21 Jun 2024 17:10:07 +0100 Subject: [PATCH] add test on the sync timestamps linear option --- setup.py | 2 +- src/ibldsp/utils.py | 2 +- src/tests/unit/cpu/test_ibldsp.py | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index e7a717c..82bfea3 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name="ibl-neuropixel", - version="1.1.0a", + version="1.1.0a01", author="The International Brain Laboratory", description="Collection of tools for Neuropixel 1.0 and 2.0 probes data", long_description=long_description, diff --git a/src/ibldsp/utils.py b/src/ibldsp/utils.py index c890f28..1b96b6b 100644 --- a/src/ibldsp/utils.py +++ b/src/ibldsp/utils.py @@ -26,7 +26,7 @@ def _interp_fcn(tsa, tsb, ib, linear=linear): ab = np.polyfit(tsa[ib >= 0], tsb[ib[ib >= 0]] - tsa[ib >= 0], 1) drift_ppm = ab[0] * 1e6 if linear: - fcn_a2b = lambda x: x * ab[0] + ab[1] # noqa + fcn_a2b = lambda x: x * (1 + ab[0]) + ab[1] # noqa else: fcn_a2b = scipy.interpolate.interp1d( tsa[ib >= 0], tsb[ib[ib >= 0]], fill_value="extrapolate" diff --git a/src/tests/unit/cpu/test_ibldsp.py b/src/tests/unit/cpu/test_ibldsp.py index 5b4ab9b..e1d8c88 100644 --- a/src/tests/unit/cpu/test_ibldsp.py +++ b/src/tests/unit/cpu/test_ibldsp.py @@ -18,7 +18,15 @@ class TestSyncTimestamps(unittest.TestCase): - def test_timestamps_lin(self): + + def test_sync_timestamps_linear(self): + ta = np.cumsum(np.abs(np.random.randn(100))) * 10 + tb = ta * 1.0001 + 100 + fcn, drif, ia, ib = utils.sync_timestamps(ta, tb, return_indices=True, linear=True) + np.testing.assert_almost_equal(drif, 100) + np.testing.assert_almost_equal(tb, fcn(ta)) + + def test_timestamps(self): np.random.seed(4132) n = 50 drift = 17.14