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) ind, ix = clib.findrfc(y, hmin)
return np.sort(ind[:ix]) 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 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 Parameters
---------- ----------
f_mM = the min2max Markov matrix, fmM = the min2max Markov matrix,
f_Mm = the max2min Markov matrix, fMm = the max2min Markov matrix,
Returns Returns
------- -------
@ -679,12 +679,12 @@ def mctp2rfc(f_mM, f_Mm=None):
''' '''
if f_Mm is None: if fMm is None:
f_mM = np.atleast_1d(f_mM) fmM = np.atleast_1d(fmM)
f_Mm = f_mM.copy() fMm = fmM.copy()
else: 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) N = max(f_mM.shape)
f_max = np.sum(f_mM, axis=1) f_max = np.sum(f_mM, axis=1)
f_min = np.sum(f_mM, axis=0) f_min = np.sum(f_mM, axis=0)

@ -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]$'

@ -1375,11 +1375,16 @@ class Spreading(object):
>>> import pylab as plb >>> import pylab as plb
>>> D = wsm.Spreading('cos2s',s_a=10.0) >>> 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) >>> w = plb.linspace(0,3,257)
>>> theta = plb.linspace(-pi,pi,129) >>> theta = plb.linspace(-pi,pi,129)
>>> t = plb.contour(D(theta,w)[0].squeeze()) >>> 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 >>> theta0 = lambda w: w*plb.pi/6.0
>>> D2 = wsm.Spreading('cos2s',theta0=theta0) >>> D2 = wsm.Spreading('cos2s',theta0=theta0)
>>> t = plb.contour(D2(theta,w)[0]) >>> 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 numpy import exp, expm1, inf, nan, pi, hstack, where, atleast_1d, cos, sin
from dispersion_relation import w2k, k2w from dispersion_relation import w2k, k2w
def hyperbolic_ratio(a, b, sa, sb): def hyperbolic_ratio(a, b, sa, sb):
''' '''
Return ratio of hyperbolic functions Return ratio of hyperbolic functions

Loading…
Cancel
Save