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


Python PdfFit.read_data方法代码示例

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


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

示例1: selectNoneExceptions

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
class selectNoneExceptions(unittest.TestCase):

    def setUp(self):
        self.P = PdfFit()
        self.iset = 1
        self.i = 1

    def tearDown(self):
        del self.P

    def test_unassignedError1(self):
        """raise pdffit2.unassignedError when set does not exist"""
        self.assertRaises(pdffit2.unassignedError, self.P.selectNone,
                self.iset, 'i')

    def test_unassignedError2(self):
        """raise pdffit2.unassignedError when set does not exist"""
        self.P.read_struct(datafile("Ni.stru"))
        # fail when there is no dataset
        self.assertRaises(pdffit2.unassignedError, self.P.selectNone,
                self.iset, 'i')
        # pass with dataset
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
        self.P.selectNone(self.iset, 'i')
        self.P.selectNone(self.iset, 'j')
        # fail for phase 2
        self.assertRaises(pdffit2.unassignedError, self.P.selectNone, 2, 'i')
        self.assertRaises(pdffit2.unassignedError, self.P.selectNone, 2, 'j')
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:30,代码来源:ExceptionsTest.py

示例2: bangExceptions

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
class bangExceptions(unittest.TestCase):

    def setUp(self):
        self.P = PdfFit()
        self.a1 = 1
        self.a2 = 2
        self.a3 = 3

    def tearDown(self):
        del self.P

    def test_unassignedError(self):
        """raise pdffit2.unassignedError when phase does not exist"""
        self.assertRaises(pdffit2.unassignedError, self.P.bang, self.a1,
                self.a2, self.a3)

    def test_ValueError1(self):
        """raise ValueError when selected atom(s) does not exist"""
        self.P.read_struct(datafile('Ni.stru'))
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
        self.assertRaises(ValueError, self.P.bang, 0,
                self.a2, self.a3)

    def test_ValueError2(self):
        """raise ValueError when selected atom(s) does not exist"""
        self.P.read_struct(datafile('Ni.stru'))
        self.assertRaises(ValueError, self.P.bang, self.a1,
                -1, self.a3)

    def test_ValueError3(self):
        """raise ValueError when selected atom(s) does not exist"""
        self.P.read_struct(datafile('Ni.stru'))
        self.assertRaises(ValueError, self.P.bang, self.a1,
                self.a2, 6)
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:36,代码来源:ExceptionsTest.py

示例3: selectAtomTypeExceptions

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
class selectAtomTypeExceptions(unittest.TestCase):

    def setUp(self):
        self.P = PdfFit()
        self.iset = 1
        self.i = 1

    def tearDown(self):
        del self.P

    def test_unassignedError1(self):
        """raise pdffit2.unassignedError when set does not exist"""
        self.assertRaises(pdffit2.unassignedError, self.P.selectAtomType,
                self.iset, 'i', 'Ni', True)

    def test_unassignedError2(self):
        """raise pdffit2.unassignedError when set does not exist"""
        self.P.read_struct(datafile("Ni.stru"))
        # selectAtomType should pass with one phase defined
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
        self.P.selectAtomType(self.iset, 'i', 'Ni', True)
        self.P.selectAtomType(self.iset, 'j', 'Ni', False)
        # but fail for phase 2 which is not present
        self.assertRaises(pdffit2.unassignedError, self.P.selectAtomType,
                2, 'i', 'Ca', True)

    def test_ijcharValueError(self):
        """raise ValueError when ijchar is neither 'i' nor 'j'"""
        self.P.read_struct(datafile("Ni.stru"))
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
        self.P.selectAtomType(self.iset, 'i', 'Ni', True)
        self.P.selectAtomType(self.iset, 'j', 'Ni', True)
        self.assertRaises(ValueError, self.P.selectAtomType,
                self.iset, 'k', 'Ni', True)
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:36,代码来源:ExceptionsTest.py

示例4: selectAtomIndexExceptions

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
class selectAtomIndexExceptions(unittest.TestCase):

    def setUp(self):
        self.P = PdfFit()
        self.iset = 1
        self.i = 1

    def tearDown(self):
        del self.P

    def test_unassignedError1(self):
        """raise pdffit2.unassignedError when set does not exist"""
        self.assertRaises(pdffit2.unassignedError, self.P.selectAtomIndex,
                self.iset, 'i', self.i, True)

    def test_unassignedError2(self):
        """raise pdffit2.unassignedError when set does not exist"""
        self.P.read_struct(datafile("Ni.stru"))
        # pass for phase 1
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
        self.P.selectAtomIndex(self.iset, 'i', 1, True)
        self.P.selectAtomIndex(self.iset, 'i', 2, False)
        # fail for phase 2
        self.assertRaises(pdffit2.unassignedError, self.P.selectAtomIndex,
                2, 'i', 1, True)

    def test_ValueError(self):
        """raise ValueError when selected atom does not exist"""
        self.P.read_struct(datafile("Ni.stru"))
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
        self.assertRaises(ValueError, self.P.selectAtomIndex,
                self.iset, 'i', 6, True)
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:34,代码来源:ExceptionsTest.py

