|
|
@ -1,6 +1,4 @@
|
|
|
|
from __future__ import absolute_import, division
|
|
|
|
from __future__ import absolute_import, division
|
|
|
|
from wafo.misc import meshgrid, gravity, cart2polar, polar2cart
|
|
|
|
|
|
|
|
from wafo.objects import TimeSeries, mat2timeseries
|
|
|
|
|
|
|
|
import warnings
|
|
|
|
import warnings
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import numpy as np
|
|
|
|
import numpy as np
|
|
|
@ -15,15 +13,18 @@ from scipy.integrate import simps, trapz
|
|
|
|
from scipy.special import erf
|
|
|
|
from scipy.special import erf
|
|
|
|
from scipy.linalg import toeplitz
|
|
|
|
from scipy.linalg import toeplitz
|
|
|
|
import scipy.interpolate as interpolate
|
|
|
|
import scipy.interpolate as interpolate
|
|
|
|
|
|
|
|
from scipy.interpolate.interpolate import interp1d, interp2d
|
|
|
|
|
|
|
|
from ..misc import meshgrid, gravity, cart2polar, polar2cart
|
|
|
|
|
|
|
|
from ..objects import TimeSeries, mat2timeseries
|
|
|
|
from ..interpolate import stineman_interp
|
|
|
|
from ..interpolate import stineman_interp
|
|
|
|
|
|
|
|
|
|
|
|
from ..wave_theory.dispersion_relation import w2k # , k2w
|
|
|
|
from ..wave_theory.dispersion_relation import w2k # , k2w
|
|
|
|
from ..containers import PlotData, now
|
|
|
|
from ..containers import PlotData, now
|
|
|
|
# , tranproc
|
|
|
|
|
|
|
|
from ..misc import sub_dict_select, nextpow2, discretize, JITImport
|
|
|
|
from ..misc import sub_dict_select, nextpow2, discretize, JITImport
|
|
|
|
# from wafo.graphutil import cltext
|
|
|
|
|
|
|
|
from ..kdetools import qlevels
|
|
|
|
from ..kdetools import qlevels
|
|
|
|
from scipy.interpolate.interpolate import interp1d
|
|
|
|
|
|
|
|
|
|
|
|
# from wafo.transform import TrData
|
|
|
|
|
|
|
|
from ..transform.models import TrLinear
|
|
|
|
|
|
|
|
from ..plotbackend import plotbackend
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from ..gaussian import Rind
|
|
|
|
from ..gaussian import Rind
|
|
|
@ -40,20 +41,16 @@ except ImportError:
|
|
|
|
warnings.warn('Compile the cov2mod.pyd again!')
|
|
|
|
warnings.warn('Compile the cov2mod.pyd again!')
|
|
|
|
cov2mod = None
|
|
|
|
cov2mod = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# from wafo.transform import TrData
|
|
|
|
|
|
|
|
from ..transform.models import TrLinear
|
|
|
|
|
|
|
|
from ..plotbackend import plotbackend
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Trick to avoid error due to circular import
|
|
|
|
# Trick to avoid error due to circular import
|
|
|
|
|
|
|
|
|
|
|
|
_WAFOCOV = JITImport('wafo.covariance')
|
|
|
|
_WAFOCOV = JITImport('wafo.covariance')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ['SpecData1D', 'SpecData2D', 'plotspec']
|
|
|
|
__all__ = ['SpecData1D', 'SpecData2D', 'plotspec']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_EPS = np.finfo(float).eps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _set_seed(iseed):
|
|
|
|
def _set_seed(iseed):
|
|
|
|
'''Set seed of random generator'''
|
|
|
|
'''Set seed of random generator'''
|
|
|
|
if iseed is not None:
|
|
|
|
if iseed is not None:
|
|
|
@ -157,64 +154,63 @@ def qtf(w, h=inf, g=9.81):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
PLOTSPEC Plot a spectral density
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
S : SpecData1D or SpecData2D object
|
|
|
|
|
|
|
|
defining spectral density.
|
|
|
|
|
|
|
|
linetype : string
|
|
|
|
|
|
|
|
defining color and linetype, see plot for possibilities
|
|
|
|
|
|
|
|
flag : scalar integer
|
|
|
|
|
|
|
|
defining the type of plot
|
|
|
|
|
|
|
|
1D:
|
|
|
|
|
|
|
|
1 plots the density, S, (default)
|
|
|
|
|
|
|
|
2 plot 10log10(S)
|
|
|
|
|
|
|
|
3 plots both the above plots
|
|
|
|
|
|
|
|
2D:
|
|
|
|
|
|
|
|
Directional spectra: S(w,theta), S(f,theta)
|
|
|
|
|
|
|
|
1 polar plot S (default)
|
|
|
|
|
|
|
|
2 plots spectral density and the directional
|
|
|
|
|
|
|
|
spreading, int S(w,theta) dw or int S(f,theta) df
|
|
|
|
|
|
|
|
3 plots spectral density and the directional
|
|
|
|
|
|
|
|
spreading, int S(w,theta)/S(w) dw or int S(f,theta)/S(f) df
|
|
|
|
|
|
|
|
4 mesh of S
|
|
|
|
|
|
|
|
5 mesh of S in polar coordinates
|
|
|
|
|
|
|
|
6 contour plot of S
|
|
|
|
|
|
|
|
7 filled contour plot of S
|
|
|
|
|
|
|
|
Wavenumber spectra: S(k1,k2)
|
|
|
|
|
|
|
|
1 contour plot of S (default)
|
|
|
|
|
|
|
|
2 filled contour plot of S
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Example
|
|
|
|
|
|
|
|
-------
|
|
|
|
|
|
|
|
>>> import numpy as np
|
|
|
|
|
|
|
|
>>> import wafo.spectrum as ws
|
|
|
|
|
|
|
|
>>> Sj = ws.models.Jonswap(Hm0=3, Tp=7)
|
|
|
|
|
|
|
|
>>> S = Sj.tospecdata()
|
|
|
|
|
|
|
|
>>> ws.plotspec(S,flag=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
S = demospec('dir'); S2 = mkdspec(jonswap,spreading);
|
|
|
|
|
|
|
|
plotspec(S,2), hold on
|
|
|
|
|
|
|
|
# Same as previous fig. due to frequency independent spreading
|
|
|
|
|
|
|
|
plotspec(S,3,'g')
|
|
|
|
|
|
|
|
# Not the same as previous figs. due to frequency dependent spreading
|
|
|
|
|
|
|
|
plotspec(S2,2,'r')
|
|
|
|
|
|
|
|
plotspec(S2,3,'m')
|
|
|
|
|
|
|
|
# transform from angular frequency and radians to frequency and degrees
|
|
|
|
|
|
|
|
Sf = ttspec(S,'f','d'); clf
|
|
|
|
|
|
|
|
plotspec(Sf,2),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See also
|
|
|
|
|
|
|
|
dat2spec, createspec, simpson
|
|
|
|
|
|
|
|
'''
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
# '''
|
|
|
|
# # label the contour levels
|
|
|
|
# PLOTSPEC Plot a spectral density
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Parameters
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# S : SpecData1D or SpecData2D object
|
|
|
|
|
|
|
|
# defining spectral density.
|
|
|
|
|
|
|
|
# linetype : string
|
|
|
|
|
|
|
|
# defining color and linetype, see plot for possibilities
|
|
|
|
|
|
|
|
# flag : scalar integer
|
|
|
|
|
|
|
|
# defining the type of plot
|
|
|
|
|
|
|
|
# 1D:
|
|
|
|
|
|
|
|
# 1 plots the density, S, (default)
|
|
|
|
|
|
|
|
# 2 plot 10log10(S)
|
|
|
|
|
|
|
|
# 3 plots both the above plots
|
|
|
|
|
|
|
|
# 2D:
|
|
|
|
|
|
|
|
# Directional spectra: S(w,theta), S(f,theta)
|
|
|
|
|
|
|
|
# 1 polar plot S (default)
|
|
|
|
|
|
|
|
# 2 plots spectral density and the directional
|
|
|
|
|
|
|
|
# spreading, int S(w,theta) dw or int S(f,theta) df
|
|
|
|
|
|
|
|
# 3 plots spectral density and the directional
|
|
|
|
|
|
|
|
# spreading, int S(w,theta)/S(w) dw or int S(f,theta)/S(f) df
|
|
|
|
|
|
|
|
# 4 mesh of S
|
|
|
|
|
|
|
|
# 5 mesh of S in polar coordinates
|
|
|
|
|
|
|
|
# 6 contour plot of S
|
|
|
|
|
|
|
|
# 7 filled contour plot of S
|
|
|
|
|
|
|
|
# Wavenumber spectra: S(k1,k2)
|
|
|
|
|
|
|
|
# 1 contour plot of S (default)
|
|
|
|
|
|
|
|
# 2 filled contour plot of S
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Example
|
|
|
|
|
|
|
|
# -------
|
|
|
|
|
|
|
|
# >>> import numpy as np
|
|
|
|
|
|
|
|
# >>> import wafo.spectrum as ws
|
|
|
|
|
|
|
|
# >>> Sj = ws.models.Jonswap(Hm0=3, Tp=7)
|
|
|
|
|
|
|
|
# >>> S = Sj.tospecdata()
|
|
|
|
|
|
|
|
# >>> ws.plotspec(S,flag=1)
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# S = demospec('dir'); S2 = mkdspec(jonswap,spreading);
|
|
|
|
|
|
|
|
# plotspec(S,2), hold on
|
|
|
|
|
|
|
|
# # Same as previous fig. due to frequency independent spreading
|
|
|
|
|
|
|
|
# plotspec(S,3,'g')
|
|
|
|
|
|
|
|
# # Not the same as previous figs. due to frequency dependent spreading
|
|
|
|
|
|
|
|
# plotspec(S2,2,'r')
|
|
|
|
|
|
|
|
# plotspec(S2,3,'m')
|
|
|
|
|
|
|
|
# % transform from angular frequency and radians to frequency and degrees
|
|
|
|
|
|
|
|
# Sf = ttspec(S,'f','d'); clf
|
|
|
|
|
|
|
|
# plotspec(Sf,2),
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# See also dat2spec, createspec, simpson
|
|
|
|
|
|
|
|
# '''
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# label the contour levels
|
|
|
|
|
|
|
|
# txtFlag = 0
|
|
|
|
# txtFlag = 0
|
|
|
|
# LegendOn = 1
|
|
|
|
# LegendOn = 1
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
# ftype = specdata.freqtype # options are 'f' and 'w' and 'k'
|
|
|
|
# ftype = specdata.freqtype # options are 'f' and 'w' and 'k'
|
|
|
|
# data = specdata.data
|
|
|
|
# data = specdata.data
|
|
|
|
# if data.ndim == 2:
|
|
|
|
# if data.ndim == 2:
|
|
|
@ -270,10 +266,10 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
# Fn = freq[-1] # Nyquist frequency
|
|
|
|
# Fn = freq[-1] # Nyquist frequency
|
|
|
|
# indm = findpeaks(data, n=4)
|
|
|
|
# indm = findpeaks(data, n=4)
|
|
|
|
# maxS = data.max()
|
|
|
|
# maxS = data.max()
|
|
|
|
# if isfield(S,'CI') && ~isempty(S.CI),
|
|
|
|
# if isfield(S,'CI') && ~isempty(S.CI):
|
|
|
|
# maxS = maxS*S.CI(2)
|
|
|
|
# maxS = maxS*S.CI(2)
|
|
|
|
# txtCI = [num2str(100*S.p), '% CI']
|
|
|
|
# txtCI = [num2str(100*S.p), '% CI']
|
|
|
|
# end
|
|
|
|
# #end
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Fp = freq[indm]# %peak frequency/wave number
|
|
|
|
# Fp = freq[indm]# %peak frequency/wave number
|
|
|
|
#
|
|
|
|
#
|
|
|
@ -293,7 +289,7 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
# ':', label=txt)
|
|
|
|
# ':', label=txt)
|
|
|
|
# plotbackend.plot(freq, data, linetype)
|
|
|
|
# plotbackend.plot(freq, data, linetype)
|
|
|
|
# specdata.labels.labelfig()
|
|
|
|
# specdata.labels.labelfig()
|
|
|
|
# if isfield(S,'CI'),
|
|
|
|
# if isfield(S,'CI'):
|
|
|
|
# plot(freq,S.S*S.CI(1), 'r:' )
|
|
|
|
# plot(freq,S.S*S.CI(1), 'r:' )
|
|
|
|
# plot(freq,S.S*S.CI(2), 'r:' )
|
|
|
|
# plot(freq,S.S*S.CI(2), 'r:' )
|
|
|
|
#
|
|
|
|
#
|
|
|
@ -320,10 +316,10 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
# maxS)).repeat(len(Fp)),
|
|
|
|
# maxS)).repeat(len(Fp)),
|
|
|
|
# 10 * log10(data.take(indm) / maxS))), ':',label=txt)
|
|
|
|
# 10 * log10(data.take(indm) / maxS))), ':',label=txt)
|
|
|
|
# hold on
|
|
|
|
# hold on
|
|
|
|
# if isfield(S,'CI'),
|
|
|
|
# if isfield(S,'CI'):
|
|
|
|
# plot(freq(ind),10*log10(S.S(ind)*S.CI(1)/maxS), 'r:' )
|
|
|
|
# plot(freq(ind),10*log10(S.S(ind)*S.CI(1)/maxS), 'r:' )
|
|
|
|
# plot(freq(ind),10*log10(S.S(ind)*S.CI(2)/maxS), 'r:' )
|
|
|
|
# plot(freq(ind),10*log10(S.S(ind)*S.CI(2)/maxS), 'r:' )
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# plotbackend.plot(freq[ind], 10 * log10(data[ind] / maxS), linetype)
|
|
|
|
# plotbackend.plot(freq[ind], 10 * log10(data[ind] / maxS), linetype)
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# a = plotbackend.axis()
|
|
|
|
# a = plotbackend.axis()
|
|
|
@ -371,7 +367,7 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
# xlabel(xlbl_txt)
|
|
|
|
# xlabel(xlbl_txt)
|
|
|
|
# ylabel(xlbl_txt)
|
|
|
|
# ylabel(xlbl_txt)
|
|
|
|
# title(ylbl4_txt)
|
|
|
|
# title(ylbl4_txt)
|
|
|
|
# %return
|
|
|
|
# # return
|
|
|
|
# km=max([-freq(1) freq(end) S.k2(1) -S.k2(end)])
|
|
|
|
# km=max([-freq(1) freq(end) S.k2(1) -S.k2(end)])
|
|
|
|
# axis([-km km -km km])
|
|
|
|
# axis([-km km -km km])
|
|
|
|
# hold on
|
|
|
|
# hold on
|
|
|
@ -380,8 +376,8 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
# axis('square')
|
|
|
|
# axis('square')
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# %cltext(z_level)
|
|
|
|
# # cltext(z_level)
|
|
|
|
# %axis('square')
|
|
|
|
# # axis('square')
|
|
|
|
# if ~ih, hold off,end
|
|
|
|
# if ~ih, hold off,end
|
|
|
|
# case {'dir'}
|
|
|
|
# case {'dir'}
|
|
|
|
# thmin = S.theta(1)-phi;thmax=S.theta(end)-phi
|
|
|
|
# thmin = S.theta(1)-phi;thmax=S.theta(end)-phi
|
|
|
@ -514,120 +510,13 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# if ~ih, hold off, end
|
|
|
|
# if ~ih, hold off, end
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# % The following two commands install point-and-click editing of
|
|
|
|
# # The following two commands install point-and-click editing of
|
|
|
|
# % all the text objects (title, xlabel, ylabel) of the current figure:
|
|
|
|
# # all the text objects (title, xlabel, ylabel) of the current figure:
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# %set(findall(gcf,'type','text'),'buttondownfcn','edtext')
|
|
|
|
# #set(findall(gcf,'type','text'),'buttondownfcn','edtext')
|
|
|
|
# %set(gcf,'windowbuttondownfcn','edtext(''hide'')')
|
|
|
|
# #set(gcf,'windowbuttondownfcn','edtext(''hide'')')
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# return
|
|
|
|
# return
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# function fixthetalabels(thmin,thmax,xy,dim)
|
|
|
|
|
|
|
|
# %FIXTHETALABELS pretty prints the ticklabels and x or y labels for theta
|
|
|
|
|
|
|
|
# %
|
|
|
|
|
|
|
|
# % CALL fixthetalabels(thmin,thmax,xy,dim)
|
|
|
|
|
|
|
|
# %
|
|
|
|
|
|
|
|
# % thmin, thmax = minimum and maximum value for theta (wave direction)
|
|
|
|
|
|
|
|
# % xy = 'x' if theta is plotted on the x-axis
|
|
|
|
|
|
|
|
# % 'y' if theta is plotted on the y-axis
|
|
|
|
|
|
|
|
# % dim = specifies the dimension of the plot (ie number of axes shown 2 or 3)
|
|
|
|
|
|
|
|
# % If abs(thmax-thmin)<3*pi it is assumed that theta is given in radians
|
|
|
|
|
|
|
|
# % otherwise degrees
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ind = [('x' == xy) ('y' == xy) ];
|
|
|
|
|
|
|
|
# yx = 'yx';
|
|
|
|
|
|
|
|
# yx = yx(ind);
|
|
|
|
|
|
|
|
# if nargin<4||isempty(dim),
|
|
|
|
|
|
|
|
# dim=2;
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# %drawnow
|
|
|
|
|
|
|
|
# %pause
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# if abs(thmax-thmin)<3*pi, %Radians given. Want xticks given as fractions of pi
|
|
|
|
|
|
|
|
# %Trick to update the axis
|
|
|
|
|
|
|
|
# if xy=='x'
|
|
|
|
|
|
|
|
# if dim<3,
|
|
|
|
|
|
|
|
# axis([thmin,thmax 0 inf ])
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# axis([thmin,thmax 0 inf 0 inf])
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# if dim<3,
|
|
|
|
|
|
|
|
# axis([0 inf thmin,thmax ])
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# axis([0 inf thmin,thmax 0 inf])
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# set(gca,[xy 'tick'],pi*(thmin/pi:0.25:thmax/pi));
|
|
|
|
|
|
|
|
# set(gca,[xy 'ticklabel'],[]);
|
|
|
|
|
|
|
|
# x = get(gca,[xy 'tick']);
|
|
|
|
|
|
|
|
# y = get(gca,[yx 'tick']);
|
|
|
|
|
|
|
|
# y1 = y(1);
|
|
|
|
|
|
|
|
# dy = y(2)-y1;
|
|
|
|
|
|
|
|
# yN = y(end)+dy;
|
|
|
|
|
|
|
|
# ylim = [y1 yN];
|
|
|
|
|
|
|
|
# dy1 = diff(ylim)/40;
|
|
|
|
|
|
|
|
# %ylim=get(gca,[yx 'lim'])%,ylim=ylim(2);
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# if xy=='x'
|
|
|
|
|
|
|
|
# for j=1:length(x)
|
|
|
|
|
|
|
|
# xtxt = num2pistr(x(j));
|
|
|
|
|
|
|
|
# figtext(x(j),y1-dy1,xtxt,'data','data','center','top');
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# % ax = [thmin thmax 0 inf];
|
|
|
|
|
|
|
|
# ax = [thmin thmax ylim];
|
|
|
|
|
|
|
|
# if dim<3,
|
|
|
|
|
|
|
|
# figtext(mean(x),y1-7*dy1,'Wave directions (rad)','data','data','center','top')
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# ax = [ax 0 inf];
|
|
|
|
|
|
|
|
# xlabel('Wave directions (rad)')
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# %ax = [0 inf thmin thmax];
|
|
|
|
|
|
|
|
# ax = [ylim thmin thmax];
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# if dim<3,
|
|
|
|
|
|
|
|
# for j=1:length(x)
|
|
|
|
|
|
|
|
# xtxt = num2pistr(x(j));
|
|
|
|
|
|
|
|
# figtext(y1-dy1/2,x(j),xtxt,'data','data','right');
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# set(gca,'DefaultTextRotation',90)
|
|
|
|
|
|
|
|
# %ylabel('Wave directions (rad)')
|
|
|
|
|
|
|
|
# figtext(y1-3*dy1,mean(x),'Wave directions (rad)','data','data','center','bottom')
|
|
|
|
|
|
|
|
# set(gca,'DefaultTextRotation',0)
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# for j=1:length(x)
|
|
|
|
|
|
|
|
# xtxt = num2pistr(x(j));
|
|
|
|
|
|
|
|
# figtext(y1-3*dy1,x(j),xtxt,'data','data','right');
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# ax = [ax 0 inf];
|
|
|
|
|
|
|
|
# ylabel('Wave directions (rad)')
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# %xtxt = num2pistr(x(j));
|
|
|
|
|
|
|
|
# %for j=2:length(x)
|
|
|
|
|
|
|
|
# % xtxt = strvcat(xtxt,num2pistr(x(j)));
|
|
|
|
|
|
|
|
# %end
|
|
|
|
|
|
|
|
# %set(gca,[xy 'ticklabel'],xtxt)
|
|
|
|
|
|
|
|
# else % Degrees given
|
|
|
|
|
|
|
|
# set(gca,[xy 'tick'],thmin:45:thmax)
|
|
|
|
|
|
|
|
# if xy=='x'
|
|
|
|
|
|
|
|
# ax=[thmin thmax 0 inf];
|
|
|
|
|
|
|
|
# if dim>=3, ax=[ax 0 inf]; end
|
|
|
|
|
|
|
|
# xlabel('Wave directions (deg)')
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# ax=[0 inf thmin thmax ];
|
|
|
|
|
|
|
|
# if dim>=3, ax=[ax 0 inf]; end
|
|
|
|
|
|
|
|
# ylabel('Wave directions (deg)')
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# axis(ax)
|
|
|
|
|
|
|
|
# return
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SpecData1D(PlotData):
|
|
|
|
class SpecData1D(PlotData):
|
|
|
@ -684,6 +573,43 @@ class SpecData1D(PlotData):
|
|
|
|
|
|
|
|
|
|
|
|
self.setlabels()
|
|
|
|
self.setlabels()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_default_dt_and_rate(self, dt):
|
|
|
|
|
|
|
|
dt_old = self.sampling_period()
|
|
|
|
|
|
|
|
if dt is None:
|
|
|
|
|
|
|
|
return dt_old, 1
|
|
|
|
|
|
|
|
rate = max(round(dt_old * 1. / dt), 1.)
|
|
|
|
|
|
|
|
return dt, rate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _check_dt(self, dt):
|
|
|
|
|
|
|
|
freq = self.args
|
|
|
|
|
|
|
|
checkdt = 1.2 * min(diff(freq)) / 2. / pi
|
|
|
|
|
|
|
|
if self.freqtype in 'f':
|
|
|
|
|
|
|
|
checkdt *= 2 * pi
|
|
|
|
|
|
|
|
if (checkdt < 2. ** -16 / dt):
|
|
|
|
|
|
|
|
print('Step dt = %g in computation of the density is ' +
|
|
|
|
|
|
|
|
'too small.' % dt)
|
|
|
|
|
|
|
|
print('The computed covariance (by FFT(2^K)) may differ from the')
|
|
|
|
|
|
|
|
print('theoretical. Solution:')
|
|
|
|
|
|
|
|
raise ValueError('use larger dt or sparser grid for spectrum.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _check_cov_matrix(self, acfmat, nt, dt):
|
|
|
|
|
|
|
|
eps0 = 0.0001
|
|
|
|
|
|
|
|
if nt + 1 >= 5:
|
|
|
|
|
|
|
|
cc2 = acfmat[0, 0] - acfmat[4, 0] * (acfmat[4, 0] / acfmat[0, 0])
|
|
|
|
|
|
|
|
if (cc2 < eps0):
|
|
|
|
|
|
|
|
warnings.warn('Step dt = %g in computation of the density ' +
|
|
|
|
|
|
|
|
'is too small.' % dt)
|
|
|
|
|
|
|
|
cc1 = acfmat[0, 0] - acfmat[1, 0] * (acfmat[1, 0] / acfmat[0, 0])
|
|
|
|
|
|
|
|
if (cc1 < eps0):
|
|
|
|
|
|
|
|
warnings.warn('Step dt = %g is small, and may cause numerical ' +
|
|
|
|
|
|
|
|
'inaccuracies.' % dt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def lagtype(self):
|
|
|
|
|
|
|
|
if self.freqtype in 'k': # options are 'f' and 'w' and 'k'
|
|
|
|
|
|
|
|
return 'x'
|
|
|
|
|
|
|
|
return 't'
|
|
|
|
|
|
|
|
|
|
|
|
def tocov_matrix(self, nr=0, nt=None, dt=None):
|
|
|
|
def tocov_matrix(self, nr=0, nt=None, dt=None):
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
Computes covariance function and its derivatives, alternative version
|
|
|
|
Computes covariance function and its derivatives, alternative version
|
|
|
@ -725,59 +651,30 @@ class SpecData1D(PlotData):
|
|
|
|
objects
|
|
|
|
objects
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
ftype = self.freqtype # %options are 'f' and 'w' and 'k'
|
|
|
|
|
|
|
|
|
|
|
|
dt, rate = self._get_default_dt_and_rate(dt)
|
|
|
|
|
|
|
|
self._check_dt(dt)
|
|
|
|
|
|
|
|
|
|
|
|
freq = self.args
|
|
|
|
freq = self.args
|
|
|
|
n_f = len(freq)
|
|
|
|
n_f = len(freq)
|
|
|
|
dt_old = self.sampling_period()
|
|
|
|
|
|
|
|
if dt is None:
|
|
|
|
|
|
|
|
dt = dt_old
|
|
|
|
|
|
|
|
rate = 1
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
rate = max(round(dt_old * 1. / dt), 1.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if nt is None:
|
|
|
|
if nt is None:
|
|
|
|
nt = rate * (n_f - 1)
|
|
|
|
nt = rate * (n_f - 1)
|
|
|
|
else: # %check if Nt is ok
|
|
|
|
else: # %check if Nt is ok
|
|
|
|
nt = minimum(nt, rate * (n_f - 1))
|
|
|
|
nt = minimum(nt, rate * (n_f - 1))
|
|
|
|
|
|
|
|
|
|
|
|
checkdt = 1.2 * min(diff(freq)) / 2. / pi
|
|
|
|
|
|
|
|
if ftype in 'k':
|
|
|
|
|
|
|
|
lagtype = 'x'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
lagtype = 't'
|
|
|
|
|
|
|
|
if ftype in 'f':
|
|
|
|
|
|
|
|
checkdt = checkdt * 2 * pi
|
|
|
|
|
|
|
|
msg1 = 'Step dt = %g in computation of the density is too small.' % dt
|
|
|
|
|
|
|
|
msg2 = 'Step dt = %g is small, and may cause numerical inaccuracies.' % dt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (checkdt < 2. ** -16 / dt):
|
|
|
|
|
|
|
|
print(msg1)
|
|
|
|
|
|
|
|
print('The computed covariance (by FFT(2^K)) may differ from the')
|
|
|
|
|
|
|
|
print('theoretical. Solution:')
|
|
|
|
|
|
|
|
raise ValueError('use larger dt or sparser grid for spectrum.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Calculating covariances
|
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
spec = self.copy()
|
|
|
|
spec = self.copy()
|
|
|
|
spec.resample(dt)
|
|
|
|
spec.resample(dt)
|
|
|
|
|
|
|
|
|
|
|
|
acf = spec.tocovdata(nr, nt, rate=1)
|
|
|
|
acf = spec.tocovdata(nr, nt, rate=1)
|
|
|
|
acfmat = zeros((nt + 1, nr + 1), dtype=float)
|
|
|
|
acfmat = zeros((nt + 1, nr + 1), dtype=float)
|
|
|
|
acfmat[:, 0] = acf.data[0:nt + 1]
|
|
|
|
acfmat[:, 0] = acf.data[0:nt + 1]
|
|
|
|
fieldname = 'R' + lagtype * nr
|
|
|
|
fieldname = 'R' + self.lagtype * nr
|
|
|
|
for i in range(1, nr + 1):
|
|
|
|
for i in range(1, nr + 1):
|
|
|
|
fname = fieldname[:i + 1]
|
|
|
|
fname = fieldname[:i + 1]
|
|
|
|
r_i = getattr(acf, fname)
|
|
|
|
r_i = getattr(acf, fname)
|
|
|
|
acfmat[:, i] = r_i[0:nt + 1]
|
|
|
|
acfmat[:, i] = r_i[0:nt + 1]
|
|
|
|
|
|
|
|
|
|
|
|
eps0 = 0.0001
|
|
|
|
self._check_cov_matrix(acfmat, nt, dt)
|
|
|
|
if nt + 1 >= 5:
|
|
|
|
|
|
|
|
cc2 = acfmat[0, 0] - acfmat[4, 0] * (acfmat[4, 0] / acfmat[0, 0])
|
|
|
|
|
|
|
|
if (cc2 < eps0):
|
|
|
|
|
|
|
|
warnings.warn(msg1)
|
|
|
|
|
|
|
|
cc1 = acfmat[0, 0] - acfmat[1, 0] * (acfmat[1, 0] / acfmat[0, 0])
|
|
|
|
|
|
|
|
if (cc1 < eps0):
|
|
|
|
|
|
|
|
warnings.warn(msg2)
|
|
|
|
|
|
|
|
return acfmat
|
|
|
|
return acfmat
|
|
|
|
|
|
|
|
|
|
|
|
def tocovdata(self, nr=0, nt=None, rate=None):
|
|
|
|
def tocovdata(self, nr=0, nt=None, rate=None):
|
|
|
@ -1657,8 +1554,8 @@ class SpecData1D(PlotData):
|
|
|
|
# ftmp = cov2mmtpdfexe(R,dt,u,defnr,Nstart,hg,options)
|
|
|
|
# ftmp = cov2mmtpdfexe(R,dt,u,defnr,Nstart,hg,options)
|
|
|
|
# err = repmat(nan,size(ftmp))
|
|
|
|
# err = repmat(nan,size(ftmp))
|
|
|
|
# else
|
|
|
|
# else
|
|
|
|
[ftmp, err, terr, options] = self._cov2mmtpdf(
|
|
|
|
ftmp, err, terr, options = self._cov2mmtpdf(R, dt, u, defnr, Nstart,
|
|
|
|
R, dt, u, defnr, Nstart, hg, options)
|
|
|
|
hg, options)
|
|
|
|
|
|
|
|
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
note = ''
|
|
|
|
note = ''
|
|
|
@ -1850,8 +1747,8 @@ class SpecData1D(PlotData):
|
|
|
|
(indI(3)=Nt+1); for i\in (indI(3)+1,indI(4)], Y(i)>0 (deriv. X''(tn))
|
|
|
|
(indI(3)=Nt+1); for i\in (indI(3)+1,indI(4)], Y(i)>0 (deriv. X''(tn))
|
|
|
|
(indI(4)=Nt+2); for i\in (indI(4)+1,indI(5)], Y(i)<0 (deriv. X'(ts))
|
|
|
|
(indI(4)=Nt+2); for i\in (indI(4)+1,indI(5)], Y(i)<0 (deriv. X'(ts))
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
R0, R1, R2, R3, R4, R5 = R[:, :5].T
|
|
|
|
R0, R1, R2, R3, R4 = R[:, :5].T
|
|
|
|
|
|
|
|
covinput = self._covinput_mmt_pdf
|
|
|
|
Ntime = len(R0)
|
|
|
|
Ntime = len(R0)
|
|
|
|
Nx0 = max(1, len(hg))
|
|
|
|
Nx0 = max(1, len(hg))
|
|
|
|
Nx1 = Nx0
|
|
|
|
Nx1 = Nx0
|
|
|
@ -1876,14 +1773,15 @@ class SpecData1D(PlotData):
|
|
|
|
if def_nr <= 1: # just plain Mm
|
|
|
|
if def_nr <= 1: # just plain Mm
|
|
|
|
Nx = Nx1 * (Nx1 - 1) / 2
|
|
|
|
Nx = Nx1 * (Nx1 - 1) / 2
|
|
|
|
IJ = (Nx1 + isOdd) / 2
|
|
|
|
IJ = (Nx1 + isOdd) / 2
|
|
|
|
if (hg[0] + hg[Nx1 - 1] == 0 and (hg[IJ - 1] == 0 or hg[IJ - 1] + hg[IJ] == 0)):
|
|
|
|
if (hg[0] + hg[Nx1 - 1] == 0 and (hg[IJ - 1] == 0 or
|
|
|
|
|
|
|
|
hg[IJ - 1] + hg[IJ] == 0)):
|
|
|
|
symmetry = 0
|
|
|
|
symmetry = 0
|
|
|
|
print(' Integration region symmetric')
|
|
|
|
print(' Integration region symmetric')
|
|
|
|
# May save Nx1-isOdd integrations in each time step
|
|
|
|
# May save Nx1-isOdd integrations in each time step
|
|
|
|
# This is not implemented yet.
|
|
|
|
# This is not implemented yet.
|
|
|
|
# Nx = Nx1*(Nx1-1)/2-Nx1+isOdd
|
|
|
|
# Nx = Nx1*(Nx1-1)/2-Nx1+isOdd
|
|
|
|
|
|
|
|
# normalizing constant:
|
|
|
|
# CC = normalizing constant = 1/ expected number of zero-up-crossings of X'
|
|
|
|
# CC = 1/ expected number of zero-up-crossings of X'
|
|
|
|
# CC = 2*pi*sqrt(-R2[0]/R4[0])
|
|
|
|
# CC = 2*pi*sqrt(-R2[0]/R4[0])
|
|
|
|
# XcScale = log(CC)
|
|
|
|
# XcScale = log(CC)
|
|
|
|
XcScale = log(2 * pi * sqrt(-R2[0] / R4[0]))
|
|
|
|
XcScale = log(2 * pi * sqrt(-R2[0] / R4[0]))
|
|
|
@ -1902,16 +1800,15 @@ class SpecData1D(PlotData):
|
|
|
|
Nc = 5
|
|
|
|
Nc = 5
|
|
|
|
NI = 5
|
|
|
|
NI = 5
|
|
|
|
Nd = 3
|
|
|
|
Nd = 3
|
|
|
|
# CC= normalizing constant= 1/ expected number of u-up-crossings of X
|
|
|
|
# CC = 1/ expected number of u-up-crossings of X
|
|
|
|
# CC = 2*pi*sqrt(-R0(1)/R2(1))*exp(0.5D0*u*u/R0(1))
|
|
|
|
# CC = 2*pi*sqrt(-R0(1)/R2(1))*exp(0.5D0*u*u/R0(1))
|
|
|
|
XcScale = log(2 * pi * sqrt(-R0[0] / R2[0])) + 0.5 * u * u / R0[0]
|
|
|
|
XcScale = log(2 * pi * sqrt(-R0[0] / R2[0])) + 0.5 * u * u / R0[0]
|
|
|
|
|
|
|
|
|
|
|
|
options['xcscale'] = XcScale
|
|
|
|
options['xcscale'] = XcScale
|
|
|
|
opt0 = struct2cell(options)
|
|
|
|
# opt0 = [options[n] for n in ('SCIS', 'XcScale', 'ABSEPS', 'RELEPS',
|
|
|
|
# opt0 = opt0(1:10)
|
|
|
|
# 'COVEPS', 'MAXPTS', 'MINPTS', 'seed',
|
|
|
|
# seed = []
|
|
|
|
# 'NIT1')]
|
|
|
|
# opt0 = {SCIS,XcScale,ABSEPS,RELEPS,COVEPS,MAXPTS,MINPTS,seed,NIT1}
|
|
|
|
rind = Rind(**options)
|
|
|
|
|
|
|
|
|
|
|
|
if (Nx > 1):
|
|
|
|
if (Nx > 1):
|
|
|
|
# (M,m) or (M,m)v distribution wanted
|
|
|
|
# (M,m) or (M,m)v distribution wanted
|
|
|
|
if ((def_nr == 0 or def_nr == 2)):
|
|
|
|
if ((def_nr == 0 or def_nr == 2)):
|
|
|
@ -1982,10 +1879,10 @@ class SpecData1D(PlotData):
|
|
|
|
indI[2] = Nt + 1
|
|
|
|
indI[2] = Nt + 1
|
|
|
|
indI[3] = Ntd
|
|
|
|
indI[3] = Ntd
|
|
|
|
# positive wave period
|
|
|
|
# positive wave period
|
|
|
|
BIG[:Ntdc, :Ntdc] = covinput(
|
|
|
|
# self._covinput_mmt_pdf(BIG, R, tn, ts, tnold)
|
|
|
|
BIG[:Ntdc, :Ntdc], R0, R1, R2, R3, R4, Ntd, 0)
|
|
|
|
BIG[:Ntdc, :Ntdc] = covinput(BIG[:Ntdc, :Ntdc], R, Ntd, 0)
|
|
|
|
[fxind, err0, terr0] = rind(BIG[:Ntdc, :Ntdc], ex[:Ntdc],
|
|
|
|
[fxind, err0, terr0] = rind(BIG[:Ntdc, :Ntdc], ex[:Ntdc],
|
|
|
|
a_lo, a_up, indI, xc, Nt, *opt0)
|
|
|
|
a_lo, a_up, indI, xc, Nt)
|
|
|
|
# fxind = CC*rind(BIG(1:Ntdc,1:Ntdc),ex(1:Ntdc),xc,Nt,NIT1,
|
|
|
|
# fxind = CC*rind(BIG(1:Ntdc,1:Ntdc),ex(1:Ntdc),xc,Nt,NIT1,
|
|
|
|
# speed1,indI,a_lo,a_up)
|
|
|
|
# speed1,indI,a_lo,a_up)
|
|
|
|
if (Nx < 2):
|
|
|
|
if (Nx < 2):
|
|
|
@ -2001,12 +1898,9 @@ class SpecData1D(PlotData):
|
|
|
|
if def_nr in [-2, -1, 0]:
|
|
|
|
if def_nr in [-2, -1, 0]:
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
J = IJ + i
|
|
|
|
J = IJ + i
|
|
|
|
pdf[:i, i, 0] = pdf[:i, i, 0] + \
|
|
|
|
pdf[:i, i, 0] += fxind[IJ:J].T * dt # *CC
|
|
|
|
fxind[IJ:J].T * dt # *CC
|
|
|
|
err[:i, i, 0] += (err0[IJ + 1:J].T * dt) ** 2
|
|
|
|
err[:i, i, 0] = err[:i, i, 0] + \
|
|
|
|
terr[:i, i, 0] += (terr0[IJ:J].T * dt)
|
|
|
|
(err0[IJ + 1:J].T * dt) ** 2
|
|
|
|
|
|
|
|
terr[:i, i, 0] = terr[
|
|
|
|
|
|
|
|
:i, i, 0] + (terr0[IJ:J].T * dt)
|
|
|
|
|
|
|
|
IJ = J
|
|
|
|
IJ = J
|
|
|
|
elif def_nr == 1: # joint density of (M,m,TMm)
|
|
|
|
elif def_nr == 1: # joint density of (M,m,TMm)
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
for i in range(1, Nx1):
|
|
|
@ -2020,24 +1914,18 @@ class SpecData1D(PlotData):
|
|
|
|
elif def_nr == 2:
|
|
|
|
elif def_nr == 2:
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
J = IJ + Nx1
|
|
|
|
J = IJ + Nx1
|
|
|
|
pdf[1:Nx1, i, 0] = pdf[1:Nx1, i, 0] + \
|
|
|
|
pdf[1:Nx1, i, 0] += fxind[IJ:J].T * dt # %*CC
|
|
|
|
fxind[IJ:J].T * dt # %*CC
|
|
|
|
err[1:Nx1, i, 0] += (err0[IJ:J].T * dt) ** 2
|
|
|
|
err[1:Nx1, i, 0] = err[1:Nx1, i, 0] + \
|
|
|
|
terr[1:Nx1, i, 0] += (terr0[IJ:J].T * dt)
|
|
|
|
(err0[IJ:J].T * dt) ** 2
|
|
|
|
|
|
|
|
terr[1:Nx1, i, 0] = terr[
|
|
|
|
|
|
|
|
1:Nx1, i, 0] + (terr0[IJ:J].T * dt)
|
|
|
|
|
|
|
|
IJ = J
|
|
|
|
IJ = J
|
|
|
|
# end %do
|
|
|
|
# end %do
|
|
|
|
elif def_nr == 3:
|
|
|
|
elif def_nr == 3:
|
|
|
|
# joint density of level v separated (M,m,TMm)v
|
|
|
|
# joint density of level v separated (M,m,TMm)v
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
J = IJ + Nx1
|
|
|
|
J = IJ + Nx1
|
|
|
|
pdf[1:Nx1, i, Ntd] = pdf[
|
|
|
|
pdf[1:Nx1, i, Ntd] += fxind[IJ:J].T # %*CC
|
|
|
|
1:Nx1, i, Ntd] + fxind[IJ:J].T # %*CC
|
|
|
|
err[1:Nx1, i, Ntd] += (err0[IJ:J].T) ** 2
|
|
|
|
err[1:Nx1, i, Ntd] = err[
|
|
|
|
terr[1:Nx1, i, Ntd] += (terr0[IJ:J].T)
|
|
|
|
1:Nx1, i, Ntd] + (err0[IJ:J].T) ** 2
|
|
|
|
|
|
|
|
terr[1:Nx1, i, Ntd] = terr[
|
|
|
|
|
|
|
|
1:Nx1, i, Ntd] + (terr0[IJ:J].T)
|
|
|
|
|
|
|
|
IJ = J
|
|
|
|
IJ = J
|
|
|
|
# end %do
|
|
|
|
# end %do
|
|
|
|
# end % SELECT
|
|
|
|
# end % SELECT
|
|
|
@ -2067,10 +1955,9 @@ class SpecData1D(PlotData):
|
|
|
|
for ts in range(1, tn - 1): # = 2:tn-1:
|
|
|
|
for ts in range(1, tn - 1): # = 2:tn-1:
|
|
|
|
# positive wave period
|
|
|
|
# positive wave period
|
|
|
|
BIG[:Ntdc, :Ntdc] = covinput(BIG[:Ntdc, :Ntdc],
|
|
|
|
BIG[:Ntdc, :Ntdc] = covinput(BIG[:Ntdc, :Ntdc],
|
|
|
|
R0, R1, R2, R3, R4,
|
|
|
|
R, tn, ts, tnold)
|
|
|
|
tn, ts, tnold)
|
|
|
|
fxind, err0, terr0 = rind(BIG[:Ntdc, :Ntdc], ex[:Ntdc],
|
|
|
|
[fxind, err0, terr0] = rind(BIG[:Ntdc, :Ntdc], ex[:Ntdc],
|
|
|
|
a_lo, a_up, indI, xc, Nt)
|
|
|
|
a_lo, a_up, indI, xc, Nt, *opt0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# tnold = tn
|
|
|
|
# tnold = tn
|
|
|
|
if def_nr in [3, 4]:
|
|
|
|
if def_nr in [3, 4]:
|
|
|
@ -2087,12 +1974,9 @@ class SpecData1D(PlotData):
|
|
|
|
IJ = 0
|
|
|
|
IJ = 0
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
J = IJ + Nx1
|
|
|
|
J = IJ + Nx1
|
|
|
|
pdf[1:Nx1, i, ts] = pdf[
|
|
|
|
pdf[1:Nx1, i, ts] += fxind[IJ:J].T * dt
|
|
|
|
1:Nx1, i, ts] + fxind[IJ:J].T * dt
|
|
|
|
err[1:Nx1, i, ts] += (err0[IJ:J].T * dt) ** 2
|
|
|
|
err[1:Nx1, i, ts] = err[
|
|
|
|
terr[1:Nx1, i, ts] += (terr0[IJ:J].T * dt)
|
|
|
|
1:Nx1, i, ts] + (err0[IJ:J].T * dt) ** 2
|
|
|
|
|
|
|
|
terr[1:Nx1, i, ts] = terr[
|
|
|
|
|
|
|
|
1:Nx1, i, ts] + (terr0[IJ:J].T * dt)
|
|
|
|
|
|
|
|
IJ = J
|
|
|
|
IJ = J
|
|
|
|
# end %do
|
|
|
|
# end %do
|
|
|
|
# end
|
|
|
|
# end
|
|
|
@ -2111,12 +1995,9 @@ class SpecData1D(PlotData):
|
|
|
|
for i in range(1, Nx1): # = 2:Nx1
|
|
|
|
for i in range(1, Nx1): # = 2:Nx1
|
|
|
|
J = IJ + Nx1
|
|
|
|
J = IJ + Nx1
|
|
|
|
# %*CC
|
|
|
|
# %*CC
|
|
|
|
pdf[1:Nx1, i, tn - ts] = pdf[1:Nx1,
|
|
|
|
pdf[1:Nx1, i, tn - ts] += fxind[IJ:J].T * dt
|
|
|
|
i, tn - ts] + fxind[IJ:J].T * dt
|
|
|
|
err[1:Nx1, i, tn - ts] += (err0[IJ:J].T * dt) ** 2
|
|
|
|
err[1:Nx1, i, tn - ts] = err[1:Nx1, i,
|
|
|
|
terr[1:Nx1, i, tn - ts] += (terr0[IJ:J].T * dt)
|
|
|
|
tn - ts] + (err0[IJ:J].T * dt) ** 2
|
|
|
|
|
|
|
|
terr[
|
|
|
|
|
|
|
|
1:Nx1, i, tn - ts] = terr[1:Nx1, i, tn - ts] + (terr0[IJ:J].T * dt)
|
|
|
|
|
|
|
|
IJ = J
|
|
|
|
IJ = J
|
|
|
|
# end %do
|
|
|
|
# end %do
|
|
|
|
# end
|
|
|
|
# end
|
|
|
@ -2129,10 +2010,9 @@ class SpecData1D(PlotData):
|
|
|
|
# linear.
|
|
|
|
# linear.
|
|
|
|
# positive wave period
|
|
|
|
# positive wave period
|
|
|
|
BIG[:Ntdc, :Ntdc] = covinput(BIG[:Ntdc, :Ntdc],
|
|
|
|
BIG[:Ntdc, :Ntdc] = covinput(BIG[:Ntdc, :Ntdc],
|
|
|
|
R0, R1, R2, R3, R4,
|
|
|
|
R, tn, ts, tnold)
|
|
|
|
tn, ts, tnold)
|
|
|
|
fxind, err0, terr0 = rind(BIG[:Ntdc, :Ntdc], ex[:Ntdc],
|
|
|
|
[fxind, err0, terr0] = rind(BIG[:Ntdc, :Ntdc], ex[:Ntdc],
|
|
|
|
a_lo, a_up, indI, xc, Nt)
|
|
|
|
a_lo, a_up, indI, xc, Nt, *opt0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[fxind,err0] = rind(BIG(1:Ntdc,1:Ntdc),ex,a_lo,a_up,indI, xc,Nt,opt0{:})
|
|
|
|
#[fxind,err0] = rind(BIG(1:Ntdc,1:Ntdc),ex,a_lo,a_up,indI, xc,Nt,opt0{:})
|
|
|
|
# tnold = tn
|
|
|
|
# tnold = tn
|
|
|
@ -2156,21 +2036,15 @@ class SpecData1D(PlotData):
|
|
|
|
# Max to the crossing of level u (M,m,TMd).
|
|
|
|
# Max to the crossing of level u (M,m,TMd).
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
for i in range(1, Nx1):
|
|
|
|
J = IJ + Nx1
|
|
|
|
J = IJ + Nx1
|
|
|
|
pdf[1:Nx1, i, ts] = pdf[
|
|
|
|
pdf[1:Nx1, i, ts] += fxind[IJ:J] * dt # %*CC
|
|
|
|
1:Nx1, i, ts] + fxind[IJ:J] * dt # %*CC
|
|
|
|
err[1:Nx1, i, ts] += (err0[IJ:J] * dt) ** 2
|
|
|
|
err[1:Nx1, i, ts] = err[
|
|
|
|
terr[1:Nx1, i, ts] += (terr0[IJ:J] * dt)
|
|
|
|
1:Nx1, i, ts] + (err0[IJ:J] * dt) ** 2
|
|
|
|
|
|
|
|
terr[1:Nx1, i, ts] = terr[
|
|
|
|
|
|
|
|
1:Nx1, i, ts] + (terr0[IJ:J] * dt)
|
|
|
|
|
|
|
|
if (ts < tn - ts):
|
|
|
|
if (ts < tn - ts):
|
|
|
|
# exploiting the symmetry
|
|
|
|
# exploiting the symmetry
|
|
|
|
# %*CC
|
|
|
|
# %*CC
|
|
|
|
pdf[i, 1:Nx1, tn - ts] = pdf[i,
|
|
|
|
pdf[i, 1:Nx1, tn - ts] += fxind[IJ:J] * dt
|
|
|
|
1:Nx1, tn - ts] + fxind[IJ:J] * dt
|
|
|
|
err[i, 1:Nx1, tn - ts] += (err0[IJ:J] * dt) ** 2
|
|
|
|
err[i, 1:Nx1, tn - ts] = err[i, 1:Nx1,
|
|
|
|
terr[i, 1:Nx1, tn - ts] += (terr0[IJ:J] * dt)
|
|
|
|
tn - ts] + (err0[IJ:J] * dt) ** 2
|
|
|
|
|
|
|
|
terr[
|
|
|
|
|
|
|
|
i, 1:Nx1, tn - ts] = terr[i, 1:Nx1, tn - ts] + (terr0[IJ:J] * dt)
|
|
|
|
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
IJ = J
|
|
|
|
IJ = J
|
|
|
|
# end %do
|
|
|
|
# end %do
|
|
|
@ -2179,20 +2053,15 @@ class SpecData1D(PlotData):
|
|
|
|
# from the crossing of level u to min (M,m,Tdm).
|
|
|
|
# from the crossing of level u to min (M,m,Tdm).
|
|
|
|
for i in range(1, Nx1): # = 2:Nx1,
|
|
|
|
for i in range(1, Nx1): # = 2:Nx1,
|
|
|
|
J = IJ + Nx1
|
|
|
|
J = IJ + Nx1
|
|
|
|
pdf[1:Nx1, i, tn - ts] = pdf[1:Nx1,
|
|
|
|
pdf[1:Nx1, i, tn - ts] += fxind[IJ:J] * dt
|
|
|
|
i, tn - ts] + fxind[IJ:J] * dt
|
|
|
|
err[1:Nx1, i, tn - ts] += (err0[IJ:J] * dt) ** 2
|
|
|
|
err[1:Nx1, i, tn - ts] = err[1:Nx1, i,
|
|
|
|
|
|
|
|
tn - ts] + (err0[IJ:J] * dt) ** 2
|
|
|
|
|
|
|
|
terr[
|
|
|
|
terr[
|
|
|
|
1:Nx1, i, tn - ts] = terr[1:Nx1, i, tn - ts] + (terr0[IJ:J] * dt)
|
|
|
|
1:Nx1, i, tn - ts] += (terr0[IJ:J] * dt)
|
|
|
|
if (ts < tn - ts + 1):
|
|
|
|
if (ts < tn - ts + 1):
|
|
|
|
# exploiting the symmetry
|
|
|
|
# exploiting the symmetry
|
|
|
|
pdf[i, 1:Nx1, ts] = pdf[
|
|
|
|
pdf[i, 1:Nx1, ts] += fxind[IJ:J] * dt
|
|
|
|
i, 1:Nx1, ts] + fxind[IJ:J] * dt
|
|
|
|
err[i, 1:Nx1, ts] += (err0[IJ:J] * dt) ** 2
|
|
|
|
err[i, 1:Nx1, ts] = err[
|
|
|
|
terr[i, 1:Nx1, ts] += (terr0[IJ:J] * dt)
|
|
|
|
i, 1:Nx1, ts] + (err0[IJ:J] * dt) ** 2
|
|
|
|
|
|
|
|
terr[i, 1:Nx1, ts] = terr[
|
|
|
|
|
|
|
|
i, 1:Nx1, ts] + (terr0[IJ:J] * dt)
|
|
|
|
|
|
|
|
# end %ENDIF
|
|
|
|
# end %ENDIF
|
|
|
|
IJ = J
|
|
|
|
IJ = J
|
|
|
|
# end %do
|
|
|
|
# end %do
|
|
|
@ -2263,7 +2132,7 @@ class SpecData1D(PlotData):
|
|
|
|
Cov(X''(t),X(s)) = r''(s-t) = r''(|s-t|)
|
|
|
|
Cov(X''(t),X(s)) = r''(s-t) = r''(|s-t|)
|
|
|
|
Cov(X''(t),X''(s)) = r''''(s-t) = r''''(|s-t|)
|
|
|
|
Cov(X''(t),X''(s)) = r''''(s-t) = r''''(|s-t|)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
R0, R1, R2, R3, R4 = R.T
|
|
|
|
R0, R1, R2, R3, R4 = R[:, :5].T
|
|
|
|
if (ts > 1):
|
|
|
|
if (ts > 1):
|
|
|
|
shft = 1
|
|
|
|
shft = 1
|
|
|
|
N = tn + 5 + shft
|
|
|
|
N = tn + 5 + shft
|
|
|
@ -4006,17 +3875,17 @@ class SpecData2D(PlotData):
|
|
|
|
# ftype = self.freqtype
|
|
|
|
# ftype = self.freqtype
|
|
|
|
freq = self.args[1]
|
|
|
|
freq = self.args[1]
|
|
|
|
theta = linspace(-pi, pi, ntOld)
|
|
|
|
theta = linspace(-pi, pi, ntOld)
|
|
|
|
[F, T] = meshgrid(freq, theta)
|
|
|
|
# [F, T] = meshgrid(freq, theta)
|
|
|
|
|
|
|
|
|
|
|
|
dtheta = self.theta[1] - self.theta[0]
|
|
|
|
dtheta = self.theta[1] - self.theta[0]
|
|
|
|
self.theta[nt] = self.theta[nt - 1] + dtheta
|
|
|
|
self.theta[nt] = self.theta[nt - 1] + dtheta
|
|
|
|
self.data[nt, :] = self.data[0, :]
|
|
|
|
self.data[nt, :] = self.data[0, :]
|
|
|
|
self.data = interp2(freq,
|
|
|
|
self.data = interp2d(freq,
|
|
|
|
np.vstack([self.theta[0] - dtheta,
|
|
|
|
np.vstack([self.theta[0] - dtheta,
|
|
|
|
self.theta]),
|
|
|
|
self.theta]),
|
|
|
|
np.vstack([self.data[nt, :],
|
|
|
|
np.vstack([self.data[nt, :],
|
|
|
|
self.data]), F, T,
|
|
|
|
self.data]),
|
|
|
|
method)
|
|
|
|
kind=method)(freq, theta)
|
|
|
|
self.args[0] = theta
|
|
|
|
self.args[0] = theta
|
|
|
|
|
|
|
|
|
|
|
|
elif stype == 'k2d':
|
|
|
|
elif stype == 'k2d':
|
|
|
@ -4274,33 +4143,16 @@ class SpecData2D(PlotData):
|
|
|
|
self.labels.zlab = labels[2]
|
|
|
|
self.labels.zlab = labels[2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_specdata():
|
|
|
|
|
|
|
|
import wafo.spectrum.models as sm
|
|
|
|
|
|
|
|
Sj = sm.Jonswap()
|
|
|
|
|
|
|
|
S = Sj.tospecdata()
|
|
|
|
|
|
|
|
me, va, sk, ku = S.stats_nl(moments='mvsk')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
import matplotlib
|
|
|
|
import matplotlib
|
|
|
|
matplotlib.interactive(True)
|
|
|
|
matplotlib.interactive(True)
|
|
|
|
from wafo.spectrum import models as sm
|
|
|
|
from wafo.spectrum import models as sm
|
|
|
|
|
|
|
|
|
|
|
|
w = linspace(0, 3, 100)
|
|
|
|
|
|
|
|
Sj = sm.Jonswap()
|
|
|
|
Sj = sm.Jonswap()
|
|
|
|
S = Sj.tospecdata()
|
|
|
|
S = Sj.tospecdata()
|
|
|
|
|
|
|
|
|
|
|
|
f = S.to_t_pdf(pdef='Tc', paramt=(0, 10, 51), speed=7)
|
|
|
|
|
|
|
|
f.err
|
|
|
|
|
|
|
|
f.plot()
|
|
|
|
|
|
|
|
f.show()
|
|
|
|
|
|
|
|
# pdfplot(f)
|
|
|
|
|
|
|
|
# hold on,
|
|
|
|
|
|
|
|
# plot(f.x{:}, f.f+f.err,'r',f.x{:}, f.f-f.err) estimated error bounds
|
|
|
|
|
|
|
|
# hold off
|
|
|
|
|
|
|
|
# S = SpecData1D(Sj(w),w)
|
|
|
|
|
|
|
|
R = S.tocovdata(nr=1)
|
|
|
|
R = S.tocovdata(nr=1)
|
|
|
|
S1 = S.copy()
|
|
|
|
|
|
|
|
Si = R.tospecdata()
|
|
|
|
Si = R.tospecdata()
|
|
|
|
ns = 5000
|
|
|
|
ns = 5000
|
|
|
|
dt = .2
|
|
|
|
dt = .2
|
|
|
|