Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
    def test_levelcrossings_extrapolate(self):
        x = wafo.data.sea()
        ts = wo.mat2timeseries(x)

        tp = ts.turning_points()
        mm = tp.cycle_pairs()
        lc = mm.level_crossings()

        s = x[:, 1].std()
        lc_gpd = lc.extrapolate(-2 * s, 2 * s, dist='rayleigh')
        assert_array_almost_equal(lc_gpd.data[:10], [
            1.789254e-37, 2.610988e-37, 3.807130e-37, 5.546901e-37,
            8.075384e-37, 1.174724e-36, 1.707531e-36, 2.480054e-36,
            3.599263e-36, 5.219466e-36
        ])
Exemplo n.º 4
0
    def test_levelcrossings_extrapolate(self):
        x = wafo.data.sea()
        ts = wo.mat2timeseries(x)

        tp = ts.turning_points()
        mm = tp.cycle_pairs()
        lc = mm.level_crossings()

        s = x[:, 1].std()
        lc_gpd = lc.extrapolate(-2 * s, 2 * s, dist='rayleigh')
        assert_array_almost_equal(lc_gpd.data[:10],
                                  [1.789254e-37,   2.610988e-37,
                                   3.807130e-37,   5.546901e-37,
                                   8.075384e-37,   1.174724e-36,
                                   1.707531e-36,   2.480054e-36,
                                   3.599263e-36,   5.219466e-36])
Exemplo n.º 5
0
    def test_timeseries(self):

        x = wafo.data.sea()
        ts = wo.mat2timeseries(x)
        assert_array_almost_equal(ts.sampling_period(), 0.25)

        S = ts.tospecdata()
        assert_array_almost_equal(S.data[:10], [
            0.00913087, 0.00881073, 0.00791944, 0.00664244, 0.00522429,
            0.00389816, 0.00282753, 0.00207843, 0.00162678, 0.0013916
        ])

        rf = ts.tocovdata(lag=150)
        assert_array_almost_equal(rf.data[:10], [
            0.22368637, 0.20838473, 0.17110733, 0.12237803, 0.07024054,
            0.02064859, -0.02218831, -0.0555993, -0.07859847, -0.09166187
        ])
Exemplo n.º 6
0
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, test0=t0, cases=50)
    assert(sum(t1 > t0) < 5)
Exemplo n.º 7
0
    def test_timeseries_trdata(self):
        Hs = 7.0
        Sj = sm.Jonswap(Hm0=Hs)
        S = Sj.tospecdata()  # Make spectrum object from numerical values
        S.tr = tm.TrOchi(mean=0, skew=0.16, kurt=0, sigma=Hs/4, ysigma=Hs/4)
        xs = S.sim(ns=2**20, iseed=10)
        ts = wo.mat2timeseries(xs)
        g0, _gemp = ts.trdata(monitor=False)  # Not Monitor the development

        # Equal weight on all points
        g1, _gemp = ts.trdata(method='mnonlinear', gvar=0.5)

        # Less weight on the ends
        g2, _gemp = ts.trdata(method='nonlinear', gvar=[3.5, 0.5, 3.5])
        self.assert_(1.2 < S.tr.dist2gauss() < 1.6)
        self.assert_(1.65 < g0.dist2gauss() < 2.05)
        self.assert_(0.54 < g1.dist2gauss() < 0.95)
        self.assert_(1.5 < g2.dist2gauss() < 1.9)
Exemplo n.º 8
0
    def test_timeseries_trdata(self):
        Hs = 7.0
        Sj = sm.Jonswap(Hm0=Hs)
        S = Sj.tospecdata()  # Make spectrum object from numerical values
        S.tr = tm.TrOchi(mean=0, skew=0.16, kurt=0, sigma=Hs/4, ysigma=Hs/4)
        xs = S.sim(ns=2**20, iseed=10)
        ts = wo.mat2timeseries(xs)
        g0, _gemp = ts.trdata(monitor=False)  # Not Monitor the development

        # Equal weight on all points
        g1, _gemp = ts.trdata(method='mnonlinear', gvar=0.5)

        # Less weight on the ends
        g2, _gemp = ts.trdata(method='nonlinear', gvar=[3.5, 0.5, 3.5])
        self.assert_(1.2 < S.tr.dist2gauss() < 1.6)
        self.assert_(1.65 < g0.dist2gauss() < 2.05)
        self.assert_(0.54 < g1.dist2gauss() < 0.95)
        self.assert_(1.5 < g2.dist2gauss() < 1.9)
