コード例 #1
0
    def test_scale(self):
        x=np.linspace(-5,5,101)
        y=np.sin(x)
        orig=Data(x+np.random.normal(size=101,scale=0.025),y+np.random.normal(size=101,scale=0.01))
        orig.setas="xy"

        XTests=[[(0,0,0.5),(0,2,-0.1)],
                 [(0,0,0.5)],
                 [(0,2,-0.2)]]
        YTests=[[(1,1,0.5),(1,2,-0.1)],
                 [(1,1,0.5)],
                 [(1,2,-0.2)]]
        for xmode,xdata,xtests in zip(["linear","scale","offset"],[x*2+0.2,x*2,x+0.2],XTests):
            for ymode,ydata,ytests in zip(["linear","scale","offset"],[y*2+0.2,y*2,y+0.2],YTests):
                to_scale=Data(xdata+np.random.normal(size=101,scale=0.025),ydata+np.random.normal(size=101,scale=0.01))
                to_scale.setas="xy"
                to_scale.scale(orig,xmode=xmode,ymode=ymode)
                transform=to_scale["Transform"]
                t_err=to_scale["Transform Err"]
                for i,j,v in xtests+ytests:
                    self.assertLessEqual(np.abs(transform[i,j]-v),5*t_err[i,j],"Failed to get correct trandorm factor for {}:{} ({} vs {}".format(xmode,ymode,transform[i,j],v))

        to_scale=Data(x*5+0.1+np.random.normal(size=101,scale=0.025),y*0.5+0.1+0.5*x+np.random.normal(size=101,scale=0.01))
        to_scale.setas="xy"
        to_scale.scale(orig,xmode="affine")
        a_tranform=np.array([[0.2,0.,-0.02],[-0.2, 2.,-0.17]])
        t_delta=np.abs(to_scale["Transform"]-a_tranform)
        t_in_range=t_delta<to_scale["Transform Err"]*5
        self.assertTrue(np.all(t_in_range),"Failed to produce correct affine scaling {} vs {}".format(to_scale["Transform"],a_tranform))
コード例 #2
0
import matplotlib as mpl
from tabulate import tabulate

mpl.rc("text", usetex=True)

x = linspace(0, 10 * pi, 201)
x2 = x * 1.5 + 0.23
y = 10 * exp(-x / (2 * pi)) * sin(x) + normal(size=len(x), scale=0.1)
y2 = 3 * exp(-x / (2 * pi)) * sin(x) - 1 + normal(size=len(x), scale=0.1)

d = Data(x, y, column_headers=["Time", "Signal 1"], setas="xy")
d2 = Data(x2, y2, column_headers=["Time", "Signal 2"], setas="xy")

d.plot(label="1$^\\mathrm{st}$ signal")
d2.plot(figure=d.fig, label="2$^\\mathrm{nd}$ signal")
d3 = d2.scale(d, header="Signal 2 scaled", xmode="affine")
d3.plot(figure=d.fig, label="1$^\\mathrm{st}$ scaled signals")
d3["test"] = linspace(1, 10, 10)
txt = tabulate(d3["Transform"], floatfmt=".2f", tablefmt="grid")
d3.text(10, 4, "Transform\n{}".format(txt), fontdict={"size": "x-small"})

np_data = column_stack((x2, y2))
d4 = d.scale(np_data,
             header="Signal 2 scaled",
             xmode="affine",
             use_estimate=True)
d4.plot(figure=d.fig, label="2$^\\mathrm{nd}$ scaled signal")
d4.ylim = (-7, 9)
txt = tabulate(d4["Transform"], floatfmt=".2f", tablefmt="grid")
d4.text(10, -7, "Transform\n{}".format(txt), fontdict={"size": "x-small"})
コード例 #3
0
"""Example of using scale to overlap data"""
from Stoner import Data
from numpy import linspace, sin, exp, pi, dstack
from numpy.random import normal
import matplotlib as mpl
from tabulate import tabulate

mpl.rc("text", usetex=True)

x = linspace(0, 10 * pi, 201)
x2 = x * 1.5 + 0.23
y = 10 * exp(-x / (2 * pi)) * sin(x) + normal(size=len(x), scale=0.1)
y2 = 3 * exp(-x / (2 * pi)) * sin(x) - 1 + normal(size=len(x), scale=0.1)

d = Data(x, y, column_headers=["Time", "Signal 1"], setas="xy")
d2 = Data(x2, y2, column_headers=["Time", "Signal 2"], setas="xy")

d.plot()
d2.plot(figure=d.fig)
d3 = d2.scale(d, header="Signal 2 scaled", xmode="affine")
d3.plot(figure=d.fig)
d3["test"] = linspace(1, 10, 10)
txt = tabulate(d3["Transform"], floatfmt=".2f", tablefmt="grid")
d3.text(20, 2, "Transform\n{}".format(txt), fontdict={"size": "x-small"})
d3.title = "Scaling Example"