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


Python SphereModel.SphereModel类代码示例

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


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

示例1: TestPerlNecklace

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,代码行数:60,代码来源:utest_model_pearlnecklace.py

示例2: TestSphere

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,代码行数:35,代码来源:utest_models_array.py

示例3: TestSphere

class TestSphere(unittest.TestCase):
    """ Unit tests for calculate_ER (sphere model) """
    
    def setUp(self):
        from sas.models.SphereModel import SphereModel
        self.comp = SphereModel()
        
    def test(self):
        """ Test 1D model for a sphere """
        self.comp.setParam("radius", 20)
        self.assertAlmostEqual(self.comp.calculate_ER(), 20)
开发者ID:ricleal,项目名称:SasModeling,代码行数:11,代码来源:utest_model_calculate_ER.py

示例4: SphereValidator

class SphereValidator(Validator):
    
    def __init__(self, radius=15, density = 0.01):
        from sas.models.SphereModel import SphereModel
        
        self.name = 'sphere'
        self.radius = radius
        self.density = density
        
        self.ana = SphereModel()
        self.ana.setParam('scale', 1.0)
        self.ana.setParam('contrast', 1.0)
        self.ana.setParam('background', 0.0)
        self.ana.setParam('radius', radius)
        self.create()
       
    def create(self):
        canvas = VolumeCanvas.VolumeCanvas()
        canvas.setParam('lores_density', self.density)
        handle = canvas.add('sphere')
        canvas.setParam('%s.radius' % handle, self.radius)
        canvas.setParam('scale' , 1.0)
        canvas.setParam('%s.contrast' % handle, 1.0)
        canvas.setParam('background' , 0.0)
        self.canvas = canvas   
开发者ID:ianhi,项目名称:sasview,代码行数:25,代码来源:sim_validation.py

示例5: TestSphere

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,代码行数:14,代码来源:utest_models.py

示例6: test_state_IO

 def test_state_IO(self):
     """
         Check that a state oject is independent from the model object it
         was generated with
     """
     self.sphere.setParam('radius', 44.0)
     _, _, state, _, _ = self.sphere.__reduce_ex__(0)
     
     sphere_copy = SphereModel()
     sphere_copy.__setstate__(state)
     sphere_clone = sphere_copy.clone()
     self.assertEqual(sphere_copy.getParam('radius'), 44)
     
     self.sphere.setParam('radius', 33.0)
     
     self.assertEqual(sphere_clone.getParam('radius'), 44)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:16,代码来源:utest_state.py

示例7: testWrongOrder

 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,代码行数:17,代码来源:utest_realspace.py

示例8: setUp

 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()
开发者ID:ricleal,项目名称:SasModeling,代码行数:9,代码来源:utest_model_pearlnecklace.py

示例9: setUp

 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)
开发者ID:ricleal,项目名称:SasModeling,代码行数:9,代码来源:utest_dispersity.py

示例10: test_1

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,代码行数:53,代码来源:early_test.py

示例11: setUp

    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() 
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:10,代码来源:utest_modelmultiplication.py

示例12: setUp

 def setUp(self):
     data = Loader().load("latex_smeared.xml")
     self.data_res = data[0]
     self.data_slit = data[1]
     
     self.sphere = SphereModel()
     self.sphere.setParam('background', 0)
     self.sphere.setParam('radius', 5000.0)
     self.sphere.setParam('scale', 0.4)
     self.sphere.setParam('sldSolv',0)
     self.sphere.setParam('sldSph',1e-6)
开发者ID:imewei,项目名称:sasview,代码行数:11,代码来源:utest_fit_smeared.py

示例13: setUp

 def setUp(self):
     # NIST sample data
     self.data = Loader().load("CMSphere5.txt")
     # NIST smeared sphere w/ param values below
     self.answer = Loader().load("CMSphere5smearsphere.txt")
     # call spheremodel
     self.model = SphereModel()
     # setparams consistent with Igor default
     self.model.setParam('scale', 1.0)
     self.model.setParam('background', 0.01)
     self.model.setParam('radius', 60.0)
     self.model.setParam('sldSolv', 6.3e-06)
     self.model.setParam('sldSph', 1.0e-06)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:13,代码来源:utest_smearing.py

示例14: __init__

 def __init__(self, radius=15, density = 0.01):
     from sas.models.SphereModel import SphereModel
     
     self.name = 'sphere'
     self.radius = radius
     self.density = density
     
     self.ana = SphereModel()
     self.ana.setParam('scale', 1.0)
     self.ana.setParam('contrast', 1.0)
     self.ana.setParam('background', 0.0)
     self.ana.setParam('radius', radius)
     self.create()
开发者ID:ianhi,项目名称:sasview,代码行数:13,代码来源:sim_validation.py

示例15: setUp

    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)
开发者ID:ricleal,项目名称:SasModeling,代码行数:14,代码来源:utest_sphere_dispersity.py


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