From 8348c5ab58298c585ee353e3cc8cd4f65a792fbc Mon Sep 17 00:00:00 2001
From: Wolfgang Kastaun <wolfgang.kastaun@aei.mpg.de>
Date: Thu, 19 Dec 2024 17:31:04 +0100
Subject: [PATCH] some cleanup, fixing typing problems

---
 lisainstrument/dynamic_delay_dask.py     |  9 +++++---
 lisainstrument/dynamic_delay_dsp_dask.py | 11 ++++------
 lisainstrument/fixed_shift_numpy.py      |  8 +++----
 lisainstrument/regular_interpolators.py  |  2 +-
 tests/test_dynamic_delay_dask.py         |  1 -
 tests/test_dynamic_delay_dsp_dask.py     | 28 +++++++++++++-----------
 6 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/lisainstrument/dynamic_delay_dask.py b/lisainstrument/dynamic_delay_dask.py
index 1962d03..144c25a 100644
--- a/lisainstrument/dynamic_delay_dask.py
+++ b/lisainstrument/dynamic_delay_dask.py
@@ -5,7 +5,7 @@ Use make_dynamic_shift_lagrange_dask to create a Lagrange interpolator for dask
 
 from __future__ import annotations
 
-from typing import Any, Callable, Final
+from typing import Any, Final
 
 import dask
 import dask.array as da
@@ -195,8 +195,11 @@ def make_dynamic_shift_lagrange_dask(
 
 
 def numpyfy_dask_multi(
-    dafunc: Callable[[*Any], DaskArray1D], chunks: int
-) -> Callable[[*Any], NumpyArray1D]:
+    # ~ dafunc: Callable[[*Any], DaskArray1D],
+    dafunc: Any,
+    chunks: int,
+) -> Any:
+    # ~ ) -> Callable[[*Any], NumpyArray1D]:
     """Convert function operating on 1D dask arrays to work with 1D numpy arrays.
 
     Before calling the dask-based function, all arguments which are numpy
diff --git a/lisainstrument/dynamic_delay_dsp_dask.py b/lisainstrument/dynamic_delay_dsp_dask.py
index a87a675..bd0ae14 100644
--- a/lisainstrument/dynamic_delay_dsp_dask.py
+++ b/lisainstrument/dynamic_delay_dsp_dask.py
@@ -2,7 +2,7 @@
 
 There are two implementations of Lagrange interpolation:
 
-1. dynamic_delay_dsp_dask.make_regular_interpolator_dsp wraps legacy implementation dsp.timeshift 
+1. dynamic_delay_dsp_dask.make_regular_interpolator_dsp wraps legacy implementation dsp.timeshift
    into new interface
 2. dynamic_delay_numpy.make_regular_interpolator_lagrange provides a completely new implementation
    of Lagrange interpolation
@@ -19,16 +19,12 @@ import numpy as np
 from lisainstrument import dsp
 from lisainstrument.dynamic_delay_dask import DynamicShiftDask
 from lisainstrument.dynamic_delay_numpy import (
+    DynamicShiftNumpy,
     DynShiftBC,
     DynShiftCfg,
-    RegularInterpCore,
-    RegularInterpolator,
-    DynamicShiftNumpy,
 )
 from lisainstrument.fir_filters_numpy import NumpyArray1D
-
-
-
+from lisainstrument.regular_interpolators import RegularInterpCore, RegularInterpolator
 
 
 class RegularInterpDSP(RegularInterpCore):
@@ -138,6 +134,7 @@ def make_dynamic_shift_dsp_dask(
     cfg = DynShiftCfg(min_delay, max_delay, left_bound, right_bound)
     return DynamicShiftDask(cfg, interp)
 
+
 def make_dynamic_shift_dsp_numpy(
     order: int,
     min_delay: float,
diff --git a/lisainstrument/fixed_shift_numpy.py b/lisainstrument/fixed_shift_numpy.py
index 538497b..8b98393 100644
--- a/lisainstrument/fixed_shift_numpy.py
+++ b/lisainstrument/fixed_shift_numpy.py
@@ -1,4 +1,4 @@
-"""Functions for interpolating numpy arrays with 1D  regularly spaced data 
+"""Functions for interpolating numpy arrays with 1D  regularly spaced data
 
 This provides a generic interface RegularInterpolator as well as two interpolation
 methods, linear and Lagrange. The latter is written from scratch, see module
@@ -110,16 +110,16 @@ def make_fir_lagrange_fixed(length: int, frac_shift: float) -> DefFilterFIR:
       \end{align*}
     $$
 
-    The offset is chosen to center the stencil around a shift 
+    The offset is chosen to center the stencil around a shift
     $s=0$ for odd length and s=$1/2$ for even length. The shift should
     not exceed the bounds $-1/2 < s < 1/2$ for odd length or $0 < s < 1$
-    for even length significantly, to avoid large overshoots that inherently 
+    for even length significantly, to avoid large overshoots that inherently
     occur off-center for high order lagrange interpolation.
 
     Arguments:
         length: Number of FIR coefficients (=Lagrange order + 1)
         frac_shift: The shift $s$
-    
+
     Returns:
         FIR filter definition
     """
