def test_tranproc(): import wafo.transform.models as wtm tr = wtm.TrHermite() x = linspace(-5, 5, 501) g = tr(x) y0, y1 = tranproc(x, g, range(5), ones(5)) assert_allclose(y0, [0.02659612, 1.00115284, 1.92872532, 2.81453257, 3.66292878]) assert_allclose(y1, [1.00005295, 0.9501118, 0.90589954, 0.86643821, 0.83096482])
def test_testgaussian(self): Hs = self.Sj.Hm0 S0 = self.S # ns =100; dt = .2 # x1 = S0.sim(ns, dt=dt) S = S0.copy() me, _va, sk, ku = S.stats_nl(moments='mvsk') S.tr = wtm.TrHermite(mean=me, sigma=Hs / 4, skew=sk, kurt=ku, ysigma=Hs / 4) ys = wo.mat2timeseries(S.sim(ns=2 ** 13)) g0, _gemp = ys.trdata() t0 = g0.dist2gauss() t1 = S0.testgaussian(ns=2 ** 13, test0=None, cases=50) assert(sum(t1 > t0) <= 5)
def test_testgaussian(): Hs = 7 Sj = sm.Jonswap(Hm0=Hs) S0 = Sj.tospecdata() #ns =100; dt = .2 #x1 = S0.sim(ns, dt=dt) S = S0.copy() me, _va, sk, ku = S.stats_nl(moments='mvsk') S.tr = wtm.TrHermite(mean=me, sigma=Hs / 4, skew=sk, kurt=ku, ysigma=Hs / 4) ys = wo.mat2timeseries(S.sim(ns=2**13)) g0, _gemp = ys.trdata() t0 = g0.dist2gauss() t1 = S0.testgaussian(ns=2**13, t0=t0, cases=50) assert (sum(t1 > t0) < 5)
#! Section 2.2.2 Transformed Gaussian models #!------------------------------------------- #! We begin with computing skewness and kurtosis #! for the data set xx and compare it with the second order wave approximation #! proposed by Winterstein: import wafo.stats as ws rho3 = ws.skew(xx[:, 1]) rho4 = ws.kurtosis(xx[:, 1]) sk, ku = S1.stats_nl(moments='sk') #! Comparisons of 3 transformations clf() import wafo.transform.models as wtm gh = wtm.TrHermite(mean=me, sigma=sa, skew=sk, kurt=ku).trdata() g = wtm.TrLinear(mean=me, sigma=sa).trdata() # Linear transformation glc, gemp = lc.trdata(mean=me, sigma=sa) glc.plot('b-') #! Transf. estimated from level-crossings gh.plot('b-.') #! Hermite Transf. estimated from moments g.plot('r') grid('on') show() #! Test Gaussianity of a stochastic process #!------------------------------------------ #! TESTGAUSSIAN simulates e(g(u)-u) = int (g(u)-u)^2 du for Gaussian processes #! given the spectral density, S. The result is plotted if test0 is given. #! This is useful for testing if the process X(t) is Gaussian. #! If 95% of TEST1 is less than TEST0 then X(t) is not Gaussian at a 5% level.