14
14
# Positive cubic squeeze coefficients
15
15
[0.2 , 0.01 , 0.001 , 0.001 ],
16
16
# Positive and negative cubic squeeze coefficients
17
- [0.2 , - 0.01 , 0.001 , - 0.001 ],
17
+ [0.2 , - 0.01 , 0.002 , - 0.001 ],
18
18
# Quadratic squeeze coefficients
19
- [- 0.2 , 0.005 , - 0.003 ],
19
+ [- 0.2 , 0.005 , - 0.007 ],
20
20
# Linear squeeze coefficients
21
21
[0.1 , 0.3 ],
22
22
# 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
25
27
[0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ],
26
28
],
27
29
)
28
30
def test_morphsqueeze (squeeze_coeffs ):
29
-
30
- x_target = np .linspace (0 , 10 , 1000 )
31
+ x_target = np .linspace (0 , 10 , 1001 )
31
32
y_target = np .sin (x_target )
32
33
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
+
33
38
squeeze_polynomial = Polynomial (squeeze_coeffs )
34
- x_squeezed = x_target + squeeze_polynomial (x_target )
39
+ x_squeezed = x_make + squeeze_polynomial (x_make )
35
40
36
- x_morph = x_target .copy ()
41
+ x_morph = x_make .copy ()
37
42
y_morph = np .sin (x_squeezed )
38
43
39
44
morph = MorphSqueeze ()
@@ -42,7 +47,14 @@ def test_morphsqueeze(squeeze_coeffs):
42
47
x_actual , y_actual , x_expected , y_expected = morph (
43
48
x_morph , y_morph , x_target , y_target
44
49
)
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