diff --git a/glassure/core/pattern.py b/glassure/core/pattern.py index 2ae61a8..bdc93f7 100644 --- a/glassure/core/pattern.py +++ b/glassure/core/pattern.py @@ -331,7 +331,7 @@ def __sub__(self, other: Pattern) -> Pattern: if orig_x.shape != other_x.shape: # todo different shape subtraction of spectra seems the fail somehow... # the background will be interpolated - other_fcn = interp1d(other_x, other_x, kind='linear') + other_fcn = interp1d(other_x, other_y, kind='linear') # find overlapping x and y values: ind = np.where((orig_x <= np.max(other_x)) & @@ -362,7 +362,7 @@ def __add__(self, other: Pattern) -> Pattern: if orig_x.shape != other_x.shape: # the background will be interpolated - other_fcn = interp1d(other_x, other_x, kind='linear') + other_fcn = interp1d(other_x, other_y, kind='linear') # find overlapping x and y values: ind = np.where((orig_x <= np.max(other_x)) & diff --git a/tests/core_tests/test_pattern.py b/tests/core_tests/test_pattern.py index 05a709e..9481ac5 100644 --- a/tests/core_tests/test_pattern.py +++ b/tests/core_tests/test_pattern.py @@ -31,6 +31,20 @@ def test_plus_and_minus_operators(): assert np.array_equal(pattern1._y, np.sin(x) * 1) +def test_plus_and_minus_operators_with_different_x(): + x1 = np.linspace(1, 9, 1000) + x2 = np.linspace(0, 10, 998) + pattern1 = Pattern(x1, np.sin(x1)) + pattern2 = Pattern(x2, np.sin(x2)) + + pattern3 = pattern1 + pattern2 + assert np.array_equal(pattern3.x, x1) + np.testing.assert_array_almost_equal(pattern3.y, np.sin(x1) * 2, decimal=5) + + pattern3 = pattern1 - pattern2 + np.testing.assert_array_almost_equal(pattern3._y, np.sin(x1) * 0, decimal=5) + + def test_multiply_operator(): x = np.linspace(0, 10, 100) pattern = 2 * Pattern(x, np.sin(x))