Exemplo n.º 9
0
    def test_timeseries(self):

        x = wafo.data.sea()
        ts = wo.mat2timeseries(x)
        assert_array_almost_equal(ts.sampling_period(), 0.25)

        S = ts.tospecdata()
        assert_array_almost_equal(S.data[:10],
                                  [0.00913087,  0.00881073,  0.00791944,
                                   0.00664244,  0.00522429, 0.00389816,
                                   0.00282753,  0.00207843,  0.00162678,
                                   0.0013916])

        rf = ts.tocovdata(lag=150)
        assert_array_almost_equal(rf.data[:10],
                                  [0.22368637,  0.20838473,  0.17110733,
                                   0.12237803,  0.07024054, 0.02064859,
                                   -0.02218831, -0.0555993, -0.07859847,
                                   -0.09166187])
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
    def test_cycles_and_levelcrossings(self):

        x = wafo.data.sea()
        ts = wo.mat2timeseries(x)

        tp = ts.turning_points()
        assert_array_almost_equal(tp.data[:10], [
            -1.200495, 0.839505, -0.090495, -0.020495, -0.090495, -0.040495,
            -0.160495, 0.259505, -0.430495, -0.080495
        ])

        mm = tp.cycle_pairs()
        assert_array_almost_equal(mm.data[:10], [
            0.839505, -0.020495, -0.040495, 0.259505, -0.080495, -0.080495,
            0.349505, 0.859505, 0.009505, 0.319505
        ])

        lc = mm.level_crossings()

        assert_array_almost_equal(lc.data[:10],
                                  [0., 1., 2., 2., 3., 4., 5., 6., 7., 9.])
Exemplo n.º 12
0
def statisticalana(t, series, h=0, mod='cw'):
    '''
    Return: significant values of crests, troughs, and double peaks,
            as well as mean level crossing period
    Parameters:
    -----------
    t: time, 1-d array
    series: data, 1-d array
    h: level, scalar
    mod: string, defines type of wave or crossing returned. Possible options are
        'dw' : downcrossing wave
        'uw' : upcrossing wave
        'cw' : crest wave
        'tw' : trough wave
        None : All crossings will be returned
    '''
    from wafo.objects import mat2timeseries
    from wafo.misc import findtc

    t = np.asarray(t, dtype='float')
    series = np.asarray(series, dtype='float')

    ts = mat2timeseries(np.stack((t, series), axis=-1))
    crestTroughID, crossID = findtc(ts.data, h, mod)

    ctp = series[crestTroughID] - h  # crest and trough point
    crests = ctp[ctp > 0]
    troughs = ctp[ctp <= 0]
    if series[crestTroughID[0]] < h:
        troughs = troughs[1:]
    n = min(crests.shape[0], troughs.shape[0])
    vpps = crests[:n] - troughs[:n]

    # mean level crossing period
    tLevelCrossing = t[crossID[::2]]

    # significant values (1/3 exceeding probability)
    ns = n // 3
    return np.mean(-np.sort(-crests)[:ns]) + h, np.mean(np.sort(troughs)[:ns]) + h,\
        np.mean(-np.sort(-vpps)[:ns]), np.mean(np.diff(tLevelCrossing))
