当前位置: 首页>>代码示例>>Python>>正文


Python SphereModel.run方法代码示例

本文整理汇总了Python中sas.models.SphereModel.SphereModel.run方法的典型用法代码示例。如果您正苦于以下问题:Python SphereModel.run方法的具体用法?Python SphereModel.run怎么用?Python SphereModel.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sas.models.SphereModel.SphereModel的用法示例。


在下文中一共展示了SphereModel.run方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSphere

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
class TestSphere(unittest.TestCase):
    """ Unit tests for sphere model using evalDistribution function """
    
    def setUp(self):
        from sas.models.SphereModel import SphereModel
        self.comp = SphereModel()
        self.x = numpy.array([1.0,2.0,3.0, 4.0])
        self.y = self.x +1
        
    def test1D(self):
        """ Test 1D model for a sphere  with vector as input"""
        answer = numpy.array([5.63877831e-05,2.57231782e-06,2.73704050e-07,2.54229069e-08])
       
       
        testvector= self.comp.evalDistribution(self.x)
       
        self.assertAlmostEqual(len(testvector),4)
        for i in xrange(len(answer)):
            self.assertAlmostEqual(testvector[i],answer[i])
       
    def test1D_1(self):
        """ Test 2D model for a sphere  with scalar as input"""
        self.assertAlmostEqual(self.comp.run(1.0),5.63877831e-05, 4)
         
    def test1D_2(self):
        """ Test 2D model for a sphere for 2 scalar """
        self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 56.3878e-06, 4)
        
    def test1D_3(self):
        """ Test 2D model for a Shpere for 2 vectors as input """
        #x= numpy.reshape(self.x, [len(self.x),1])
        #y= numpy.reshape(self.y, [1,len(self.y)])
        vect = self.comp.evalDistribution([self.x,self.y])
        self.assertAlmostEqual(vect[0],9.2985e-07, 4)
        self.assertAlmostEqual(vect[len(self.x)-1],1.3871e-08, 4)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:37,代码来源:utest_models_array.py

示例2: testGetIq

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
 def testGetIq(self):
     """ Test the output of I(q) to the analytical solution
         If the normalization is wrong, we will have to fix it.
         
         getIq() should call getPr() behind the scenes so that
         the user doesnt have to do it if he doesn't need to.
     """
     from sas.models.SphereModel import SphereModel
     sphere = SphereModel()
     sphere.setParam('radius', 10.0)
     sphere.setParam('contrast', 1.0)
     sphere.setParam('background', 0.0)
     sphere.setParam('scale', 1.0)
             
     handle = self.canvas.add('sphere')
     self.canvas.setParam('%s.radius' % handle, 10.0)
     self.canvas.setParam('%s.contrast' % handle, 1.0)
     
     
     sim_1 = self.canvas.getIq(0.001)
     ana_1 = sphere.run(0.001)
     sim_2 = self.canvas.getIq(0.01)
     ana_2 = sphere.run(0.01)
     
     # test the shape of the curve (calculate relative error 
     # on the output and it should be compatible with zero
     # THIS WILL DEPEND ON THE NUMBER OF SPACE POINTS:
     # that why we need some error analysis.
     self.assert_( (sim_2*ana_1/sim_1 - ana_2)/ana_2 < 0.1)
     
     # test the absolute amplitude
     self.assert_( math.fabs(sim_2-ana_2)/ana_2 < 0.1)
开发者ID:ianhi,项目名称:sasview,代码行数:34,代码来源:utest_realspace.py

