def setUp(self):
     from sas.models.CoreShellCylinderModel import CoreShellCylinderModel
     self.model= CoreShellCylinderModel()
     
     self.model.setParam('scale', 1.0)
     self.model.setParam('radius', 20.0)
     self.model.setParam('thickness', 10.0)
     self.model.setParam('length', 400.0)
     self.model.setParam('core_sld', 1.e-6)
     self.model.setParam('shell_sld', 4.e-6)
     self.model.setParam('solvent_sld', 1.e-6)
     self.model.setParam('background', 0.0)
     self.model.setParam('axis_theta', 0.0)
     self.model.setParam('axis_phi', 90.0)
class TestCoreShellCylinder(unittest.TestCase):
    """ Unit tests for calculate_ER (CoreShellcylinder model) """
    def setUp(self):
        from sas.models.CoreShellCylinderModel import CoreShellCylinderModel
        from sas.models.DiamCylFunc import DiamCylFunc
        self.comp = CoreShellCylinderModel()
        self.diam = DiamCylFunc()

    def test(self):
        """ Test 1D model for a CoreShellCylinder """
        self.comp.setParam("radius", 20)
        self.comp.setParam("thickness", 10)
        self.comp.setParam("length", 400)
        self.diam.setParam("radius", 30)
        self.diam.setParam("length", 420)
        self.assertAlmostEqual(self.comp.calculate_ER(),
                               self.diam.run(0.1) / 2)
class TestCoreShellCylinder(unittest.TestCase):
    """ Unit tests for calculate_ER (CoreShellcylinder model) """
    
    def setUp(self):
        from sas.models.CoreShellCylinderModel import CoreShellCylinderModel
        from sas.models.DiamCylFunc import DiamCylFunc
        self.comp = CoreShellCylinderModel()
        self.diam = DiamCylFunc()
        
    def test(self):
        """ Test 1D model for a CoreShellCylinder """
        self.comp.setParam("radius", 20)
        self.comp.setParam("thickness", 10)
        self.comp.setParam("length",400)
        self.diam.setParam("radius", 30)
        self.diam.setParam("length",420)       
        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)   
 def setUp(self):
     from sas.models.CoreShellCylinderModel import CoreShellCylinderModel
     from sas.models.DiamCylFunc import DiamCylFunc
     self.comp = CoreShellCylinderModel()
     self.diam = DiamCylFunc()
class TestCoreShellCylinder(unittest.TestCase):
    """
        Testing C++ Cylinder model
    """
    def setUp(self):
        from sas.models.CoreShellCylinderModel import CoreShellCylinderModel
        self.model= CoreShellCylinderModel()
        
        self.model.setParam('scale', 1.0)
        self.model.setParam('radius', 20.0)
        self.model.setParam('thickness', 10.0)
        self.model.setParam('length', 400.0)
        self.model.setParam('core_sld', 1.e-6)
        self.model.setParam('shell_sld', 4.e-6)
        self.model.setParam('solvent_sld', 1.e-6)
        self.model.setParam('background', 0.0)
        self.model.setParam('axis_theta', 0.0)
        self.model.setParam('axis_phi', 90.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.assertAlmostEqual(self.model.run(0.001), 353.55013216754583, 3)
        self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 
                               355.25355270620543, 3)
        
    def test_dispersion(self):
        """
            Test with dispersion
        """
        from sas.models.DisperseModel import DisperseModel
        disp = DisperseModel(self.model, ['radius', 
                                          'thickness', 
                                          'length'], [5, 2, 50])
        disp.setParam('n_pts', 10)
        self.assertAlmostEqual(disp.run(0.001), 358.44062724936009, 3)
        self.assertAlmostEqual(disp.runXY([0.001,0.001]), 360.22673635224584, 3)

    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.25
        self.model.dispersion['radius']['npts'] = 10
        self.model.dispersion['radius']['nsigmas'] = 2

        disp_rr = GaussianDispersion()
        self.model.set_dispersion('thickness', disp_rr)
        self.model.dispersion['thickness']['width'] = 0.2
        self.model.dispersion['thickness']['npts'] = 10
        self.model.dispersion['thickness']['nsigmas'] = 2

        disp_len = GaussianDispersion()
        self.model.set_dispersion('length', disp_len)
        self.model.dispersion['length']['width'] = 1.0/8.0
        self.model.dispersion['length']['npts'] = 10
        self.model.dispersion['length']['nsigmas'] = 2

        self.assertAlmostEqual(self.model.run(0.001), 
                               1.07832610*358.44062724936009, 3)
        self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 
                               1.07844010*360.22673635224584, 3)
        

    def test_array(self):
        """
            Perform complete rotational average and
            compare to 1D
        """
        from sas.models.dispersion_models import ArrayDispersion
        disp_ph = ArrayDispersion()
        disp_th = ArrayDispersion()
        
        values_ph = numpy.zeros(100)
        values_th = numpy.zeros(100)
        weights   = numpy.zeros(100)
        for i in range(100):
            values_ph[i]=(360/99.0*i)
            values_th[i]=(180/99.0*i)
            weights[i]=(1.0)
        
        disp_ph.set_weights(values_ph, weights)
        disp_th.set_weights(values_th, weights)
        
        self.model.set_dispersion('axis_theta', disp_th)
        self.model.set_dispersion('axis_phi', disp_ph)
        
        val_1d = self.model.run(math.sqrt(0.0002))
        val_2d = self.model.runXY([0.01,0.01]) 
        
        self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02)
 def setUp(self):
     from sas.models.CoreShellCylinderModel import CoreShellCylinderModel
     from sas.models.DiamCylFunc import DiamCylFunc
     self.comp = CoreShellCylinderModel()
     self.diam = DiamCylFunc()