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)
2830def 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