示例5: pdfrangeExceptions

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
class pdfrangeExceptions(unittest.TestCase):

    def setUp(self):
        self.P = PdfFit()
        self.iset = 1
        self.rmin = 4.0
        self.rmax = 10.0

    def tearDown(self):
        del self.P

    def test_ValueError1(self):
        """raise ValueError when iset does not exist"""
        self.assertRaises(ValueError, self.P.pdfrange, self.iset, self.rmin,
                self.rmax)

    def test_ValueError2(self):
        """raise ValueError when rmax < rmin"""
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.5)
        self.assertRaises(ValueError, self.P.pdfrange, self.iset, self.rmax,
                self.rmin)

    def test_ValueError3(self):
        """raise ValueError when range outside of data"""
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.5)
        self.assertRaises(ValueError, self.P.pdfrange, self.iset, -self.rmin,
                self.rmax)
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:29,代码来源:ExceptionsTest.py

示例6: setdataExceptions

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
class setdataExceptions(unittest.TestCase):

    def setUp(self):
        self.P = PdfFit()

    def tearDown(self):
        del self.P

    def test_unassignedError(self):
        """raise pdffit2.unassignedError when data set does not exist"""
        self.P.read_struct(datafile("Ni.stru"))
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
        self.assertRaises(pdffit2.unassignedError, self.P.setdata, 2)
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:15,代码来源:ExceptionsTest.py

示例7: constrainExceptions

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
class constrainExceptions(unittest.TestCase):

    def setUp(self):
        self.P = PdfFit()
        self.par = 1
        return

    def tearDown(self):
        self.P = None
        return

    def test_constraintError(self):
        """raise constraintError when constraint is bad"""
        self.P.read_struct(datafile("Ni.stru"))
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
        self.P.constrain('x(1)', '[email protected]')
        self.P.setpar(1, 0.01)
        self.assertRaises(pdffit2.constraintError, self.P.calc)
        self.assertRaises(pdffit2.constraintError, self.P.refine)
        return

    def test_unassignedError(self):
        """raise pdffit2.unassignedError when variable is undefined"""
        self.assertRaises(pdffit2.unassignedError, self.P.constrain, self.P.x(1),
                self.par)
        return

    def test_ValueError(self):
        """raise ValueError when a variable index does not exist"""
        self.P.read_struct(datafile("Ni.stru"))
        self.assertRaises(ValueError, self.P.constrain, self.P.x(6),
                self.par)
        return

    def test_constrainNonRefVar(self):
        "raise constraintError when attempting to constrain non-refinables"
        self.P.read_struct(datafile("Ni.stru"))
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
        self.assertRaises(pdffit2.constraintError,
                self.P.constrain, 'rcut', '@7')
        self.assertRaises(pdffit2.constraintError,
                self.P.constrain, 'rcut', 13)
        self.assertRaises(pdffit2.constraintError,
                self.P.constrain, 'stepcut', '@17')
        return
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:47,代码来源:ExceptionsTest.py

示例8: save_difExceptions

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
class save_difExceptions(unittest.TestCase):

    def setUp(self):
        self.P = PdfFit()
        self.strufile = "temp.dif"

    def tearDown(self):
        del self.P

    def test_IOError(self):
        """raise IOError when dif cannot be saved"""
        self.P.read_struct(datafile("Ni.stru"))
        self.P.alloc('X', 30.0, 0.05, 2, 10, 100)
        self.P.calc()
        self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.5)
        self.assertRaises(IOError, self.P.save_dif, 1,
                "nodir183160/"+self.strufile)

    def test_unassignedError(self):
        """raise pdffit2.unassignedError when structure is undefined"""
        self.assertRaises(pdffit2.unassignedError, self.P.save_dif, 1,
        self.strufile)
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:24,代码来源:ExceptionsTest.py

