diff --git a/docs/source/release/v6.11.0/Inelastic/Bugfixes/37898.rst b/docs/source/release/v6.11.0/Inelastic/Bugfixes/37898.rst new file mode 100644 index 000000000000..6e1c76e3a218 --- /dev/null +++ b/docs/source/release/v6.11.0/Inelastic/Bugfixes/37898.rst @@ -0,0 +1 @@ +- Fixed an 'index out of range' error in the :ref:`BayesQuasi ` algorithm when using a sample with a Numeric Axis. \ No newline at end of file diff --git a/scripts/Inelastic/IndirectCommon.py b/scripts/Inelastic/IndirectCommon.py index d0b6a9a369f5..cd6401fb7953 100644 --- a/scripts/Inelastic/IndirectCommon.py +++ b/scripts/Inelastic/IndirectCommon.py @@ -169,13 +169,8 @@ def get_two_theta_and_q(workspace: Union[str, MatrixWorkspace]) -> Tuple[np.ndar # If axis is in Q need to calculate back to angles and just return axis values elif axis.isNumeric() and axis.getUnit().unitID() == "MomentumTransfer": - q_bin_edge = axis.extractValues() - q = list() - for i in range(1, len(q_bin_edge)): - q_centre = ((q_bin_edge[i] - q_bin_edge[i - 1]) / 2) + q_bin_edge[i - 1] - q.append(q_centre) - np_q = np.array(q) - two_theta = 2.0 * np.degrees(np.arcsin(np_q / k0)) + q = axis.extractValues() + two_theta = 2.0 * np.degrees(np.arcsin(np.array(q) / k0)) # Out of options here else: diff --git a/scripts/test/IndirectCommonTests.py b/scripts/test/IndirectCommonTests.py index 920afdee13db..917657687cc1 100644 --- a/scripts/test/IndirectCommonTests.py +++ b/scripts/test/IndirectCommonTests.py @@ -9,7 +9,7 @@ from os.path import join from mantid import config -from mantid.api import AnalysisDataService +from mantid.api import AnalysisDataService, NumericAxis from mantid.simpleapi import ( AddSampleLog, CreateSampleWorkspace, @@ -96,7 +96,7 @@ def test_get_two_theta_angles(self): actual_result = indirect_common.get_two_theta_angles(ws) self.assert_lists_almost_match(expected_result, actual_result) - def test_get_two_theta_and_q(self): + def test_get_two_theta_and_q_with_spectra_axis(self): ws = self.make_dummy_QENS_workspace() expected_theta_result = [29.700000000000006, 32.32, 34.949999999999996, 37.58, 40.209999999999994] expected_Q_result = [0.48372274526965625, 0.5253047207470042, 0.5667692111215948, 0.6079351677527525, 0.6487809073399485] @@ -104,6 +104,23 @@ def test_get_two_theta_and_q(self): self.assert_lists_almost_match(expected_theta_result, actual_theta_result) self.assert_lists_almost_match(expected_Q_result, actual_Q_result) + def test_get_two_theta_and_q_with_numeric_axis(self): + q_values = [0.48372274526965625, 0.5253047207470042, 0.5667692111215948, 0.6079351677527525, 0.6487809073399485] + + ws = AnalysisDataService.retrieve(self.make_dummy_QENS_workspace()) + numeric_axis = NumericAxis.create(len(q_values)) + numeric_axis.setUnit("MomentumTransfer") + for i, q_value in enumerate(q_values): + numeric_axis.setValue(i, q_value) + + ws.replaceAxis(1, numeric_axis) + + actual_theta_values, actual_q_values = indirect_common.get_two_theta_and_q(ws) + + expected_theta_values = [29.700000000000006, 32.32, 34.949999999999996, 37.58, 40.209999999999994] + self.assert_lists_almost_match(expected_theta_values, actual_theta_values) + self.assert_lists_almost_match(q_values, actual_q_values) + def test_extract_float(self): data = "0.0 1 .2 3e-3 4.3 -5.5 6.0" expected_result = [0, 1, 0.2, 3e-3, 4.3, -5.5, 6.0]