本文整理匯總了Python中diffpy.srreal.pdfcalculator.PDFCalculator._setDoubleAttr方法的典型用法代碼示例。如果您正苦於以下問題:Python PDFCalculator._setDoubleAttr方法的具體用法?Python PDFCalculator._setDoubleAttr怎麽用?Python PDFCalculator._setDoubleAttr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類diffpy.srreal.pdfcalculator.PDFCalculator
的用法示例。
在下文中一共展示了PDFCalculator._setDoubleAttr方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test__setDoubleAttr
# 需要導入模塊: from diffpy.srreal.pdfcalculator import PDFCalculator [as 別名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import _setDoubleAttr [as 別名]
def test__setDoubleAttr(self):
"""check Attributes._setDoubleAttr()
"""
pdfc = PDFCalculator()
pdfc._setDoubleAttr('scale', 1.23)
self.assertFalse('scale' in pdfc.__dict__)
self.assertEqual(1.23, pdfc.scale)
return
示例2: test___getattr__
# 需要導入模塊: from diffpy.srreal.pdfcalculator import PDFCalculator [as 別名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import _setDoubleAttr [as 別名]
def test___getattr__(self):
"""check Attributes.__getattr__()
"""
a = Attributes()
self.assertRaises(AttributeError, getattr, a, 'invalid')
a.x = 11
self.assertEqual(11, a.x)
pdfc = PDFCalculator()
pdfc._setDoubleAttr('rmax', 12.34)
self.assertEqual(12.34, pdfc.rmax)
return
示例3: TestPDFCalculator
# 需要導入模塊: from diffpy.srreal.pdfcalculator import PDFCalculator [as 別名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import _setDoubleAttr [as 別名]
class TestPDFCalculator(unittest.TestCase):
nickel = None
tio2rutile = None
def setUp(self):
self.pdfcalc = PDFCalculator()
if not self.nickel:
type(self).nickel = loadDiffPyStructure('Ni.stru')
if not self.tio2rutile:
type(self).tio2rutile = (
loadDiffPyStructure('TiO2_rutile-fit.stru'))
return
def tearDown(self):
return
def test___init__(self):
"""check PDFCalculator.__init__()
"""
pdfc = PDFCalculator(qmin=13, rmin=4, rmax=99)
self.assertEqual(13, pdfc.qmin)
self.assertEqual(4, pdfc.rmin)
self.assertEqual(99, pdfc.rmax)
self.assertEqual(99, pdfc._getDoubleAttr('rmax'))
return
def test___call__(self):
"""Check PDFCalculator.__call__()
"""
from diffpy.Structure import Structure
r0, g0 = self.pdfcalc(self.tio2rutile, rmin=2)
self.assertEqual(2.0, r0[0])
r1, g1 = self.pdfcalc(self.tio2rutile, scale=7)
self.assertAlmostEqual(7.0, g1[0] / g0[0])
# check application of spdiameter
rutile2 = Structure(self.tio2rutile)
# work around Structure bug of shared pdffit dictionary
rutile2.pdffit = dict(self.tio2rutile.pdffit)
rutile2.pdffit['spdiameter'] = 5.0
r3, g3 = self.pdfcalc(rutile2)
self.assertEqual(0.0, sum(g3[r3 >= 5] ** 2))
r4, g4 = self.pdfcalc(rutile2, scale=1, spdiameter=0)
self.failUnless(numpy.all(r4 == r0))
self.failUnless(numpy.all(g4 == g0))
return
def test__getDoubleAttr(self):
"""check PDFCalculator._getDoubleAttr()
"""
gdba = self.pdfcalc._getDoubleAttr
self.assertEqual(1.0, gdba('scale'))
self.assertEqual(0.0, gdba('qdamp'))
self.assertRaises(Exception, gdba, 'notanattribute')
return
def test__hasDoubleAttr(self):
"""check PDFCalculator._hasDoubleAttr()
"""
self.failUnless(self.pdfcalc._hasDoubleAttr('scale'))
self.failIf(self.pdfcalc._hasDoubleAttr('notanattribute'))
return
def test__namesOfDoubleAttributes(self):
"""check PDFCalculator._namesOfDoubleAttributes()
"""
self.failUnless(type(self.pdfcalc._namesOfDoubleAttributes()) is set)
self.failUnless('qmax' in self.pdfcalc._namesOfDoubleAttributes())
return
def test__setDoubleAttr(self):
"""check PDFCalculator._setDoubleAttr()
"""
gdba = self.pdfcalc._getDoubleAttr
sdba = self.pdfcalc._setDoubleAttr
self.assertEqual(0.0, gdba('rmin'))
sdba('rmin', 3.0)
self.assertEqual(3.0, gdba('rmin'))
return
def test_eval_nickel(self):
"""check PDFCalculator.eval() on simple Nickel data
"""
fnipf2 = datafile('Ni-fit.fgr')
gpf2 = numpy.loadtxt(fnipf2, usecols=(1,))
self.pdfcalc._setDoubleAttr('rmax', 10.0001)
self.pdfcalc.eval(self.nickel)
gcalc = self.pdfcalc.pdf
self.failUnless(_maxNormDiff(gpf2, gcalc) < 0.0091)
return
def test_eval_rutile(self):
"""check PDFCalculator.eval() on anisotropic rutile data
"""
frutile = datafile('TiO2_rutile-fit.fgr')
gpf2 = numpy.loadtxt(frutile, usecols=(1,))
# configure calculator according to testdata/TiO2_ruitile-fit.fgr
self.pdfcalc.qmax = 26
self.pdfcalc.qdamp = 0.0665649
dscale = 0.655857
#.........這裏部分代碼省略.........