From 2bd6f5aafb205892cbaf120bce754a2859640663 Mon Sep 17 00:00:00 2001 From: Wolfgang Kastaun <wolfgang.kastaun@aei.mpg.de> Date: Sun, 15 Dec 2024 22:48:32 +0100 Subject: [PATCH] add unit test for dsp based interpolator, apply same test to previous one --- tests/test_dynamic_delay_dask.py | 6 ++-- tests/test_dynamic_delay_dsp_dask.py | 47 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tests/test_dynamic_delay_dsp_dask.py diff --git a/tests/test_dynamic_delay_dask.py b/tests/test_dynamic_delay_dask.py index 41d1315..f21a36d 100644 --- a/tests/test_dynamic_delay_dask.py +++ b/tests/test_dynamic_delay_dask.py @@ -37,14 +37,14 @@ def test_dynamic_shift_linear_dask(): def test_dynamic_shift_lagrange_dask(): - order = 4 + 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 + 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) @@ -61,7 +61,7 @@ def test_dynamic_shift_lagrange_dask(): 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 + s_da[op_da.margin_left :], abs=1e-15, rel=1e-13 ) op_np = make_dynamic_shift_lagrange_numpy( diff --git a/tests/test_dynamic_delay_dsp_dask.py b/tests/test_dynamic_delay_dsp_dask.py new file mode 100644 index 0000000..e9f7897 --- /dev/null +++ b/tests/test_dynamic_delay_dsp_dask.py @@ -0,0 +1,47 @@ +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_numpy import DynShiftBC + + + + + +def test_dynamic_shift_dsp_dask(): + 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 + + 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) + + 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-13 + ) + + op_np = make_dynamic_shift_dsp_numpy( + order, d.min(), d.max(), DynShiftBC.FLAT, DynShiftBC.EXCEPTION + ) + + s_np = op_np(y, d) + + assert np.all(s_np == s_da) + -- GitLab