From a0b77afee48ea20013cc970ed6b8ee723aa86947 Mon Sep 17 00:00:00 2001 From: y8z Date: Thu, 19 Dec 2024 16:19:23 -0500 Subject: [PATCH] solve the interpolation issue This is a squashed version of #38534 into `ornl-next` fix the doc and add release note simply codes --- .../WorkflowAlgorithms/InterpolateBackground.py | 4 ++-- .../WorkflowAlgorithms/InterpolateBackgroundTest.py | 6 ++++-- docs/source/algorithms/InterpolateBackground-v1.rst | 9 +++++---- .../v6.12.0/Diffraction/Powder/Bugfixes/38534.rst | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 docs/source/release/v6.12.0/Diffraction/Powder/Bugfixes/38534.rst diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/InterpolateBackground.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/InterpolateBackground.py index da8584f152a0..209e6a5955a6 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/InterpolateBackground.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/InterpolateBackground.py @@ -74,8 +74,8 @@ def PyExec(self): lowWS = mtd[self.low_ws] highWS = mtd[self.high_ws] - scalar = (self.interpo_temp - self.low_temp) / (self.high_temp - self.interpo_temp) - outputWS = lowWS + scalar * highWS - scalar * lowWS + scalar = (self.interpo_temp - self.low_temp) / (self.high_temp - self.low_temp) + outputWS = scalar * highWS + (1 - scalar) * lowWS output_ws_name = self.getProperty("OutputWorkspace").value RenameWorkspace(InputWorkspace=outputWS, OutputWorkspace=output_ws_name) diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/WorkflowAlgorithms/InterpolateBackgroundTest.py b/Framework/PythonInterface/test/python/plugins/algorithms/WorkflowAlgorithms/InterpolateBackgroundTest.py index e959238cab68..f1853adec263 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/WorkflowAlgorithms/InterpolateBackgroundTest.py +++ b/Framework/PythonInterface/test/python/plugins/algorithms/WorkflowAlgorithms/InterpolateBackgroundTest.py @@ -6,6 +6,7 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest +import numpy as np from mantid.simpleapi import DeleteWorkspace, InterpolateBackground, CreateWorkspace, GroupWorkspaces @@ -26,8 +27,9 @@ def test_nominal(self): self.ws1.getRun().addProperty("SampleTemp", "100", False) self.ws2.getRun().addProperty("SampleTemp", "400", False) outputWS = InterpolateBackground(self.wsGroup, self.interpo) - expected = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150] - self.assertListEqual(list(outputWS.readY(0)), expected) + expected = [8.33333333, 16.66666667, 25.0, 33.33333333, 41.66666667, 50.0, 58.33333333, 66.66666667, 75.0, 83.33333333] + tolerance = 1.0e-8 + np.testing.assert_allclose(list(outputWS.readY(0)), expected, rtol=tolerance) def test_bad_input(self): # Test raises Runtime error if a workspace is missing SampleTemp property diff --git a/docs/source/algorithms/InterpolateBackground-v1.rst b/docs/source/algorithms/InterpolateBackground-v1.rst index 993e1268aac0..619466c3b71a 100644 --- a/docs/source/algorithms/InterpolateBackground-v1.rst +++ b/docs/source/algorithms/InterpolateBackground-v1.rst @@ -20,7 +20,8 @@ Below is the function used for the interpolation: .. math:: - WS_{interpolated} = WS_{low} + (temp_{interpo} - temp_{low}) / (temp_{high} - temp_{interpo}) * (WS_{high} - WS_{low}), + factor = (temp_{interpo} - temp_{low}) / (temp_{high} - temp_{low}) + WS_{interpolated} = WS_{high} * factor + WS_{low} * (1 - factor) where :math:`WS_{low}` and :math:`WS_{high}` are the workspaces containing the run data, :math:`temp_{low}` and :math:`temp_{high}` are the two extreme temperatures the empty containers were measured at, and @@ -44,10 +45,10 @@ Usage ws1 = CreateWorkspace(dataX, dataY1) ws2 = CreateWorkspace(dataX, dataY2) wsGroup = GroupWorkspaces("ws1,ws2") - interpoTemp = "300" + interpoTemp = "200" # CreateWorkspace does not add the "SampleTemp" property so we need to add it here ws1.getRun().addProperty("SampleTemp", "100", False) - ws2.getRun().addProperty("SampleTemp", "400", False) + ws2.getRun().addProperty("SampleTemp", "300", False) # Perform the background interpolation outputWS = InterpolateBackground(wsGroup, interpoTemp) @@ -59,7 +60,7 @@ Output: .. testoutput:: - Interpolated Y values are: [3. 3. 3. 3. 3. 3. 3. 3. 3. 3.] + Interpolated Y values are: [1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5] .. categories:: diff --git a/docs/source/release/v6.12.0/Diffraction/Powder/Bugfixes/38534.rst b/docs/source/release/v6.12.0/Diffraction/Powder/Bugfixes/38534.rst new file mode 100644 index 000000000000..c86767268419 --- /dev/null +++ b/docs/source/release/v6.12.0/Diffraction/Powder/Bugfixes/38534.rst @@ -0,0 +1 @@ +- Fix the issue with the :ref:`InterpolateBackground ` algorithm.