Exemple #1
0
 def setUp(self):
     from sas.models.DebyeModel import DebyeModel
     self.model= DebyeModel()
     self.model.setParam('rg', 50.0)    
     self.model.setParam('scale',1.0) 
     self.model.setParam('background',0.001)   
Exemple #2
0
class TestDebye(unittest.TestCase):
    """
        Unit tests for Debye function
        
        F(x) = 2( exp(-x)+x -1 )/x**2
        
        The model has three parameters: 
            Rg     =  radius of gyration
            scale  =  scale factor
            bkd    =  Constant background
    """
    def _func(self, Rg, scale, bkg, x):
        y = (Rg * x)**2
        return scale * (2*(math.exp(-y) + y -1)/y**2) + bkg
    
    def setUp(self):
        from sas.models.DebyeModel import DebyeModel
        self.model= DebyeModel()
        self.model.setParam('rg', 50.0)    
        self.model.setParam('scale',1.0) 
        self.model.setParam('background',0.001)   
        
    def test1D(self):
        value = self._func(50.0, 1.0, 0.001, 2.0)
        self.assertEqual(self.model.run(2.0), value)
        self.assertEqual(self.model.runXY(2.0), value)

        # User enter zero as a value of x, y= 1
        self.assertAlmostEqual(self.model.run(0.0), 1.00, 2)
        
    def test1D_clone(self):
        value = self._func(50.0, 1.0, 10.0, 2.0)
        self.model.setParam('background', 10.0)
        clone = self.model.clone()
        self.assertEqual(clone.run(2.0), value)
        self.assertEqual(clone.runXY(2.0), value)
        
        # User enter zero as a value of x
        # An exceptio is raised: No more exception
        #self.assertRaises(ZeroDivisionError, clone.run, 0.0)
        
    def test2D(self):
        #value = self._func(50.0, 1.0, 0.001, 1.0)*self._func(50.0, 1.0, 0.001, 2.0)
        value = self._func(50.0, 1.0, 0.001, math.sqrt(5.0))
        self.assertEqual(self.model.runXY([1.0,2.0]), value)
        
    def test2Dphi(self):
        x = 1.0
        y = 2.0
        r = math.sqrt(x**2 + y**2)
        phi = math.atan2(y, x)
        
        value = self._func(50.0, 1.0, 0.001, 1.0)*self._func(50.0, 1.0, 0.001, 2.0)
        self.assertAlmostEquals(self.model.run([r, phi]), value,1)