Fixed doctests

master
pbrod 9 years ago
parent 9a2990e463
commit a855fcb0e9

@ -68,7 +68,7 @@ def rndnormnd(mean, cov, cases=1):
Example Example
------- -------
>>> mu = [0, 5] >>> mu = [0, 5]
>>> S = [[1 0.45], [0.45 0.25]] >>> S = [[1 0.45], [0.45, 0.25]]
>>> r = rndnormnd(mu, S, 1) >>> r = rndnormnd(mu, S, 1)
plot(r(:,1),r(:,2),'.') plot(r(:,1),r(:,2),'.')
@ -208,7 +208,8 @@ class CovData1D(PlotData):
>>> S = Sj.tospecdata() >>> S = Sj.tospecdata()
>>> R2 = S.tocovdata() >>> R2 = S.tocovdata()
>>> S1 = R2.tospecdata() >>> S1 = R2.tospecdata()
>>> abs(S1.data-S.data).max() >>> abs(S1.data-S.data).max() < 1e-4
True
>>> S1.plot('r-') >>> S1.plot('r-')
>>> S.plot('b:') >>> S.plot('b:')

@ -110,7 +110,8 @@ class CovarianceEstimator(object):
>>> x = wafo.data.sea() >>> x = wafo.data.sea()
>>> ts = wo.mat2timeseries(x) >>> ts = wo.mat2timeseries(x)
>>> acf = ts.tocovdata(150) >>> acf = ts.tocovdata(150)
>>> h = acf.plot()
h = acf.plot()
''' '''
lag = self.lag lag = self.lag
window = self.window window = self.window

@ -20,7 +20,7 @@ included in WAFO
""" """
import numpy as np import numpy as np
from numpy import (loadtxt, nan)
import os import os
__path2data = os.path.dirname(os.path.realpath(__file__)) __path2data = os.path.dirname(os.path.realpath(__file__))
@ -31,7 +31,7 @@ _NANS = set(['nan', 'NaN', '-1.#IND00+00', '1.#IND00+00', '-1.#INF00+00'])
def _tofloat(x): def _tofloat(x):
return nan if x in _NANS else float(x or 0) return np.nan if x in _NANS else float(x or 0)
_MYCONVERTER = {} _MYCONVERTER = {}
@ -42,13 +42,13 @@ for i in range(2):
def _load(file): # @ReservedAssignment def _load(file): # @ReservedAssignment
""" local load function """ local load function
""" """
return loadtxt(os.path.join(__path2data, file)) return np.loadtxt(os.path.join(__path2data, file))
def _loadnan(file): # @ReservedAssignment def _loadnan(file): # @ReservedAssignment
""" local load function accepting nan's """ local load function accepting nan's
""" """
return loadtxt(os.path.join(__path2data, file), converters=_MYCONVERTER) return np.loadtxt(os.path.join(__path2data, file), converters=_MYCONVERTER)
def atlantic(): def atlantic():
@ -188,8 +188,8 @@ def gfaksr89():
>>> import pylab >>> import pylab
>>> import wafo >>> import wafo
>>> x = wafo.data.gfaksr89() >>> x = wafo.data.gfaksr89()
>>> h = pylab.plot(x[:,0],x[:,1])
h = pylab.plot(x[:,0],x[:,1])
See also See also
-------- --------
@ -378,7 +378,8 @@ def sfa89():
>>> import pylab >>> import pylab
>>> import wafo >>> import wafo
>>> x = wafo.data.sfa89() >>> x = wafo.data.sfa89()
>>> h = pylab.plot(x[:,0],x[:,1])
h = pylab.plot(x[:,0],x[:,1])
Acknowledgement Acknowledgement
---------------- ----------------
@ -415,7 +416,8 @@ def sn():
>>> import pylab >>> import pylab
>>> import wafo >>> import wafo
>>> x = wafo.data.sn() >>> x = wafo.data.sn()
>>> h = pylab.plot(x[:,0],x[:,1])
h = pylab.plot(x[:,0],x[:,1])
See also See also
-------- --------
@ -463,7 +465,8 @@ def yura87():
>>> import pylab >>> import pylab
>>> import wafo >>> import wafo
>>> x = wafo.data.yura87() >>> x = wafo.data.yura87()
>>> h = pylab.plot(x[:,0],x[:,1])
h = pylab.plot(x[:,0],x[:,1])
Acknowledgement: Acknowledgement:
----------------- -----------------

