Skip to content

Commit

Permalink
solve the interpolation issue
Browse files Browse the repository at this point in the history
This is a squashed version of #38534 into `ornl-next`

fix the doc and add release note

simply codes
  • Loading branch information
y8z authored and peterfpeterson committed Dec 20, 2024
1 parent 5b8b829 commit a0b77af
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# SPDX - License - Identifier: GPL - 3.0 +

import unittest
import numpy as np
from mantid.simpleapi import DeleteWorkspace, InterpolateBackground, CreateWorkspace, GroupWorkspaces


Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions docs/source/algorithms/InterpolateBackground-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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::
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix the issue with the :ref:`InterpolateBackground <algm-InterpolateBackground>` algorithm.

0 comments on commit a0b77af

Please sign in to comment.