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


Python CreateWorkspace.sample方法代码示例

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


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

示例1: SampleTest

# 需要导入模块: from mantid.simpleapi import CreateWorkspace [as 别名]
# 或者: from mantid.simpleapi.CreateWorkspace import sample [as 别名]
class SampleTest(unittest.TestCase):

    def setUp(self):
        self._ws = CreateWorkspace(DataX=[1,2,3,4,5], DataY=[1,2,3,4,5], OutputWorkspace="dummy")

    def test_geometry_getters_and_setters(self):
        sample = self._ws.sample()

        sample.setThickness(12.5)
        self.assertEquals(sample.getThickness(), 12.5)
        sample.setHeight(10.2)
        self.assertEquals(sample.getHeight(), 10.2)
        sample.setWidth(5.9)
        self.assertEquals(sample.getWidth(), 5.9)

    def test_crystal_structure_handling(self):
        sample = self._ws.sample()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)

        cs = CrystalStructure('5.43 5.43 5.43',
                              'F d -3 m',
                              'Si 0 0 0 1.0 0.01')

        sample.setCrystalStructure(cs)

        self.assertEquals(sample.hasCrystalStructure(), True)

        cs_from_sample = sample.getCrystalStructure()

        self.assertEquals(cs.getSpaceGroup().getHMSymbol(), cs_from_sample.getSpaceGroup().getHMSymbol())
        self.assertEquals(cs.getUnitCell().a(), cs_from_sample.getUnitCell().a())
        self.assertEquals(len(cs.getScatterers()), len(cs_from_sample.getScatterers()))
        self.assertEquals(cs.getScatterers()[0], cs_from_sample.getScatterers()[0])


        sample.clearCrystalStructure()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)

    def test_material(self):
        SetSampleMaterial(self._ws,"Al2 O3",SampleMassDensity=4)
        material = self._ws.sample().getMaterial()

        self.assertAlmostEqual(material.numberDensity, 0.0236, places=4)
        self.assertAlmostEqual(material.relativeMolecularMass(), 101.961, places=3)

        atoms, numatoms = material.chemicalFormula()

        self.assertEquals(len(atoms), len(numatoms))
        self.assertEquals(len(atoms), 2)
        self.assertEquals(numatoms[0], 2)
        self.assertEquals(numatoms[1], 3)

        xs0 = atoms[0].neutron()
        xs1 = atoms[1].neutron()
        xs = ( xs0['coh_scatt_xs']*2 + xs1['coh_scatt_xs']*3 ) / 5
        self.assertAlmostEquals(material.cohScatterXSection(), xs, places=4)
开发者ID:liyulun,项目名称:mantid,代码行数:62,代码来源:SampleTest.py

示例2: test_simple

# 需要导入模块: from mantid.simpleapi import CreateWorkspace [as 别名]
# 或者: from mantid.simpleapi.CreateWorkspace import sample [as 别名]
 def test_simple(self):
     input_x = np.array([0.1,0.2,0.3,0.4,0.5])
     input_y = np.array([1.,2,3,2,1])
     input_e = np.array([0.1,0.14,0.17,0.14,0.1])
     sq = CreateWorkspace(DataX=input_x,
                          DataY=input_y,
                          DataE=input_e,
                          UnitX='MomentumTransfer')
     SetSampleMaterial(InputWorkspace=sq, ChemicalFormula='Ar')
     fq = PDConvertReciprocalSpace(InputWorkspace=sq,
                                   To='F(Q)',
                                   From='S(Q)')
     x=fq.readX(0)
     y=fq.readY(0)
     e=fq.readE(0)
     self.assertTrue(np.array_equal(x, input_x))
     self.assertTrue(np.array_equal(y, input_x*(input_y-1)))
     self.assertTrue(np.array_equal(e, input_x*input_e))
     fkq = PDConvertReciprocalSpace(InputWorkspace=sq,
                                    To='FK(Q)',
                                    From='S(Q)')
     x=fkq.readX(0)
     y=fkq.readY(0)
     e=fkq.readE(0)
     bsq = sq.sample().getMaterial().cohScatterLengthSqrd()
     self.assertTrue(np.array_equal(x, input_x))
     self.assertTrue(np.allclose(y, bsq*(input_y-1)))
     self.assertTrue(np.allclose(e, bsq*input_e))
开发者ID:mantidproject,项目名称:mantid,代码行数:30,代码来源:PDConvertReciprocalSpaceTest.py

示例3: SampleTest

