|
1 | 1 | import unittest
|
2 | 2 | import numpy as np
|
| 3 | +import scipy |
3 | 4 | import dill
|
4 | 5 | import numpy.testing as nptest
|
5 | 6 | from mock import MagicMock
|
6 | 7 | from mvesuvio.util.analysis_helpers import extractWS, _convert_dict_to_table, \
|
7 |
| - fix_profile_parameters, calculate_h_ratio |
| 8 | + fix_profile_parameters, calculate_h_ratio, extend_range_of_array, numerical_third_derivative |
8 | 9 | from mantid.simpleapi import CreateWorkspace, DeleteWorkspace
|
9 | 10 |
|
10 | 11 |
|
@@ -126,5 +127,27 @@ def test_conversion_of_constraints(self):
|
126 | 127 | self.assertEqual(converted_constraints[1]['fun']([0, 0, 0, 2, 0, 0, 1]), 2-0.7234)
|
127 | 128 |
|
128 | 129 |
|
| 130 | + def test_extend_range_of_array_for_increasing_range(self): |
| 131 | + x = np.arange(10) |
| 132 | + x = np.vstack([x, 2*x]) |
| 133 | + x_extended = extend_range_of_array(x, 5) |
| 134 | + np.testing.assert_array_equal(x_extended, np.vstack([np.arange(-5, 15, 1), np.arange(-10, 30, 2)])) |
| 135 | + |
| 136 | + |
| 137 | + def test_extend_range_of_array_for_decreasing_range(self): |
| 138 | + x = np.linspace(-5, 5, 21) |
| 139 | + x = np.vstack([x, 2*x]) |
| 140 | + x_extended = extend_range_of_array(x, 5) |
| 141 | + np.testing.assert_array_equal(x_extended, np.vstack([np.linspace(-7.5, 7.5, 31), np.linspace(-15, 15, 31)])) |
| 142 | + |
| 143 | + |
| 144 | + def test_numerical_third_derivative(self): |
| 145 | + x= np.linspace(-20, 20, 300) # Workspaces are about 300 points of range |
| 146 | + x = np.vstack([x, 2*x]) |
| 147 | + y = scipy.special.voigt_profile(x, 5, 5) |
| 148 | + numerical_derivative = numerical_third_derivative(x, y) |
| 149 | + expected_derivative = np.array([np.gradient(np.gradient(np.gradient(y_i, x_i), x_i), x_i)[6: -6] for y_i, x_i in zip(y, x) ]) |
| 150 | + np.testing.assert_allclose(numerical_derivative, expected_derivative, atol=1e-6) |
| 151 | + |
129 | 152 | if __name__ == "__main__":
|
130 | 153 | unittest.main()
|
0 commit comments