Exemplo n.º 1
0
class TestSphere(unittest.TestCase):
    """
        Testing C++ Cylinder model
    """
    def setUp(self):
        from sas.models.SphereModel import SphereModel
        self.model = SphereModel()

        self.model.setParam('scale', 1.0)
        self.model.setParam('radius', 60.0)
        self.model.setParam('sldSph', 2.0)
        self.model.setParam('sldSolv', 1.0)
        self.model.setParam('background', 0.0)

    def test_simple(self):
        """
            Test simple 1D and 2D values
            Numbers taken from model that passed validation, before
            the update to C++ underlying class.
        """
        self.assertTrue(
            math.fabs(self.model.run(0.001) - 90412744456148.094) <= 50.0)
        self.assertAlmostEqual(self.model.runXY([0.001, 0.001]),
                               90347660670656.391, 1)

    def test_dispersion(self):
        """
            Test with dispersion
        """
        from sas.models.DisperseModel import DisperseModel
        disp = DisperseModel(self.model, ['radius'], [10])
        disp.setParam('n_pts', 10)
        disp.setParam('radius.npts', 10)
        disp.setParam('radius.nsigmas', 2.5)
        self.assertTrue(math.fabs(disp.run(0.001) - 96795008379475.219 < 50.0))

    def test_new_disp(self):
        from sas.models.dispersion_models import GaussianDispersion
        disp_rm = GaussianDispersion()
        self.model.set_dispersion('radius', disp_rm)
        self.model.dispersion['radius']['width'] = 0.1666666667
        self.model.dispersion['radius']['npts'] = 10
        self.model.dispersion['radius']['nsigmas'] = 2
Exemplo n.º 2
0
class TestSphere(unittest.TestCase):
    """
        Testing C++ Cylinder model
    """
    def setUp(self):
        from sas.models.SphereModel import SphereModel
        self.model= SphereModel()
        
        self.model.setParam('scale', 1.0)
        self.model.setParam('radius', 60.0)
        self.model.setParam('sldSph', 2.0)
        self.model.setParam('sldSolv', 1.0)
        self.model.setParam('background', 0.0)
        
    def test_simple(self):
        """
            Test simple 1D and 2D values
            Numbers taken from model that passed validation, before
            the update to C++ underlying class.
        """
        self.assertTrue(math.fabs(self.model.run(0.001)-90412744456148.094)<=50.0)
        self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 
                               90347660670656.391, 1)

    def test_dispersion(self):
        """
            Test with dispersion
        """
        from sas.models.DisperseModel import DisperseModel
        disp = DisperseModel(self.model, ['radius'], [10])
        disp.setParam('n_pts', 10)
        disp.setParam('radius.npts', 10)
        disp.setParam('radius.nsigmas', 2.5)
        self.assertTrue(math.fabs(disp.run(0.001)-96795008379475.219<50.0))
        
    def test_new_disp(self):
        from sas.models.dispersion_models import GaussianDispersion
        disp_rm = GaussianDispersion()
        self.model.set_dispersion('radius', disp_rm)
        self.model.dispersion['radius']['width'] = 0.1666666667
        self.model.dispersion['radius']['npts'] = 10
        self.model.dispersion['radius']['nsigmas'] = 2
class TestSphereGauss(unittest.TestCase):
    """
        Testing C++  Polydispersion w/ sphere comparing to IGOR/NIST computation
    """
    def setUp(self):
        loader = Loader()
        ## IGOR/NIST computation
        self.output_gauss = loader.load('Gausssphere.txt')
        self.output_shulz = loader.load('Schulzsphere.txt')

        from sas.models.SphereModel import SphereModel
        self.model = SphereModel()

        self.model.setParam('scale', 0.01)
        self.model.setParam('radius', 60.0)
        self.model.setParam('sldSph', 1.e-6)
        self.model.setParam('sldSolv', 3.e-6)
        self.model.setParam('background', 0.001)

    def test_gauss(self):
        from sas.models.dispersion_models import GaussianDispersion
        disp_g = GaussianDispersion()
        self.model.set_dispersion('radius', disp_g)
        self.model.dispersion['radius']['width'] = 0.2
        self.model.dispersion['radius']['npts'] = 100
        self.model.dispersion['radius']['nsigmas'] = 10
        for ind in range(len(self.output_gauss.x)):
            self.assertAlmostEqual(self.model.run(self.output_gauss.x[ind]),
                                   self.output_gauss.y[ind], 2)

    def test_shulz(self):
        from sas.models.dispersion_models import SchulzDispersion
        disp_s = SchulzDispersion()
        self.model.set_dispersion('radius', disp_s)
        self.model.dispersion['radius']['width'] = 0.2
        self.model.dispersion['radius']['npts'] = 100
        self.model.dispersion['radius']['nsigmas'] = 10
        for ind in range(len(self.output_shulz.x)):
            self.assertAlmostEqual(self.model.run(self.output_gauss.x[ind]),
                                   self.output_shulz.y[ind], 3)
class TestSphereGauss(unittest.TestCase):
    """
        Testing C++  Polydispersion w/ sphere comparing to IGOR/NIST computation
    """
    def setUp(self):
        loader = Loader()
        ## IGOR/NIST computation
        self.output_gauss=loader.load('Gausssphere.txt')
        self.output_shulz=loader.load('Schulzsphere.txt')

        from sas.models.SphereModel import SphereModel
        self.model= SphereModel()

        self.model.setParam('scale', 0.01)
        self.model.setParam('radius', 60.0)
        self.model.setParam('sldSph', 1.e-6)
        self.model.setParam('sldSolv', 3.e-6)
        self.model.setParam('background', 0.001)

    def test_gauss(self):
        from sas.models.dispersion_models import GaussianDispersion
        disp_g = GaussianDispersion()
        self.model.set_dispersion('radius', disp_g)
        self.model.dispersion['radius']['width'] = 0.2
        self.model.dispersion['radius']['npts'] = 100
        self.model.dispersion['radius']['nsigmas'] = 10
        for ind in range(len(self.output_gauss.x)):
            self.assertAlmostEqual(self.model.run(self.output_gauss.x[ind]), 
                                   self.output_gauss.y[ind], 2)
        
    def test_shulz(self):
        from sas.models.dispersion_models import SchulzDispersion
        disp_s = SchulzDispersion()
        self.model.set_dispersion('radius', disp_s)
        self.model.dispersion['radius']['width'] = 0.2
        self.model.dispersion['radius']['npts'] = 100
        self.model.dispersion['radius']['nsigmas'] = 10
        for ind in range(len(self.output_shulz.x)):
            self.assertAlmostEqual(self.model.run(self.output_gauss.x[ind]), 
                                   self.output_shulz.y[ind], 3)