Exemplo n.º 13
0
    def test_cycles_and_levelcrossings(self):

        x = wafo.data.sea()
        ts = wo.mat2timeseries(x)

        tp = ts.turning_points()
        assert_array_almost_equal(tp.data[:10],
                                  [-1.200495,  0.839505, -0.090495, -0.020495,
                                   -0.090495, -0.040495, -0.160495,  0.259505,
                                   -0.430495, -0.080495]
                                  )

        mm = tp.cycle_pairs()
        assert_array_almost_equal(mm.data[:10],
                                  [0.839505, -0.020495, -0.040495,  0.259505,
                                   -0.080495, -0.080495, 0.349505,  0.859505,
                                   0.009505,  0.319505])

        lc = mm.level_crossings()

        assert_array_almost_equal(lc.data[:10],
                                  [0.,  1.,  2.,  2.,  3.,  4.,
                                   5.,  6.,  7.,  9.])
Exemplo n.º 14
0
#!

#! Chapter 4 Fatigue load analysis and rain-flow cycles
#!------------------------------------------------------

printing = 0

#! Section 4.3.1 Crossing intensity
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import numpy as np
from wafo.plotbackend import plotbackend as plt
import wafo.data as wd
import wafo.objects as wo

xx_sea = wd.sea()
ts = wo.mat2timeseries(xx_sea)
tp = ts.turning_points()
mM = tp.cycle_pairs(kind='min2max')
lc = mM.level_crossings(intensity=True)
T_sea = ts.args[-1] - ts.args[0]

plt.subplot(1, 2, 1)
lc.plot()
plt.subplot(1, 2, 2)
lc.setplotter(plotmethod='step')
lc.plot()
plt.show()

m_sea = ts.data.mean()
f0_sea = np.interp(m_sea, lc.args, lc.data)
extr_sea = len(tp.data) / (2 * T_sea)
Exemplo n.º 15
0
#! from commands used in Chapter 4
#!

#! Chapter 4 Fatigue load analysis and rain-flow cycles
#!------------------------------------------------------

printing = 0


#! Section 4.3.1 Crossing intensity
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import wafo.data as wd
import wafo.objects as wo

xx_sea = wd.sea()
ts = wo.mat2timeseries(xx_sea)
tp = ts.turning_points()
mM = tp.cycle_pairs(kind="min2max")
lc = mM.level_crossings(intensity=True)
T_sea = ts.args[-1] - ts.args[0]

subplot(1, 2, 1)
lc.plot()
subplot(1, 2, 2)
lc.setplotter(plotmethod="step")
lc.plot()
show()


m_sea = ts.data.mean()
f0_sea = interp(m_sea, lc.args, lc.data)
Exemplo n.º 16
0
Tlength = xx_sea[-1, 0] - xx_sea[0, 0]
beta = 3
K1 = 6.5e-31
Np = 200
Tp = Tlength / Np
A = 100e6
log.info("setting sin wave with Tp={} and T={}".format(Tp, Tlength))
Nc = 1.0 / damage_vs_S(A, beta, K1)
damage = float(Np) / float(Nc)
log.info("budget at S={} N={}: damage = {} ".format(A, Nc, damage))
#xx_sea[:, 1] = A * np.cos(2 * np.pi * xx_sea[:, 0]/Tp)
xx_sea[:, 1] *= 500e6

log.info("loaded sea time series {}".format(xx_sea.shape))
ts = wo.mat2timeseries(xx_sea)

tp = ts.turning_points()
mM = tp.cycle_pairs(kind='min2max')
Mm = tp.cycle_pairs(kind='max2min')
lc = mM.level_crossings(intensity=True)
T_sea = ts.args[-1] - ts.args[0]

# for i in dir(mM):
#    print(i)

ts1 = wo.mat2timeseries(xx_sea[:, :])
tp1 = ts1.turning_points()
sig_tp = ts.turning_points(h=0, wavetype='astm')
try:
    sig_cp = sig_tp.cycle_astm()
Exemplo n.º 17
0
 def setUp(self):
     x = wafo.data.sea()
     self.ts = wo.mat2timeseries(x)
Exemplo n.º 18
0
#! Section 3.2 Estimation of wave characteristics from data
#!----------------------------------------------------------
#! Example 1
#!~~~~~~~~~~

