|
|
@ -13,10 +13,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import division
|
|
|
|
|
|
|
|
from wafo.transform.core import TrData
|
|
|
|
|
|
|
|
from scipy.interpolate.interpolate import interp1d
|
|
|
|
|
|
|
|
from scipy.integrate.quadrature import cumtrapz
|
|
|
|
|
|
|
|
from wafo.interpolate import SmoothSpline
|
|
|
|
import warnings
|
|
|
|
import warnings
|
|
|
|
import numpy as np
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
from numpy import (inf, pi, zeros, ones, sqrt, where, log, exp, sin, arcsin, mod, #@UnresolvedImport
|
|
|
|
from numpy import (inf, pi, zeros, ones, sqrt, where, log, exp, sin, arcsin, mod, finfo, interp, #@UnresolvedImport
|
|
|
|
newaxis, linspace, arange, sort, all, abs, linspace, vstack, hstack, atleast_1d, #@UnresolvedImport
|
|
|
|
newaxis, linspace, arange, sort, all, abs, linspace, vstack, hstack, atleast_1d, #@UnresolvedImport
|
|
|
|
polyfit, r_, nonzero, cumsum, ravel, size, isnan, nan, floor, ceil, diff, array) #@UnresolvedImport
|
|
|
|
polyfit, r_, nonzero, cumsum, ravel, size, isnan, nan, floor, ceil, diff, array) #@UnresolvedImport
|
|
|
|
from numpy.fft import fft
|
|
|
|
from numpy.fft import fft
|
|
|
@ -26,10 +30,11 @@ from pylab import stineman_interp
|
|
|
|
from matplotlib.mlab import psd
|
|
|
|
from matplotlib.mlab import psd
|
|
|
|
import scipy.signal
|
|
|
|
import scipy.signal
|
|
|
|
|
|
|
|
|
|
|
|
from scipy.special import erf
|
|
|
|
|
|
|
|
|
|
|
|
from scipy.special import erf, ndtri
|
|
|
|
|
|
|
|
|
|
|
|
from wafo.misc import (nextpow2, findtp, findtc, findcross, sub_dict_select,
|
|
|
|
from wafo.misc import (nextpow2, findtp, findtc, findcross, sub_dict_select,
|
|
|
|
ecross, JITImport)
|
|
|
|
ecross, JITImport, DotDict)
|
|
|
|
from wafodata import WafoData
|
|
|
|
from wafodata import WafoData
|
|
|
|
from plotbackend import plotbackend
|
|
|
|
from plotbackend import plotbackend
|
|
|
|
import matplotlib
|
|
|
|
import matplotlib
|
|
|
@ -177,18 +182,23 @@ class LevelCrossings(WafoData):
|
|
|
|
|
|
|
|
|
|
|
|
Z = ((u >= 0) * 2 - 1) * sqrt(-2 * log(G))
|
|
|
|
Z = ((u >= 0) * 2 - 1) * sqrt(-2 * log(G))
|
|
|
|
|
|
|
|
|
|
|
|
## sumcr = trapz(lc(:,1),lc(:,2))
|
|
|
|
sumcr = trapz(self.data, self.args)
|
|
|
|
## lc(:,2) = lc(:,2)/sumcr
|
|
|
|
lc = self.data / sumcr
|
|
|
|
## mcr = trapz(lc(:,1),lc(:,1).*lc(:,2))
|
|
|
|
lc1 = self.args
|
|
|
|
## scr = trapz(lc(:,1),lc(:,1).^2.*lc(:,2))
|
|
|
|
mcr = trapz(lc1 * lc, lc1)
|
|
|
|
## scr = sqrt(scr-mcr^2)
|
|
|
|
scr = trapz(lc1 ** 2 * lc, lc1)
|
|
|
|
## g = lc2tr(lc,mcr,scr)
|
|
|
|
scr = sqrt(scr - mcr ** 2)
|
|
|
|
##
|
|
|
|
|
|
|
|
## f = [u u]
|
|
|
|
lc2 = LevelCrossings(lc, lc1, mean=mcr, stdev=scr)
|
|
|
|
## f(:,2) = tranproc(Z,fliplr(g))
|
|
|
|
|
|
|
|
##
|
|
|
|
g = lc2.trdata()
|
|
|
|
## process = tranproc(L,f)
|
|
|
|
|
|
|
|
## process = [(1:length(process)) process]
|
|
|
|
f = [u, u]
|
|
|
|
|
|
|
|
f = g.dat2gauss(Z)
|
|
|
|
|
|
|
|
G = TrData(f, u)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process = G.dat2gauss(L)
|
|
|
|
|
|
|
|
return np.vstack((arange(len(process)), process)).T
|
|
|
|
##
|
|
|
|
##
|
|
|
|
##
|
|
|
|
##
|
|
|
|
## %Check the result without reference to getrfc:
|
|
|
|
## %Check the result without reference to getrfc:
|
|
|
@ -224,36 +234,40 @@ class LevelCrossings(WafoData):
|
|
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
----------
|
|
|
|
options = structure with the fields:
|
|
|
|
mean, sigma : real scalars
|
|
|
|
csm, gsm - defines the smoothing of the crossing intensity and the
|
|
|
|
mean and standard deviation of the process
|
|
|
|
transformation g. Valid values must be
|
|
|
|
**options :
|
|
|
|
0<=csm,gsm<=1. (default csm = 0.9 gsm=0.05)
|
|
|
|
csm, gsm : real scalars
|
|
|
|
|
|
|
|
defines the smoothing of the crossing intensity and the transformation g.
|
|
|
|
|
|
|
|
Valid values must be 0<=csm,gsm<=1. (default csm = 0.9 gsm=0.05)
|
|
|
|
Smaller values gives smoother functions.
|
|
|
|
Smaller values gives smoother functions.
|
|
|
|
param - vector which defines the region of variation of the data X.
|
|
|
|
param :
|
|
|
|
|
|
|
|
vector which defines the region of variation of the data X.
|
|
|
|
(default [-5 5 513]).
|
|
|
|
(default [-5 5 513]).
|
|
|
|
|
|
|
|
monitor : bool
|
|
|
|
|
|
|
|
if true monitor development of estimation
|
|
|
|
|
|
|
|
linextrap : bool
|
|
|
|
|
|
|
|
if true use a smoothing spline with a constraint on the ends to
|
|
|
|
|
|
|
|
ensure linear extrapolation outside the range of the data. (default)
|
|
|
|
|
|
|
|
otherwise use a regular smoothing spline
|
|
|
|
|
|
|
|
cvar, gvar : real scalars
|
|
|
|
|
|
|
|
Variances for the crossing intensity and the empirical transformation, g. (default 1)
|
|
|
|
|
|
|
|
ne : scalar integer
|
|
|
|
|
|
|
|
Number of extremes (maxima & minima) to remove from the estimation
|
|
|
|
|
|
|
|
of the transformation. This makes the estimation more robust against
|
|
|
|
|
|
|
|
outliers. (default 7)
|
|
|
|
|
|
|
|
ntr : scalar integer
|
|
|
|
|
|
|
|
Maximum length of empirical crossing intensity. The empirical
|
|
|
|
|
|
|
|
crossing intensity is interpolated linearly before smoothing if the
|
|
|
|
|
|
|
|
length exceeds ntr. A reasonable NTR will significantly speed up the
|
|
|
|
|
|
|
|
estimation for long time series without loosing any accuracy.
|
|
|
|
|
|
|
|
NTR should be chosen greater than PARAM(3). (default 1000)
|
|
|
|
|
|
|
|
|
|
|
|
monitor monitor development of estimation
|
|
|
|
|
|
|
|
linextrap - 0 use a regular smoothing spline
|
|
|
|
|
|
|
|
1 use a smoothing spline with a constraint on the ends to
|
|
|
|
|
|
|
|
ensure linear extrapolation outside the range of the data.
|
|
|
|
|
|
|
|
(default)
|
|
|
|
|
|
|
|
cvar - Variances for the crossing intensity. (default 1)
|
|
|
|
|
|
|
|
gvar - Variances for the empirical transformation, g. (default 1)
|
|
|
|
|
|
|
|
ne - Number of extremes (maxima & minima) to remove from the
|
|
|
|
|
|
|
|
estimation of the transformation. This makes the
|
|
|
|
|
|
|
|
estimation more robust against outliers. (default 7)
|
|
|
|
|
|
|
|
Ntr - Maximum length of empirical crossing intensity.
|
|
|
|
|
|
|
|
The empirical crossing intensity is interpolated
|
|
|
|
|
|
|
|
linearly before smoothing if the length exceeds Ntr.
|
|
|
|
|
|
|
|
A reasonable NTR will significantly speed up the
|
|
|
|
|
|
|
|
estimation for long time series without loosing any
|
|
|
|
|
|
|
|
accuracy. NTR should be chosen greater than
|
|
|
|
|
|
|
|
PARAM(3). (default 1000)
|
|
|
|
|
|
|
|
Returns
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
-------
|
|
|
|
gs, ge : TrData objects
|
|
|
|
gs, ge : TrData objects
|
|
|
|
smoothed and empirical estimate of the transformation g.
|
|
|
|
smoothed and empirical estimate of the transformation g.
|
|
|
|
ma,sa = mean and standard deviation of the process
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Notes
|
|
|
|
Notes
|
|
|
|
-----
|
|
|
|
-----
|
|
|
@ -268,15 +282,21 @@ class LevelCrossings(WafoData):
|
|
|
|
|
|
|
|
|
|
|
|
Example
|
|
|
|
Example
|
|
|
|
-------
|
|
|
|
-------
|
|
|
|
Hm0 = 7
|
|
|
|
>>> import wafo.spectrum.models as sm
|
|
|
|
S = jonswap([],Hm0); g=ochitr([],[Hm0/4]);
|
|
|
|
>>> import wafo.transform.models as tm
|
|
|
|
S.tr = g; S.tr(:,2)=g(:,2)*Hm0/4;
|
|
|
|
>>> Hs = 7.0
|
|
|
|
xs = spec2sdat(S,2^13);
|
|
|
|
>>> Sj = sm.Jonswap(Hm0=Hs)
|
|
|
|
lc = dat2lc(xs)
|
|
|
|
>>> S = Sj.tospecdata() #Make spectrum object from numerical values
|
|
|
|
g0 = lc2tr2(lc,0,Hm0/4,'plot','iter'); % Monitor the development
|
|
|
|
>>> S.tr = tm.TrOchi(mean=0, skew=sk, kurt=0, sigma=Hs/4, ysigma=Hs/4)
|
|
|
|
g1 = lc2tr2(lc,0,Hm0/4,troptset('gvar', .5 )); % Equal weight on all points
|
|
|
|
>>> xs = S.sim(ns=2**13)
|
|
|
|
g2 = lc2tr2(lc,0,Hm0/4,'gvar', [3.5 .5 3.5]); % Less weight on the ends
|
|
|
|
>>> ts = mat2timeseries(xs)
|
|
|
|
hold on, trplot(g1,g) % Check the fit
|
|
|
|
>>> tp = ts.turning_points()
|
|
|
|
|
|
|
|
>>> mm = tp.cycle_pairs()
|
|
|
|
|
|
|
|
>>> lc = mm.level_crossings()
|
|
|
|
|
|
|
|
>>> g0, gemp = lc.trdata(monitor=True) # Monitor the development
|
|
|
|
|
|
|
|
>>> g1, gemp = lc.trdata(gvar=0.5 ) # Equal weight on all points
|
|
|
|
|
|
|
|
>>> g2, gemp = lc.trdata(gvar=[3.5, 0.5, 3.5]) # Less weight on the ends
|
|
|
|
|
|
|
|
hold on, trplot(g1,g) # Check the fit
|
|
|
|
trplot(g2)
|
|
|
|
trplot(g2)
|
|
|
|
|
|
|
|
|
|
|
|
See also troptset, dat2tr, trplot, findcross, smooth
|
|
|
|
See also troptset, dat2tr, trplot, findcross, smooth
|
|
|
@ -298,138 +318,108 @@ class LevelCrossings(WafoData):
|
|
|
|
# by pab 29.12.2000
|
|
|
|
# by pab 29.12.2000
|
|
|
|
# based on lc2tr, but the inversion is faster.
|
|
|
|
# based on lc2tr, but the inversion is faster.
|
|
|
|
# by IR and PJ
|
|
|
|
# by IR and PJ
|
|
|
|
pass
|
|
|
|
if mean is None:
|
|
|
|
|
|
|
|
mean = self.mean
|
|
|
|
|
|
|
|
if sigma is None:
|
|
|
|
|
|
|
|
sigma = self.stdev
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opt = DotDict(chkder=True, plotflag=False, csm=0.9, gsm=.05,
|
|
|
|
|
|
|
|
param=(-5, 5, 513), delay=2, lin_extrap=True, ntr=1000, ne=7, cvar=1, gvar=1)
|
|
|
|
|
|
|
|
# If just 'defaults' passed in, return the default options in g
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opt.update(options)
|
|
|
|
|
|
|
|
param = opt.param
|
|
|
|
|
|
|
|
Ne = opt.ne
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ncr = len(self.data)
|
|
|
|
|
|
|
|
if ncr > opt.ntr and opt.ntr > 0:
|
|
|
|
|
|
|
|
x0 = linspace(self.args[Ne], self.args[-1 - Ne], opt.ntr)
|
|
|
|
|
|
|
|
lc1, lc2 = x0, interp(x0, self.args, self.data)
|
|
|
|
|
|
|
|
Ne = 0
|
|
|
|
|
|
|
|
Ner = opt.ne
|
|
|
|
|
|
|
|
ncr = opt.ntr
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
Ner = 0
|
|
|
|
|
|
|
|
lc1, lc2 = self.args, self.data
|
|
|
|
|
|
|
|
ng = len(opt.gvar)
|
|
|
|
|
|
|
|
if ng == 1:
|
|
|
|
|
|
|
|
gvar = opt.gvar * ones(ncr)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
gvar = interp1d(linspace(0, 1, ng) , opt.gvar, kind='linear')( linspace(0, 1, ncr))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ng = len(opt.cvar)
|
|
|
|
|
|
|
|
if ng == 1:
|
|
|
|
|
|
|
|
cvar = opt.cvar * ones(ncr)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
cvar = interp1d(linspace(0, 1, ng), opt.cvar, kind='linear')( linspace(0, 1, ncr))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uu = linspace(*param)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g1 = sigma * uu + mean
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g22 = lc2.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if Ner > 0: # Compute correction factors
|
|
|
|
|
|
|
|
cor1 = trapz(lc2[0:Ner + 1], lc1[0:Ner + 1])
|
|
|
|
|
|
|
|
cor2 = trapz(lc2[-Ner - 1::], lc1[-Ner - 1::])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
cor1 = 0
|
|
|
|
|
|
|
|
cor2 = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lc22 = cumtrapz(lc2, lc1) + cor1
|
|
|
|
|
|
|
|
lc22 = (lc22 + 0.5) / (lc22[-1] + cor2 + 1)
|
|
|
|
|
|
|
|
lc11 = (lc1 - mean) / sigma
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# find the mode
|
|
|
|
|
|
|
|
imin = abs(lc22 - 0.15).argmin()
|
|
|
|
|
|
|
|
imax = abs(lc22 - 0.85).argmin()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inde = slice(imin, imax + 1)
|
|
|
|
|
|
|
|
lc222 = SmoothSpline(lc11[inde], g22[inde], opt.csm, opt.lin_extrap, cvar[inde])(lc11[inde])
|
|
|
|
|
|
|
|
|
|
|
|
# opt = troptset('chkder','on','plotflag','off','csm',.9,'gsm',.05,....
|
|
|
|
|
|
|
|
# 'param',[-5 5 513],'delay',2,'linextrap','on','ntr',1000,'ne',7,'cvar',1,'gvar',1);
|
|
|
|
|
|
|
|
# # If just 'defaults' passed in, return the default options in g
|
|
|
|
|
|
|
|
# if nargin==1 && nargout <= 1 && isequal(cross,'defaults')
|
|
|
|
|
|
|
|
# g = opt;
|
|
|
|
|
|
|
|
# return
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# error(nargchk(3,inf,nargin))
|
|
|
|
|
|
|
|
# if nargin>=4 , opt = troptset(opt,varargin{:}); end
|
|
|
|
|
|
|
|
# csm2 = opt.gsm;
|
|
|
|
|
|
|
|
# param = opt.param;
|
|
|
|
|
|
|
|
# ptime = opt.delay;
|
|
|
|
|
|
|
|
# Ne = opt.ne;
|
|
|
|
|
|
|
|
# switch opt.chkder;
|
|
|
|
|
|
|
|
# case 'off', chkder = 0;
|
|
|
|
|
|
|
|
# case 'on', chkder = 1;
|
|
|
|
|
|
|
|
# otherwise, chkder = opt.chkder;
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# switch opt.linextrap;
|
|
|
|
|
|
|
|
# case 'off', def = 0;
|
|
|
|
|
|
|
|
# case 'on', def = 1;
|
|
|
|
|
|
|
|
# otherwise, def = opt.linextrap;
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# switch opt.plotflag
|
|
|
|
|
|
|
|
# case {'none','off'}, plotflag = 0;
|
|
|
|
|
|
|
|
# case 'final', plotflag = 1;
|
|
|
|
|
|
|
|
# case 'iter', plotflag = 2;
|
|
|
|
|
|
|
|
# otherwise, plotflag = opt.plotflag;
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# ncr = length(cross);
|
|
|
|
|
|
|
|
# if ncr>opt.ntr && opt.ntr>0,
|
|
|
|
|
|
|
|
# x0 = linspace(cross(1+Ne,1),cross(end-Ne,1),opt.ntr)';
|
|
|
|
|
|
|
|
# cros = [ x0,interp1q(cross(:,1),cross(:,2),x0)];
|
|
|
|
|
|
|
|
# Ne = 0;
|
|
|
|
|
|
|
|
# Ner = opt.ne;
|
|
|
|
|
|
|
|
# ncr = opt.ntr;
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# Ner = 0;
|
|
|
|
|
|
|
|
# cros=cross;
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ng = length(opt.gvar);
|
|
|
|
|
|
|
|
# if ng==1
|
|
|
|
|
|
|
|
# gvar = opt.gvar(ones(ncr,1));
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# gvar = interp1(linspace(0,1,ng)',opt.gvar(:),linspace(0,1,ncr)','*linear');
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# ng = length(opt.cvar);
|
|
|
|
|
|
|
|
# if ng==1
|
|
|
|
|
|
|
|
# cvar = opt.cvar(ones(ncr,1));
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# cvar = interp1(linspace(0,1,ng)',opt.cvar(:),linspace(0,1,ncr)','*linear');
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# g = zeros(param(3),2);
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# uu = levels(param);
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# g(:,1) = sa*uu' + ma;
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# g2 = cros;
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# if Ner>0, # Compute correction factors
|
|
|
|
|
|
|
|
# cor1 = trapz(cross(1:Ner+1,1),cross(1:Ner+1,2));
|
|
|
|
|
|
|
|
# cor2 = trapz(cross(end-Ner-1:end,1),cross(end-Ner-1:end,2));
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# cor1 = 0;
|
|
|
|
|
|
|
|
# cor2 = 0;
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# cros(:,2) = cumtrapz(cros(:,1),cros(:,2))+cor1;
|
|
|
|
|
|
|
|
# cros(:,2) = (cros(:,2)+.5)/(cros(end,2) + cor2 +1);
|
|
|
|
|
|
|
|
# cros(:,1) = (cros(:,1)-ma)/sa;
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# # find the mode
|
|
|
|
|
|
|
|
# [tmp,imin]= min(abs(cros(:,2)-.15));
|
|
|
|
|
|
|
|
# [tmp,imax]= min(abs(cros(:,2)-.85));
|
|
|
|
|
|
|
|
# inde = imin:imax;
|
|
|
|
|
|
|
|
#tmp = smooth(cros(inde,1),g2(inde,2),opt.csm,cros(inde,1),def,cvar(inde));
|
|
|
|
#tmp = smooth(cros(inde,1),g2(inde,2),opt.csm,cros(inde,1),def,cvar(inde));
|
|
|
|
#
|
|
|
|
|
|
|
|
# [tmp imax] = max(tmp);
|
|
|
|
|
|
|
|
# u0 = cros(inde(imax),1);
|
|
|
|
|
|
|
|
# #u0 = interp1q(cros(:,2),cros(:,1),.5)
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# cros(:,2) = invnorm(cros(:,2),-u0,1);
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# g2(:,2) = cros(:,2);
|
|
|
|
|
|
|
|
# # NB! the smooth function does not always extrapolate well outside the edges
|
|
|
|
|
|
|
|
# # causing poor estimate of g
|
|
|
|
|
|
|
|
# # We may alleviate this problem by: forcing the extrapolation
|
|
|
|
|
|
|
|
# # to be linear outside the edges or choosing a lower value for csm2.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# inds = 1+Ne:ncr-Ne;# indices to points we are smoothing over
|
|
|
|
|
|
|
|
# scros2 = smooth(cros(inds,1),cros(inds,2),csm2,uu,def,gvar(inds));
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# g(:,2) = scros2';#*sa; #multiply with stdev
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# if chkder~=0
|
|
|
|
|
|
|
|
# for ix = 1:5
|
|
|
|
|
|
|
|
# dy = diff(g(:,2));
|
|
|
|
|
|
|
|
# if any(dy<=0)
|
|
|
|
|
|
|
|
# warning('WAFO:LCTR2','The empirical crossing spectrum is not sufficiently smoothed.')
|
|
|
|
|
|
|
|
# disp(' The estimated transfer function, g, is not ')
|
|
|
|
|
|
|
|
# disp(' a strictly increasing function.')
|
|
|
|
|
|
|
|
# dy(dy>0)=eps;
|
|
|
|
|
|
|
|
# gvar = -([dy;0]+[0;dy])/2+eps;
|
|
|
|
|
|
|
|
# g(:,2) = smooth(g(:,1),g(:,2),1,g(:,1),def,ix*gvar);
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# break
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# if 0, #either
|
|
|
|
|
|
|
|
# test = sqrt((param(2)-param(1))/(param(3)-1)*sum((uu-scros2).^2));
|
|
|
|
|
|
|
|
# else # or
|
|
|
|
|
|
|
|
# #test=sqrt(simpson(uu,(uu-scros2).^2));
|
|
|
|
|
|
|
|
# # or
|
|
|
|
|
|
|
|
# test=sqrt(trapz(uu,(uu-scros2).^2));
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# if plotflag>0,
|
|
|
|
|
|
|
|
# trplot(g ,g2,ma,sa)
|
|
|
|
|
|
|
|
# #legend(['Smoothed (T=' num2str(test) ')'],'g(u)=u','Not smoothed',0)
|
|
|
|
|
|
|
|
# #ylabel('Transfer function g(u)')
|
|
|
|
|
|
|
|
# #xlabel('Crossing level u')
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# if plotflag>1,pause(ptime),end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imax = lc222.argmax()
|
|
|
|
|
|
|
|
u0 = lc22[inde][imax]
|
|
|
|
|
|
|
|
#u0 = interp1q(cros(:,2),cros(:,1),.5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lc22 = ndtri(lc22)-u0 #invnorm(lc22, -u0, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g2 = TrData(lc22.copy(), lc1.copy(), mean, sigma**2)
|
|
|
|
|
|
|
|
# NB! the smooth function does not always extrapolate well outside the edges
|
|
|
|
|
|
|
|
# causing poor estimate of g
|
|
|
|
|
|
|
|
# We may alleviate this problem by: forcing the extrapolation
|
|
|
|
|
|
|
|
# to be linear outside the edges or choosing a lower value for csm2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inds = slice(Ne, ncr - Ne) # indices to points we are smoothing over
|
|
|
|
|
|
|
|
scros2 = SmoothSpline(lc11[inds], lc22[inds], opt.gsm, opt.lin_extrap, gvar[inds])(uu)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g = TrData(scros2, g1, mean, sigma**2) #*sa; #multiply with stdev
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if opt.chkder:
|
|
|
|
|
|
|
|
for ix in range(5):
|
|
|
|
|
|
|
|
dy = diff(g.data)
|
|
|
|
|
|
|
|
if any(dy <= 0):
|
|
|
|
|
|
|
|
warnings.warn(
|
|
|
|
|
|
|
|
''' The empirical crossing spectrum is not sufficiently smoothed.
|
|
|
|
|
|
|
|
The estimated transfer function, g, is not a strictly increasing function.
|
|
|
|
|
|
|
|
''')
|
|
|
|
|
|
|
|
eps = finfo(float).eps
|
|
|
|
|
|
|
|
dy[dy > 0] = eps
|
|
|
|
|
|
|
|
gvar = -(hstack((dy, 0)) + hstack((0, dy))) / 2 + eps
|
|
|
|
|
|
|
|
g.data = SmoothSpline(g.args, g.data, 1, opt.lin_extrap, ix * gvar)(g.args)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if opt.plotflag > 0:
|
|
|
|
|
|
|
|
g.plot()
|
|
|
|
|
|
|
|
g2.plot()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return g, g2
|
|
|
|
|
|
|
|
|
|
|
|
class CyclePairs(WafoData):
|
|
|
|
class CyclePairs(WafoData):
|
|
|
|
'''
|
|
|
|
'''
|
|
|
@ -707,6 +697,7 @@ class TimeSeries(WafoData):
|
|
|
|
n = len(self.data)
|
|
|
|
n = len(self.data)
|
|
|
|
self.args = range(0, n)
|
|
|
|
self.args = range(0, n)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sampling_period(self):
|
|
|
|
def sampling_period(self):
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
Returns sampling interval
|
|
|
|
Returns sampling interval
|
|
|
@ -1330,7 +1321,7 @@ def sensortypeid(*sensortypes):
|
|
|
|
>>> sensortypeid('W','v')
|
|
|
|
>>> sensortypeid('W','v')
|
|
|
|
[11, 10]
|
|
|
|
[11, 10]
|
|
|
|
>>> sensortypeid('rubbish')
|
|
|
|
>>> sensortypeid('rubbish')
|
|
|
|
[1.#QNAN]
|
|
|
|
[nan]
|
|
|
|
|
|
|
|
|
|
|
|
See also
|
|
|
|
See also
|
|
|
|
--------
|
|
|
|
--------
|
|
|
|