Skip to content

Allow a Separate High Angle Bank Scale Factor to Be Defined in User File #39806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def PyExec(self):
# 7. Multiply by volume and absolute scale
# --------------------------------------------------------------------------------------------------------------
progress.report("Multiplying by volume and absolute scale ...")
scatter_data = self._scale(state=state, workspace=scatter_data)
scatter_data = self._scale(state=state, workspace=scatter_data, component=component_as_string)

# --------------------------------------------------------------------------------------------------------------
# 8. Create adjustment workspaces, those are
Expand Down Expand Up @@ -349,9 +349,9 @@ def _convert_to_wavelength(self, state, workspace):
grouped_ws = wavelength_alg.getProperty("OutputWorkspace").value
return grouped_ws.getItem(0)

def _scale(self, state, workspace):
def _scale(self, state, workspace, component: str):
instrument = state.data.instrument
output_ws = scale_workspace(workspace=workspace, instrument=instrument, state_scale=state.scale)
output_ws = scale_workspace(workspace=workspace, instrument=instrument, state_scale=state.scale, component=DetectorType(component))

return output_ws

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def PyExec(self):
# 7. Multiply by volume and absolute scale
# --------------------------------------------------------------------------------------------------------------
progress.report("Multiplying by volume and absolute scale ...")
workspaces = self._scale(state=state, ws_list=workspaces)
workspaces = self._scale(state=state, ws_list=workspaces, component=component_as_string)

# --------------------------------------------------------------------------------------------------------------
# 8. Create adjustment workspaces, those are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ def _convert_to_wavelength(self, workspace, wavelength_state) -> WsList:
processed = {tuple(wav_range): ws for wav_range, ws in zip(selected_ranges, grouped_ws)}
return processed

def _scale(self, state, ws_list: WsList):
def _scale(self, state, ws_list: WsList, component: str):
instrument = state.data.instrument
for key, ws in ws_list.items():
output_ws = scale_workspace(instrument=instrument, state_scale=state.scale, workspace=ws)
output_ws = scale_workspace(instrument=instrument, state_scale=state.scale, workspace=ws, component=DetectorType(component))
ws_list[key] = output_ws
return ws_list

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def PyExec(self):
# 6. Multiply by volume and absolute scale
# --------------------------------------------------------------------------------------------------------------
progress.report("Multiplying by volume and absolute scale ...")
workspace = self._scale(state=state, workspace=workspace)
workspace = self._scale(state=state, ws_list=workspace, component=component_as_string)

progress.report("Completed SANSReductionCorePreprocess ...")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tests for ISIS SANS

set(TEST_PY_FILES SANSConvertToWavelengthAndRebinTest.py SANSTubeCalibrationTest.py)
set(TEST_PY_FILES SANSConvertToWavelengthAndRebinTest.py SANSTubeCalibrationTest.py SANSBeamCentreFinderTest.py)

check_tests_valid(${CMAKE_CURRENT_SOURCE_DIR} ${TEST_PY_FILES})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import unittest

from unittest import mock

from mantid.kernel import Logger
from plugins.algorithms.WorkflowAlgorithms.SANS.SANSBeamCentreFinder import SANSBeamCentreFinder, _ResidualsDetails


Expand All @@ -19,6 +21,10 @@ def gen_mock_data(q_vals, y_vals):
mocked_quartile.readY.return_value = y_vals
return mocked_quartile

def setUp(self):
self.centre_finder = SANSBeamCentreFinder()
self.centre_finder.logger = Logger("SANSBeamCentreFinderTest")

def test_points_calculates_correctly(self):
points_1 = [1.0, 2.0, 4.0]
points_2 = [1.0, 3.0, 5.0]
Expand All @@ -29,8 +35,7 @@ def test_points_calculates_correctly(self):
expected_points = len(set().union(points_1, points_2))
mismatched_points = len(set(points_1).symmetric_difference(set(points_2)))

obj = SANSBeamCentreFinder()
result = obj._calculate_residuals(q1_data, q2_data)
result = self.centre_finder._calculate_residuals(q1_data, q2_data)
self.assertIsInstance(result, _ResidualsDetails)
self.assertEqual(mismatched_points, result.mismatched_points)
self.assertEqual(expected_points, result.num_points_considered)
Expand All @@ -40,8 +45,7 @@ def test_residual_diff_with_only_mismatched(self):
q2_data = self.gen_mock_data([1.0, 2.0], [0.0, 1.0])

# Mismatched points should always contribute their entire val, not the diff (i.e. 1. above)
obj = SANSBeamCentreFinder()
result = obj._calculate_residuals(q1_data, q2_data)
result = self.centre_finder._calculate_residuals(q1_data, q2_data)
self.assertEqual(2.0, result.total_residual)

def test_residual_diff_with_only_matched(self):
Expand All @@ -52,8 +56,7 @@ def test_residual_diff_with_only_matched(self):

expected_matched = (y_data_1[0] - y_data_2[0]) ** 2

obj = SANSBeamCentreFinder()
result = obj._calculate_residuals(q1_data, q2_data)
result = self.centre_finder._calculate_residuals(q1_data, q2_data)

self.assertEqual(expected_matched, result.total_residual)

Expand All @@ -63,11 +66,14 @@ def test_residual_diff_with_mixed_mismatched(self):
q1_data = self.gen_mock_data([1.0, 3.0], y_data_1)
q2_data = self.gen_mock_data([1.0, 2.0], y_data_2)

obj = SANSBeamCentreFinder()
result = obj._calculate_residuals(q1_data, q2_data)
result = self.centre_finder._calculate_residuals(q1_data, q2_data)

# Matched bins contribute the diff ([0]) whilst mismatched ([1]) contribute all
expected_matched = (y_data_1[0] - y_data_2[0]) ** 2
expected_mismatched = (y_data_1[1] ** 2) + (y_data_2[1] ** 2)
squared_expected = expected_matched + expected_mismatched
self.assertEqual(squared_expected, result.total_residual)


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletions docs/source/release/v6.14.0/SANS/New_features/39341.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- The option to specify a separate scale factor for the High Angle Bank on compatible instruments (such as LOQ and
SANS2D) has been added to the :ref:`sans_toml_v1-ref`.
Loading