本文整理汇总了Python中Stoner.Data.add方法的典型用法代码示例。如果您正苦于以下问题:Python Data.add方法的具体用法?Python Data.add怎么用?Python Data.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stoner.Data
的用法示例。
在下文中一共展示了Data.add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_functions
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import add [as 别名]
def test_functions(self):
#Test section:
self.s1=self.d1.section(z=(12,13))
self.assertTrue(142.710<self.d2.mean("Temp")<142.711,"Failed on the mean test.")
self.assertTrue(round(self.d2.span("Temp")[0],1)==4.3 and round(self.d2.span("Temp")[1],1)==291.6,"Span test failed.")
f=self.d2.split(lambda r:r["Temp"]<150)
self.assertTrue(len(f[0])==838,"Split failed to work.")
self.assertEqual(len(self.d3.threshold(2000,rising=True,falling=True,all_vals=True)),5,"Threshold failure.")
self.d4.add(0,1,"Add")
self.d4.subtract(1,0,header="Subtract")
self.d4.multiply(0,1,header="Multiply")
self.d4.divide(0,1,header="Divide")
self.d4.diffsum(0,1,header="Diffsum")
self.assertTrue(np.all(self.d4[0]==np.array([-0.5,-1,-3,3,-1,2])),"Test column ops failed.")
d=Data(np.zeros((100,1)))
d.add(0,1.0)
self.assertEqual(np.sum(d[:,0]),100.,"Add with a flot didn't work")
d.add(0,np.ones(100))
self.assertEqual(np.sum(d[:,0]),200.,"Add with an array failed.")
示例2: Analysis_test
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import add [as 别名]
class Analysis_test(unittest.TestCase):
"""Path to sample Data File"""
datadir=path.join(pth,"sample-data")
def setUp(self):
self.d1=Data(path.join(self.datadir,"OVF1.ovf"))
self.d2=Data(path.join(self.datadir,"TDI_Format_RT.txt"))
self.d3=Data(path.join(self.datadir,"New-XRay-Data.dql"))
self.d4=Data(np.column_stack([np.ones(100),np.ones(100)*2]),setas="xy")
def test_functions(self):
#Test section:
self.s1=self.d1.section(z=(12,13))
self.assertTrue(142.710<self.d2.mean("Temp")<142.711,"Failed on the mean test.")
self.assertTrue(round(self.d2.span("Temp")[0],1)==4.3 and round(self.d2.span("Temp")[1],1)==291.6,"Span test failed.")
f=self.d2.split(lambda r:r["Temp"]<150)
self.assertTrue(len(f[0])==838,"Split failed to work.")
self.assertEqual(len(self.d3.threshold(2000,rising=True,falling=True,all_vals=True)),5,"Threshold failure.")
self.d4.add(0,1,"Add")
self.d4.subtract(1,0,header="Subtract")
self.d4.multiply(0,1,header="Multiply")
self.d4.divide(0,1,header="Divide")
self.d4.diffsum(0,1,header="Diffsum")
self.assertTrue(np.all(self.d4[0]==np.array([-0.5,-1,-3,3,-1,2])),"Test column ops failed.")
d=Data(np.zeros((100,1)))
d.add(0,1.0)
self.assertEqual(np.sum(d[:,0]),100.,"Add with a flot didn't work")
d.add(0,np.ones(100))
self.assertEqual(np.sum(d[:,0]),200.,"Add with an array failed.")
def test_peaks(self):
d=self.d3.clone
d.peaks(width=8,poly=4,significance=100,modify=True)
self.assertEqual(len(d),11,"Failed on peaks test.")
def test_threshold(self):
#set up some zigzag data
#mins at 0,100,200,300,400, max at 50, 150, 250, 350 and zeros in between
ar = np.zeros((400,2))
ar[:,0]=np.arange(0,len(ar))
for i in range(4):
ar[i*100:i*100+50,1] = np.linspace(-1,1,50)
for i in range(4):
ar[i*100+50:i*100+100,1] = np.linspace(1,-1,50)
d = Data(ar, setas='xy')
self.assertTrue(len(d.threshold(0,rising=True,falling=False,all_vals=True)==4))
self.assertTrue(len(d.threshold(0,rising=False,falling=True,all_vals=True)==4))
self.assertTrue(len(d.threshold(0,interpolate=False,rising=False,falling=True,all_vals=True)==4))
self.assertTrue(d.threshold(0,all_vals=True)[1]==124.5)
self.thresh=d
self.assertTrue(np.sum(d.threshold([0.0,0.5,1.0])-np.array([[24.5,36.74999999, 49.]]))<1E-6,"Multiple threshold failed.")
self.assertAlmostEqual(d.threshold(0,interpolate=False,all_vals=True)[1],124.5,6,"Threshold without interpolation failed.")
result=d.threshold(0,interpolate=False,all_vals=True,xcol=False)
self.assertTrue(np.allclose(result,np.array([[ 24.5, 0. ],[124.5, 0. ],[224.5, 0. ],[324.5, 0. ]])),
"Failed threshold with False scol - result was {}".format(result))
def test_apply(self):
self.app=Data(np.zeros((100,1)),setas="y")
self.app.apply(lambda r:r.i[0],header="Counter")
def calc(r,omega=1.0,k=1.0):
return np.sin(r.y*omega)
self.app.apply(calc,replace=False,header="Sin",_extra={"omega":0.1},k=1.0)
self.app.apply(lambda r:r.__class__([r[1],r[0]]),replace=True,header=["Index","Sin"])
self.app.setas="xy"
self.assertAlmostEqual(self.app.integrate(),-64.1722191259037,msg="Integrate after aplies failed.")
示例3: linspace
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import add [as 别名]
from Stoner import Data
from numpy import linspace, ones_like, sin, cos, pi
from numpy.random import normal
from Stoner.plot.utils import errorfill
x = linspace(0, 10 * pi, 101)
e = 0.01 * ones_like(x)
y = 0.1 * sin(x) + normal(size=len(x), scale=0.01) + 0.1
e2 = 0.01 * cos(x)
y2 = 0.1 * ones_like(x)
d = Data(
x,
y,
e,
y2,
e2,
column_headers=["$X$", "$Y_+$", r"$\delta Y_+$", "$Y_-$", r"$\delta Y_-$"],
setas="xyeye",
)
a = tuple(d.column_headers[1:3])
b = tuple(d.column_headers[3:5])
d.add(a, b, replace=False)
d.subtract(a, b, replace=False)
d.multiply(a, b, replace=False)
d.divide(a, b, replace=False)
d.diffsum(a, b, replace=False)
d.setas = "xyeyeyeyeyeyeye"
d.plot(multiple="panels", plotter=errorfill, color="red", alpha_fill=0.2)