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

Some cleanup to fix linting pipelines

parent ebcb4052
No related branches found
No related tags found
No related merge requests found
Pipeline #376918 passed
......@@ -64,8 +64,8 @@ class FixedShiftDask: # pylint: disable=too-few-public-methods
)
case DynShiftBC.EXCEPTION:
msg = (
f"FixedShiftDask: left edge handling {self._left_bound.name} not "
f"possible for given delay, need margin of {margin_left}."
f"FixedShiftDask: left edge handling {self._left_bound.name} "
f"impossible for given delay, would need margin of {margin_left}."
)
raise RuntimeError(msg)
case _ as unreachable:
......@@ -85,8 +85,8 @@ class FixedShiftDask: # pylint: disable=too-few-public-methods
)
case DynShiftBC.EXCEPTION:
msg = (
f"FixedShiftNumpy: right edge handling {self._right_bound.name} not "
f"possible for given delay, need margin of {margin_right}."
f"FixedShiftDask: right edge handling {self._right_bound.name} "
f"impossible for given delay, would need margin of {margin_right}."
)
raise RuntimeError(msg)
case _ as unreachable:
......
......@@ -2,7 +2,7 @@
There are two implementations of fixed-shift Lagrange interpolation:
1. fixed_shift_dsp.make_fixed_shift_dsp wraps legacy implementation dsp.timeshift
1. fixed_shift_dsp.make_fixed_shift_dsp wraps legacy implementation dsp.timeshift
into new interface
2. fixed_shift_numpy.make_fixed_shift_lagrange provides a completely new implementation
of Lagrange interpolation
......@@ -17,15 +17,13 @@ from typing import Final
import numpy as np
from lisainstrument import dsp
from lisainstrument.fixed_shift_dask import FixedShiftDask
from lisainstrument.dynamic_delay_numpy import DynShiftBC
from lisainstrument.fir_filters_numpy import NumpyArray1D, make_numpy_array_1d
from lisainstrument.fixed_shift_dask import FixedShiftDask
from lisainstrument.fixed_shift_numpy import (
make_numpy_array_1d_float,
FixedShiftCore,
FixedShiftFactory,
make_numpy_array_1d_float,
)
......
......@@ -334,9 +334,11 @@ class FixedShiftNumpy: # pylint: disable=too-few-public-methods
Numpy array with interpolated samples
"""
# pylint: disable=duplicate-code
loc = -shift
loc_int = int(np.floor(loc))
loc_frac = loc - loc_int
# pylint: enable=duplicate-code
interp = self._interp_fac(-loc_frac)
......
import numpy as np
import pytest
from lisainstrument.dynamic_delay_numpy import DynShiftBC
from lisainstrument.dynamic_delay_dask import numpyfy_dask_multi
from lisainstrument.fixed_shift_numpy import make_fixed_shift_lagrange_numpy
from lisainstrument.dynamic_delay_numpy import DynShiftBC
from lisainstrument.fixed_shift_dask import make_fixed_shift_lagrange_dask
from lisainstrument.fixed_shift_numpy import make_fixed_shift_lagrange_numpy
def test_fixed_shift_lagrange_dask() -> None:
......@@ -27,7 +26,7 @@ def test_fixed_shift_lagrange_dask() -> None:
y = g(t)
for d in (0.93456456 / dt, 3.1, 3.5, 3.9, 4.0, 4.1, 4.5, 4.9, 116.0):
op_np = make_fixed_shift_lagrange_numpy(
DynShiftBC.FLAT, DynShiftBC.EXCEPTION, length
)
......@@ -42,11 +41,9 @@ def test_fixed_shift_lagrange_dask() -> None:
margin_ex = -int(np.floor(-d)) + order // 2
assert s_na == pytest.approx(s_np, rel=1e-14, abs=0)
assert s_ex[margin_ex:] == pytest.approx(s_na[margin_ex:], abs=1e-15, rel=5e-13)
with pytest.raises(RuntimeError):
op_na(y, -d)
......@@ -68,21 +65,17 @@ def test_fixed_shift_lagrange_dask() -> None:
assert s2_ex[:-margin2_ex] == pytest.approx(
s2_na[:-margin2_ex], abs=1e-15, rel=5e-13
)
with pytest.raises(RuntimeError):
op2_na(y, d)
op3_da = make_fixed_shift_lagrange_dask(
DynShiftBC.FLAT, DynShiftBC.FLAT, length
)
op3_na = numpyfy_dask_multi(op3_da, chunks=113)
s3_na = op3_na(y, d)
op3_na = numpyfy_dask_multi(op3_da, chunks=113)
s3_na = op3_na(y, d)
assert s3_na == pytest.approx(s_np, rel=1e-14, abs=0)
s4_na = op3_na(y, -d)
s4_na = op3_na(y, -d)
assert s4_na == pytest.approx(s2_np, rel=1e-14, abs=0)
import numpy as np
import pytest
from lisainstrument.dynamic_delay_numpy import DynShiftBC
from lisainstrument.fixed_shift_numpy import make_fixed_shift_lagrange_numpy
......@@ -25,30 +23,31 @@ def test_fixed_shift_lagrange_dask() -> None:
y = g(t)
for d in (0.93456456/dt, 3.1, 3.5, 3.9, 4.0, 4.1, 4.5, 4.9):
# ~ d = 0.93456456 / dt
op_np = make_fixed_shift_lagrange_numpy(DynShiftBC.FLAT, DynShiftBC.EXCEPTION, length)
for d in (0.93456456 / dt, 3.1, 3.5, 3.9, 4.0, 4.1, 4.5, 4.9):
# ~ d = 0.93456456 / dt
op_np = make_fixed_shift_lagrange_numpy(
DynShiftBC.FLAT, DynShiftBC.EXCEPTION, length
)
s_np = op_np(y, d)
s_ex = g(t - d * dt)
margin_ex = -int(np.floor(-d)) + order // 2
print(d, d*dt, margin_ex)
assert s_ex[margin_ex:] == pytest.approx(
s_np[margin_ex:], abs=1e-15, rel=5e-13
)
margin_ex = -int(np.floor(-d)) + order // 2
print(d, d * dt, margin_ex)
assert s_ex[margin_ex:] == pytest.approx(s_np[margin_ex:], abs=1e-15, rel=5e-13)
# ~ assert np.min(np.abs(s_ex[:margin_ex] - s_np[:margin_ex])) > np.max(np.abs(y[:margin_ex]))*1e-10
with pytest.raises(RuntimeError):
op_np(y, -d)
op2_np = make_fixed_shift_lagrange_numpy(DynShiftBC.EXCEPTION, DynShiftBC.FLAT, length)
op2_np = make_fixed_shift_lagrange_numpy(
DynShiftBC.EXCEPTION, DynShiftBC.FLAT, length
)
s2_np = op2_np(y, -d)
s2_ex = g(t + d * dt)
......
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