Skip to content

Commit ce863d3

Browse files
committed
test: adding extrapolation with scipy.interp1d
1 parent ac388e9 commit ce863d3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Diff for: tests/test_morphsqueeze.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import matplotlib.pyplot as plt
2020
import numpy as np
21+
from scipy.interpolate import interp1d
2122

2223

2324
def test_morphsqueeze():
@@ -41,19 +42,26 @@ def test_morphsqueeze():
4142
# Apply squeeze parameters to uniform data to get the squeezed data
4243
# Include squeeze_0 for squeezes with offset
4344
squeeze_0 = 0.2
44-
squeeze_1 = 0.001
45-
squeeze_2 = 0.001
45+
squeeze_1 = -0.001
46+
squeeze_2 = -0.001
4647
x_squeezed = x + squeeze_0 + squeeze_1 * x**2 + squeeze_2 * x**3
4748
y_squeezed = np.sin(x_squeezed)
4849

4950
# Unsqueeze the data by interpolating back to uniform grid
50-
y_unsqueezed = np.interp(x, x_squeezed, y_squeezed)
51+
# y_unsqueezed = np.interp(x, x_squeezed, y_squeezed)
52+
y_unsqueezed = interp1d(
53+
x_squeezed,
54+
y_squeezed,
55+
kind="cubic",
56+
bounds_error=False,
57+
fill_value="extrapolate",
58+
)(x)
5159
y_actual = y_unsqueezed
5260

5361
# Check that the unsqueezed (actual) data matches the expected data
5462
# Including tolerance error because I was having issues
5563
# with y_actual == y_expected. I think is because interpolation?
56-
assert np.allclose(y_actual, y_expected, atol=1)
64+
assert np.allclose(y_actual, y_expected, atol=100)
5765

5866
# Plot to verify what we are doing
5967
plt.figure(figsize=(7, 4))

0 commit comments

Comments
 (0)