Skip to content
Snippets Groups Projects
Commit 8348c5ab authored by Wolfgang Kastaun's avatar Wolfgang Kastaun
Browse files

some cleanup, fixing typing problems

parent d2cb05f1
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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,
......
"""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
"""
......
"""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
......
......@@ -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)
......
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment