|
|
@ -160,18 +160,21 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
PLOTSPEC Plot a spectral density
|
|
|
|
PLOTSPEC Plot a spectral density
|
|
|
|
|
|
|
|
|
|
|
|
CALL: plotspec(S,plotflag,linetype)
|
|
|
|
Parameters
|
|
|
|
|
|
|
|
----------
|
|
|
|
S = an array of spectral density structs:
|
|
|
|
S : SpecData1D or SpecData2D object
|
|
|
|
1D (see dat2spec)
|
|
|
|
defining spectral density.
|
|
|
|
2D (see createspec)
|
|
|
|
linetype : string
|
|
|
|
|
|
|
|
defining color and linetype, see plot for possibilities
|
|
|
|
|
|
|
|
flag : scalar integer
|
|
|
|
|
|
|
|
defining the type of plot
|
|
|
|
1D:
|
|
|
|
1D:
|
|
|
|
plotflag = 1 plots the density, S, (default)
|
|
|
|
1 plots the density, S, (default)
|
|
|
|
2 plot 10log10(S)
|
|
|
|
2 plot 10log10(S)
|
|
|
|
3 plots both the above plots
|
|
|
|
3 plots both the above plots
|
|
|
|
2D:
|
|
|
|
2D:
|
|
|
|
Directional spectra: S(w,theta), S(f,theta)
|
|
|
|
Directional spectra: S(w,theta), S(f,theta)
|
|
|
|
plotflag = 1 polar plot S (default)
|
|
|
|
1 polar plot S (default)
|
|
|
|
2 plots spectral density and the directional
|
|
|
|
2 plots spectral density and the directional
|
|
|
|
spreading, int S(w,theta) dw or int S(f,theta) df
|
|
|
|
spreading, int S(w,theta) dw or int S(f,theta) df
|
|
|
|
3 plots spectral density and the directional
|
|
|
|
3 plots spectral density and the directional
|
|
|
@ -181,18 +184,16 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
6 contour plot of S
|
|
|
|
6 contour plot of S
|
|
|
|
7 filled contour plot of S
|
|
|
|
7 filled contour plot of S
|
|
|
|
Wavenumber spectra: S(k1,k2)
|
|
|
|
Wavenumber spectra: S(k1,k2)
|
|
|
|
plotflag = 1 contour plot of S (default)
|
|
|
|
1 contour plot of S (default)
|
|
|
|
2 filled contour plot of S
|
|
|
|
2 filled contour plot of S
|
|
|
|
lintype : specify color and lintype, see PLOT for possibilities.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOTE: - lintype may be given anywhere after S.
|
|
|
|
Example
|
|
|
|
|
|
|
|
-------
|
|
|
|
Examples
|
|
|
|
|
|
|
|
>>> import numpy as np
|
|
|
|
>>> import numpy as np
|
|
|
|
>>> import wafo.spectrum.models as sm
|
|
|
|
>>> import wafo.spectrum as ws
|
|
|
|
>>> Sj = sm.Jonswap(Hm0=3, Tp=7)
|
|
|
|
>>> Sj = ws.models.Jonswap(Hm0=3, Tp=7)
|
|
|
|
>>> S = Sj.tospecdata()
|
|
|
|
>>> S = Sj.tospecdata()
|
|
|
|
>>> plotspec(S,1)
|
|
|
|
>>> ws.plotspec(S,flag=1)
|
|
|
|
|
|
|
|
|
|
|
|
S = demospec('dir'); S2 = mkdspec(jonswap,spreading);
|
|
|
|
S = demospec('dir'); S2 = mkdspec(jonswap,spreading);
|
|
|
|
plotspec(S,2), hold on
|
|
|
|
plotspec(S,2), hold on
|
|
|
@ -206,7 +207,6 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
See also dat2spec, createspec, simpson
|
|
|
|
See also dat2spec, createspec, simpson
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# label the contour levels
|
|
|
|
# label the contour levels
|
|
|
|
txtFlag = 0;
|
|
|
|
txtFlag = 0;
|
|
|
|
LegendOn = 1;
|
|
|
|
LegendOn = 1;
|
|
|
@ -281,13 +281,13 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
for i, fp in enumerate(Fp.tolist()):
|
|
|
|
for i, fp in enumerate(Fp.tolist()):
|
|
|
|
txt.append(('fp%d = %0.2g' % (i, fp)) + funit)
|
|
|
|
txt.append(('fp%d = %0.2g' % (i, fp)) + funit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
txt = ''.join(txt)
|
|
|
|
if (flag == 3):
|
|
|
|
if (flag == 3):
|
|
|
|
plotbackend.subplot(2, 1, 1)
|
|
|
|
plotbackend.subplot(2, 1, 1)
|
|
|
|
if (flag == 1) or (flag == 3):#% Plot in normal scale
|
|
|
|
if (flag == 1) or (flag == 3):#% Plot in normal scale
|
|
|
|
plotbackend.plot(np.vstack([Fp, Fp]), np.vstack([zeros(len(indm)), data.take(indm)]), ':',
|
|
|
|
plotbackend.plot(np.vstack([Fp, Fp]), np.vstack([zeros(len(indm)), data.take(indm)]), ':', label=txt)
|
|
|
|
freq, data, linetype)
|
|
|
|
plotbackend.plot(freq, data, linetype)
|
|
|
|
|
|
|
|
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:' )
|
|
|
@ -299,9 +299,9 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
a1 = max(min(Fn, 10 * max(Fp)), a[1]);
|
|
|
|
a1 = max(min(Fn, 10 * max(Fp)), a[1]);
|
|
|
|
|
|
|
|
|
|
|
|
plotbackend.axis([0, a1 , 0, max(1.01 * maxS, a[3])])
|
|
|
|
plotbackend.axis([0, a1 , 0, max(1.01 * maxS, a[3])])
|
|
|
|
plotbackend.title('Spectral density')
|
|
|
|
#plotbackend.title('Spectral density')
|
|
|
|
plotbackend.xlabel(xlbl_txt)
|
|
|
|
#plotbackend.xlabel(xlbl_txt)
|
|
|
|
plotbackend.ylabel(ylbl1_txt)
|
|
|
|
#plotbackend.ylabel(ylbl1_txt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (flag == 3):
|
|
|
|
if (flag == 3):
|
|
|
@ -310,8 +310,9 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
if (flag == 2) or (flag == 3) : # Plot in logaritmic scale
|
|
|
|
if (flag == 2) or (flag == 3) : # Plot in logaritmic scale
|
|
|
|
ind = np.flatnonzero(data > 0)
|
|
|
|
ind = np.flatnonzero(data > 0)
|
|
|
|
|
|
|
|
|
|
|
|
plotbackend.plot(np.vstack([Fp, Fp]), np.vstack((min(10 * log10(data.take(ind) / maxS)).repeat(len(Fp)),
|
|
|
|
plotbackend.plot(np.vstack([Fp, Fp]),
|
|
|
|
10 * log10(data.take(indm) / maxS))), ':')
|
|
|
|
np.vstack((min(10 * log10(data.take(ind) / maxS)).repeat(len(Fp)),
|
|
|
|
|
|
|
|
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:' )
|
|
|
@ -319,13 +320,21 @@ def plotspec(specdata, linetype='b-', flag=1):
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
plotbackend.plot(freq[ind], 10 * log10(data[ind] / maxS), linetype)
|
|
|
|
plotbackend.plot(freq[ind], 10 * log10(data[ind] / maxS), linetype)
|
|
|
|
|
|
|
|
|
|
|
|
# if ih, a=axis; else a=[0 0 0 0]; end
|
|
|
|
a = plotbackend.axis()
|
|
|
|
# axis([0 max(min(Fn,max(10*Fp)),a(2)) -20 max(1.01*10*log10(1),a(4))]) % log10(maxS)
|
|
|
|
|
|
|
|
# title('Spectral density')
|
|
|
|
a1 = Fn
|
|
|
|
# xlabel(xlbl_txt)
|
|
|
|
if (Fp > 0):
|
|
|
|
# ylabel(ylbl2_txt )
|
|
|
|
a1 = max(min(Fn, 10 * max(Fp)), a[1]);
|
|
|
|
#
|
|
|
|
|
|
|
|
# if LegendOn
|
|
|
|
plotbackend.axis([0, a1 , -20, max(1.01 * 10 * log10(1), a[3])])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
specdata.labels.labelfig()
|
|
|
|
|
|
|
|
#plotbackend.title('Spectral density')
|
|
|
|
|
|
|
|
#plotbackend.xlabel(xlbl_txt)
|
|
|
|
|
|
|
|
plotbackend.ylabel(ylbl2_txt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if LegendOn:
|
|
|
|
|
|
|
|
plotbackend.legend()
|
|
|
|
# if isfield(S,'CI'),
|
|
|
|
# if isfield(S,'CI'),
|
|
|
|
# legend(txt{:},txtCI,1)
|
|
|
|
# legend(txt{:},txtCI,1)
|
|
|
|
# else
|
|
|
|
# else
|
|
|
@ -3148,7 +3157,7 @@ class SpecData1D(WafoData):
|
|
|
|
title = 'Directional Spectrum'
|
|
|
|
title = 'Directional Spectrum'
|
|
|
|
if self.freqtype.startswith('w'):
|
|
|
|
if self.freqtype.startswith('w'):
|
|
|
|
labels[0] = 'Frequency [rad/s]'
|
|
|
|
labels[0] = 'Frequency [rad/s]'
|
|
|
|
labels[2] = r'S(w,$\theta$) $[m^2 s / rad^2]$'
|
|
|
|
labels[2] = r'S($\omega$,$\theta$) $[m^2 s / rad^2]$'
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
labels[0] = 'Frequency [Hz]'
|
|
|
|
labels[0] = 'Frequency [Hz]'
|
|
|
|
labels[2] = r'S(f,$\theta$) $[m^2 s / rad]$'
|
|
|
|
labels[2] = r'S(f,$\theta$) $[m^2 s / rad]$'
|
|
|
@ -3161,7 +3170,7 @@ class SpecData1D(WafoData):
|
|
|
|
title = 'Spectral density'
|
|
|
|
title = 'Spectral density'
|
|
|
|
if self.freqtype.startswith('w'):
|
|
|
|
if self.freqtype.startswith('w'):
|
|
|
|
labels[0] = 'Frequency [rad/s]'
|
|
|
|
labels[0] = 'Frequency [rad/s]'
|
|
|
|
labels[1] = r'S(w) $[m^2 s/ rad]$'
|
|
|
|
labels[1] = r'S($\omega$) $[m^2 s/ rad]$'
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
labels[0] = 'Frequency [Hz]'
|
|
|
|
labels[0] = 'Frequency [Hz]'
|
|
|
|
labels[1] = r'S(f) $[m^2 s]$'
|
|
|
|
labels[1] = r'S(f) $[m^2 s]$'
|
|
|
|