diff --git a/pywafo/src/wafo/c_library.pyd b/pywafo/src/wafo/c_library.pyd index c0af1f9..4b0e899 100644 Binary files a/pywafo/src/wafo/c_library.pyd and b/pywafo/src/wafo/c_library.pyd differ diff --git a/pywafo/src/wafo/data/info.py b/pywafo/src/wafo/data/info.py index 83dc599..14ffa29 100644 --- a/pywafo/src/wafo/data/info.py +++ b/pywafo/src/wafo/data/info.py @@ -19,31 +19,31 @@ This module gives gives detailed information and easy access to all datasets included in WAFO """ -#from pylab import load -#from scipy.io import read_array -from numpy import (loadtxt,nan) +from numpy import (loadtxt, nan) import os -__path2data = os.path.dirname( os.path.realpath(__file__)) +__path2data = os.path.dirname(os.path.realpath(__file__)) -__all__ =['atlantic','gfaks89','gfaksr89','japansea','northsea','sea','sfa89', - 'sn','yura87'] +__all__ = ['atlantic', 'gfaks89', 'gfaksr89', 'japansea', 'northsea', 'sea', + 'sfa89', 'sn', 'yura87'] + +_NANS = set(['nan', 'NaN', '-1.#IND00+00', '1.#IND00+00', '-1.#INF00+00']) + +def _tofloat(x): + return nan if x in _NANS else float(x or 0) + +_MYCONVERTER = {} +for i in range(2): + _MYCONVERTER[i] = _tofloat def _load(file): """ local load function """ - return loadtxt(os.path.join(__path2data,file)) - -def _tofloat(x): - if x=='nan' or x=='NaN': - y = nan - else: - y = float(x or 0) - return y + return loadtxt(os.path.join(__path2data, file)) + def _loadnan(file): """ local load function accepting nan's """ - myconverter = {0: _tofloat, 1: _tofloat} - return loadtxt(os.path.join(__path2data,file),converters=myconverter) + return loadtxt(os.path.join(__path2data, file), converters=_MYCONVERTER) def atlantic(): """ @@ -437,6 +437,6 @@ def yura87(): japansea """ return _load('yura87.dat') -if __name__=='__main__': +if __name__ == '__main__': import doctest - doctest.testmod() \ No newline at end of file + doctest.testmod() diff --git a/pywafo/src/wafo/misc.py b/pywafo/src/wafo/misc.py index f0831b6..3a70072 100644 --- a/pywafo/src/wafo/misc.py +++ b/pywafo/src/wafo/misc.py @@ -41,7 +41,7 @@ from numpy import r_ from numpy import sign from numpy import sin from numpy import sqrt -from numpy import unique1d +from numpy import unique from numpy import vstack from numpy import where from numpy import zeros @@ -275,7 +275,7 @@ def _findcross(xn): n = len(xn) iz, = (xn == 0).nonzero() - if any(iz): + if len(iz)>0: # Trick to avoid turning points on the crossinglevel. if iz[0] == 0: if len(iz) == n: @@ -283,14 +283,15 @@ def _findcross(xn): return zeros(0, dtype=np.int) diz = diff(iz) - ix = iz((diz > 1).argmax()) - if not any(ix): + if len(diz)>0 and (diz>1).any(): + ix = iz[(diz > 1).argmax()] + else: ix = iz[-1] #x(ix) is a up crossing if x(1:ix) = v and x(ix+1) > v. #x(ix) is a downcrossing if x(1:ix) = v and x(ix+1) < v. - xn[0:ix] = -xn[ix + 1] - iz = iz[ix::] + xn[0:ix+1] = -xn[ix + 1] + iz = iz[ix+1::] for ix in iz.tolist(): xn[ix] = xn[ix - 1] @@ -328,6 +329,8 @@ def findcross(x, v=0.0, kind=None): ------- >>> from matplotlib import pylab as plb >>> ones = plb.ones + >>> findcross([0, 1, -1, 1],0) + array([0, 1, 2]) >>> v = 0.75 >>> t = plb.linspace(0,7*plb.pi,250) >>> x = plb.sin(t) @@ -988,7 +991,7 @@ def findoutliers(x, zcrit=0.0, dcrit=None, ddcrit=None, verbose=False): indg = ones(xn.size, dtype=bool) if ind.size > 1: - ind = unique1d(ind) + ind = unique(ind) indg[ind] = 0 indg, = nonzero(indg) @@ -1862,8 +1865,8 @@ def tranproc(x, f, x0, *xi): return y #y0,y1,y2,y3,y4 - - +def test_find_cross(): + t = findcross([0, 0, 1, -1, 1],0) def test_common_shape(): @@ -1979,8 +1982,8 @@ def _test_parse_kwargs(): print out1 if __name__ == "__main__": - if False: # True:# + if True:# False: # import doctest doctest.testmod() else: - _test_discretize2() + test_find_cross() diff --git a/pywafo/src/wafo/mvn.pyd b/pywafo/src/wafo/mvn.pyd index 758b1aa..2d0a064 100644 Binary files a/pywafo/src/wafo/mvn.pyd and b/pywafo/src/wafo/mvn.pyd differ diff --git a/pywafo/src/wafo/mvnprdmod.pyd b/pywafo/src/wafo/mvnprdmod.pyd index e144ff7..dd135d4 100644 Binary files a/pywafo/src/wafo/mvnprdmod.pyd and b/pywafo/src/wafo/mvnprdmod.pyd differ diff --git a/pywafo/src/wafo/plotbackend.py b/pywafo/src/wafo/plotbackend.py index 4bd251e..9c80173 100644 --- a/pywafo/src/wafo/plotbackend.py +++ b/pywafo/src/wafo/plotbackend.py @@ -1,13 +1,13 @@ """ Modify this file if another plotbackend is wanted. """ - +import warnings if False: try: from scitools import easyviz as plotbackend print('wafo.wafodata: plotbackend is set to scitools.easyviz') except: - print('wafo: Unable to load scitools.easyviz as plotbackend') + warnings.warn('wafo: Unable to load scitools.easyviz as plotbackend') plotbackend = None else: try: @@ -15,5 +15,5 @@ else: plotbackend.interactive(True) print('wafo.wafodata: plotbackend is set to matplotlib.pyplot') except: - print('wafo: Unable to load matplotlib.pyplot as plotbackend') + warnings.warn('wafo: Unable to load matplotlib.pyplot as plotbackend') plotbackend = None \ No newline at end of file diff --git a/pywafo/src/wafo/rindmod.pyd b/pywafo/src/wafo/rindmod.pyd index f4953c7..dfa681d 100644 Binary files a/pywafo/src/wafo/rindmod.pyd and b/pywafo/src/wafo/rindmod.pyd differ diff --git a/pywafo/src/wafo/source/c_codes/c_functions.c b/pywafo/src/wafo/source/c_codes/c_functions.c index ac37a56..febbc6b 100644 --- a/pywafo/src/wafo/source/c_codes/c_functions.c +++ b/pywafo/src/wafo/source/c_codes/c_functions.c @@ -140,13 +140,13 @@ void findcross(double *y, double v, int *ind, int n, int *info) for (i=1; i v){ - ind[ix] = i; /* first crossing is a up-crossing*/ + ind[ix] = i-1; /* first crossing is a up-crossing*/ ix++; dcross=1; /*The next crossing is a down-crossing*/ goto L120; diff --git a/pywafo/src/wafo/source/c_codes/c_library.pyd b/pywafo/src/wafo/source/c_codes/c_library.pyd index c0af1f9..4b0e899 100644 Binary files a/pywafo/src/wafo/source/c_codes/c_library.pyd and b/pywafo/src/wafo/source/c_codes/c_library.pyd differ diff --git a/pywafo/src/wafo/source/mvnprd/mvnprdmod.pyd b/pywafo/src/wafo/source/mvnprd/mvnprdmod.pyd index e144ff7..dd135d4 100644 Binary files a/pywafo/src/wafo/source/mvnprd/mvnprdmod.pyd and b/pywafo/src/wafo/source/mvnprd/mvnprdmod.pyd differ diff --git a/pywafo/src/wafo/source/rind2007/rindmod.pyd b/pywafo/src/wafo/source/rind2007/rindmod.pyd index f4953c7..dfa681d 100644 Binary files a/pywafo/src/wafo/source/rind2007/rindmod.pyd and b/pywafo/src/wafo/source/rind2007/rindmod.pyd differ