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


Python SphereModel.calculate_ER方法代码示例

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


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

示例1: TestSphere

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import calculate_ER [as 别名]
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,代码行数:13,代码来源:utest_model_calculate_ER.py

示例2: TestsphereHardS

# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import calculate_ER [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.calculate_ER方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。