示例3: TestPerlNecklace

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
class TestPerlNecklace(unittest.TestCase):
    """ Unit tests for PerlNecklace """
    
    def setUp(self):
        from sas.models.PearlNecklaceModel import PearlNecklaceModel
        self.pnl = PearlNecklaceModel()
        from sas.models.LinearPearlsModel import LinearPearlsModel
        self.lpm = LinearPearlsModel()
        from sas.models.SphereModel import SphereModel
        self.sphere = SphereModel()
        from sas.models.BarBellModel import BarBellModel
        self.bar = BarBellModel()
        
    def testwithsphere(self):
        """ Compare 1D model with sphere """
        self.pnl.setParam("radius", 60)
        self.pnl.setParam("num_pearls", 1)
        self.pnl.setParam("sld_pearl", 2e-06)
        self.pnl.setParam("sld_solv", 1e-06)
        self.assertAlmostEqual(self.pnl.run(0.001), self.sphere.run(0.001), 5)
        self.assertAlmostEqual(self.pnl.run(0.005), self.sphere.run(0.005), 5)
        self.assertAlmostEqual(self.pnl.run(0.01), self.sphere.run(0.01), 5)
        self.assertAlmostEqual(self.pnl.run(0.05), self.sphere.run(0.05), 5)
        self.assertAlmostEqual(self.pnl.run(0.1), self.sphere.run(0.1), 5)
        self.assertAlmostEqual(self.pnl.run(0.5), self.sphere.run(0.5), 5)
        
    def testwithbarbell(self):
        """ 
        Compare 1D model with barbell
        
        Note:  pearlnecklace assumes infinite thin rod
        """
        self.pnl.setParam("radius", 20)
        self.pnl.setParam("num_pearls", 2)
        self.pnl.setParam("sld_pearl", 1e-06)
        self.pnl.setParam("sld_string", 1e-06)
        self.pnl.setParam("sld_solv", 6.3e-06)
        self.pnl.setParam("thick_string", 0.1)
        self.pnl.setParam("edge_separation", 400)
        self.bar.setParam("rad_bar", 0.1)
        self.bar.setParam("rad_bell", 20)
        self.lpm.setParam("radius", 20)
        self.lpm.setParam("num_pearls", 2)
        self.lpm.setParam("sld_pearl", 1e-06)
        self.lpm.setParam("sld_solv", 6.3e-06)
        self.lpm.setParam("edge_separation", 400)
                
        self.assertAlmostEqual(self.pnl.run(0.001), self.bar.run(0.001), 1)
        self.assertAlmostEqual(self.pnl.run(0.005), self.bar.run(0.005), 1)
        self.assertAlmostEqual(self.pnl.run(0.01), self.bar.run(0.01), 1)
        self.assertAlmostEqual(self.pnl.run(0.05), self.bar.run(0.05), 1)
        self.assertAlmostEqual(self.pnl.run(0.1), self.bar.run(0.1), 1)
        self.assertAlmostEqual(self.pnl.run(0.5), self.bar.run(0.5), 1)
        
        self.assertAlmostEqual(self.pnl.run(0.001), self.lpm.run(0.001), 1)
        self.assertAlmostEqual(self.pnl.run(0.005), self.lpm.run(0.005), 1)
        self.assertAlmostEqual(self.pnl.run(0.01), self.lpm.run(0.01), 1)
        self.assertAlmostEqual(self.pnl.run(0.05), self.lpm.run(0.05), 1)
        self.assertAlmostEqual(self.pnl.run(0.1), self.lpm.run(0.1), 1)
        self.assertAlmostEqual(self.pnl.run(0.5), self.lpm.run(0.5), 1)
开发者ID:ricleal,项目名称:SasModeling,代码行数:62,代码来源:utest_model_pearlnecklace.py

示例4: TestSphere

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
class TestSphere(unittest.TestCase):
    """ Unit tests for sphere model """
    
    def setUp(self):
        from sas.models.SphereModel import SphereModel
        self.comp = SphereModel()
        
    def test1D(self):
        """ Test 1D model for a sphere """
        self.assertAlmostEqual(self.comp.run(1.0), 5.6387e-5, 4)
        
    def test1D_2(self):
        """ Test 2D model for a sphere """
        self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 5.6387e-5, 4)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:16,代码来源:utest_models.py

示例5: test_1

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
def test_1():
    
    radius = 15
    
    density = .1
    vol = 4/3*math.pi*radius*radius*radius
    npts = vol*density
     
    canvas = VolumeCanvas.VolumeCanvas()
    canvas.setParam('lores_density', density)
    handle = canvas.add('sphere')
    canvas.setParam('%s.radius' % handle, radius)
    canvas.setParam('%s.contrast' % handle, 1.0)
    
    
    if False:
        # Time test
        t_0 = time.time()
        value_1 = 1.0e8*canvas.getIq(0.1)
        print "density = 0.1:  output=%g  time=%g" % (value_1, time.time()-t_0)
        
        t_0 = time.time()
        canvas.setParam('lores_density', 1)
        value_1 = 1.0e8*canvas.getIq(0.1)
        print "density = 1000:  output=%g  time=%g" % (value_1, time.time()-t_0)
        
        t_0 = time.time()
        canvas.setParam('lores_density', 0.01)
        value_1 = 1.0e8*canvas.getIq(0.1)
        print "density = 0.00001:  output=%g  time=%g" % (value_1, time.time()-t_0)
        print
    
    
    sphere = SphereModel()
    sphere.setParam('radius', radius)
    sphere.setParam('scale', 1.0)
    sphere.setParam('contrast', 1.0)
        
        
    # Simple sphere sum(Pr) = (rho*V)^2    
    # each p(r) point has a volume of 1/density    
        
    for i in range(35):
        q = 0.001 + 0.01*i
        
        
        
        #sim_1 = 1.0e8*canvas.getIq(q)*4/3*math.pi/(density*density*density)
        sim_1 = canvas.getIq(q)
        ana_1 = sphere.run(q)
        #ana_1 = form_factor(q, radius)
        
        print "q=%g  sim=%g  ana=%g   ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:55,代码来源:early_test.py

示例6: TestSphereGauss

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
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)        
开发者ID:ricleal,项目名称:SasModeling,代码行数:42,代码来源:utest_sphere_dispersity.py

示例7: testWrongOrder

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
 def testWrongOrder(self):
     from sas.models.SphereModel import SphereModel
     self.set_coreshell_on_canvas(1, 0)
     
     # Core shell model
     sphere = SphereModel()
     # Core radius
     sphere.setParam('radius', self.outer_radius)
     # Shell thickness
     sphere.setParam('contrast', self.shell_sld)
     sphere.setParam('background', 0.0)
     sphere.setParam('scale', 1.0)
     
     ana = sphere.run(0.05)
     val, err = self.canvas.getIqError(0.05)
     #print 'wrong', ana, val, err
     self.assert_(math.fabs(ana-val)/ana < 1.1)
开发者ID:ianhi,项目名称:sasview,代码行数:19,代码来源:utest_realspace.py

示例8: TestSphere

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
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
开发者ID:ricleal,项目名称:SasModeling,代码行数:44,代码来源:utest_dispersity.py

示例9: test_4

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
def test_4():
    radius = 15
    
    density = .1
    vol = 4/3*math.pi*radius*radius*radius
    npts = vol*density

    
    canvas = VolumeCanvas.VolumeCanvas()
    canvas.setParam('lores_density', density)
    #handle = canvas.add('sphere')
    #canvas.setParam('%s.radius' % handle, radius)
    #canvas.setParam('%s.contrast' % handle, 1.0)
    
    pdb = canvas.add('test.pdb')
    
    
    
    sphere = SphereModel()
    sphere.setParam('radius', radius)
    sphere.setParam('scale', 1.0)
    sphere.setParam('contrast', 1.0)
        
        
    # Simple sphere sum(Pr) = (rho*V)^2    
    # each p(r) point has a volume of 1/density    
        
    for i in range(35):
        q = 0.001 + 0.01*i
        
        
        
        #sim_1 = 1.0e8*canvas.getIq(q)*4/3*math.pi/(density*density*density)
        sim_1 = canvas.getIq(q)
        ana_1 = sphere.run(q)
        #ana_1 = form_factor(q, radius)
        
        print "q=%g  sim=%g  ana=%g   ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:40,代码来源:early_test.py

