class TestFractal(unittest.TestCase): """ Unit tests for Fractal model """ def setUp(self): from sas.models.FractalModel import FractalModel self.comp = FractalModel() def test1D(self): """ Test 1D model for a Fractal """ self.assertAlmostEqual(self.comp.run(0.001), 39.288146, 4) def test1D_2(self): """ Test 2D model for a Fractal """ self.assertAlmostEqual(self.comp.run([0.001, 1]), 39.288146, 4)
def setUp(self): from sas.models.FractalModel import FractalModel self.model= FractalModel() self.r0 = 5.0 self.sldp = 2.0e-6 self.sldm = 6.35e-6 self.phi = 0.05 self.Df = 2 self.corr = 100.0 self.bck = 1.0 self.model.setParam('scale', self.phi) self.model.setParam('radius', self.r0) self.model.setParam('fractal_dim',self.Df) self.model.setParam('cor_length', self.corr) self.model.setParam('sldBlock', self.sldp) self.model.setParam('sldSolv', self.sldm) self.model.setParam('background', self.bck)
class TestFractalModel(unittest.TestCase): """ Unit tests for Number Density Fractal function F(x)= P(x)*S(x) + bkd The model has Seven parameters: scale = Volume fraction Radius = Block radius Fdim = Fractal dimension L = correlation Length SDLB = SDL block SDLS = SDL solvent bkd = background """ def setUp(self): from sas.models.FractalModel import FractalModel self.model= FractalModel() self.r0 = 5.0 self.sldp = 2.0e-6 self.sldm = 6.35e-6 self.phi = 0.05 self.Df = 2 self.corr = 100.0 self.bck = 1.0 self.model.setParam('scale', self.phi) self.model.setParam('radius', self.r0) self.model.setParam('fractal_dim',self.Df) self.model.setParam('cor_length', self.corr) self.model.setParam('sldBlock', self.sldp) self.model.setParam('sldSolv', self.sldm) self.model.setParam('background', self.bck) def _func(self, x): r0 = self.r0 sldp = self.sldp sldm = self.sldm phi = self.phi Df = self.Df corr = self.corr bck = self.bck pq = 1.0e8*phi*4.0/3.0*math.pi*r0*r0*r0*(sldp-sldm)*(sldp-sldm)*math.pow((3*(math.sin(x*r0) - x*r0*math.cos(x*r0))/math.pow((x*r0),3)),2); sq = Df*math.exp(gammaln(Df-1.0))*math.sin((Df-1.0)*math.atan(x*corr)); sq /= math.pow((x*r0),Df) * math.pow((1.0 + 1.0/(x*corr)/(x*corr)),((Df-1.0)/2.0)); sq += 1.0; #self.assertAlmostEqual(self.model._scatterRanDom(x), pq, 8 ) #self.assertEqual(self.model._Block(x),sq ) return sq*pq+bck def test1D(self): x = 0.001 iq = self._func(x) self.assertEqual(self.model.run(x), iq) self.assertEqual(self.model.runXY(x), iq) def test2D(self): x = 1.0 y = 2.0 r = math.sqrt(x**2 + y**2) phi = math.atan2(y, x) iq_x = self._func(x) iq_y = self._func(y) #self.assertEqual(self.model.run([r, phi]), iq_x*iq_y) self.assertEqual(self.model.run([r, phi]), self.model.run(r)) #self.assertEqual(self.model.runXY([x,y]), iq_x*iq_y) self.assertEqual(self.model.runXY([x,y]), self.model.run(r))
def setUp(self): from sas.models.FractalModel import FractalModel self.comp = FractalModel()