speed = 'fast'
#speed = 'slow'
import scipy.signal as ss
import wafo.data as wd
import wafo.misc as wm
import wafo.objects as wo
import wafo.stats as ws
import wafo.spectrum.models as wsm
xx = wd.sea()
xx[:, 1] = ss.detrend(xx[:, 1])
ts = wo.mat2timeseries(xx)
Tcrcr, ix = ts.wave_periods(vh=0, pdef='c2c', wdef='tw', rate=8)
Tc, ixc = ts.wave_periods(vh=0, pdef='u2d', wdef='tw', rate=8)

#! Histogram of crestperiod compared to the kernel density estimate
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import wafo.kdetools as wk
plt.clf()
print(Tc.mean())
print(Tc.max())

t = np.linspace(0.01,8,200);
ftc = wk.TKDE(Tc, L2=0, inc=128)

plt.plot(t,ftc.eval_grid(t), t, ftc.eval_grid_fast(t),'-.')
wm.plot_histgrm(Tc, normed=True)
Exemplo n.º 19
0
#!
#! Some of the commands are edited for fast computation.
#!
#! Section 2.1 Introduction and preliminary analysis
#!====================================================
#! Example 1: Sea data
#!----------------------
#! Observed crossings compared to the expected for Gaussian signals

import wafo
import wafo.objects as wo
xx = wafo.data.sea()
me = xx[:, 1].mean()
sa = xx[:, 1].std()
xx[:, 1] -= me
ts = wo.mat2timeseries(xx)
tp = ts.turning_points()

cc = tp.cycle_pairs()
lc = cc.level_crossings()
lc.plot()
show()

#! Average number of upcrossings per time unit
#!----------------------------------------------
#! Next we compute the mean frequency as the average number of upcrossings
#! per time unit of the mean level (= 0); this may require interpolation in the
#! crossing intensity curve, as follows.
T = xx[:, 0].max() - xx[:, 0].min()
f0 = np.interp(0, lc.args, lc.data, 0) / T  #! zero up-crossing frequency
print(('f0 = %g' % f0))
Exemplo n.º 20
0
 def df2ts(series):
     return wo.mat2timeseries(
         pd.concat(
             [(series.index.to_series() - series.index.values[0]).dt.total_seconds(),
              series
              ], axis=1).values)
Exemplo n.º 21
0
#! Section 1.4.1 Simulation from spectrum, estimation of spectrum 
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#! Simulation of the sea surface from spectrum
#! The following code generates 200 seconds of data sampled with 10Hz from
#! the Torsethaugen spectrum
import wafo.spectrum.models as wsm
S = wsm.Torsethaugen(Hm0=6, Tp=8);
S1 = S.tospecdata()
S1.plot()
show()


##
import wafo.objects as wo
xs = S1.sim(ns=2000, dt=0.1)
ts = wo.mat2timeseries(xs)
ts.plot_wave('-')
show()


#! Estimation of spectrum 
#!~~~~~~~~~~~~~~~~~~~~~~~
#! A common situation is that one wants to estimate the spectrum for wave
#! measurements. The following code simulate 20 minutes signal sampled at 4Hz
#! and compare the spectral estimate with the original Torsethaugen spectum.
clf()
Fs = 4;  
xs = S1.sim(ns=fix(20 * 60 * Fs), dt=1. / Fs) 
ts = wo.mat2timeseries(xs) 
Sest = ts.tospecdata(L=400)
S1.plot()
Exemplo n.º 22
0
#! Section 3.2 Estimation of wave characteristics from data
#!----------------------------------------------------------
#! Example 1
#!~~~~~~~~~~

speed = 'fast'
#speed = 'slow'
import scipy.signal as ss
import wafo.data as wd
import wafo.misc as wm
import wafo.objects as wo
import wafo.stats as ws
import wafo.spectrum.models as wsm
xx = wd.sea()
xx[:, 1] = ss.detrend(xx[:, 1])
ts = wo.mat2timeseries(xx)
Tcrcr, ix = ts.wave_periods(vh=0, pdef='c2c', wdef='tw', rate=8)
Tc, ixc = ts.wave_periods(vh=0, pdef='u2d', wdef='tw', rate=8)

