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

added unit tests for dynamic shift interpolation

parent d11887d0
No related branches found
No related tags found
No related merge requests found
import numpy as np
import pytest
from lisainstrument.dynamic_delay_dask import (
make_dynamic_shift_linear_dask,
make_dynamic_shift_lagrange_dask,
make_dynamic_shift_lagrange_numpy,
numpyfy_dask_bivariate,
DynShiftBC,
make_lagrange_polynomials,
)
def test_dynamic_shift_linear_dask():
t, dt = np.linspace(-5.345, 10.345, 103, retstep=True)
def g(x):
return 4.32546 + 3.34324 * x
y = g(t)
d = (0.93456456 + 0.0235345 * np.cos(4.3354 * t)) / dt
# ~ print(y[0], t[0], d[0])
op_da = make_dynamic_shift_linear_dask(
d.min(), d.max(), DynShiftBC.FLAT, DynShiftBC.EXCEPTION
)
op_np = numpyfy_dask_bivariate(op_da, chunks=19)
s_da = op_np(y, d)
s_ex = g(np.maximum(t[0], t - d * dt))
assert s_ex == pytest.approx(s_da, abs=1e-15, rel=1e-14)
def test_dynamic_shift_lagrange_dask():
order = 4
length = order + 1
t, dt = np.linspace(-5.345, 10.345, 1003, retstep=True)
def g(x):
n = x / 10.
return 4.32546 + 3.34324 * x + 4.342 * x**2 + 0.46 * x**3 + 1.43598 * x**4
y = g(t)
d = (0.93456456 + 0.0235345 * np.cos(4.3354 * t)) / dt
# ~ print(y[0], t[0], d[0])
op_da = make_dynamic_shift_lagrange_dask(length,
d.min(), d.max(), DynShiftBC.FLAT, DynShiftBC.EXCEPTION
)
op_na = numpyfy_dask_bivariate(op_da, chunks=19)
s_da = op_na(y, d)
s_ex = g(np.maximum(t[0], t - d * dt))
assert s_ex[op_da.margin_left:] == pytest.approx(s_da[op_da.margin_left:], abs=1e-15, rel=1e-14)
op_np = make_dynamic_shift_lagrange_numpy(length,
d.min(), d.max(), DynShiftBC.FLAT, DynShiftBC.EXCEPTION
)
s_np = op_np(y,d)
assert np.all(s_np == s_da)
def test_lagrange_polynomials():
length = 11
d = -(length//2)
lagps = make_lagrange_polynomials(length,d)
for j,p in enumerate(lagps):
for x in range(d,d+length):
if x-d == j:
assert p(x) == pytest.approx(1, abs=0, rel=1e-12)
else:
assert p(x) == pytest.approx(0, abs=1e-11, rel=0)
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