def test_trochi(): std = 7. / 4 g = TrOchi(sigma=std, ysigma=std) assert_array_almost_equal(g.dist2gauss(), 1.4106988010566603) assert_array_almost_equal(g.mean, 0.0) assert_array_almost_equal(g.sigma, 1.75) vals = g.dat2gauss([0, 1, 2, 3]) true_vals = np.array( [6.21927960e-04, 9.90237621e-01, 1.96075606e+00, 2.91254576e+00]) assert_array_almost_equal(vals, true_vals)
def test_trochi(): std = 7. / 4 g = TrOchi(sigma=std, ysigma=std) assert_array_almost_equal(g.dist2gauss(), 1.4106988010566603) assert_array_almost_equal(g.mean, 0.0) assert_array_almost_equal(g.sigma, 1.75) vals = g.dat2gauss([0, 1, 2, 3]) true_vals = np.array([6.21927960e-04, 9.90237621e-01, 1.96075606e+00, 2.91254576e+00]) assert_array_almost_equal(vals, true_vals)
def test_trochi(): std = 7./4 g = TrOchi(sigma=std, ysigma=std) assert(g.dist2gauss()== 1.4106988010566603) assert(g.mean== 0.0) assert(g.sigma==1.75) vals = g.dat2gauss([0,1,2,3]) true_vals = np.array([ 6.21927960e-04, 9.90237621e-01, 1.96075606e+00, 2.91254576e+00]) assert((np.abs(vals-true_vals)<1e-7).all())
def test_trochi(): std = 7. / 4 g = TrOchi(sigma=std, ysigma=std) assert (g.dist2gauss() == 1.4106988010566603) assert (g.mean == 0.0) assert (g.sigma == 1.75) vals = g.dat2gauss([0, 1, 2, 3]) true_vals = np.array( [6.21927960e-04, 9.90237621e-01, 1.96075606e+00, 2.91254576e+00]) assert ((np.abs(vals - true_vals) < 1e-7).all())
def trdata(self, timeseries): ''' Returns ------- tr, tr_emp : TrData objects with the smoothed and empirical transformation, respectively. TRDATA estimates the transformation in a transformed Gaussian model. Assumption: a Gaussian process, Y, is related to the non-Gaussian process, X, by Y = g(X). The empirical crossing intensity is usually very irregular. More than one local maximum of the empirical crossing intensity may cause poor fit of the transformation. In such case one should use a smaller value of CSM. In order to check the effect of smoothing it is recomended to also plot g and g2 in the same plot or plot the smoothed g against an interpolated version of g (when CSM=GSM=1). Example ------- >>> import wafo.spectrum.models as sm >>> import wafo.transform.models as tm >>> from wafo.objects import mat2timeseries >>> 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**16, iseed=10) >>> ts = mat2timeseries(xs) >>> g0, g0emp = ts.trdata(monitor=True) >>> g1, g1emp = ts.trdata(method='m', gvar=0.5 ) >>> g2, g2emp = ts.trdata(method='n', gvar=[3.5, 0.5, 3.5]) >>> int(S.tr.dist2gauss()*100) 141 >>> int(g0emp.dist2gauss()*100) 217949 >>> int(g0.dist2gauss()*100) 93 >>> int(g1.dist2gauss()*100) 66 >>> int(g2.dist2gauss()*100) 84 See also -------- LevelCrossings.trdata wafo.transform.models References ---------- Rychlik, I. , Johannesson, P and Leadbetter, M. R. (1997) "Modelling and statistical analysis of ocean wavedata using transformed Gaussian process." Marine structures, Design, Construction and Safety, Vol. 10, No. 1, pp 13--47 Brodtkorb, P, Myrhaug, D, and Rue, H (1999) "Joint distribution of wave height and crest velocity from reconstructed data" in Proceedings of 9th ISOPE Conference, Vol III, pp 66-73 ''' data = np.atleast_1d(timeseries.data) ma = data.mean() sa = data.std() method = self.method[0] if method == 'l': return TrLinear(mean=ma, sigma=sa), TrLinear(mean=ma, sigma=sa) if method == 'n': tp = timeseries.turning_points() mM = tp.cycle_pairs() lc = mM.level_crossings(self.crossdef) return self._trdata_lc(lc) elif method == 'm': return self._trdata_cdf(data) elif method == 'h': ga1 = skew(data) ga2 = kurtosis(data, fisher=True) # kurt(xx(n+1:end))-3; up = min(4 * (4 * ga1 / 3)**2, 13) lo = (ga1**2) * 3 / 2 kurt1 = min(up, max(ga2, lo)) + 3 return TrHermite(mean=ma, var=sa**2, skew=ga1, kurt=kurt1) elif method[0] == 'o': ga1 = skew(data) return TrOchi(mean=ma, var=sa**2, skew=ga1)