#! Histogram of crestperiod compared to the kernel density estimate
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import wafo.kdetools as wk
plt.clf()
print(Tc.mean())
print(Tc.max())

t = np.linspace(0.01, 8, 200)
ftc = wk.TKDE(Tc, L2=0, inc=128)

plt.plot(t, ftc.eval_grid(t), t, ftc.eval_grid_fast(t), '-.')
wm.plot_histgrm(Tc, normed=True)
Exemplo n.º 23
0
#!
#! Some of the commands are edited for fast computation. 
#! 
#! Section 2.1 Introduction and preliminary analysis
#!====================================================
#! Example 1: Sea data
#!----------------------
#! Observed crossings compared to the expected for Gaussian signals

import wafo
import wafo.objects as wo
xx = wafo.data.sea()
me = xx[:, 1].mean()
sa = xx[:, 1].std()
xx[:, 1] -= me
ts = wo.mat2timeseries(xx)
tp = ts.turning_points()

cc = tp.cycle_pairs()
lc = cc.level_crossings()
lc.plot()
show()

#! Average number of upcrossings per time unit
#!----------------------------------------------
#! Next we compute the mean frequency as the average number of upcrossings 
#! per time unit of the mean level (= 0); this may require interpolation in the 
#! crossing intensity curve, as follows.  
T = xx[:, 0].max() - xx[:, 0].min()
f0 = np.interp(0, lc.args, lc.data, 0) / T  #! zero up-crossing frequency 
print('f0 = %g' % f0)
Exemplo n.º 24
0
 
# Chapter 4 Fatigue load analysis and rain-flow cycles
#------------------------------------------------------
"""

printing=0


# Section 4.3.1 Crossing intensity
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import wafo.data as wd
import wafo.objects as wo

xx_sea = wd.sea()
log.info("loaded sea time series {}".format(xx_sea.shape))
ts = wo.mat2timeseries(xx_sea)
tp = ts.turning_points()
mM = tp.cycle_pairs(kind='min2max')
lc = mM.level_crossings(intensity=True)
T_sea = ts.args[-1]-ts.args[0]

ts1 = wo.mat2timeseries(xx_sea[:1000,:])
tp1 = ts1.turning_points()
tp2 = ts1.turning_points(wavetype='Mw')
tc1 = ts1.trough_crest()
ts1.plot('b-')
tp1.plot('ro')
tp2.plot('yv')
tc1.plot('gx')
set_windows_title("Sea time series", log)
Exemplo n.º 25
0
 def setUp(self):
     x = wafo.data.sea()
     self.ts = wo.mat2timeseries(x)
Exemplo n.º 26
0
#! Section 1.4.1 Simulation from spectrum, estimation of spectrum
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#! Simulation of the sea surface from spectrum
#! The following code generates 200 seconds of data sampled with 10Hz from
#! the Torsethaugen spectrum
import wafo.spectrum.models as wsm
S = wsm.Torsethaugen(Hm0=6, Tp=8)
S1 = S.tospecdata()
S1.plot()
plt.show()


##
import wafo.objects as wo
xs = S1.sim(ns=2000, dt=0.1)
ts = wo.mat2timeseries(xs)
ts.plot_wave('-')
plt.show()


#! Estimation of spectrum
#!~~~~~~~~~~~~~~~~~~~~~~~
#! A common situation is that one wants to estimate the spectrum for wave
#! measurements. The following code simulate 20 minutes signal sampled at 4Hz
#! and compare the spectral estimate with the original Torsethaugen spectum.
plt.clf()
Fs = 4
xs = S1.sim(ns=np.fix(20 * 60 * Fs), dt=1. / Fs)
ts = wo.mat2timeseries(xs)
Sest = ts.tospecdata(L=400)
S1.plot()