Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/release/v6.11.0/Inelastic/Bugfixes/37898.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed an 'index out of range' error in the :ref:`BayesQuasi <algm-BayesQuasi>` algorithm when using a sample with a Numeric Axis.
9 changes: 2 additions & 7 deletions scripts/Inelastic/IndirectCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 19 additions & 2 deletions scripts/test/IndirectCommonTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -96,14 +96,31 @@ 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]
actual_theta_result, actual_Q_result = indirect_common.get_two_theta_and_q(ws)
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]
Expand Down
Loading