def __init__(self): """ Initialization """ # Initialize PowerLawAbsModel PowerLawModel.__init__(self) ## Name of the model self.name = "Absolute Power_Law" self.description = """ The Power_Law model.
def setUp(self): from sas.models.PowerLawModel import PowerLawModel self.model= PowerLawModel()
class TestPowerLaw(unittest.TestCase): """ Unit tests for PowerLaw function F(x) = scale* (x)^(m) + bkd The model has three parameters: m = power scale = scale factor bkd = incoherent background """ def _func(self, a, m, bgd, qval): return a*math.pow(qval,-m) + bgd def setUp(self): from sas.models.PowerLawModel import PowerLawModel self.model= PowerLawModel() def test1D(self): self.model.setParam('scale', math.exp(-6)) self.model.setParam('m', 4.0) self.model.setParam('background', 1.0) #self.assertEqual(self.model.run(0.0), 1.0) self.assertEqual(self.model.run(2.0), self._func(math.exp(-6), 4.0, 1.0, 2.0)) self.assertEqual(self.model.runXY(2.0), self._func(math.exp(-6), 4.0, 1.0, 2.0)) def testlimit(self): self.model.setParam('scale', math.exp(-6)) self.model.setParam('m', -4.0) self.model.setParam('background', 1.0) self.assertEqual(self.model.run(0.0), 1.0) def test2D(self): self.model.setParam('scale', math.exp(-6)) self.model.setParam('m', 4.0) self.model.setParam('background', 1.0) #value = self._func(math.exp(-6), 4.0, 1.0, 1.0)\ #*self._func(math.exp(-6), 4.0, 1.0, 2.0) value = self._func(math.exp(-6), 4.0, 1.0, math.sqrt(5.0)) self.assertEqual(self.model.runXY([1.0,2.0]), value) def test2Dphi(self): self.model.setParam('scale', math.exp(-6)) self.model.setParam('m', 4.0) self.model.setParam('background', 1.0) x = 1.0 y = 2.0 r = math.sqrt(x**2 + y**2) phi = math.atan2(y, x) value = self._func(math.exp(-6), 4.0, 1.0, x)\ *self._func(math.exp(-6), 4.0, 1.0, y) self.assertAlmostEquals(self.model.run([r, phi]), value,1)
def _PowerLaw(self, x): return PowerLawModel._PowerLaw(self, math.fabs(x))