# 需要导入模块: from mantid.simpleapi import CreateWorkspace [as 别名]
# 或者: from mantid.simpleapi.CreateWorkspace import sample [as 别名]
class SampleTest(unittest.TestCase):

    def setUp(self):
        self._ws = CreateWorkspace(DataX=[1,2,3,4,5], DataY=[1,2,3,4,5], OutputWorkspace="dummy")

    def test_geometry_getters_and_setters(self):
        sample = self._ws.sample()

        sample.setThickness(12.5)
        self.assertEquals(sample.getThickness(), 12.5)
        sample.setHeight(10.2)
        self.assertEquals(sample.getHeight(), 10.2)
        sample.setWidth(5.9)
        self.assertEquals(sample.getWidth(), 5.9)

    def test_crystal_structure_handling(self):
        sample = self._ws.sample()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)

        cs = CrystalStructure('5.43 5.43 5.43',
                              'F d -3 m',
                              'Si 0 0 0 1.0 0.01')

        sample.setCrystalStructure(cs)

        self.assertEquals(sample.hasCrystalStructure(), True)

        cs_from_sample = sample.getCrystalStructure()

        self.assertEquals(cs.getSpaceGroup().getHMSymbol(), cs_from_sample.getSpaceGroup().getHMSymbol())
        self.assertEquals(cs.getUnitCell().a(), cs_from_sample.getUnitCell().a())
        self.assertEquals(len(cs.getScatterers()), len(cs_from_sample.getScatterers()))
        self.assertEquals(cs.getScatterers()[0], cs_from_sample.getScatterers()[0])


        sample.clearCrystalStructure()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)
开发者ID:dezed,项目名称:mantid,代码行数:43,代码来源:SampleTest.py

示例4: test_simple

# 需要导入模块: from mantid.simpleapi import CreateWorkspace [as 别名]
# 或者: from mantid.simpleapi.CreateWorkspace import sample [as 别名]
    def test_simple(self):
        input_x = np.array([0.1,0.2,0.3,0.4,0.5])
        input_y = np.array([1.,2,3,2,1])
        input_e = np.array([0.1,0.14,0.17,0.14,0.1])
        Gr = CreateWorkspace(DataX=input_x,
                             DataY=input_y,
                             DataE=input_e)
        SetSampleMaterial(InputWorkspace=Gr, ChemicalFormula='Ar')
        GKr = PDConvertRealSpace(InputWorkspace=Gr,
                                 To='GK(r)',
                                 From='G(r)')
        x=GKr.readX(0)
        y=GKr.readY(0)
        e=GKr.readE(0)

        bsq = Gr.sample().getMaterial().cohScatterLengthSqrd()
        rho = Gr.sample().getMaterial().numberDensity
        factor = bsq / (4. * np.pi *rho)
        self.assertTrue(np.array_equal(x, input_x))
        self.assertTrue(np.allclose(y, factor*input_y/input_x))
        self.assertTrue(np.allclose(e, factor*input_e/input_x))
开发者ID:mantidproject,项目名称:mantid,代码行数:23,代码来源:PDConvertRealSpaceTest.py

示例5: SampleTest

# 需要导入模块: from mantid.simpleapi import CreateWorkspace [as 别名]
# 或者: from mantid.simpleapi.CreateWorkspace import sample [as 别名]
class SampleTest(unittest.TestCase):

    def setUp(self):
        self._ws = CreateWorkspace(DataX=[1,2,3,4,5], DataY=[1,2,3,4,5], OutputWorkspace="dummy")

    def test_geometry_getters_and_setters(self):
        sample = self._ws.sample()

        sample.setThickness(12.5)
        self.assertEquals(sample.getThickness(), 12.5)
        sample.setHeight(10.2)
        self.assertEquals(sample.getHeight(), 10.2)
        sample.setWidth(5.9)
        self.assertEquals(sample.getWidth(), 5.9)
开发者ID:BigShows,项目名称:mantid,代码行数:16,代码来源:SampleTest.py

示例6: _parseStructure