@ -1072,6 +1072,7 @@ class SpecData1D(PlotData):
>>> w = np.linspace(0,4,256) >>> w = np.linspace(0,4,256)
>>> S1 = Sj.tospecdata(w) #Make spectrum object from numerical values >>> S1 = Sj.tospecdata(w) #Make spectrum object from numerical values
>>> S = sm.SpecData1D(Sj(w),w) # Alternatively do it manually >>> S = sm.SpecData1D(Sj(w),w) # Alternatively do it manually
mm = S.to_mm_pdf() mm = S.to_mm_pdf()
mm.plot() mm.plot()
mm.plot(plotflag=1) mm.plot(plotflag=1)
@ -1174,12 +1175,11 @@ class SpecData1D(PlotData):
>>> 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 = S.to_t_pdf(pdef='Tc', paramt=(0, 10, 51), speed=7)
>>> h = f.plot()
estimated error bounds
>>> h2 = plb.plot(f.args, f.data+f.err, 'r', f.args, f.data-f.err, 'r')
>>> plb.close('all') h = f.plot()
# estimated error bounds
h2 = plb.plot(f.args, f.data+f.err, 'r', f.args, f.data-f.err, 'r')
plb.close('all')
See also See also
-------- --------
@ -3955,11 +3955,13 @@ class SpecData2D(PlotData):
>>> D = sm.Spreading() >>> D = sm.Spreading()
>>> SD = D.tospecdata2d(sm.Jonswap().tospecdata(),nt=101) >>> SD = D.tospecdata2d(sm.Jonswap().tospecdata(),nt=101)
>>> m,mtext = SD.moment(nr=2,vari='xyt') >>> m,mtext = SD.moment(nr=2,vari='xyt')
>>> np.round(m,3),mtext >>> np.allclose(np.round(m,3),
(array([ 3.061, 0.132, -0. , 2.13 , 0.011, 0.008, 1.677, -0., ... [ 3.061, 0.132, -0. , 2.13 , 0.011, 0.008, 1.677, -0.,
0.109, 0.109]), ... 0.109, 0.109])
['m0', 'mx', 'my', 'mt', 'mxx', 'myy', 'mtt', 'mxy', 'mxt', True
'myt']) >>> mtext == ['m0', 'mx', 'my', 'mt', 'mxx', 'myy', 'mtt', 'mxy',
... 'mxt', 'myt']
True
References References
---------- ----------

