From 20d1eb1d5619b74c2e88f7436b2e8add47db8ce0 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Bayle <j2b.bayle@gmail.com>
Date: Mon, 1 Feb 2021 21:51:22 +0100
Subject: [PATCH] Remove unnecessary function in dsp.py

---
 lisainstrument/dsp.py | 85 ++-----------------------------------------
 1 file changed, 3 insertions(+), 82 deletions(-)

diff --git a/lisainstrument/dsp.py b/lisainstrument/dsp.py
index c3506ae..18791c1 100644
--- a/lisainstrument/dsp.py
+++ b/lisainstrument/dsp.py
@@ -95,85 +95,6 @@ def lagrange_coeffs(eps, num_tabs, p): # pylint: disable=invalid-name
     return coeffs.T
 
 
-def time_shift(data, shift, order=31):
-    """Shift data in time by tau
-
-    Args:
-        data (numpy.ndarray): data to be shited
-        tau (numpy.ndarray): amount of time each data point is to be shifted
-                            (must be of same dimension as data)
-        fs (double): sampling frequency in (Hz)
-        order (int): interpolation order
-    """
-    logging.debug("Time shifting data '%s' by '%s' (order=%d)", data, shift, order)
-
-    if numpy.isscalar(data):
-        logging.debug("Data is a constant scalar and cannot be time shifted")
-        return data
-    if numpy.all(shift == 0):
-        logging.debug("Time shift is vanishing and cannot be applied")
-        return data
-
-    data = numpy.asarray(data)
-    mode = "timeseries" if isinstance(shift, numpy.ndarray) else "constant"
-    logging.debug("Using mode '%s'", mode)
-
-    if mode == "timeseries" and data.size != shift.size:
-        raise ValueError(f"`data` and `tau` must be of the same size (got {data.size}, {shift.size})")
-
-    num_tabs = order + 1
-    p = num_tabs // 2 # pylint: disable=invalid-name
-    size = data.size
-
-    def lagrange_coeffs(eps):
-        """Calculate coefficients for lagrange interpolation"""
-        coeffs = numpy.zeros([num_tabs, eps.size])
-
-        if p > 1:
-            factor = numpy.ones(eps.size, dtype=numpy.float64)
-            factor *= eps * (1 - eps)
-
-            for j in range(1, p):
-                factor *= (-1) * (1 - j / p) / (1 + j / p)
-                coeffs[p - 1 - j] = factor / (j + eps)
-                coeffs[p + j] = factor / (j + 1 - eps)
-
-            coeffs[p - 1] = 1 - eps
-            coeffs[p] = eps
-
-            for j in range(2, p):
-                coeffs *= 1 - (eps / j)**2
-
-            coeffs *= (1 + eps) * (1 - eps / p)
-        else:
-            coeffs[p - 1] = 1 - eps
-            coeffs[p] = eps
-
-        return coeffs.T
-
-    k = numpy.floor(shift).astype(int)
-    eps = shift - k
-    coeffs = lagrange_coeffs(eps)
-    logging.debug("Using Lagrange coefficiens '%s'", coeffs)
-
-    if mode == "timeseries":
-        logging.debug("Computing Lagrange matrix")
-        indices = numpy.arange(size)
-        i_min = numpy.min(k - (p - 1) + indices)
-        i_max = numpy.max(k + p + indices + 1)
-        csr_ind = numpy.tile(numpy.arange(num_tabs), size) + numpy.repeat(k + indices, num_tabs) - (p - 1)
-        csr_ptr = num_tabs * numpy.arange(size + 1)
-        mat = scipy.sparse.csr_matrix((numpy.ravel(coeffs), csr_ind - i_min, csr_ptr), shape=(size, i_max - i_min))
-        logging.debug("Padding data (left=%d, right=%d)", max(0, -i_min), max(0, i_max - size))
-        data_padded = numpy.pad(data[max(0, i_min):min(size, i_max)], (max(0, -i_min), max(0, i_max - size)))
-        logging.debug("Computing matrix-vector product")
-        shifted = mat.dot(data_padded)
-    elif mode == "constant":
-        i_min = k - (p - 1)
-        i_max = k + p + size
-        logging.debug("Padding data (left=%d, right=%d)", max(0, -i_min), max(0, i_max - size))
-        data_padded = numpy.pad(data[max(0, i_min):min(size, i_max)], (max(0, -i_min), max(0, i_max - size)))
-        logging.debug("Computing correlation product")
-        shifted = numpy.correlate(data_padded, coeffs[0], mode="valid")
-
-    return shifted
+def identity(x):
+    """Identity function, no operations."""
+    return x
-- 
GitLab