def test_rfcfilter(): # 1. Filtered signal y is the turning points of x. x = sea() y = rfcfilter(x[:, 1], h=0.0, method=1) assert_array_almost_equal( y[0:5], np.array([-1.2004945, 0.83950546, -0.09049454, -0.02049454, -0.09049454])) # 2. This removes all rainflow cycles with range less than 0.5. y1 = rfcfilter(x[:, 1], h=0.5, method=0) assert_array_almost_equal( y1[0:5], np.array([-1.2004945, 0.83950546, -0.43049454, 0.34950546, -0.51049454])) # return t = linspace(0, 7 * pi, 250) x = sin(t) + 0.1 * sin(50 * t) ind = findextrema(x) assert_array_almost_equal( ind, np.array( [1, 3, 4, 6, 7, 9, 11, 13, 14, 16, 18, 19, 21, 23, 25, 26, 28, 29, 31, 33, 35, 36, 38, 39, 41, 43, 45, 46, 48, 50, 51, 53, 55, 56, 58, 60, 61, 63, 65, 67, 68, 70, 71, 73, 75, 77, 78, 80, 81, 83, 85, 87, 88, 90, 92, 93, 95, 97, 99, 100, 102, 103, 105, 107, 109, 110, 112, 113, 115, 117, 119, 120, 122, 124, 125, 127, 129, 131, 132, 134, 135, 137, 139, 141, 142, 144, 145, 147, 149, 151, 152, 154, 156, 157, 159, 161, 162, 164, 166, 167, 169, 171, 173, 174, 176, 177, 179, 181, 183, 184, 186, 187, 189, 191, 193, 194, 196, 198, 199, 201, 203, 205, 206, 208, 209, 211, 213, 215, 216, 218, 219, 221, 223, 225, 226, 228, 230, 231, 233, 235, 237, 238, 240, 241, 243, 245, 247, 248])) _ti, tp = t[ind], x[ind] tp03 = rfcfilter(tp, 0.3) assert_array_almost_equal( tp03, np.array( [-0.00743352, 1.08753972, -1.07206545, 1.09550837, -1.07940458, 1.07849396, -1.0995006, 1.08094452, 0.11983423])) tp3 = findrfc_astm(tp) assert_array_almost_equal((77, 3), tp3.shape) # print(tp3[-5:]) assert_array_almost_equal(tp3[-5:], [[0.01552179, 0.42313414, 1.], [1.09750448, -0.00199612, 0.5], [1.09022256, -0.00927804, 0.5], [0.48055514, 0.60038938, 0.5], [0.03200274, 0.15183698, 0.5]]) assert_array_almost_equal(tp3[:5], [[0.03578165, 0.28906389, 1.], [0.03602834, 0.56726584, 1.], [0.03816623, 0.76461446, 1.], [0.0638364, 0.92381302, 1.], [0.07759006, 0.99628738, 1.]])
def test_rfcfilter(): # 1. Filtered signal y is the turning points of x. x = sea() y = rfcfilter(x[:, 1], h=0.0, method=1) assert_array_almost_equal( y[0:5], np.array( [-1.2004945, 0.83950546, -0.09049454, -0.02049454, -0.09049454])) # 2. This removes all rainflow cycles with range less than 0.5. y1 = rfcfilter(x[:, 1], h=0.5, method=0) assert_array_almost_equal( y1[0:5], np.array( [-1.2004945, 0.83950546, -0.43049454, 0.34950546, -0.51049454])) # return t = linspace(0, 7 * pi, 250) x = sin(t) + 0.1 * sin(50 * t) ind = findextrema(x) assert_array_almost_equal( ind, np.array([ 1, 3, 4, 6, 7, 9, 11, 13, 14, 16, 18, 19, 21, 23, 25, 26, 28, 29, 31, 33, 35, 36, 38, 39, 41, 43, 45, 46, 48, 50, 51, 53, 55, 56, 58, 60, 61, 63, 65, 67, 68, 70, 71, 73, 75, 77, 78, 80, 81, 83, 85, 87, 88, 90, 92, 93, 95, 97, 99, 100, 102, 103, 105, 107, 109, 110, 112, 113, 115, 117, 119, 120, 122, 124, 125, 127, 129, 131, 132, 134, 135, 137, 139, 141, 142, 144, 145, 147, 149, 151, 152, 154, 156, 157, 159, 161, 162, 164, 166, 167, 169, 171, 173, 174, 176, 177, 179, 181, 183, 184, 186, 187, 189, 191, 193, 194, 196, 198, 199, 201, 203, 205, 206, 208, 209, 211, 213, 215, 216, 218, 219, 221, 223, 225, 226, 228, 230, 231, 233, 235, 237, 238, 240, 241, 243, 245, 247, 248 ])) _ti, tp = t[ind], x[ind] tp03 = rfcfilter(tp, 0.3) assert_array_almost_equal( tp03, np.array([ -0.00743352, 1.08753972, -1.07206545, 1.09550837, -1.07940458, 1.07849396, -1.0995006, 1.08094452, 0.11983423 ])) tp3 = findrfc_astm(tp) assert_array_almost_equal((77, 3), tp3.shape) # print(tp3[-5:]) assert_array_almost_equal( tp3[-5:], [[0.01552179, 0.42313414, 1.], [1.09750448, -0.00199612, 0.5], [1.09022256, -0.00927804, 0.5], [0.48055514, 0.60038938, 0.5], [0.03200274, 0.15183698, 0.5]]) assert_array_almost_equal( tp3[:5], [[0.03578165, 0.28906389, 1.], [0.03602834, 0.56726584, 1.], [0.03816623, 0.76461446, 1.], [0.0638364, 0.92381302, 1.], [0.07759006, 0.99628738, 1.]])
def test_findoutliers(): xx = sea() dt = diff(xx[:2, 0]) dcrit = 5 * dt ddcrit = 9.81 / 2 * dt * dt zcrit = 0 [inds, indg] = findoutliers(xx[:, 1], zcrit, dcrit, ddcrit, verbose=False) assert_array_almost_equal(inds[np.r_[0, 1, 2, -3, -2, -1]], np.array([6, 7, 8, 9509, 9510, 9511])) assert_array_almost_equal(indg[np.r_[0, 1, 2, -3, -2, -1]], np.array([0, 1, 2, 9521, 9522, 9523]))
def test_findtc(): x = sea() x1 = x[0:200, :] itc, iv = findtc(x1[:, 1], 0, 'dw') assert_array_almost_equal( itc, np.array( [28, 31, 39, 56, 64, 69, 78, 82, 83, 89, 94, 101, 108, 119, 131, 140, 148, 159, 173, 184])) assert_array_almost_equal( iv, np.array( [19, 29, 34, 53, 60, 67, 76, 81, 82, 84, 90, 99, 103, 112, 127, 137, 143, 154, 166, 180, 185]))
def test_findtp(): x = sea() x1 = x[0:200, :] itp = findtp(x1[:, 1], 0, 'Mw') itph = findtp(x1[:, 1], 0.3, 'Mw') assert_array_almost_equal( itp, np.array( [11, 21, 22, 24, 26, 28, 31, 39, 43, 45, 47, 51, 56, 64, 70, 78, 82, 84, 89, 94, 101, 108, 119, 131, 141, 148, 149, 150, 159, 173, 184, 190, 199])) assert_array_almost_equal( itph, np.array( [11, 28, 31, 39, 47, 51, 56, 64, 70, 78, 89, 94, 101, 108, 119, 131, 141, 148, 159, 173, 184, 190, 199]))
def test_rfcfilter(): # 1. Filtered signal y is the turning points of x. x = sea() y = rfcfilter(x[:, 1], h=0, method=1) assert_array_almost_equal( y[0:5], np.array([-1.2004945, 0.83950546, -0.09049454, -0.02049454, -0.09049454])) # 2. This removes all rainflow cycles with range less than 0.5. y1 = rfcfilter(x[:, 1], h=0.5) assert_array_almost_equal( y1[0:5], np.array([-1.2004945, 0.83950546, -0.43049454, 0.34950546, -0.51049454])) t = linspace(0, 7 * pi, 250) x = sin(t) + 0.1 * sin(50 * t) ind = findextrema(x) assert_array_almost_equal( ind, np.array( [1, 3, 4, 6, 7, 9, 11, 13, 14, 16, 18, 19, 21, 23, 25, 26, 28, 29, 31, 33, 35, 36, 38, 39, 41, 43, 45, 46, 48, 50, 51, 53, 55, 56, 58, 60, 61, 63, 65, 67, 68, 70, 71, 73, 75, 77, 78, 80, 81, 83, 85, 87, 88, 90, 92, 93, 95, 97, 99, 100, 102, 103, 105, 107, 109, 110, 112, 113, 115, 117, 119, 120, 122, 124, 125, 127, 129, 131, 132, 134, 135, 137, 139, 141, 142, 144, 145, 147, 149, 151, 152, 154, 156, 157, 159, 161, 162, 164, 166, 167, 169, 171, 173, 174, 176, 177, 179, 181, 183, 184, 186, 187, 189, 191, 193, 194, 196, 198, 199, 201, 203, 205, 206, 208, 209, 211, 213, 215, 216, 218, 219, 221, 223, 225, 226, 228, 230, 231, 233, 235, 237, 238, 240, 241, 243, 245, 247, 248])) _ti, tp = t[ind], x[ind] tp03 = rfcfilter(tp, 0.3) assert_array_almost_equal( tp03, np.array( [-0.00743352, 1.08753972, -1.07206545, 1.09550837, -1.07940458, 1.07849396, -1.0995006, 1.08094452, 0.11983423]))
#! Created by GL July 13, 2000 #! 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()
#! Some of the commands are edited for fast computation. #! #! 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)
#! Some of the commands are edited for fast computation. #! #! 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)