master
Per A Brodtkorb 7 years ago
parent 888afd48fb
commit 1fa0dc5217

@ -523,7 +523,7 @@ def transformdata_1d(x, f, plotflag):
transform_id = np.mod(plotflag // 10, 10)
transform = [lambda f, x: f,
lambda f, x: 1 - f,
lambda f, x: cumtrapz(f, x),
cumtrapz(f, x),
lambda f, x: 1 - cumtrapz(f, x),
lambda f, x: np.log(f),
lambda f, x: np.log1p(-f),

@ -42,7 +42,7 @@ def _set_seed(iseed):
if iseed is not None:
try:
random.set_state(iseed)
except:
except Exception:
random.seed(iseed)

@ -347,7 +347,6 @@ def shiftdim(x, n=None):
return x.reshape(no_leading_ones(x.shape))
elif n >= 0:
return x.transpose(np.roll(range(x.ndim), -n))
else:
return x.reshape((1,) * -n + x.shape)
@ -405,6 +404,7 @@ def example_dct2(debug=True):
print(out)
return out
if __name__ == '__main__':
from wafo.testing import test_docstrings
test_docstrings(__file__)

@ -1053,6 +1053,8 @@ class _Gaussq(object):
self._plot_final_trace()
return val, abserr
gaussq = _Gaussq()
@ -1259,6 +1261,7 @@ class _Quadgr(object):
return q_val, err
quadgr = _Quadgr()

@ -55,6 +55,8 @@ class PolyBasis(object):
def __call__(self, t, k):
return t**k
poly_basis = PolyBasis()
@ -73,6 +75,8 @@ class ChebyshevBasis(PolyBasis):
def __call__(self, t, k):
c = self._coefficients(k)
return self.eval(t, c)
chebyshev_basis = ChebyshevBasis()

@ -325,6 +325,7 @@ class _KernelMulti(_Kernel):
p=3; Multivariate Tri-weight Kernel
p=4; Multivariate Four-weight Kernel
"""
def __init__(self, r=1.0, p=1, stats=None, name=''):
self.p = p
super(_KernelMulti, self).__init__(r, stats, name)
@ -342,6 +343,7 @@ class _KernelMulti(_Kernel):
x2 = x ** 2
return ((1.0 - x2.sum(axis=0) / r ** 2).clip(min=0.0)) ** p
mkernel_epanechnikov = _KernelMulti(p=1, stats=_stats_epan,
name='epanechnikov')
mkernel_biweight = _KernelMulti(p=2, stats=_stats_biwe, name='biweight')
@ -356,6 +358,7 @@ class _KernelProduct(_KernelMulti):
p=3; 1D product Tri-weight Kernel
p=4; 1D product Four-weight Kernel
"""
def norm_factor(self, d=1, n=None):
r = self.r
p = self.p
@ -368,6 +371,7 @@ class _KernelProduct(_KernelMulti):
pdf = (1 - (x / r) ** 2).clip(min=0.0) ** self.p
return pdf.prod(axis=0)
mkernel_p1epanechnikov = _KernelProduct(p=1, stats=_stats_epan,
name='p1epanechnikov')
mkernel_p1biweight = _KernelProduct(p=2, stats=_stats_biwe, name='p1biweight')
@ -383,6 +387,8 @@ class _KernelRectangular(_Kernel):
def norm_factor(self, d=1, n=None):
r = self.r
return (2 * r) ** d
mkernel_rectangular = _KernelRectangular(stats=_stats_rect)
@ -391,6 +397,8 @@ class _KernelTriangular(_Kernel):
def _kernel(self, x):
pdf = (1 - np.abs(x)).clip(min=0.0)
return pdf.prod(axis=0)
mkernel_triangular = _KernelTriangular(stats=_stats_tria)
@ -425,6 +433,7 @@ class _KernelGaussian(_Kernel):
) / (sqrt(pi) * (2 * sigma) ** (r + 1))
return psi_r
mkernel_gaussian = _KernelGaussian(r=4.0, stats=_stats_gaus)
_GAUSS_KERNEL = mkernel_gaussian
@ -437,6 +446,8 @@ class _KernelLaplace(_Kernel):
def norm_factor(self, d=1, n=None):
return 2 ** d
mkernel_laplace = _KernelLaplace(r=7.0, stats=_stats_lapl)
@ -445,6 +456,8 @@ class _KernelLogistic(_Kernel):
def _kernel(self, x):
s = exp(x)
return np.prod(s / (s + 1) ** 2, axis=0)
mkernel_logistic = _KernelLogistic(r=7.0, stats=_stats_logi)
_MKERNEL_DICT = dict(

@ -588,5 +588,6 @@ def findrfc_astm(tp, t=None):
# n = len(sig_rfc)
return sig_rfc[:n - cnr[0]]
if __name__ == '__main__':
pass

@ -613,6 +613,7 @@ class CycleMatrix(PlotData):
"""
Container class for Cycle Matrix data objects in WAFO
"""
def __init__(self, *args, **kwds):
self.kind = kwds.pop('kind', 'min2max')
self.sigma = kwds.pop('sigma', None)
@ -798,15 +799,25 @@ class CyclePairs(PlotData):
nx = extr[0].argmax() + 1
levels = extr[0, 0:nx]
if defnr == 2: # This are upcrossings + maxima
dcount = cumsum(extr[1, 0:nx]) + extr[2, 0:nx] - extr[3, 0:nx]
elif defnr == 4: # This are upcrossings + minima
def _upcrossings_and_maxima(extr, nx):
return cumsum(extr[1, 0:nx]) + extr[2, 0:nx] - extr[3, 0:nx]
def _upcrossings_and_minima(extr, nx):
dcount = cumsum(extr[1, 0:nx])
dcount[nx - 1] = dcount[nx - 2]
elif defnr == 1: # This are only upcrossings
dcount = cumsum(extr[1, 0:nx]) - extr[3, 0:nx]
elif defnr == 3: # This are upcrossings + minima + maxima
dcount = cumsum(extr[1, 0:nx]) + extr[2, 0:nx]
return dcount
def _upcrossings(extr, nx):
return cumsum(extr[1, 0:nx]) - extr[3, 0:nx]
def _upcrossings_minima_and_maxima(extr, nx):
return cumsum(extr[1, 0:nx]) + extr[2, 0:nx]
dcount = {1: _upcrossings,
2: _upcrossings_and_maxima,
3: _upcrossings_minima_and_maxima,
4: _upcrossings_and_minima}[defnr](extr, nx)
ylab = 'Count'
if intensity:
dcount = dcount / self.time
@ -1142,7 +1153,7 @@ class TurningPoints(PlotData):
ind = findrfc(self.data, max(h, 0.0), method)
try:
t = self.args[ind]
except:
except Exception:
t = ind
mean = self.mean
sigma = self.sigma
@ -1386,7 +1397,8 @@ class TimeSeries(PlotData):
'''
if isinstance(wname, tuple):
wname = wname[0]
dof = int(dict(parzen=3.71, hanning=2.67,
dof = int(dict(parzen=3.71,
hanning=2.67,
bartlett=3).get(wname, np.nan) * n / L)
Be = dict(parzen=1.33, hanning=1,
bartlett=1.33).get(wname, np.nan) * 2 * pi / (L * dt)
@ -1680,7 +1692,7 @@ class TimeSeries(PlotData):
ind = findtp(self.data, max(h, 0.0), wavetype)
try:
t = self.args[ind]
except:
except Exception:
t = ind
mean = self.data.mean()
sigma = self.data.std()
@ -1710,7 +1722,7 @@ class TimeSeries(PlotData):
ind = findtc(self.data, v, wavetype)[0]
try:
t = self.args[ind]
except:
except Exception:
t = ind
mean = self.data.mean()
sigma = self.data.std()

@ -284,6 +284,8 @@ class _ExampleFunctions(object):
s.exp_fun100, s.cos30, s.constant, s.exp_xy, s.runge,
s.abs_cubed, s.gauss, s.exp_inv]
return test_function[i](x, y)
example_functions = _ExampleFunctions()

@ -2279,7 +2279,7 @@ def chebvalnd(c, *xi):
"""
try:
xi = np.array(xi, copy=0)
except:
except Exception:
raise ValueError('x, y, z are incompatible')
chebval = np.polynomial.chebyshev.chebval
c = chebval(xi[0], c)

@ -469,6 +469,7 @@ def demo_hodrick_on_cardioid():
x, y, 'r.',
xs, ys, 'k', linewidth=2)
if __name__ == '__main__':
from wafo.testing import test_docstrings
test_docstrings(__file__)

Loading…
Cancel
Save