• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python SphereModel.SphereModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_5

def test_5():
    from sas.models.SphereModel import SphereModel
    model = VolumeCanvas.VolumeCanvas()
    
    handle = model.add('sphere')
    
    radius = 10
    density = .1
    
    ana = SphereModel()
    ana.setParam('scale', 1.0)
    ana.setParam('contrast', 1.0)
    ana.setParam('background', 0.0)
    ana.setParam('radius', radius)
    
    model.setParam('lores_density', density)
    model.setParam('%s.radius' % handle, radius)
    model.setParam('scale' , 1.0)
    model.setParam('%s.contrast' % handle, 1.0)
    model.setParam('background' , 0.0)
    
    ana = ana.runXY([0.1, 0.1])
    sim = model.getIq2D(0.1, 0.1)
    print ana, sim, sim/ana, ana/sim
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:24,代码来源:early_test.py


示例17: setUp

 def setUp(self):
     """
         Set up canvas
     """
     from sas.models.SphereModel import SphereModel
     self.model = VolumeCanvas.VolumeCanvas()
 
     handle = self.model.add('sphere')
     
     radius = 10
     density = .1
     
     ana = SphereModel()
     ana.setParam('scale', 1.0)
     ana.setParam('contrast', 1.0)
     ana.setParam('background', 0.0)
     ana.setParam('radius', radius)
     self.ana = ana
     
     self.model.setParam('lores_density', density)
     self.model.setParam('%s.radius' % handle, radius)
     self.model.setParam('scale' , 1.0)
     self.model.setParam('%s.contrast' % handle, 1.0)
     self.model.setParam('background' , 0.0)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:24,代码来源:utest_oriented.py


示例18: test_4

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


示例19: TestsphereHardS

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


示例20: TestSphere

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python loader.Loader类代码示例发布时间:2022-05-27
下一篇:
Python CylinderModel.CylinderModel类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap