本文整理汇总了Python中sas.models.CylinderModel.CylinderModel类的典型用法代码示例。如果您正苦于以下问题:Python CylinderModel类的具体用法?Python CylinderModel怎么用?Python CylinderModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CylinderModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
""" initialize data"""
self.data1 = Loader().load("cyl_400_20.txt")
self.data2 = Loader().load("cyl_400_40.txt")
# Receives the type of model for the fitting
from sas.models.CylinderModel import CylinderModel
cyl1 = CylinderModel()
cyl1.name = "C1"
self.model1 = Model(cyl1)
self.model1.set(scale=1.0)
self.model1.set(radius=18)
self.model1.set(length=200)
self.model1.set(sldCyl=3e-006, sldSolv=0.0)
self.model1.set(background=0.0)
cyl2 = CylinderModel()
cyl2.name = "C2"
self.model2 = Model(cyl2)
self.model2.set(scale=1.0)
self.model2.set(radius=37)
self.model2.set(length=300)
self.model2.set(sldCyl=3e-006, sldSolv=0.0)
self.model2.set(background=0.0)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:26,代码来源:utest_fit_cylinder.py
示例2: TestSingleFit
class TestSingleFit(unittest.TestCase):
""" test single fitting """
def setUp(self):
""" initialize data"""
self.data = Loader().load("cyl_400_20.txt")
# Create model that fitter understands
from sas.models.CylinderModel import CylinderModel
self.model = CylinderModel()
self.model.setParam("scale", 1.0)
self.model.setParam("radius", 18)
self.model.setParam("length", 397)
self.model.setParam("sldCyl", 3e-006)
self.model.setParam("sldSolv", 0.0)
self.model.setParam("background", 0.0)
# select parameters to fit
self.pars1 = ["length", "radius", "scale"]
def test_fit(self):
"""Simple cylinder model fit"""
fitter = Fit()
fitter.set_data(self.data, 1)
fitter.set_model(self.model, 1, self.pars1)
fitter.select_problem_for_fit(id=1, value=1)
result1, = fitter.fit()
self.assert_(result1)
self.assertTrue(len(result1.pvec) > 0 or len(result1.pvec) == 0)
self.assertTrue(len(result1.stderr) > 0 or len(result1.stderr) == 0)
self.assertTrue(math.fabs(result1.pvec[0] - 400.0) / 3.0 < result1.stderr[0])
self.assertTrue(math.fabs(result1.pvec[1] - 20.0) / 3.0 < result1.stderr[1])
self.assertTrue(math.fabs(result1.pvec[2] - 1.0) / 3.0 < result1.stderr[2])
self.assertTrue(result1.fitness < 1.0)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:35,代码来源:utest_fit_cylinder.py
示例3: TestDispModel
class TestDispModel(unittest.TestCase):
def setUp(self):
from sas.models.CylinderModel import CylinderModel
self.model = CylinderModel()
def test_disp_params(self):
self.assertEqual(self.model.dispersion['radius']['width'], 0.0)
self.model.setParam('radius.width', 0.25)
self.assertEqual(self.model.dispersion['radius']['width'], 0.25)
self.assertEqual(self.model.getParam('radius.width'), 0.25)
self.assertEqual(self.model.dispersion['radius']['type'], 'gaussian')
开发者ID:ricleal,项目名称:SasModeling,代码行数:13,代码来源:utest_dispersity.py
示例4: TestCylinder
class TestCylinder(unittest.TestCase):
""" Unit tests for calculate_ER (cylinder model) """
def setUp(self):
from sas.models.CylinderModel import CylinderModel
from sas.models.DiamCylFunc import DiamCylFunc
self.comp = CylinderModel()
self.diam = DiamCylFunc()
def test(self):
""" Test 1D model for a Cylinder """
self.comp.setParam("radius", 20)
self.comp.setParam("length",400)
self.diam.setParam("radius", 20)
self.diam.setParam("length",400)
self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)
开发者ID:ricleal,项目名称:SasModeling,代码行数:16,代码来源:utest_model_calculate_ER.py
示例5: setUp
def setUp(self):
""" Set up cylinder model """
from sas.models.CylinderModel import CylinderModel
radius = 5
length = 40
density = 20
# Analytical model
self.ana = CylinderModel()
self.ana.setParam('scale', 1.0)
self.ana.setParam('contrast', 1.0)
self.ana.setParam('background', 0.0)
self.ana.setParam('radius', radius)
self.ana.setParam('length', length)
self.ana.setParam('cyl_theta', math.pi/2.0)
self.ana.setParam('cyl_phi', math.pi/2.0)
# Simulation model
self.model = VolumeCanvas.VolumeCanvas()
self.handle = self.model.add('cylinder')
self.model.setParam('lores_density', density)
self.model.setParam('%s.radius' % self.handle, radius)
self.model.setParam('%s.length' % self.handle, length)
self.model.setParam('scale' , 1.0)
self.model.setParam('%s.contrast' % self.handle, 1.0)
self.model.setParam('background' , 0.0)
self.model.setParam('%s.orientation' % self.handle, [0,0,0])
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:27,代码来源:utest_oriented.py
示例6: test_cylinder_fit
def test_cylinder_fit(self):
""" Simple cylinder model fit """
out= Loader().load("cyl_400_20.txt")
fitter = Fit()
# Receives the type of model for the fitting
from sas.models.CylinderModel import CylinderModel
model = CylinderModel()
model.setParam('sldCyl', 1)
model.setParam('sldSolv', 0)
model.setParam('scale', 1e-10)
pars1 =['length','radius','scale']
fitter.set_data(out,1)
fitter.set_model(model,1,pars1, constraints=())
fitter.select_problem_for_fit(id=1,value=1)
result1, = fitter.fit()
#print result1
#print result1.__dict__
self.assert_(result1)
self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 )
self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0)
self.assertTrue( math.fabs(result1.pvec[0]-400.0)/3.0 < result1.stderr[0] )
self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 < result1.stderr[1] )
self.assertTrue( math.fabs(result1.pvec[2]-9.0e-12)/3.0 < result1.stderr[2] )
self.assertTrue( result1.fitness < 1.0 )
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:29,代码来源:utest_small_test.py
示例7: setUp
def setUp(self):
from sas.models.CylinderModel import CylinderModel
from sas.models.HayterMSAStructure import HayterMSAStructure
from sas.models.DiamCylFunc import DiamCylFunc
from sas.models.MultiplicationModel import MultiplicationModel
self.model = CylinderModel()
self.model2 = HayterMSAStructure()
self.model3 = MultiplicationModel(self.model, self.model2)
self.modelD = DiamCylFunc()
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:10,代码来源:utest_modelmultiplication.py
示例8: setUp
def setUp(self):
from sas.models.CylinderModel import CylinderModel
self.model= CylinderModel()
self.model.setParam('scale', 1.0)
self.model.setParam('radius', 20.0)
self.model.setParam('length', 400.0)
self.model.setParam('sldCyl', 4.e-6)
self.model.setParam('sldSolv', 1.e-6)
self.model.setParam('background', 0.0)
self.model.setParam('cyl_theta', 0.0)
self.model.setParam('cyl_phi', 90.0)
开发者ID:ricleal,项目名称:SasModeling,代码行数:12,代码来源:utest_dispersity.py
示例9: __init__
def __init__(self, radius=15, length=100, density = 0.01):
from sas.models.CylinderModel import CylinderModel
self.name = 'cylinder'
self.radius = radius
self.length = length
self.density = density
self.ana = CylinderModel()
self.ana.setParam('scale', 1.0)
self.ana.setParam('contrast', 1.0)
self.ana.setParam('background', 0.0)
self.ana.setParam('radius', radius)
self.ana.setParam('length', length)
self.ana.setParam('cyl_theta', math.pi/2.0)
self.ana.setParam('cyl_phi', math.pi/2.0)
self.create()
开发者ID:ianhi,项目名称:sasview,代码行数:17,代码来源:sim_validation.py
示例10: TestCylinder
class TestCylinder(unittest.TestCase):
""" Unit tests for Cylinder model using evalDistribution function """
def setUp(self):
from sas.models.CylinderModel import CylinderModel
self.comp = CylinderModel()
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 cylinder with vector as input"""
answer = numpy.array([1.98860592e-04,7.03686335e-05,2.89144683e-06,2.04282827e-06])
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 cylinder with scalar as input"""
self.assertAlmostEqual(self.comp.run(0.2), 0.041761386790780453, 4)
def test1D_2(self):
""" Test 2D model of a cylinder """
self.comp.setParam('cyl_theta', 10.0)
self.comp.setParam('cyl_phi', 10.0)
self.assertAlmostEqual(self.comp.run([0.2, 2.5]),
0.038176446608393366, 2)
def test1D_3(self):
""" Test 2D model for a cylinder for 2 vectors as input """
vect = self.comp.evalDistribution([self.x,self.y])
self.assertAlmostEqual(vect[0],5.06121018e-08,4)
self.assertAlmostEqual(vect[len(self.x)-1],2.5978e-11, 4)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:36,代码来源:utest_models_array.py
示例11: TestCyl
class TestCyl(unittest.TestCase):
"""Unit tests for cylinder"""
def setUp(self):
from sas.models.CylinderModel import CylinderModel
self.comp = CylinderModel()
def test1D(self):
""" Test 1D model of a cylinder """
self.assertAlmostEqual(self.comp.run(0.2), 0.041761386790780453, 4)
def testTime(self):
""" Time profiling """
self.comp.run(2.0)
t0 = time.clock()
self.assertTrue(time.clock()-t0<1e-4)
def test2D(self):
""" Test 2D model of a cylinder """
self.comp.setParam('cyl_theta', 10.0)
self.comp.setParam('cyl_phi', 10.0)
self.assertAlmostEqual(self.comp.run([0.2, 2.5]),
0.038176446608393366, 2)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:24,代码来源:utest_models.py
示例12: TestDisperserModel
class TestDisperserModel(unittest.TestCase):
""" Unit tests for sphere model """
def setUp(self):
self.model = CylinderModel()
self.model.setParam("cyl_theta", 1.57)
self.model.setParam("cyl_phi", 0.1)
def test2Disp(self):
q = 0.005
phi = 0.10
sigma = 0.3
value_0 = self.model.run([q, phi])
app = Smear(self.model, ['cyl_phi', 'cyl_theta'], [sigma, sigma])
val_py = app.run([q, phi])
# Check that the parameters were returned to original values
self.assertEqual(value_0, self.model.run([q, phi]))
d = DisperseModel(self.model, ["cyl_phi", "cyl_theta"], [sigma, sigma])
val_c = d.run([q, phi])
self.assertEqual(val_py, val_c)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:21,代码来源:utest_disperser.py
示例13: _reset_helper
def _reset_helper(self, path=None, npts=NPTS):
"""
Set value to fitter and prepare inputs for map function
"""
for i in range(npts):
data = Loader().load(path)
fitter = Fit()
#create model
model = CylinderModel()
model.setParam('scale', 1.0)
model.setParam('radius', 20.0)
model.setParam('length', 400.0)
model.setParam('sldCyl', 4e-006)
model.setParam('sldSolv', 1e-006)
model.setParam('background', 0.0)
for param in model.dispersion.keys():
model.set_dispersion(param, self.polydisp['gaussian']())
model.setParam('cyl_phi.width', 10)
model.setParam('cyl_phi.npts', 3)
model.setParam('cyl_theta.nsigmas', 10)
# for 2 data cyl_theta = 60.0 [deg] cyl_phi= 60.0 [deg]
fitter.set_model(model, i, self.param_to_fit,
self.list_of_constraints)
#smear data
current_smearer = smear_selection(data, model)
import cPickle
p = cPickle.dumps(current_smearer)
sm = cPickle.loads(p)
fitter.set_data(data=data, id=i,
smearer=current_smearer, qmin=self.qmin, qmax=self.qmax)
fitter.select_problem_for_fit(id=i, value=1)
self.list_of_fitter.append(copy.deepcopy(fitter))
self.list_of_function.append('fit')
self.list_of_mapper.append(classMapper)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:34,代码来源:batch_fit.py
示例14: test_6
def test_6():
from sas.models.CylinderModel import CylinderModel
radius = 5
length = 40
density = 20
ana = CylinderModel()
ana.setParam('scale', 1.0)
ana.setParam('contrast', 1.0)
ana.setParam('background', 0.0)
ana.setParam('radius', radius)
ana.setParam('length', length)
# Along Y
ana.setParam('cyl_theta', 1.57)
ana.setParam('cyl_phi', 1.57)
# Along Z
#ana.setParam('cyl_theta', 0)
#ana.setParam('cyl_phi', 0)
model = VolumeCanvas.VolumeCanvas()
handle = model.add('cylinder')
model.setParam('lores_density', density)
model.setParam('%s.radius' % handle, radius)
model.setParam('%s.length' % handle, length)
model.setParam('scale' , 1.0)
model.setParam('%s.contrast' % handle, 1.0)
model.setParam('background' , 0.0)
# Along Y
model.setParam('%s.orientation' % handle, [0,0,0])
# Along Z
#model.setParam('%s.orientation' % handle, [1.57,0,0])
print model.npts
for i in range(40):
qmax = 0.5
anaX = ana.runXY([qmax*i/40.0, 0.0])
simX = model.getIq2D(qmax*i/40.0, 0.0)
anaY = ana.runXY([0, qmax*i/40.0])
simY = model.getIq2D(0, qmax*i/40.0)
print anaX, simX, simX/anaX, '|', anaY, simY, simY/anaY
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:46,代码来源:early_test.py
示例15: setUp
def setUp(self):
from sas.models.CylinderModel import CylinderModel
self.comp = CylinderModel()
self.x = numpy.array([1.0,2.0,3.0, 4.0])
self.y = self.x +1
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:5,代码来源:utest_models_array.py
示例16: TestCylinder
class TestCylinder(unittest.TestCase):
"""
Testing C++ Cylinder model
"""
def setUp(self):
from sas.models.CylinderModel import CylinderModel
self.model= CylinderModel()
self.model.setParam('scale', 1.0)
self.model.setParam('radius', 20.0)
self.model.setParam('length', 400.0)
self.model.setParam('sldCyl', 4.e-6)
self.model.setParam('sldSolv', 1.e-6)
self.model.setParam('background', 0.0)
self.model.setParam('cyl_theta', 0.0)
self.model.setParam('cyl_phi', 90.0)
def test_simple(self):
self.assertAlmostEqual(self.model.run(0.001), 450.355, 3)
self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 452.299, 3)
def test_constant(self):
from sas.models.dispersion_models import DispersionModel
disp = DispersionModel()
self.model.setParam('scale', 10.0)
self.model.set_dispersion('radius', disp)
self.model.dispersion['radius']['width'] = 0.25
self.model.dispersion['radius']['npts'] = 100
self.model.dispersion['radius']['nsigmas'] = 2.5
self.assertAlmostEqual(self.model.run(0.001), 1.021051*4527.47250339, 3)
self.assertAlmostEqual(self.model.runXY([0.001, 0.001]),
1.021048*4546.997777604715, 2)
def test_gaussian(self):
from sas.models.dispersion_models import GaussianDispersion
disp = GaussianDispersion()
self.model.set_dispersion('radius', disp)
self.model.dispersion['radius']['width'] = 0.25
self.model.dispersion['radius']['npts'] = 100
self.model.dispersion['radius']['nsigmas'] = 2
self.model.setParam('scale', 10.0)
self.assertAlmostEqual(self.model.run(0.001),
1.1804794*4723.32213339, 3)
self.assertAlmostEqual(self.model.runXY([0.001,0.001]),
1.180454*4743.56, 2)
def test_clone(self):
from sas.models.dispersion_models import GaussianDispersion
disp = GaussianDispersion()
self.model.set_dispersion('radius', disp)
self.model.dispersion['radius']['width'] = 0.25
self.model.dispersion['radius']['npts'] = 100
self.model.dispersion['radius']['nsigmas'] = 2
self.model.setParam('scale', 10.0)
new_model = self.model.clone()
self.assertAlmostEqual(new_model.run(0.001),
1.1804794*4723.32213339, 3)
self.assertAlmostEqual(new_model.runXY([0.001,0.001]),
1.180454*4743.56, 2)
def test_gaussian_zero(self):
from sas.models.dispersion_models import GaussianDispersion
disp = GaussianDispersion()
self.model.set_dispersion('radius', disp)
self.model.dispersion['radius']['width'] = 0.0
self.model.dispersion['radius']['npts'] = 100
self.model.dispersion['radius']['nsigmas'] = 2.5
self.model.setParam('scale', 1.0)
self.assertAlmostEqual(self.model.run(0.001), 450.355, 3)
self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 452.299, 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('cyl_theta', disp_th)
self.model.set_dispersion('cyl_phi', disp_ph)
val_1d = self.model.run(math.sqrt(0.0002))
val_2d = self.model.runXY([0.01,0.01])
#.........这里部分代码省略.........
开发者ID:ricleal,项目名称:SasModeling,代码行数:101,代码来源:utest_dispersity.py
示例17: CylinderModel
import pickle
from sas.models.CylinderModel import CylinderModel
import copy
model = CylinderModel()
model.setParam('cyl_theta', 1.234)
p = copy.deepcopy(model)
assert p.getParam('cyl_theta') == model.getParam('cyl_theta')
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:9,代码来源:test_pickle_cyl.py
示例18: setUp
def setUp(self):
from sas.models.CylinderModel import CylinderModel
from sas.models.DiamCylFunc import DiamCylFunc
self.comp = CylinderModel()
self.diam = DiamCylFunc()
开发者ID:ricleal,项目名称:SasModeling,代码行数:5,代码来源:utest_model_calculate_ER.py
示例19: checkCylinder2D
def checkCylinder2D(self, phi):
"""
Check that the 2D scattering intensity reduces
to a cylinder when r_ratio = 1.0
@param phi: angle of the vector q on the detector
@return: True if the test passed, otherwise False
"""
from sas.models.CylinderModel import CylinderModel
cyl = CylinderModel()
cyl.setParam("cyl_theta", 90)
cyl.setParam("cyl_phi", 0.0)
cyl.setParam("radius", 20)
cyl.setParam("length", 400)
cyl.setParam("sldCyl", 2.0e-6)
cyl.setParam("sldSolv", 1.0e-6)
ell = EllipticalCylinderModel()
ell.setParam("r_ratio", 1.0)
ell.setParam("r_minor", 20)
ell.setParam("cyl_theta", 90)
ell.setParam("cyl_phi", 0.0)
ell.setParam("length", 400)
ell.setParam("sldCyl", 2.0e-6)
ell.setParam("sldSolv", 1.0e-6)
passed = True
for i_q in range(1, 30):
q = 0.025*i_q
ell_val = ell.run([q, phi])
cyl_val = cyl.run([q, phi])
if self.verbose:
print "Q=%g Ell=%g Cyl=%g R=%g" %(q, ell_val, cyl_val, ell_val/cyl_val)
if math.fabs(ell_val-cyl_val)/cyl_val>0.05:
passed= False
return passed
开发者ID:ricleal,项目名称:SasModeling,代码行数:37,代码来源:validate_2D_elliptical_cyl.py
示例20: setUp
def setUp(self):
self.model = CylinderModel()
self.model.setParam("cyl_theta", 1.57)
self.model.setParam("cyl_phi", 0.1)
开发者ID:diffpy,项目名称:srfit-sasview,代码行数:4,代码来源:utest_disperser.py
注:本文中的sas.models.CylinderModel.CylinderModel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论