|
1 | 1 | import numpy as np
|
2 | 2 | import pytest
|
3 | 3 | from numpy.polynomial import Polynomial
|
4 |
| -from scipy.interpolate import interp1d |
5 | 4 |
|
6 | 5 | from diffpy.morph.morphs.morphsqueeze import MorphSqueeze
|
7 | 6 |
|
|
29 | 28 | ],
|
30 | 29 | )
|
31 | 30 | def test_morphsqueeze(squeeze_coeffs):
|
32 |
| - x_expected = np.linspace(0, 10, 1001) |
33 |
| - y_expected = np.sin(x_expected) |
34 |
| - x_make = np.linspace(-3, 13, 3250) |
| 31 | + x_target_expected = np.linspace(0, 10, 101) |
| 32 | + y_target_expected = np.sin(x_target_expected) |
| 33 | + # Different grid for morph data to test inputs with different grids |
| 34 | + # Morph grid must be finer than the target to avoid interpolation issues |
| 35 | + x_morph = np.linspace(-3, 13, 301) |
35 | 36 | squeeze_polynomial = Polynomial(squeeze_coeffs)
|
36 |
| - x_squeezed = x_make + squeeze_polynomial(x_make) |
| 37 | + x_squeezed = x_morph + squeeze_polynomial(x_morph) |
37 | 38 | y_morph = np.sin(x_squeezed)
|
38 | 39 | morph = MorphSqueeze()
|
39 | 40 | morph.squeeze = squeeze_coeffs
|
40 |
| - x_actual, y_actual, x_target, y_target = morph( |
41 |
| - x_make, y_morph, x_expected, y_expected |
| 41 | + x_morph_actual, y_morph_actual, x_target_actual, y_target_actual = morph( |
| 42 | + x_morph, y_morph, x_target_expected, y_target_expected |
42 | 43 | )
|
43 |
| - y_actual = interp1d(x_actual, y_actual)(x_target) |
44 |
| - x_actual = x_target |
45 |
| - assert np.allclose(y_actual, y_expected) |
46 |
| - assert np.allclose(x_actual, x_expected) |
47 |
| - assert np.allclose(x_target, x_expected) |
48 |
| - assert np.allclose(y_target, y_expected) |
49 |
| - |
50 |
| - # Plotting code used for figures in PR comments |
51 |
| - # https://github.com/diffpy/diffpy.morph/pull/180 |
52 |
| - # plt.figure() |
53 |
| - # plt.scatter(x_expected, y_expected, color='black', label='Expected') |
54 |
| - # plt.plot(x_make, y_morph, color='purple', label='morph') |
55 |
| - # plt.plot(x_actual, y_actual, '--', color='gold', label='Actual') |
56 |
| - # plt.legend() |
57 |
| - # plt.show() |
| 44 | + assert np.allclose(y_morph_actual, y_target_expected) |
| 45 | + assert np.allclose(x_morph_actual, x_target_expected) |
| 46 | + assert np.allclose(x_target_actual, x_target_expected) |
| 47 | + assert np.allclose(y_target_actual, y_target_expected) |
0 commit comments