@ -297,17 +297,18 @@ def jonswap_peakfact(Hm0, Tp):
>>> [T,H] = plb.meshgrid(Tp,Hm0) >>> [T,H] = plb.meshgrid(Tp,Hm0)
>>> gam = wsm.jonswap_peakfact(H,T) >>> gam = wsm.jonswap_peakfact(H,T)
>>> v = plb.arange(0,8) >>> v = plb.arange(0,8)
>>> h = plb.contourf(Tp,Hm0,gam,v);h=plb.colorbar()
>>> Hm0 = plb.arange(1,11) >>> Hm0 = plb.arange(1,11)
>>> Tp = plb.linspace(2,16) >>> Tp = plb.linspace(2,16)
>>> T,H = plb.meshgrid(Tp,Hm0) >>> T,H = plb.meshgrid(Tp,Hm0)
>>> gam = wsm.jonswap_peakfact(H,T) >>> gam = wsm.jonswap_peakfact(H,T)
>>> h = plb.plot(Tp,gam.T)
>>> h = plb.xlabel('Tp [s]')
>>> h = plb.ylabel('Peakedness parameter')
>>> plb.close('all') h = plb.contourf(Tp,Hm0,gam,v);h=plb.colorbar()
h = plb.plot(Tp,gam.T)
h = plb.xlabel('Tp [s]')
h = plb.ylabel('Peakedness parameter')
plb.close('all')
See also See also
-------- --------
@ -495,13 +496,13 @@ class Jonswap(ModelSpectrum):
>>> import pylab as plb >>> import pylab as plb
>>> import wafo.spectrum.models as wsm >>> import wafo.spectrum.models as wsm
>>> S = wsm.Jonswap(Hm0=7, Tp=11,gamma=1) >>> S = wsm.Jonswap(Hm0=7, Tp=11,gamma=1)
>>> w = plb.linspace(0,5)
>>> h = plb.plot(w,S(w))
>>> S2 = wsm.Bretschneider(Hm0=7, Tp=11) >>> S2 = wsm.Bretschneider(Hm0=7, Tp=11)
>>> w = plb.linspace(0,5)
>>> all(abs(S(w)-S2(w))<1.e-7) >>> all(abs(S(w)-S2(w))<1.e-7)
True True
>>> plb.close('all')
h = plb.plot(w,S(w))
plb.close('all')
See also See also
-------- --------
@ -755,11 +756,12 @@ class Tmaspec(Jonswap):
>>> import pylab as plb >>> import pylab as plb
>>> w = plb.linspace(0,2.5) >>> w = plb.linspace(0,2.5)
>>> S = wsm.Tmaspec(h=10,gamma=1) # Bretschneider spectrum Hm0=7, Tp=11 >>> S = wsm.Tmaspec(h=10,gamma=1) # Bretschneider spectrum Hm0=7, Tp=11
>>> o=plb.plot(w,S(w))
>>> o=plb.plot(w,S(w,h=21)) o=plb.plot(w,S(w))
>>> o=plb.plot(w,S(w,h=42)) o=plb.plot(w,S(w,h=21))
>>> plb.show() o=plb.plot(w,S(w,h=42))
>>> plb.close('all') plb.show()
plb.close('all')
See also See also
--------- ---------
@ -850,7 +852,8 @@ class Torsethaugen(ModelSpectrum):
>>> import pylab as plb >>> import pylab as plb
>>> w = plb.linspace(0,4) >>> w = plb.linspace(0,4)
>>> S = wsm.Torsethaugen(Hm0=6, Tp=8) >>> S = wsm.Torsethaugen(Hm0=6, Tp=8)
>>> h=plb.plot(w,S(w),w,S.wind(w),w,S.swell(w))
h=plb.plot(w,S(w),w,S.wind(w),w,S.swell(w))
See also See also
-------- --------
@ -1429,25 +1432,26 @@ class Spreading(object):
# Make directionale spectrum # Make directionale spectrum
>>> S = wsm.Jonswap().tospecdata() >>> S = wsm.Jonswap().tospecdata()
>>> SD = D.tospecdata2d(S) >>> 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())
# Make frequency dependent direction spreading # 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])
h = SD.plot()
t = plb.contour(D(theta,w)[0].squeeze())
t = plb.contour(D2(theta,w)[0])
# Plot all spreading functions # Plot all spreading functions
>>> alltypes = ('cos2s','box','mises','poisson','sech2','wrap_norm') alltypes = ('cos2s','box','mises','poisson','sech2','wrap_norm')
>>> for ix in range(len(alltypes)): for ix in range(len(alltypes)):
... D3 = wsm.Spreading(alltypes[ix]) ... D3 = wsm.Spreading(alltypes[ix])
... t = plb.figure(ix) ... t = plb.figure(ix)
... t = plb.contour(D3(theta,w)[0]) ... t = plb.contour(D3(theta,w)[0])
... t = plb.title(alltypes[ix]) ... t = plb.title(alltypes[ix])
>>> plb.close('all') plb.close('all')
See also See also
@ -2007,7 +2011,8 @@ class Spreading(object):
>>> S = wsm.Jonswap().tospecdata() >>> S = wsm.Jonswap().tospecdata()
>>> D = wsm.Spreading('cos2s') >>> D = wsm.Spreading('cos2s')
>>> SD = D.tospecdata2d(S) >>> SD = D.tospecdata2d(S)
>>> h = SD.plot()
h = SD.plot()
See also spreading, rotspec, jonswap, torsethaugen See also spreading, rotspec, jonswap, torsethaugen
''' '''