示例9: save_resExceptions

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
class save_resExceptions(unittest.TestCase):

    def setUp(self):
        self.P = PdfFit()
        self.resfile = "temp.res"

    def tearDown(self):
        del self.P

    def test_IOError(self):
        """raise IOError when residual file cannot be saved"""
        self.P.read_struct(datafile("Ni.stru"))
        self.P.read_data(datafile("Ni.dat"), 'X', 30.0, 0.0)
        self.P.constrain(self.P.lat(1), 1)
        self.P.setpar(1, 3.0)
        self.P.pdfrange(1,2.0,10.0)
        self.P.refine_step()
        self.assertRaises(IOError, self.P.save_res,
                "nodir183160/"+self.resfile)

    def test_unassignedError(self):
        """raise pdffit2.unassignedError when structure is undefined"""
        self.assertRaises(pdffit2.unassignedError, self.P.save_res,
        self.resfile)
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:26,代码来源:ExceptionsTest.py

示例10: TestPdfFit

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]

#.........这里部分代码省略.........
        a2 = self.P.get_atoms(2)
        self.assertEqual(4*['NI'], a1)
        self.assertEqual(8*['PB']+24*['O']+8*['SC']+8*['W']+8*['TI'], a2)
        return

    def test_get_atom_types(self):
        """check PdfFit.get_atom_types()
        """
        self.P.read_struct(datafile('Ni.stru'))
        self.P.read_struct(datafile('PbScW25TiO3.stru'))
        self.P.setphase(1)
        atp1 = self.P.get_atom_types()
        atp2 = self.P.get_atom_types(2)
        self.assertEqual(['NI'], atp1)
        self.assertEqual(['PB', 'O', 'SC', 'W', 'TI'], atp2)
        return

    def test_num_phases(self):
        """check PdfFit.num_phases()
        """
        self.assertEqual(0, self.P.num_phases())
        self.P.read_struct(datafile('Ni.stru'))
        self.assertEqual(1, self.P.num_phases())
        self.P.read_struct(datafile('PbScW25TiO3.stru'))
        self.assertEqual(2, self.P.num_phases())
        self.P.reset()
        self.assertEqual(0, self.P.num_phases())
        return

    def test_num_datasets(self):
        """check PdfFit.num_datasets()
        """
        self.assertEqual(0, self.P.num_datasets())
        self.P.read_data(datafile('Ni.dat'), 'X', 25.0, 0.5)
        self.assertEqual(1, self.P.num_datasets())
        # failed data should not increase num_datasets
        try:
            self.P.read_data(datafile('badNi.dat'))
        except:
            pass
        self.assertEqual(1, self.P.num_datasets())
        # alloc should increase number of datasets
        # alloc requires a loaded structure
        self.P.read_struct(datafile('Ni.stru'))
        self.P.alloc('X', 30.0, 0.05, 2, 10, 100)
        self.assertEqual(2, self.P.num_datasets())
        self.P.reset()
        self.assertEqual(0, self.P.num_datasets())
        return

    def test_getcrw(self):
        """check PdfFit.getcrw()
        """
        import numpy
        self.assertEqual(0, self.P.num_datasets())
        # Setting qmax=0 so that partial crw are not disturbed by
        # termination ripples.
        self.P.read_data(datafile('Ni.dat'), 'X', 0.0, 0.0)
        # crw is empty before data refinement
        self.assertEqual([], self.P.getcrw())
        self.P.read_struct(datafile('Ni.stru'))
        self.P.pdfrange(1, 2, 19)
        self.P.refine()
        crw19 = numpy.array(self.P.getcrw())
        self.failUnless(numpy.all(crw19 >= 0.0))
        # check that crw19 is non decreasing
开发者ID:diffpy,项目名称:diffpy.pdffit2,代码行数:70,代码来源:TestPdfFit.py

示例11: PdfFit

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_data [as 别名]
'''Perform simple refinement of Ni structure to the experimental x-ray PDF.
Save fitted curve, refined structure and results summary.
'''

from diffpy.pdffit2 import PdfFit

# Create new PDF calculator object.
pf = PdfFit()

# Load data ------------------------------------------------------------------

# Load experimental x-ray PDF data
qmax = 30.0  # Q-cutoff used in PDF calculation in 1/A
qdamp = 0.01 # instrument Q-resolution factor, responsible for PDF decay
pf.read_data('Ni-xray.gr', 'X', qmax, qdamp)

# Load nickel structure, must be in PDFFIT or DISCUS format
pf.read_struct('Ni.stru')

# Configure Refinement -------------------------------------------------------

# Refine lattice parameters a, b, c.
# Make them all equal to parameter @1.
pf.constrain(pf.lat(1), "@1")
pf.constrain(pf.lat(2), "@1")
pf.constrain(pf.lat(3), "@1")
# set initial value of parameter @1
pf.setpar(1, pf.lat(1))

# Refine phase scale factor.  Right side can have formulas.
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:32,代码来源:Ni_refinement.py


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