示例10: TestEvalMethods

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
class TestEvalMethods(unittest.TestCase):
    """ Testing evalDistribution for C models """

    def setUp(self):
        self.model= SphereModel()
        
    def test_scalar_methods(self):
        """
            Simple test comparing the run(), runXY() and
            evalDistribution methods
        """
        q1 = self.model.run(0.001)
        q2 = self.model.runXY(0.001)
        q4 = self.model.run(0.002)
        qlist3 = numpy.asarray([0.001, 0.002])
        q3 = self.model.evalDistribution(qlist3)

        self.assertEqual(q1, q2)
        self.assertEqual(q1, q3[0])
        self.assertEqual(q4, q3[1])
        
    def test_XY_methods(self):
        """
            Compare to the runXY() method for 2D models.
            
                      +--------+--------+--------+
            qy=0.009  |        |        |        | 
                      +--------+--------+--------+
            qy-0.006  |        |        |        |
                      +--------+--------+--------+            
            qy=0.003  |        |        |        | 
                      +--------+--------+--------+
                      qx=0.001   0.002   0.003
            
        """
        # These are the expected values for all bins
        expected = numpy.zeros([3,3])
        for i in range(3):
            for j in range(3):
                q_length = math.sqrt( (0.001*(i+1.0))*(0.001*(i+1.0)) + (0.003*(j+1.0))*(0.003*(j+1.0)) )
                expected[i][j] = self.model.run(q_length)
        
        qx_values = [0.001, 0.002, 0.003]
        qy_values = [0.003, 0.006, 0.009]
        
        qx = numpy.asarray(qx_values)
        qy = numpy.asarray(qy_values)
              
        new_x = numpy.tile(qx, (len(qy),1))
        new_y = numpy.tile(qy, (len(qx),1))
        new_y = new_y.swapaxes(0,1)
    
        #iq is 1d array now (since 03-12-2010)
        qx_prime = new_x.flatten()
        qy_prime = new_y.flatten()
        
        iq = self.model.evalDistribution([qx_prime, qy_prime])
        
        for i in range(3):
            for j in range(3):
                # convert index into 1d array
                k = i+len(qx)*j
                self.assertAlmostEquals(iq[k], expected[i][j])
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:65,代码来源:utest_evaldist.py

示例11: TestsphereHardS

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import run [as 别名]
class TestsphereHardS(unittest.TestCase):
    """ 
        Unit tests for SphereModel(Q) * HardsphereStructure(Q)
    """
    def setUp(self):
        from sas.models.SphereModel import SphereModel
        from sas.models.HardsphereStructure import HardsphereStructure
        from sas.models.DiamCylFunc import DiamCylFunc
        from sas.models.MultiplicationModel import MultiplicationModel

        self.model = SphereModel()
        self.model2 = HardsphereStructure()
        self.model3 = MultiplicationModel(self.model, self.model2)  
        self.modelD = DiamCylFunc() 

    #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions
    def test_multplication_radius(self):
        """
            test multiplication model (check the effective radius & the output
             of the multiplication)
        """
        self.model.setParam("radius", 60)
        modelDrun = 60
        self.model2.setParam("volfraction", 0.2)
        self.model2.setParam("effect_radius", modelDrun )
        
        #Compare new method with old method         
        self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1))
        
        #Compare radius from two different calculations. Note: modelD.run(0.0) is DIAMETER
        self.assertEqual(self.model.calculate_ER(), modelDrun)
        
        
    def testMultiplicationParam(self):
        """ Test Multiplication  (check the parameters)"""
        ## test details dictionary

        ## test parameters list
        list3= self.model3.getParamList()

        for item in self.model.getParamList():
            if not 'scale' in item: 
                self.assert_(item in list3)
        for item in self.model2.getParamList():
            #model3 parameters should not include effect_radius*
            if not 'effect_radius' in item:  
                self.assert_(item in list3)
            
        ## test set value for parameters and get paramaters
        self.model3.setParam("scale_factor", 15)
        self.assertEqual(self.model3.getParam("scale_factor"), 15)
        self.model3.setParam("radius", 20)
        self.assertEqual(self.model3.getParam("radius"), 20)
        self.model3.setParam("radius.width", 15)
        self.assertEqual(self.model3.getParam("radius.width"), 15)
        self.model3.setParam("scale_factor", 15)
        self.assertEqual(self.model3.getParam("scale_factor"), 15)
        self.assertEqual(self.model3.getParam("volfraction"), self.model.getParam("scale"))
        
        ## Dispersity 
        list3= self.model3.getDispParamList()
        self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width'])
        
        from sas.models.dispersion_models import ArrayDispersion
        disp_th = ArrayDispersion()
        
        values_th = numpy.zeros(100)
        weights   = numpy.zeros(100)
        for i in range(100):
            values_th[i]=(math.pi/99.0*i)
            weights[i]=(1.0)
    
        disp_th.set_weights(values_th, weights)
        
        self.model3.set_dispersion('radius', disp_th)
        
        val_1d = self.model3.run(math.sqrt(0.0002))
        val_2d = self.model3.runXY([0.01,0.01]) 
        
        self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02)
        model4= self.model3.clone()
        self.assertEqual(model4.getParam("radius"), 20)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:84,代码来源:utest_modelmultiplication.py


注:本文中的sas.models.SphereModel.SphereModel.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。