Commit ae91e885 authored by Gemma Guest's avatar Gemma Guest
Browse files

Avoid passing lists of mixed value types to algorithms

parent 1091f6de
......@@ -184,7 +184,7 @@ void export_leaf_classes() {
"Algorithm", "Base class for all algorithms")
.def("fromString", &Algorithm::fromString, "Initialize the algorithm from a string representation")
.staticmethod("fromString")
.def("createChildAlgorithm", raw_function(&createChildWithProps, 1),
.def("createChildAlgorithm", raw_function(&createChildWithProps, std::size_t(1)),
"Creates and intializes a named child algorithm. Output workspaces "
"are given a dummy name.")
.def("declareProperty", (declarePropertyType1)&PythonAlgorithm::declarePyAlgProperty,
......
......@@ -123,7 +123,7 @@ class CrystalFieldPythonInterface(MantidSystemTest):
# ---------------------------
cf = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[44.0, 50], FWHM=[1.1, 0.9])
Temperature=[44.0, 50.], FWHM=[1.1, 0.9])
cf.PeakShape = 'Lorentzian'
cf.peaks[0].param[0]['FWHM'] = 1.11
cf.peaks[1].param[1]['FWHM'] = 1.12
......@@ -176,7 +176,7 @@ class CrystalFieldPythonInterface(MantidSystemTest):
fit.fit()
params = {'B20': 0.377, 'B22': 3.9, 'B40': -0.03, 'B42': -0.116, 'B44': -0.125,
'Temperature': [44.0, 50], 'FWHM': [1.1, 0.9]}
'Temperature': [44.0, 50.], 'FWHM': [1.1, 0.9]}
cf1 = CrystalField('Ce', 'C2v', **params)
cf2 = CrystalField('Pr', 'C2v', **params)
cfms = cf1 + cf2
......@@ -392,6 +392,6 @@ class CrystalFieldPythonInterface(MantidSystemTest):
PPchi = PhysicalProperties('susc', 'powder', Unit='cgs')
PPMag = PhysicalProperties('M(H)', [1, 1, 1], 5, 'bohr')
cf = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[44.0, 50], FWHM=[1.1, 0.9], PhysicalProperty=[PPCv, PPchi, PPMag] )
Temperature=[44.0, 50.], FWHM=[1.1, 0.9], PhysicalProperty=[PPCv, PPchi, PPMag] )
fit = CrystalFieldFit(Model=cf, InputWorkspace=[ws_ins_44K, ws_ins_50K, ws_cp, ws_chi, ws_mag])
fit.fit()
......@@ -498,6 +498,8 @@ class CrystalField(object):
if len(value) != len(self.Temperature):
if self.PhysicalProperty is not None and len(value) == len(self.Temperature) - len(self.PhysicalProperty):
value = value + [0] * len(self.PhysicalProperty)
# Cast all types to match the first elem so we don't have mixed lists of int/doubles
value = [type(value[0])(v) for v in value]
else:
raise RuntimeError('Vector of FWHMs must either have same size as '
'Temperatures (%i) or have size 1.' % (len(self.Temperature)))
......
......@@ -571,7 +571,7 @@ class CrystalFieldMultiSiteTests(unittest.TestCase):
def test_multi_ion_intensity_scaling_multi_spectrum(self):
from CrystalField import CrystalField
params = {'B20': 0.37737, 'B22': 3.9770, 'B40': -0.031787, 'B42': -0.11611, 'B44': -0.12544,
'Temperature': [44.0, 50], 'FWHM': [1.1, 1.6]}
'Temperature': [44.0, 50.0], 'FWHM': [1.1, 1.6]}
cf1 = CrystalField('Ce', 'C2v', **params)
cf2 = CrystalField('Pr', 'C2v', **params)
cf = cf1 + cf2
......
......@@ -577,7 +577,7 @@ class CrystalFieldTests(unittest.TestCase):
self.assertEqual(cf.FWHM[0], 1.0)
self.assertEqual(cf.FWHM[1], 1.0)
self.assertRaises(RuntimeError, CrystalField, 'Ce', 'C2v', B20=0.035, Temperature=[5, 10], FWHM=[0.5, 1, 2])
cf = CrystalField('Ce', 'C2v', B20=0.035, Temperature=[5, 10], FWHM=[0.5, 1])
cf = CrystalField('Ce', 'C2v', B20=0.035, Temperature=[5, 10], FWHM=[0.5, 1.0])
def set_intensity_scaling(cf, value):
cf.IntensityScaling = value
......@@ -748,7 +748,7 @@ class CrystalFieldFitTest(unittest.TestCase):
from CrystalField.fitting import makeWorkspace
from CrystalField import CrystalField, CrystalFieldFit, Background, Function
origin = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[44.0, 50], FWHM=[1.1, 0.9])
Temperature=[44.0, 50.0], FWHM=[1.1, 0.9])
origin.PeakShape = 'Lorentzian'
origin.peaks[0].param[1]['FWHM'] = 1.22
origin.background = Background(peak=Function('Gaussian', Height=10, Sigma=0.3),
......@@ -775,7 +775,7 @@ class CrystalFieldFitTest(unittest.TestCase):
self.assertEqual(fun.getParameterValue('f1.f3.FWHM'), 0.9)
cf = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[44.0, 50], FWHM=[1.1, 0.9])
Temperature=[44.0, 50.0], FWHM=[1.1, 0.9])
cf.PeakShape = 'Lorentzian'
cf.peaks[0].param[0]['FWHM'] = 1.11
cf.peaks[1].param[1]['FWHM'] = 1.12
......@@ -834,7 +834,7 @@ class CrystalFieldFitTest(unittest.TestCase):
from CrystalField.fitting import makeWorkspace
from CrystalField import CrystalField, CrystalFieldFit, Background, Function
origin = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[44.0, 50], FWHM=[1.1, 0.9])
Temperature=[44.0, 50.], FWHM=[1.1, 0.9])
origin.PeakShape = 'Lorentzian'
origin.background = Background(background=Function('FlatBackground', A0=1.0))
origin.background[1].background.param['A0'] = 1.2
......@@ -854,7 +854,7 @@ class CrystalFieldFitTest(unittest.TestCase):
self.assertEqual(fun.getParameterValue('f1.f3.FWHM'), 0.9)
cf = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[44.0, 50], FWHM=[1.1, 0.9])
Temperature=[44.0, 50.], FWHM=[1.1, 0.9])
cf.PeakShape = 'Lorentzian'
cf.background = Background(background=Function('FlatBackground', A0=0.9))
cf.peaks[0].param[0]['FWHM'] = 1.11
......@@ -874,7 +874,7 @@ class CrystalFieldFitTest(unittest.TestCase):
from CrystalField.fitting import makeWorkspace
from CrystalField import CrystalField, CrystalFieldFit, Background, Function
origin = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[44.0, 50], FWHM=[1.1, 0.9])
Temperature=[44.0, 50.], FWHM=[1.1, 0.9])
origin.PeakShape = 'Lorentzian'
origin.background = Background(peak=Function('Gaussian', Height=10, Sigma=0.3))
origin.background[1].peak.param['Sigma'] = 0.8
......@@ -895,7 +895,7 @@ class CrystalFieldFitTest(unittest.TestCase):
self.assertEqual(fun.getParameterValue('f1.f3.FWHM'), 0.9)
cf = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[44.0, 50], FWHM=[1.1, 0.9])
Temperature=[44.0, 50.0], FWHM=[1.1, 0.9])
cf.PeakShape = 'Lorentzian'
cf.background = Background(peak=Function('Gaussian', Height=10, Sigma=0.3))
cf.peaks[0].param[0]['FWHM'] = 1.11
......@@ -926,7 +926,7 @@ class CrystalFieldFitTest(unittest.TestCase):
def test_fit_single_multi_check(self):
from CrystalField.fitting import makeWorkspace
from CrystalField import CrystalField, CrystalFieldFit
cf = CrystalField('Nd', 'C2v', B20=-0.4, Temperature=[5, 10], FWHM=[0.5, 1])
cf = CrystalField('Nd', 'C2v', B20=-0.4, Temperature=[5, 10], FWHM=[0.5, 1.])
x, y = cf.getSpectrum()
ws = makeWorkspace(x, y)
cf.IntensityScaling = [1, 2]
......@@ -1078,7 +1078,7 @@ class CrystalFieldFitTest(unittest.TestCase):
from mantid.simpleapi import FunctionFactory
cf = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[44.0, 50], FWHM=[1.1, 0.9])
Temperature=[44.0, 50.], FWHM=[1.1, 0.9])
cf.PeakShape = 'Lorentzian'
cf.background = Background(peak=Function('Gaussian', Height=10, Sigma=0.3),
background=Function('FlatBackground', A0=1.0))
......@@ -1143,7 +1143,7 @@ class CrystalFieldFitTest(unittest.TestCase):
from mantid.simpleapi import FunctionFactory
cf = CrystalField('Ce', 'C2v', B20=0.37737, B22=3.9770, B40=-0.031787, B42=-0.11611, B44=-0.12544,
Temperature=[50, 20], FWHM=[0.9, 10])
Temperature=[50, 20], FWHM=[0.9, 10.])
cf.peaks[0].constrainAll('0.1 < FWHM <=2.1', 2)
cf.peaks[1].constrainAll('FWHM > 12.1', 3, 5)
......@@ -1341,7 +1341,7 @@ class CrystalFieldFitTest(unittest.TestCase):
rm = ResolutionModel([(x0, y0), (x1, y1)])
cf = CrystalField('Ce', 'C2v', B20=0.37, B22=3.97, B40=-0.0317, B42=-0.116, B44=-0.12,
Temperature=[44.0, 50], ResolutionModel=rm)
Temperature=[44.0, 50.0], ResolutionModel=rm)
att = cf.function.getAttributeValue('FWHMX0')
self.assertEqual(att[0], 0)
......@@ -1366,7 +1366,7 @@ class CrystalFieldFitTest(unittest.TestCase):
rm = ResolutionModel([(x0, y0), (x1, y1)])
cf = CrystalField('Ce', 'C2v', B20=0.37, B22=3.97, B40=-0.0317, B42=-0.116, B44=-0.12,
Temperature=[44.0, 50], ResolutionModel=rm, FWHMVariation=0.1)
Temperature=[44.0, 50.], ResolutionModel=rm, FWHMVariation=0.1)
att = cf.function.getAttributeValue('FWHMX0')
self.assertEqual(att[0], 0)
......@@ -1386,7 +1386,7 @@ class CrystalFieldFitTest(unittest.TestCase):
from CrystalField import ResolutionModel, CrystalField
x = [0, 50]
y = [0.1, 2]
y = [0.1, 2.]
rm = ResolutionModel((x, y))
cf1 = CrystalField('Ce', 'C2v', B20=0.37, B22=3.97, B40=-0.0317, B42=-0.116, B44=-0.12,
......
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