From 139cc277307790208e2d27751c3af68ccb34b1d0 Mon Sep 17 00:00:00 2001 From: pbrod Date: Sun, 29 Nov 2015 19:50:36 +0100 Subject: [PATCH] Fixed failing tests. --- wafo/spectrum/core.py | 22 +++++++++++----------- wafo/spectrum/test/test_specdata1d.py | 19 ++++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/wafo/spectrum/core.py b/wafo/spectrum/core.py index 04bf8c0..051bae5 100644 --- a/wafo/spectrum/core.py +++ b/wafo/spectrum/core.py @@ -2040,7 +2040,7 @@ class SpecData1D(PlotData): # end %ENDIF # waitTxt = sprintf('%s Ready: %d of %d',datestr(now),Ntd,Ntime) # fwaitbar(Ntd/Ntime,h11,waitTxt) - + # end %do # close(h11) err = sqrt(err) @@ -2102,7 +2102,7 @@ class SpecData1D(PlotData): else: # 5, gives level u separated Max2min and wave period from # the crossing of level u to the min (M,m,Tdm). - + IJ = 0 for i in range(1, Nx1): # = 2:Nx1 J = IJ + Nx1 @@ -2282,9 +2282,9 @@ class SpecData1D(PlotData): # Cov(Xd,Xc) BIG[tn - 1, N] = R2[ts] # %cov(X''(t1),X(ts)) BIG[tn, N] = R2[tn - ts] # %cov(X''(tn),X(ts)) - + # ADD a level u crossing at ts - + # Cov(Xt,Xd) # for i = np.arange(tn - 2) # 1:tn-2 @@ -2326,17 +2326,17 @@ class SpecData1D(PlotData): # N = tn+4 shft = 0 # end %if - + if (tn > 2): # for i=1:tn-2 # cov(Xt) # for j=i:tn-2 # BIG(i,j) = -R2(j-i+1) % cov(X'(ti+1),X'(tj+1)) # end %do - + # % cov(Xt) = % cov(X'(ti+1),X'(tj+1)) BIG[:tn - 2, :tn - 2] = toeplitz(-R2[:tn - 2]) - + # cov(Xt,Xc) BIG[:tn - 2, tn + shft] = -R2[1:tn - 1] # cov(X'(ti+1),X'(t1)) # cov(X'(ti+1),X'(tn)) @@ -2344,7 +2344,7 @@ class SpecData1D(PlotData): BIG[:tn - 2, tn + shft + 2] = R1[1:tn - 1] # cov(X'(ti+1),X(t1)) # cov(X'(ti+1),X(tn)) BIG[:tn - 2, tn + shft + 3] = -R1[tn - 2:0:-1] - + # Cov(Xt,Xd) BIG[:tn - 2, tn - 2] = R3[1:tn - 1] # cov(X'(ti+1),X''(t1)) BIG[:tn - 2, tn - 1] = -R3[tn - 2:0:-1] # cov(X'(ti+1),X''(tn)) @@ -2354,7 +2354,7 @@ class SpecData1D(PlotData): BIG[tn - 2, tn - 2] = R4[0] BIG[tn - 2, tn - 1] = R4[tn - 1] # cov(X''(t1),X''(tn)) BIG[tn - 1, tn - 1] = R4[0] - + # cov(Xc) BIG[tn + shft + 2, tn + shft + 2] = R0[0] # cov(X(t1),X(t1)) # cov(X(t1),X(tn)) @@ -2929,8 +2929,8 @@ class SpecData1D(PlotData): # 1'st order + 2'nd order component. x2[:, 1::] = x[:, 1::] + x2o[0:ns, :].real if output == 'timeseries': - xx2 = mat2timeseries(x2[:, 1::], x2[:, 0].ravel()) - xx = mat2timeseries(x[:, 1::], x[:, 0].ravel()) + xx2 = mat2timeseries(x2) + xx = mat2timeseries(x) return xx2, xx return x2, x diff --git a/wafo/spectrum/test/test_specdata1d.py b/wafo/spectrum/test/test_specdata1d.py index 46b043f..8d36675 100644 --- a/wafo/spectrum/test/test_specdata1d.py +++ b/wafo/spectrum/test/test_specdata1d.py @@ -3,6 +3,7 @@ import wafo.transform.models as wtm import wafo.objects as wo from wafo.spectrum import SpecData1D import numpy as np +from numpy.testing import assert_array_almost_equal import unittest @@ -93,10 +94,10 @@ def test_sim_nl(): funs = [np.mean, np.std, st.skew, st.kurtosis] for fun, trueval in zip(funs, truth1): - res = fun(x2[:, 1::], axis=0) + res = fun(x2.data, axis=0) m = res.mean() sa = res.std() - #trueval, m, sa + # trueval, m, sa assert(np.abs(m - trueval) < 2 * sa) @@ -107,9 +108,9 @@ def test_stats_nl(): S = Sj.tospecdata() me, va, sk, ku = S.stats_nl(moments='mvsk') assert(me == 0.0) - assert(va == 3.0608203389019537) - assert(sk == 0.18673120577479801) - assert(ku == 3.0619885212624176) + assert_array_almost_equal(va, 3.0608203389019537) + assert_array_almost_equal(sk, 0.18673120577479801) + assert_array_almost_equal(ku, 3.0619885212624176) def test_testgaussian(): @@ -127,7 +128,7 @@ def test_testgaussian(): 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) + t1 = S0.testgaussian(ns=2 ** 13, test0=t0, cases=50) assert(sum(t1 > t0) < 5) @@ -138,9 +139,9 @@ def test_moment(): true_vals = [1.5614600345079888, 0.95567089481941048] true_txt = ['m0', 'm0tt'] for tv, v in zip(true_vals, vals): - assert(tv == v) + assert_array_almost_equal(tv, v) for tv, v in zip(true_txt, txt): - assert(tv == v) + assert(tv==v) def test_nyquist_freq(): @@ -163,7 +164,7 @@ def test_normalize(): vals, _txt = S.moment(2) true_vals = [1.5614600345079888, 0.95567089481941048] for tv, v in zip(true_vals, vals): - assert(tv == v) + assert_array_almost_equal(tv, v) Sn = S.copy() Sn.normalize()