コード例 #1
0
    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)
コード例 #2
0
ファイル: early_test.py プロジェクト: zattala/sasview
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))
コード例 #3
0
 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)
コード例 #4
0
 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()
コード例 #5
0
    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() 
コード例 #6
0
 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)
コード例 #7
0
ファイル: early_test.py プロジェクト: zattala/sasview
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))
コード例 #8
0
 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)
コード例 #9
0
ファイル: sim_validation.py プロジェクト: willend/sasview
 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()
コード例 #10
0
    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)
コード例 #11
0
ファイル: utest_state.py プロジェクト: ricleal/SasModeling
    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)
コード例 #12
0
    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)
コード例 #13
0
 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)
コード例 #14
0
ファイル: early_test.py プロジェクト: zattala/sasview
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)
コード例 #15
0
 def setUp(self):
     from sas.models.SphereModel import SphereModel
     self.comp = SphereModel()
コード例 #16
0
 def setUp(self):
     self.sldloader = sas_gen.SLDReader()
     self.pdbloader = sas_gen.PDBReader()
     self.omfloader = sas_gen.OMFReader() 
     self.comp = SphereModel()
コード例 #17
0
ファイル: utest_state.py プロジェクト: ricleal/SasModeling
 def setUp(self):
     self.sphere = SphereModel()
コード例 #18
0
 def setUp(self):
     self.model = SphereModel()
コード例 #19
0
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))
コード例 #20
0
 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