コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
ファイル: early_test.py プロジェクト: diffpy/srfit-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
コード例 #4
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)
コード例 #5
0
class TestEvalMethods(unittest.TestCase):
    """ Testing evalDistribution for C models """
    def setUp(self):
        self.model = SphereModel()

    def test_scalar_methods(self):
        """
            Simple test comparing the run(), runXY() and
            evalDistribution methods
        """
        q1 = self.model.run(0.001)
        q2 = self.model.runXY(0.001)
        q4 = self.model.run(0.002)
        qlist3 = numpy.asarray([0.001, 0.002])
        q3 = self.model.evalDistribution(qlist3)

        self.assertEqual(q1, q2)
        self.assertEqual(q1, q3[0])
        self.assertEqual(q4, q3[1])

    def test_XY_methods(self):
        """
            Compare to the runXY() method for 2D models.
            
                      +--------+--------+--------+
            qy=0.009  |        |        |        | 
                      +--------+--------+--------+
            qy-0.006  |        |        |        |
                      +--------+--------+--------+            
            qy=0.003  |        |        |        | 
                      +--------+--------+--------+
                      qx=0.001   0.002   0.003
            
        """
        # These are the expected values for all bins
        expected = numpy.zeros([3, 3])
        for i in range(3):
            for j in range(3):
                q_length = math.sqrt((0.001 * (i + 1.0)) * (0.001 *
                                                            (i + 1.0)) +
                                     (0.003 * (j + 1.0)) * (0.003 * (j + 1.0)))
                expected[i][j] = self.model.run(q_length)

        qx_values = [0.001, 0.002, 0.003]
        qy_values = [0.003, 0.006, 0.009]

        qx = numpy.asarray(qx_values)
        qy = numpy.asarray(qy_values)

        new_x = numpy.tile(qx, (len(qy), 1))
        new_y = numpy.tile(qy, (len(qx), 1))
        new_y = new_y.swapaxes(0, 1)

        #iq is 1d array now (since 03-12-2010)
        qx_prime = new_x.flatten()
        qy_prime = new_y.flatten()

        iq = self.model.evalDistribution([qx_prime, qy_prime])

        for i in range(3):
            for j in range(3):
                # convert index into 1d array
                k = i + len(qx) * j
                self.assertAlmostEquals(iq[k], expected[i][j])
コード例 #6
0
class TestEvalMethods(unittest.TestCase):
    """ Testing evalDistribution for C models """

    def setUp(self):
        self.model= SphereModel()
        
    def test_scalar_methods(self):
        """
            Simple test comparing the run(), runXY() and
            evalDistribution methods
        """
        q1 = self.model.run(0.001)
        q2 = self.model.runXY(0.001)
        q4 = self.model.run(0.002)
        qlist3 = numpy.asarray([0.001, 0.002])
        q3 = self.model.evalDistribution(qlist3)

        self.assertEqual(q1, q2)
        self.assertEqual(q1, q3[0])
        self.assertEqual(q4, q3[1])
        
    def test_XY_methods(self):
        """
            Compare to the runXY() method for 2D models.
            
                      +--------+--------+--------+
            qy=0.009  |        |        |        | 
                      +--------+--------+--------+
            qy-0.006  |        |        |        |
                      +--------+--------+--------+            
            qy=0.003  |        |        |        | 
                      +--------+--------+--------+
                      qx=0.001   0.002   0.003
            
        """
        # These are the expected values for all bins
        expected = numpy.zeros([3,3])
        for i in range(3):
            for j in range(3):
                q_length = math.sqrt( (0.001*(i+1.0))*(0.001*(i+1.0)) + (0.003*(j+1.0))*(0.003*(j+1.0)) )
                expected[i][j] = self.model.run(q_length)
        
        qx_values = [0.001, 0.002, 0.003]
        qy_values = [0.003, 0.006, 0.009]
        
        qx = numpy.asarray(qx_values)
        qy = numpy.asarray(qy_values)
              
        new_x = numpy.tile(qx, (len(qy),1))
        new_y = numpy.tile(qy, (len(qx),1))
        new_y = new_y.swapaxes(0,1)
    
        #iq is 1d array now (since 03-12-2010)
        qx_prime = new_x.flatten()
        qy_prime = new_y.flatten()
        
        iq = self.model.evalDistribution([qx_prime, qy_prime])
        
        for i in range(3):
            for j in range(3):
                # convert index into 1d array
                k = i+len(qx)*j
                self.assertAlmostEquals(iq[k], expected[i][j])
コード例 #7
0
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))

ixy = [ comp.runXY(list(i)) for i in qxy]
ixy = np.array(ixy)


ixy = ixy.reshape(400,400)
ixy = np.log(ixy)

plt.figure()
plt.imshow(ixy)
plt.show()