Commit c7f970dd authored by David Fairbrother's avatar David Fairbrother Committed by Peterson, Peter
Browse files

Fix garbage RedField test input(s)

- Refactor RedField to use a built in named constant
- Use numpy.power instead of **2

For the test we were using a tiny Gauss value. The original value was
0.1, for reference a Iron Bar Magnet has a value of 100G so naturally
we're going to get garbage back out.

Tweak the values in to be more sensible as they were falling off to 0
due to the 1/x^2 calculation
parent 76a64bdc
......@@ -7,10 +7,12 @@
# pylint: disable=invalid-name, anomalous-backslash-in-string, attribute-defined-outside-init
from mantid.api import IFunction1D, FunctionFactory
from mantid.kernel import PhysicalConstants
import numpy as np
class Redfield(IFunction1D):
class Redfield(IFunction1D):
def category(self):
return "Muon\\MuonModelling"
......@@ -24,8 +26,8 @@ class Redfield(IFunction1D):
A0 = self.getParameterValue("A0")
Hloc = self.getParameterValue("Hloc")
tau = self.getParameterValue("Tau")
gmu = 0.01355342
return A0 * 2 * (gmu * Hloc) ** 2 * tau / (1 + (gmu * x * tau) ** 2)
gmu = PhysicalConstants.MuonGyromagneticRatio
return A0 * 2 * np.power((gmu * Hloc), 2) * tau / (1 + np.power((gmu * x * tau), 2))
FunctionFactory.subscribe(Redfield)
......@@ -18,10 +18,11 @@ class RedfieldTest(unittest.TestCase):
self.fail(msg)
def test_function_output(self):
input = [0.0, 4.0, 8.0, 12.0]
expected = [7.34780775e-08, 7.34759179e-08, 7.34694400e-08, 7.34586461e-08]
input = np.linspace(0, 1000, 4) # Between 0-1000 Gauss
expected = [0.91847597, 0.76278678, 0.5056509, 0.3237545]
tolerance = 1.0e-05
status, output = check_output("Redfield", input, expected, tolerance, A0 = 0.2, Hloc = 0.1, Tau = 0.1)
function_params = {"A0": 10, "Hloc": 50, "Tau": 0.1}
status, output = check_output("Redfield", input, expected, tolerance, **function_params)
if not status:
msg = 'Computed output {} from input {} unequal to expected: {}'
self.fail(msg.format(*[str(i) for i in (output, input, expected)]))
......@@ -29,5 +30,6 @@ class RedfieldTest(unittest.TestCase):
def test_do_fit(self):
do_a_fit(np.arange(0.1, 16, 0.2), 'Redfield', guess = dict(A0 = 0.2, Hloc = 0.1, Tau = 0.1),target = dict(A0 = 0.2, Hloc = 0.1, Tau = 0.1), atol = 0.01)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment