Пример #1
0
 def setUp(self):
     from sas.models.TeubnerStreyModel import TeubnerStreyModel
     self.model= TeubnerStreyModel()
Пример #2
0
class TestTeubnerStrey(unittest.TestCase):
    """
        Unit tests for PowerLaw function

        F(x) = 1/( scale + c1*(x)^(2)+  c2*(x)^(4)) + bkd
        
        The model has Four parameters: 
            scale  =  scale factor
            c1     =  constant
            c2     =  constant
            bkd    =  incoherent background
    """
    def _func(self, scale, c1, c2, bck, q):
        
        q2 = q*q;
        q4 = q2*q2;
    
        return 1.0/(scale + c1*q2+c2*q4) + bck
    
    def setUp(self):
        from sas.models.TeubnerStreyModel import TeubnerStreyModel
        self.model= TeubnerStreyModel()
        
    def test1D(self):
        
        self.model.setParam('c1', -30.0) 
        self.model.setParam('c2', 5000.0) 
        self.model.setParam('scale', 0.1)
        self.model.setParam('background', 0.1)
        #self.assertEqual(1/(math.sqrt(4)), math.pow(4,-1/2))
        #self.assertEqual(self.model.TeubnerStreyLengths(),False )
        
        self.assertEqual(self.model.run(0.0), 10.1)
        self.assertEqual(self.model.run(2.0), self._func(0.1,-30.0,5000.0,0.1,2.0))
        self.assertEqual(self.model.runXY(2.0), self._func(0.1,-30.0,5000.0,0.1,2.0))
        
    def test2D(self):
        self.model.setParam('c1', -30.0) 
        self.model.setParam('c2', 5000.0) 
        self.model.setParam('scale', 0.1)
        self.model.setParam('background', 0.1)
        #value = self._func(0.1,-30.0,5000.0,0.1, 1.0)\
        #*self._func(0.1,-30.0,5000.0,0.1, 2.0)    
        value = self._func(0.1,-30.0,5000.0,0.1, math.sqrt(5.0))
        
        self.assertEqual(self.model.runXY([1.0,2.0]), value)
        
    def test2Dphi(self):
        self.model.setParam('c1', -30.0) 
        self.model.setParam('c2', 5000.0) 
        self.model.setParam('scale', 0.1)
        self.model.setParam('background', 0.1)
        
        x = 1.0
        y = 2.0
        r = math.sqrt(x**2 + y**2)
        phi = math.atan2(y, x)
        
        #value = self._func(0.1,-30.0,5000.0,0.1, x)\
        #*self._func(0.1,-30.0,5000.0,0.1, y)
        value = self._func(0.1,-30.0,5000.0,0.1, r)
        self.assertAlmostEquals(self.model.run([r, phi]), value,1)