本文整理汇总了Python中sas.models.SphereModel.SphereModel.setParam方法的典型用法代码示例。如果您正苦于以下问题:Python SphereModel.setParam方法的具体用法?Python SphereModel.setParam怎么用?Python SphereModel.setParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sas.models.SphereModel.SphereModel
的用法示例。
在下文中一共展示了SphereModel.setParam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSphere
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [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)
示例2: smear_test_1Dpinhole
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [as 别名]
class smear_test_1Dpinhole(unittest.TestCase):
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)
def test_q(self):
"""
Compare Pinhole resolution smearing with NIST
"""
# x values
input = numpy.zeros(len(self.data.x))
# set time
st1 = time()
# cal I w/o smear
input = self.model.evalDistribution(self.data.x)
# Cal_smear (first call)
for i in range(1000):
s = QSmearer(self.data, self.model)
# stop and record time taken
first_call_time = time()-st1
# set new time
st = time()
# cal I w/o smear (this is not neccessary to call but just to be fare
input = self.model.evalDistribution(self.data.x)
# smear cal (after first call done above)
for i in range(1000):
output = s(input)
# record time taken
last_call_time = time()-st
# compare the ratio of ((NIST_answer-SsanView_answer)/NIST_answer)
# If the ratio less than 1%, pass the test
for i in range(len(self.data.x)):
ratio = math.fabs((self.answer.y[i]-output[i])/self.answer.y[i])
if ratio > 0.006:
ratio = 0.006
self.assertEqual(math.fabs((self.answer.y[i]-output[i])/ \
self.answer.y[i]), ratio)
# print
print "\n NIST_time = 10sec:"
print "Cal_time(1000 times of first_calls; ) = ", first_call_time
print "Cal_time(1000 times of calls) = ", last_call_time
示例3: SphereValidator
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [as 别名]
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
示例4: testGetIq
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [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)
示例5: TestSphere
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [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
示例6: TestSphere
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [as 别名]
class TestSphere(unittest.TestCase):
def setUp(self):
self.sphere = SphereModel()
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)
示例7: TestSphereGauss
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [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)
示例8: testWrongOrder
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [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)
示例9: test_1
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [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)
示例10: setUp
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [as 别名]
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)
示例11: test_5
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [as 别名]
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
示例12: test_4
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [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)
示例13: smear_testdata
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [as 别名]
class smear_testdata(unittest.TestCase):
"""
Test fitting with the smearing operations
The output of the fits should be compated to fits
done with IGOR for the same models and data sets.
"""
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)
#self.sphere.setParam('radius.npts', 30)
#self.sphere.setParam('radius.width',50)
def test_reso(self):
# Let the data module find out what smearing the
# data needs
smear = smear_selection(self.data_res)
#self.assertEqual(smear.__class__.__name__, 'QSmearer')
#self.assertEqual(smear.__class__.__name__, 'PySmearer')
# Fit
fitter = Fit()
# Data: right now this is the only way to set the smearer object
# We should improve that and have a way to get access to the
# data for a given fit.
fitter.set_data(self.data_res,1)
fitter.fit_arrange_dict[1].data_list[0].smearer = smear
# Model: maybe there's a better way to do this.
# Ideally we should have to create a new model from our sas model.
fitter.set_model(Model(self.sphere),1, ['radius','scale', 'background'])
# Why do we have to do this...?
fitter.select_problem_for_fit(id=1,value=1)
# Perform the fit (might take a while)
result1, = fitter.fit()
#print "v",result1.pvec
#print "dv",result1.stderr
#print "chisq(v)",result1.fitness
self.assertTrue( math.fabs(result1.pvec[0]-5000) < 20 )
self.assertTrue( math.fabs(result1.pvec[1]-0.48) < 0.02 )
self.assertTrue( math.fabs(result1.pvec[2]-0.060) < 0.002 )
def test_slit(self):
smear = smear_selection(self.data_slit)
#self.assertEqual(smear.__class__.__name__, 'SlitSmearer')
#self.assertEqual(smear.__class__.__name__, 'PySmearer')
fitter = Fit()
# Data: right now this is the only way to set the smearer object
# We should improve that and have a way to get access to the
# data for a given fit.
fitter.set_data(self.data_slit,1)
fitter.fit_arrange_dict[1].data_list[0].smearer = smear
fitter.fit_arrange_dict[1].data_list[0].qmax = 0.003
# Model
fitter.set_model(Model(self.sphere),1, ['radius','scale'])
fitter.select_problem_for_fit(id=1,value=1)
result1, = fitter.fit()
#print "v",result1.pvec
#print "dv",result1.stderr
#print "chisq(v)",result1.fitness
numpy.testing.assert_allclose(result1.pvec, [2323.466,0.22137], rtol=0.001)
示例14: SphereModel
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [as 别名]
import sys
sys.path.append('../build/temp.macosx-10.11-x86_64-2.7/src/sas')
"""
Test plotting sphere
"""
import numpy as np
import matplotlib.pyplot as plt
from sas.models.SphereModel import SphereModel
comp = SphereModel()
comp.setParam("radius", 30.0)
comp.setParam("background", 0.01)
# Generate Q and calculate I
q = np.linspace(0.001, 1, num=200)
i = map(comp.run,q)
# Plot I(q)
plt.figure()
plt.plot(q,np.log(i))
qx = np.linspace(-1, 1, num=400)
qy = qx
xv, yv = np.meshgrid(qx, qy)
xv= xv.flatten()
yv= yv.flatten()
qxy = np.column_stack((xv,yv))
示例15: TestsphereHardS
# 需要导入模块: from sas.models.SphereModel import SphereModel [as 别名]
# 或者: from sas.models.SphereModel.SphereModel import setParam [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)