# 需要导入模块: from mantid.simpleapi import CreateWorkspace [as 别名]
# 或者: from mantid.simpleapi.CreateWorkspace import sample [as 别名]
 def _parseStructure(self, structure):
     from mantid.simpleapi import mtd, LoadCIF, CreateWorkspace, DeleteWorkspace
     import uuid
     self._fromCIF = False
     if isinstance(structure, string_types):
         if mtd.doesExist(structure):
             try:
                 self._cryst = self._copyCrystalStructure(mtd[structure].sample().getCrystalStructure())
                 self._getUniqueAtoms()
             except RuntimeError:
                 raise ValueError('Workspace ''%s'' has no valid CrystalStructure' % (structure))
         else:
             tmpws = CreateWorkspace(1, 1, OutputWorkspace='_tempPointCharge_'+str(uuid.uuid4())[:8])
             try:
                 LoadCIF(tmpws, structure)
                 # Attached CrystalStructure object gets destroyed when workspace is deleted
                 self._cryst = self._copyCrystalStructure(tmpws.sample().getCrystalStructure())
             except:
                 DeleteWorkspace(tmpws)
                 raise
             else:
                 DeleteWorkspace(tmpws)
                 self._getUniqueAtoms()
     elif isinstance(structure, list):
         if (len(structure) == 4 and all([isinstance(x, (int, float)) for x in structure])):
             structure = [structure]
         if (all([isinstance(x, list) and (len(x) == 4) and
            all([isinstance(y, (int, float)) for y in x]) for x in structure])):
             self._ligands = structure
         else:
             raise ValueError('Incorrect ligands direct input. Must be a 4-element list or a list '
                              'of 4-element list. Each ligand must be of the form [charge, x, y, z]')
     elif hasattr(structure, 'getScatterers'):
         self._cryst = structure
         self._getUniqueAtoms()
     else:
         if not hasattr(structure, 'sample'):
             raise ValueError('First input must be a Mantid CrystalStructure object, workspace or string '
                              '(name of CIF file or workspace)')
         try:
             self._cryst = self._copyCrystalStructure(structure.sample().getCrystalStructure())
             self._getUniqueAtoms()
         except RuntimeError:
             raise ValueError('Workspace ''%s'' has no valid CrystalStructure' % (structure.name()))
开发者ID:DanNixon,项目名称:mantid,代码行数:46,代码来源:pointcharge.py

示例7: SampleTest

# 需要导入模块: from mantid.simpleapi import CreateWorkspace [as 别名]
# 或者: from mantid.simpleapi.CreateWorkspace import sample [as 别名]
class SampleTest(unittest.TestCase):

    def setUp(self):
        self._ws = CreateWorkspace(DataX=[1,2,3,4,5], DataY=[1,2,3,4,5], OutputWorkspace="dummy")

    def test_geometry_getters_and_setters(self):
        sample = self._ws.sample()

        sample.setThickness(12.5)
        self.assertEquals(sample.getThickness(), 12.5)
        sample.setHeight(10.2)
        self.assertEquals(sample.getHeight(), 10.2)
        sample.setWidth(5.9)
        self.assertEquals(sample.getWidth(), 5.9)

    def test_crystal_structure_handling(self):
        sample = self._ws.sample()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)

        cs = CrystalStructure('5.43 5.43 5.43',
                              'F d -3 m',
                              'Si 0 0 0 1.0 0.01')

        sample.setCrystalStructure(cs)

        self.assertEquals(sample.hasCrystalStructure(), True)

        cs_from_sample = sample.getCrystalStructure()

        self.assertEquals(cs.getSpaceGroup().getHMSymbol(), cs_from_sample.getSpaceGroup().getHMSymbol())
        self.assertEquals(cs.getUnitCell().a(), cs_from_sample.getUnitCell().a())
        self.assertEquals(len(cs.getScatterers()), len(cs_from_sample.getScatterers()))
        self.assertEquals(cs.getScatterers()[0], cs_from_sample.getScatterers()[0])


        sample.clearCrystalStructure()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)

    def test_material(self):
        SetSampleMaterial(self._ws,"Al2 O3",SampleMassDensity=4)
        material = self._ws.sample().getMaterial()

        self.assertAlmostEqual(material.numberDensity, 0.1181, places=4)
        self.assertAlmostEqual(material.relativeMolecularMass(), 101.961, places=3)

        atoms, numatoms = material.chemicalFormula()

        self.assertEquals(len(atoms), len(numatoms))
        self.assertEquals(len(atoms), 2)
        self.assertEquals(numatoms[0], 2)
        self.assertEquals(numatoms[1], 3)

        xs0 = atoms[0].neutron()
        xs1 = atoms[1].neutron()
        # the correct way to calculate for coherent cross section
        # is to average the scattering lengths then convert to a cross section
        b_real = (xs0['coh_scatt_length_real']*2 + xs1['coh_scatt_length_real']*3) / 5
        b_imag = (xs0['coh_scatt_length_img']*2 + xs1['coh_scatt_length_img']*3) / 5
        xs = .04 * pi * (b_real * b_real + b_imag * b_imag)
        self.assertAlmostEquals(material.cohScatterXSection(), xs, places=4)

    def test_get_shape(self):
        sample = self._ws.sample()
        self.assertEquals(type(sample.getShape()), CSGObject)

    def test_get_shape_xml(self):
        sample = self._ws.sample()
        shape = sample.getShape()
        xml = shape.getShapeXML()
        self.assertEquals(type(xml), str)
开发者ID:mantidproject,项目名称:mantid,代码行数:76,代码来源:SampleTest.py


注:本文中的mantid.simpleapi.CreateWorkspace.sample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。