Skip to content

Commit 14d92cb

Browse files
committed
Test: added expanded x-axis and no tolerance
1 parent a1b6425 commit 14d92cb

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

Diff for: src/diffpy/morph/morphs/morphsqueeze.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class MorphSqueeze(Morph):
2626
parnames = ["squeeze"]
2727

2828
def morph(self, x_morph, y_morph, x_target, y_target):
29-
3029
Morph.morph(self, x_morph, y_morph, x_target, y_target)
3130
if self.squeeze is None or np.allclose(self.squeeze, 0):
3231
self.x_morph_out = self.x_morph_in
@@ -37,12 +36,8 @@ def morph(self, x_morph, y_morph, x_target, y_target):
3736
x_squeezed = self.x_morph_in + squeeze_polynomial(self.x_morph_in)
3837

3938
self.y_morph_out = interp1d(
40-
x_squeezed,
41-
self.y_morph_in,
42-
kind="cubic",
43-
bounds_error=False,
44-
fill_value="extrapolate",
39+
x_squeezed, self.y_morph_in, kind="cubic", bounds_error=False
4540
)(self.x_morph_in)
46-
self.x_morph_out = self.x_morph_in
4741

42+
self.x_morph_out = self.x_morph_in
4843
return self.xyallout

Diff for: tests/test_morphsqueeze.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,31 @@
1414
# Positive cubic squeeze coefficients
1515
[0.2, 0.01, 0.001, 0.001],
1616
# Positive and negative cubic squeeze coefficients
17-
[0.2, -0.01, 0.001, -0.001],
17+
[0.2, -0.01, 0.002, -0.001],
1818
# Quadratic squeeze coefficients
19-
[-0.2, 0.005, -0.003],
19+
[-0.2, 0.005, -0.007],
2020
# Linear squeeze coefficients
2121
[0.1, 0.3],
2222
# 4th order squeeze coefficients
23-
[0.2, -0.01, 0.001, -0.001, 0.0001],
24-
# Testing zeros
23+
[0.2, -0.01, 0.001, -0.001, 0.0004],
24+
# Zeros and non-zeros, expect 0 + a1x + 0 + a3x**3
25+
[0, 0.03, 0, -0.001],
26+
# Testing zeros, expect no squeezing
2527
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2628
],
2729
)
2830
def test_morphsqueeze(squeeze_coeffs):
29-
30-
x_target = np.linspace(0, 10, 1000)
31+
x_target = np.linspace(0, 10, 1001)
3132
y_target = np.sin(x_target)
3233

34+
x_make = np.linspace(-3, 13, 1601)
35+
lower_idx = np.where(x_make == 0.0)[0][0]
36+
upper_idx = np.where(x_make == 10.0)[0][0]
37+
3338
squeeze_polynomial = Polynomial(squeeze_coeffs)
34-
x_squeezed = x_target + squeeze_polynomial(x_target)
39+
x_squeezed = x_make + squeeze_polynomial(x_make)
3540

36-
x_morph = x_target.copy()
41+
x_morph = x_make.copy()
3742
y_morph = np.sin(x_squeezed)
3843

3944
morph = MorphSqueeze()
@@ -42,7 +47,14 @@ def test_morphsqueeze(squeeze_coeffs):
4247
x_actual, y_actual, x_expected, y_expected = morph(
4348
x_morph, y_morph, x_target, y_target
4449
)
45-
46-
# Check that the morphed (actual) data matches the expected data
47-
# Including tolerance error because of extrapolation error
48-
assert np.allclose(y_actual, y_expected, atol=0.1)
50+
y_actual = y_actual[lower_idx : upper_idx + 1]
51+
assert np.allclose(y_actual, y_expected)
52+
53+
# Plotting code used for figures in PR comments
54+
# https://github.com/diffpy/diffpy.morph/pull/180
55+
# plt.figure()
56+
# plt.scatter(x_expected, y_expected, color='black', label='Expected')
57+
# plt.plot(x_morph, y_morph, color='purple', label='morph')
58+
# plt.plot(x_actual, y_actual, '--', color='gold', label='Actual')
59+
# plt.legend()
60+
# plt.show()

0 commit comments

Comments
 (0)