Small updates

master
per.andreas.brodtkorb 13 years ago
parent 48e9b77785
commit 560995835b

@ -642,7 +642,7 @@ def findrfc(tp, hmin=0.0, method='clib'):
ind, ix = clib.findrfc(y, hmin)
return np.sort(ind[:ix])
def mctp2rfc(f_mM, f_Mm=None):
def mctp2rfc(fmM, fMm=None):
'''
Return Rainflow matrix given a Markov matrix of a Markov chain of turning points
@ -650,8 +650,8 @@ def mctp2rfc(f_mM, f_Mm=None):
Parameters
----------
f_mM = the min2max Markov matrix,
f_Mm = the max2min Markov matrix,
fmM = the min2max Markov matrix,
fMm = the max2min Markov matrix,
Returns
-------
@ -679,12 +679,12 @@ def mctp2rfc(f_mM, f_Mm=None):
'''
if f_Mm is None:
f_mM = np.atleast_1d(f_mM)
f_Mm = f_mM.copy()
if fMm is None:
fmM = np.atleast_1d(fmM)
fMm = fmM.copy()
else:
f_mM, f_Mm = np.atleast_1d(f_mM, f_Mm)
fmM, fMm = np.atleast_1d(fmM, fMm)
f_mM, f_Mm = fmM.copy(), fMm.copy()
N = max(f_mM.shape)
f_max = np.sum(f_mM, axis=1)
f_min = np.sum(f_mM, axis=0)

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

@ -1374,12 +1374,17 @@ class Spreading(object):
>>> import wafo.spectrum.models as wsm
>>> import pylab as plb
>>> D = wsm.Spreading('cos2s',s_a=10.0)
# Make directionale spectrum
>>> S = wsm.Jonswap().tospecdata()
>>> SD = D.tospecdata2d(S)
>>> h = SD.plot()
>>> w = plb.linspace(0,3,257)
>>> theta = plb.linspace(-pi,pi,129)
>>> t = plb.contour(D(theta,w)[0].squeeze())
# Make frequency dependent direction
# Make frequency dependent direction spreading
>>> theta0 = lambda w: w*plb.pi/6.0
>>> D2 = wsm.Spreading('cos2s',theta0=theta0)
>>> t = plb.contour(D2(theta,w)[0])

@ -7,7 +7,6 @@ import numpy as np
from numpy import exp, expm1, inf, nan, pi, hstack, where, atleast_1d, cos, sin
from dispersion_relation import w2k, k2w
def hyperbolic_ratio(a, b, sa, sb):
'''
Return ratio of hyperbolic functions

Loading…
Cancel
Save