|
7 | 7 | squeeze_coeffs_list = [ |
8 | 8 | # The order of coefficients is [a0, a1, a2, ..., an] |
9 | 9 | # Negative cubic squeeze coefficients |
10 | | - [-0.2, -0.01, -0.001, -0.001], |
| 10 | + [-0.2, -0.01, -0.001, -0.0001], |
11 | 11 | # Positive cubic squeeze coefficients |
12 | | - [0.2, 0.01, 0.001, 0.001], |
| 12 | + [0.2, 0.01, 0.001, 0.0001], |
13 | 13 | # Positive and negative cubic squeeze coefficients |
14 | | - [0.2, -0.01, 0.002, -0.001], |
| 14 | + [0.2, -0.01, 0.002, -0.0001], |
15 | 15 | # Quadratic squeeze coefficients |
16 | 16 | [-0.2, 0.005, -0.007], |
17 | 17 | # Linear squeeze coefficients |
18 | 18 | [0.1, 0.3], |
19 | 19 | # 4th order squeeze coefficients |
20 | 20 | [0.2, -0.01, 0.001, -0.001, 0.0004], |
21 | 21 | # Zeros and non-zeros, the full polynomial is applied |
22 | | - [0, 0.03, 0, -0.001], |
| 22 | + [0, 0.03, 0, -0.0001], |
23 | 23 | # Testing zeros, expect no squeezing |
24 | 24 | [0, 0, 0, 0, 0, 0], |
25 | 25 | ] |
@@ -51,10 +51,28 @@ def test_morphsqueeze(x_morph, x_target, squeeze_coeffs): |
51 | 51 | y_morph_expected = np.sin(x_morph) |
52 | 52 | morph = MorphSqueeze() |
53 | 53 | morph.squeeze = squeeze_coeffs |
54 | | - x_morph_actual, y_morph_actual, x_target_actual, y_target_actual = morph( |
55 | | - x_morph, y_morph, x_target, y_target |
56 | | - ) |
57 | | - assert np.allclose(y_morph_actual, y_morph_expected) |
| 54 | + ( |
| 55 | + x_morph_actual, |
| 56 | + y_morph_actual, |
| 57 | + x_target_actual, |
| 58 | + y_target_actual, |
| 59 | + low_extrap_idx, |
| 60 | + high_extrap_idx, |
| 61 | + ) = morph(x_morph, y_morph, x_target, y_target) |
| 62 | + if low_extrap_idx is None and high_extrap_idx is None: |
| 63 | + assert np.allclose(y_morph_actual, y_morph_expected, atol=1e-6) |
| 64 | + else: |
| 65 | + interp_start = low_extrap_idx + 1 if low_extrap_idx is not None else 0 |
| 66 | + interp_end = ( |
| 67 | + high_extrap_idx |
| 68 | + if high_extrap_idx is not None |
| 69 | + else len(y_morph_actual) |
| 70 | + ) |
| 71 | + assert np.allclose( |
| 72 | + y_morph_actual[interp_start:interp_end], |
| 73 | + y_morph_expected[interp_start:interp_end], |
| 74 | + atol=1e-6, |
| 75 | + ) |
58 | 76 | assert np.allclose(x_morph_actual, x_morph_expected) |
59 | 77 | assert np.allclose(x_target_actual, x_target) |
60 | 78 | assert np.allclose(y_target_actual, y_target) |
0 commit comments