diff --git a/lisainstrument/regular_interpolators.py b/lisainstrument/regular_interpolators.py
index a8433c7..4f4cc69 100644
--- a/lisainstrument/regular_interpolators.py
+++ b/lisainstrument/regular_interpolators.py
@@ -1,4 +1,4 @@
-"""Functions for interpolating numpy arrays with 1D  regularly spaced data 
+"""Functions for interpolating numpy arrays with 1D  regularly spaced data
 
 This provides a generic interface RegularInterpolator as well as two interpolation
 methods, linear and Lagrange. The latter is written from scratch, see module
diff --git a/tests/test_dynamic_delay_dask.py b/tests/test_dynamic_delay_dask.py
index 7f3b12f..fc147c9 100644
--- a/tests/test_dynamic_delay_dask.py
+++ b/tests/test_dynamic_delay_dask.py
@@ -77,7 +77,6 @@ def test_dynamic_shift_lagrange_dask() -> None:
     assert np.all(s_np == s_da)
 
 
-
 def test_lagrange_polynomials():
     length = 11
     d = -(length // 2)
diff --git a/tests/test_dynamic_delay_dsp_dask.py b/tests/test_dynamic_delay_dsp_dask.py
index e9f7897..8be00af 100644
--- a/tests/test_dynamic_delay_dsp_dask.py
+++ b/tests/test_dynamic_delay_dsp_dask.py
@@ -1,34 +1,37 @@
 import numpy as np
 import pytest
 
-from lisainstrument.dynamic_delay_dsp_dask import make_dynamic_shift_dsp_dask, make_dynamic_shift_dsp_numpy
-from lisainstrument.dynamic_delay_dask import numpyfy_dask_bivariate
-
+from lisainstrument.dynamic_delay_dask import numpyfy_dask_multi
+from lisainstrument.dynamic_delay_dsp_dask import (
+    make_dynamic_shift_dsp_dask,
+    make_dynamic_shift_dsp_numpy,
+)
 from lisainstrument.dynamic_delay_numpy import DynShiftBC
 
 
-
-
-
-def test_dynamic_shift_dsp_dask():
+def test_dynamic_shift_dsp_dask() -> None:
     order = 5
-    length = order + 1
 
     t, dt = np.linspace(-5.345, 10.345, 1003, retstep=True)
 
     def g(x):
-        n = x / 10.0
-        return 4.32546 + 3.34324 * x + 4.342 * x**2 + 0.46 * x**3 + 1.43598 * x**4 + 3.3456 * x**5
+        return (
+            4.32546
+            + 3.34324 * x
+            + 4.342 * x**2
+            + 0.46 * x**3
+            + 1.43598 * x**4
+            + 3.3456 * x**5
+        )
 
     y = g(t)
 
     d = (0.93456456 + 0.0235345 * np.cos(4.3354 * t)) / dt
 
-
     op_da = make_dynamic_shift_dsp_dask(
         order, d.min(), d.max(), DynShiftBC.FLAT, DynShiftBC.EXCEPTION
     )
-    op_na = numpyfy_dask_bivariate(op_da, chunks=19)
+    op_na = numpyfy_dask_multi(op_da, chunks=19)
 
     s_da = op_na(y, d)
     s_ex = g(np.maximum(t[0], t - d * dt))
@@ -44,4 +47,3 @@ def test_dynamic_shift_dsp_dask():
     s_np = op_np(y, d)
 
     assert np.all(s_np == s_da)
-
-- 
GitLab