@ -196,7 +196,7 @@ class TransformEstimator(object):
>>> tp = ts.turning_points() >>> tp = ts.turning_points()
>>> mm = tp.cycle_pairs() >>> mm = tp.cycle_pairs()
>>> lc = mm.level_crossings() >>> lc = mm.level_crossings()
>>> g0, g0emp = lc.trdata(monitor=True) # Monitor the development >>> g0, g0emp = lc.trdata(monitor=False) # Monitor the development
>>> g1, g1emp = lc.trdata(gvar=0.5 ) # Equal weight on all points >>> g1, g1emp = lc.trdata(gvar=0.5 ) # Equal weight on all points
>>> g2, g2emp = lc.trdata(gvar=[3.5, 0.5, 3.5]) # Less weight on ends >>> g2, g2emp = lc.trdata(gvar=[3.5, 0.5, 3.5]) # Less weight on ends
>>> int(S.tr.dist2gauss()*100) >>> int(S.tr.dist2gauss()*100)
@ -213,6 +213,7 @@ class TransformEstimator(object):
g0.plot() # Check the fit. g0.plot() # Check the fit.
See also See also
--------
troptset, dat2tr, trplot, findcross, smooth troptset, dat2tr, trplot, findcross, smooth
NB! the transformated data will be N(0,1) NB! the transformated data will be N(0,1)
@ -389,7 +390,7 @@ class TransformEstimator(object):
... sigma=Hs/4, ysigma=Hs/4) ... sigma=Hs/4, ysigma=Hs/4)
>>> xs = S.sim(ns=2**16, iseed=10) >>> xs = S.sim(ns=2**16, iseed=10)
>>> ts = mat2timeseries(xs) >>> ts = mat2timeseries(xs)
>>> g0, g0emp = ts.trdata(monitor=True) >>> g0, g0emp = ts.trdata(monitor=False)
>>> g1, g1emp = ts.trdata(method='m', gvar=0.5 ) >>> g1, g1emp = ts.trdata(method='m', gvar=0.5 )
>>> g2, g2emp = ts.trdata(method='n', gvar=[3.5, 0.5, 3.5]) >>> g2, g2emp = ts.trdata(method='n', gvar=[3.5, 0.5, 3.5])
>>> int(S.tr.dist2gauss()*100) >>> int(S.tr.dist2gauss()*100)

@ -245,14 +245,15 @@ class TransferFunction(object):
>>> stypes = ['n', 'n_x', 'n_y']; >>> stypes = ['n', 'n_x', 'n_y'];
>>> tf = TransferFunction(pos=(0, 0, 0), h=50) >>> tf = TransferFunction(pos=(0, 0, 0), h=50)
>>> vals = [] >>> vals = []
>>> fh = plt.plot(t, eta0.real, 'r.')
>>> plt.hold(True)
>>> for i,stype in enumerate(stypes): >>> for i,stype in enumerate(stypes):
... tf.sensortype = stype ... tf.sensortype = stype
... Hw, Gwt = tf.tran(w0,th0) ... Hw, Gwt = tf.tran(w0,th0)
... vals.append((Hw*Gwt*eta0).real.ravel()) ... vals.append((Hw*Gwt*eta0).real.ravel())
fh = plt.plot(t, vals[i]) fh = plt.plot(t, eta0.real, 'r.')
plt.hold(True)
for val in vals:
fh = plt.plot(t, val)
plt.show() plt.show()
@ -543,8 +544,10 @@ def wave_pressure(z, Hm0, h=10000, g=9.81, rho=1028):
----- -----
>>> import pylab as plt >>> import pylab as plt
>>> z = -np.linspace(10,20) >>> z = -np.linspace(10,20)
>>> fh = plt.plot(z, wave_pressure(z, Hm0=1, h=20)) >>> p = wave_pressure(z, Hm0=1, h=20)
>>> plt.show()
fh = plt.plot(z, p)
plt.show()
See also See also
-------- --------

@ -5,7 +5,7 @@ k2w - Translates from wave number to frequency
w2k - Translates from frequency to wave number w2k - Translates from frequency to wave number
""" """
import warnings import warnings
#import numpy as np # import numpy as np
from numpy import (atleast_1d, sqrt, ones_like, zeros_like, arctan2, where, from numpy import (atleast_1d, sqrt, ones_like, zeros_like, arctan2, where,
tanh, any, sin, cos, sign, inf, tanh, any, sin, cos, sign, inf,
flatnonzero, finfo, cosh, abs) flatnonzero, finfo, cosh, abs)
@ -124,13 +124,13 @@ def w2k(w, theta=0.0, h=inf, g=9.81, count_limit=100):
>>> import pylab as plb >>> import pylab as plb
>>> import wafo.wave_theory.dispersion_relation as wsd >>> import wafo.wave_theory.dispersion_relation as wsd
>>> w = plb.linspace(0,3); >>> w = plb.linspace(0,3);
>>> h = plb.plot(w,w2k(w)[0])
>>> wsd.w2k(range(4))[0] >>> wsd.w2k(range(4))[0]
array([ 0. , 0.1019368 , 0.4077472 , 0.91743119]) array([ 0. , 0.1019368 , 0.4077472 , 0.91743119])
>>> wsd.w2k(range(4),h=20)[0] >>> wsd.w2k(range(4),h=20)[0]
array([ 0. , 0.10503601, 0.40774726, 0.91743119]) array([ 0. , 0.10503601, 0.40774726, 0.91743119])
>>> plb.close('all') h = plb.plot(w,w2k(w)[0])
plb.close('all')
See also See also
-------- --------

Loading…
Cancel
Save