|
|
|
@ -6,7 +6,8 @@ from __future__ import division
|
|
|
|
|
import sys
|
|
|
|
|
import fractions
|
|
|
|
|
import numpy as np
|
|
|
|
|
from numpy import (abs, amax, any, logical_and, arange, linspace, atleast_1d, #atleast_2d,
|
|
|
|
|
from numpy import (
|
|
|
|
|
abs, amax, any, logical_and, arange, linspace, atleast_1d, # atleast_2d,
|
|
|
|
|
array, asarray, broadcast_arrays, ceil, floor, frexp, hypot,
|
|
|
|
|
sqrt, arctan2, sin, cos, exp, log, mod, diff, empty_like,
|
|
|
|
|
finfo, inf, pi, interp, isnan, isscalar, zeros, ones, linalg,
|
|
|
|
@ -25,7 +26,8 @@ except:
|
|
|
|
|
floatinfo = finfo(float)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ['is_numlike', 'JITImport', 'DotDict', 'Bunch', 'printf', 'sub_dict_select',
|
|
|
|
|
__all__ = [
|
|
|
|
|
'is_numlike', 'JITImport', 'DotDict', 'Bunch', 'printf', 'sub_dict_select',
|
|
|
|
|
'parse_kwargs', 'detrendma', 'ecross', 'findcross',
|
|
|
|
|
'findextrema', 'findpeaks', 'findrfc', 'rfcfilter', 'findtp', 'findtc',
|
|
|
|
|
'findoutliers', 'common_shape', 'argsreduce',
|
|
|
|
@ -43,7 +45,9 @@ def is_numlike(obj):
|
|
|
|
|
else:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class JITImport(object):
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
Just In Time Import of module
|
|
|
|
|
|
|
|
|
@ -53,9 +57,11 @@ class JITImport(object):
|
|
|
|
|
>>> np.exp(0)==1.0
|
|
|
|
|
True
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
def __init__(self, module_name):
|
|
|
|
|
self._module_name = module_name
|
|
|
|
|
self._module = None
|
|
|
|
|
|
|
|
|
|
def __getattr__(self, attr):
|
|
|
|
|
try:
|
|
|
|
|
return getattr(self._module, attr)
|
|
|
|
@ -67,7 +73,9 @@ class JITImport(object):
|
|
|
|
|
else:
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DotDict(dict):
|
|
|
|
|
|
|
|
|
|
''' Implement dot access to dict values
|
|
|
|
|
|
|
|
|
|
Example
|
|
|
|
@ -78,7 +86,9 @@ class DotDict(dict):
|
|
|
|
|
'''
|
|
|
|
|
__getattr__ = dict.__getitem__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Bunch(object):
|
|
|
|
|
|
|
|
|
|
''' Implement keyword argument initialization of class
|
|
|
|
|
|
|
|
|
|
Example
|
|
|
|
@ -87,13 +97,17 @@ class Bunch(object):
|
|
|
|
|
>>> d.test1
|
|
|
|
|
1
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
|
self.__dict__.update(kwargs)
|
|
|
|
|
|
|
|
|
|
def keys(self):
|
|
|
|
|
return self.__dict__.keys()
|
|
|
|
|
|
|
|
|
|
def update(self, ** kwargs):
|
|
|
|
|
self.__dict__.update(kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def printf(format, *args): # @ReservedAssignment
|
|
|
|
|
sys.stdout.write(format % args)
|
|
|
|
|
|
|
|
|
@ -122,7 +136,7 @@ def sub_dict_select(somedict, somekeys):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_kwargs(options, **kwargs):
|
|
|
|
|
''' Update options dict from keyword arguments if the keyword exists in options
|
|
|
|
|
''' Update options dict from keyword arguments if it exists in options
|
|
|
|
|
|
|
|
|
|
Example
|
|
|
|
|
>>> opt = dict(arg1=2, arg2=3)
|
|
|
|
@ -140,13 +154,16 @@ def parse_kwargs(options, **kwargs):
|
|
|
|
|
options.update(newopts)
|
|
|
|
|
return options
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testfun(*args, **kwargs):
|
|
|
|
|
opts = dict(opt1=1, opt2=2)
|
|
|
|
|
if len(args) == 1 and len(kwargs) == 0 and type(args[0]) is str and args[0].startswith('default'):
|
|
|
|
|
if (len(args) == 1 and len(kwargs) == 0 and type(args[0]) is str and
|
|
|
|
|
args[0].startswith('default')):
|
|
|
|
|
return opts
|
|
|
|
|
opts = parse_kwargs(opts, **kwargs)
|
|
|
|
|
return opts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def detrendma(x, L):
|
|
|
|
|
"""
|
|
|
|
|
Removes a trend from data using a moving average
|
|
|
|
@ -194,7 +211,6 @@ def detrendma(x, L):
|
|
|
|
|
if n < 2 * L + 1: # only able to remove the mean
|
|
|
|
|
return x1 - x1.mean(axis=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mn = x1[0:2 * L + 1].mean(axis=0)
|
|
|
|
|
y = empty_like(x1)
|
|
|
|
|
y[0:L] = x1[0:L] - mn
|
|
|
|
@ -205,6 +221,7 @@ def detrendma(x, L):
|
|
|
|
|
y[n - L::] = x1[n - L::] - trend[-1]
|
|
|
|
|
return y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ecross(t, f, ind, v=0):
|
|
|
|
|
'''
|
|
|
|
|
Extracts exact level v crossings
|
|
|
|
@ -252,7 +269,9 @@ def ecross(t, f, ind, v=0):
|
|
|
|
|
# Tested on: Python 2.5
|
|
|
|
|
# revised pab Feb2004
|
|
|
|
|
# By pab 18.06.2001
|
|
|
|
|
return t[ind] + (v - f[ind]) * (t[ind + 1] - t[ind]) / (f[ind + 1] - f[ind])
|
|
|
|
|
return (t[ind] + (v - f[ind]) * (t[ind + 1] - t[ind]) /
|
|
|
|
|
(f[ind + 1] - f[ind]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _findcross(xn):
|
|
|
|
|
'''Return indices to zero up and downcrossings of a vector
|
|
|
|
@ -288,6 +307,7 @@ def _findcross(xn):
|
|
|
|
|
ind, = (xn[:n - 1] * xn[1:] < 0).nonzero()
|
|
|
|
|
return ind
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findcross(x, v=0.0, kind=None):
|
|
|
|
|
'''
|
|
|
|
|
Return indices to level v up and/or downcrossings of a vector
|
|
|
|
@ -352,10 +372,11 @@ def findcross(x, v=0.0, kind=None):
|
|
|
|
|
t_0 = int(xn[ind[0] + 1] < 0)
|
|
|
|
|
ind = ind[t_0::2]
|
|
|
|
|
elif kind in ('dw', 'uw', 'tw', 'cw'):
|
|
|
|
|
#make sure that the first is a level v down-crossing if wdef=='dw'
|
|
|
|
|
#or make sure that the first is a level v up-crossing if wdef=='uw'
|
|
|
|
|
#make sure that the first is a level v down-crossing if wdef=='tw'
|
|
|
|
|
#or make sure that the first is a level v up-crossing if wdef=='cw'
|
|
|
|
|
# make sure the first is a level v down-crossing if wdef=='dw'
|
|
|
|
|
# or make sure the first is a level v up-crossing if wdef=='uw'
|
|
|
|
|
# make sure the first is a level v down-crossing if wdef=='tw'
|
|
|
|
|
# or make sure the first is a level v up-crossing if
|
|
|
|
|
# wdef=='cw'
|
|
|
|
|
xor = lambda a, b: a ^ b
|
|
|
|
|
first_is_down_crossing = int(xn[ind[0]] > xn[ind[0] + 1])
|
|
|
|
|
if xor(first_is_down_crossing, kind in ('dw', 'tw')):
|
|
|
|
@ -372,6 +393,7 @@ def findcross(x, v=0.0, kind=None):
|
|
|
|
|
raise ValueError('Unknown wave/crossing definition!')
|
|
|
|
|
return ind
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findextrema(x):
|
|
|
|
|
'''
|
|
|
|
|
Return indices to minima and maxima of a vector
|
|
|
|
@ -402,6 +424,8 @@ def findextrema(x):
|
|
|
|
|
'''
|
|
|
|
|
xn = atleast_1d(x).ravel()
|
|
|
|
|
return findcross(diff(xn), 0.0) + 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findpeaks(data, n=2, min_h=None, min_p=0.0):
|
|
|
|
|
'''
|
|
|
|
|
Find peaks of vector or matrix possibly rainflow filtered
|
|
|
|
@ -461,7 +485,8 @@ def findpeaks(data, n=2, min_h=None, min_p=0.0):
|
|
|
|
|
elif iy == nrows - 1:
|
|
|
|
|
ind2 = np.flatnonzero(S[iy, ind] > S[iy - 1, ind])
|
|
|
|
|
else:
|
|
|
|
|
ind2 = np.flatnonzero((S[iy, ind] > S[iy - 1, ind]) & (S[iy, ind] > S[iy + 1, ind]))
|
|
|
|
|
ind2 = np.flatnonzero((S[iy, ind] > S[iy - 1, ind]) &
|
|
|
|
|
(S[iy, ind] > S[iy + 1, ind]))
|
|
|
|
|
|
|
|
|
|
if len(ind2):
|
|
|
|
|
indP.append((ind[ind2] + iy * mcols))
|
|
|
|
@ -474,16 +499,17 @@ def findpeaks(data, n=2, min_h=None, min_p=0.0):
|
|
|
|
|
peaks = S.take(ind)
|
|
|
|
|
ind2 = peaks.argsort()[::-1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# keeping only the Np most significant peak frequencies.
|
|
|
|
|
nmax = min(n, len(ind))
|
|
|
|
|
ind = ind[ind2[:nmax]]
|
|
|
|
|
if (min_p > 0):
|
|
|
|
|
# Keeping only peaks larger than min_p percent relative to the maximum peak
|
|
|
|
|
# Keeping only peaks larger than min_p percent relative to the maximum
|
|
|
|
|
# peak
|
|
|
|
|
ind = ind[(S.take(ind) > min_p * smax)]
|
|
|
|
|
|
|
|
|
|
return ind
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findrfc_astm(tp):
|
|
|
|
|
"""
|
|
|
|
|
Return rainflow counted cycles
|
|
|
|
@ -514,6 +540,7 @@ def findrfc_astm(tp):
|
|
|
|
|
# sig_rfc holds the actual rainflow counted cycles, not the indices
|
|
|
|
|
return sig_rfc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findrfc(tp, h=0.0, method='clib'):
|
|
|
|
|
'''
|
|
|
|
|
Return indices to rainflow cycles of a sequence of TP.
|
|
|
|
@ -624,7 +651,6 @@ def findrfc(tp, h=0.0, method='clib'):
|
|
|
|
|
#iy = i
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# goto L180
|
|
|
|
|
# L170:
|
|
|
|
|
if (xplus <= xminus):
|
|
|
|
@ -646,9 +672,11 @@ def findrfc(tp, h=0.0, method='clib'):
|
|
|
|
|
ind, ix = clib.findrfc(y, h)
|
|
|
|
|
return np.sort(ind[:ix])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
computes f_rfc = f_mM + F_mct(f_mM).
|
|
|
|
|
|
|
|
|
@ -707,7 +735,8 @@ def mctp2rfc(fmM, fMm=None):
|
|
|
|
|
SRA = RAA.sum()
|
|
|
|
|
|
|
|
|
|
DRFC = SA - SRA
|
|
|
|
|
NT = min(mA[0] - sum(RAA[:, 0]), MA[0] - sum(RAA[0, :])) # ?? check
|
|
|
|
|
# ?? check
|
|
|
|
|
NT = min(mA[0] - sum(RAA[:, 0]), MA[0] - sum(RAA[0, :]))
|
|
|
|
|
NT = max(NT, 0) # ??check
|
|
|
|
|
|
|
|
|
|
if NT > 1e-6 * max(MA[0], mA[0]):
|
|
|
|
@ -722,13 +751,14 @@ def mctp2rfc(fmM, fMm=None):
|
|
|
|
|
e[j] = e[j] / norm
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
fx = 0.0;
|
|
|
|
|
if max(abs(e)) > 1e-6 and max(abs(NN)) > 1e-6 * max(MA[0], mA[0]):
|
|
|
|
|
fx = 0.0
|
|
|
|
|
if (max(abs(e)) > 1e-6 and
|
|
|
|
|
max(abs(NN)) > 1e-6 * max(MA[0], mA[0])):
|
|
|
|
|
PMm = AA1.copy()
|
|
|
|
|
for j in range(nA):
|
|
|
|
|
norm = MA[j]
|
|
|
|
|
if norm != 0:
|
|
|
|
|
PMm[j, :] = PMm[j, :] / norm;
|
|
|
|
|
PMm[j, :] = PMm[j, :] / norm
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
PMm = np.fliplr(PMm)
|
|
|
|
@ -740,7 +770,8 @@ def mctp2rfc(fmM, fMm=None):
|
|
|
|
|
fx = NN * (A / (1 - B * A) * e)
|
|
|
|
|
else:
|
|
|
|
|
rh = np.eye(A.shape[0]) - np.dot(B, A)
|
|
|
|
|
fx = np.dot(NN, np.dot(A, linalg.solve(rh, e))) #least squares
|
|
|
|
|
#least squares
|
|
|
|
|
fx = np.dot(NN, np.dot(A, linalg.solve(rh, e)))
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
f_rfc[N - 1 - k, k - i] = fx + DRFC
|
|
|
|
@ -758,8 +789,8 @@ def mctp2rfc(fmM, fMm=None):
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
for k in range(1, N):
|
|
|
|
|
M0 = max(0, f_max[0] - np.sum(f_rfc[0, N - k:N]));
|
|
|
|
|
m0 = max(0, f_min[N - 1 - k] - np.sum(f_rfc[1:k+1, N - 1 - k]));
|
|
|
|
|
M0 = max(0, f_max[0] - np.sum(f_rfc[0, N - k:N]))
|
|
|
|
|
m0 = max(0, f_min[N - 1 - k] - np.sum(f_rfc[1:k + 1, N - 1 - k]))
|
|
|
|
|
f_rfc[0, N - 1 - k] = min(m0, M0)
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
@ -781,7 +812,6 @@ def mctp2rfc(fmM, fMm=None):
|
|
|
|
|
return f_rfc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rfcfilter(x, h, method=0):
|
|
|
|
|
"""
|
|
|
|
|
Rainflow filter a signal.
|
|
|
|
@ -866,9 +896,11 @@ def rfcfilter(x, h, method=0):
|
|
|
|
|
z1 = 0
|
|
|
|
|
t1, y1 = (t0, y0) if z1 == 0 else (ti, yi)
|
|
|
|
|
else:
|
|
|
|
|
if (((z0 == +1) & cmpfun1(yi, fmi)) | ((z0 == -1) & cmpfun2(yi, fpi))):
|
|
|
|
|
if (((z0 == +1) & cmpfun1(yi, fmi)) |
|
|
|
|
|
((z0 == -1) & cmpfun2(yi, fpi))):
|
|
|
|
|
z1 = -1
|
|
|
|
|
elif (((z0 == +1) & cmpfun2(fmi, yi)) | ((z0 == -1) & cmpfun1(fpi, yi))):
|
|
|
|
|
elif (((z0 == +1) & cmpfun2(fmi, yi)) |
|
|
|
|
|
((z0 == -1) & cmpfun1(fpi, yi))):
|
|
|
|
|
z1 = +1
|
|
|
|
|
else:
|
|
|
|
|
warnings.warn('Something wrong, i=%d' % tim1)
|
|
|
|
@ -898,6 +930,7 @@ def rfcfilter(x, h, method=0):
|
|
|
|
|
t[j] = t0
|
|
|
|
|
return y[t[:j + 1]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findtp(x, h=0.0, kind=None):
|
|
|
|
|
'''
|
|
|
|
|
Return indices to turning points (tp) of data, optionally rainflowfiltered.
|
|
|
|
@ -936,7 +969,9 @@ def findtp(x, h=0.0, kind=None):
|
|
|
|
|
>>> itph = wm.findtp(x1[:,1],0.3,'Mw')
|
|
|
|
|
>>> tp = x1[itp,:]
|
|
|
|
|
>>> tph = x1[itph,:]
|
|
|
|
|
>>> a = plb.plot(x1[:,0],x1[:,1],tp[:,0],tp[:,1],'ro',tph[:,1],tph[:,1],'k.')
|
|
|
|
|
>>> a = plb.plot(x1[:,0],x1[:,1],
|
|
|
|
|
... tp[:,0],tp[:,1],'ro',
|
|
|
|
|
... tph[:,1],tph[:,1],'k.')
|
|
|
|
|
>>> plb.close('all')
|
|
|
|
|
>>> itp
|
|
|
|
|
array([ 11, 21, 22, 24, 26, 28, 31, 39, 43, 45, 47, 51, 56,
|
|
|
|
@ -970,7 +1005,8 @@ def findtp(x, h=0.0, kind=None):
|
|
|
|
|
if kind == 'astm':
|
|
|
|
|
# the Nieslony approach always put the first loading point as the first
|
|
|
|
|
# turning point.
|
|
|
|
|
if x[ind[0]] != x[0]: # add the first turning point is the first of the signal
|
|
|
|
|
# add the first turning point is the first of the signal
|
|
|
|
|
if x[ind[0]] != x[0]:
|
|
|
|
|
ind = np.r_[0, ind, n - 1]
|
|
|
|
|
else: # only add the last point of the signal
|
|
|
|
|
ind = np.r_[ind, n - 1]
|
|
|
|
@ -1000,6 +1036,7 @@ def findtp(x, h=0.0, kind=None):
|
|
|
|
|
ind = ind[:-1]
|
|
|
|
|
return ind
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findtc(x_in, v=None, kind=None):
|
|
|
|
|
"""
|
|
|
|
|
Return indices to troughs and crests of data.
|
|
|
|
@ -1092,6 +1129,7 @@ def findtc(x_in, v=None, kind=None):
|
|
|
|
|
|
|
|
|
|
return v_ind[:n_c - 1] + ind + 1, v_ind
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findoutliers(x, zcrit=0.0, dcrit=None, ddcrit=None, verbose=False):
|
|
|
|
|
"""
|
|
|
|
|
Return indices to spurious points of data
|
|
|
|
@ -1120,7 +1158,8 @@ def findoutliers(x, zcrit=0.0, dcrit=None, ddcrit=None, verbose=False):
|
|
|
|
|
-----
|
|
|
|
|
Consecutive points less than zcrit apart are considered as spurious.
|
|
|
|
|
The point immediately after and before are also removed. Jumps greater than
|
|
|
|
|
dcrit in Dxn and greater than ddcrit in D^2xn are also considered as spurious.
|
|
|
|
|
dcrit in Dxn and greater than ddcrit in D^2xn are also considered as
|
|
|
|
|
spurious.
|
|
|
|
|
(All distances to be interpreted in the vertical direction.)
|
|
|
|
|
Another good choice for dcrit and ddcrit are:
|
|
|
|
|
|
|
|
|
@ -1153,7 +1192,6 @@ def findoutliers(x, zcrit=0.0, dcrit=None, ddcrit=None, verbose=False):
|
|
|
|
|
waveplot, reconstruct
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# finding outliers
|
|
|
|
|
findjumpsDx = True # find jumps in Dx
|
|
|
|
|
# two point spikes and Spikes dcrit above/under the
|
|
|
|
@ -1168,7 +1206,6 @@ def findoutliers(x, zcrit=0.0, dcrit=None, ddcrit=None, verbose=False):
|
|
|
|
|
if xn.size < 2:
|
|
|
|
|
raise ValueError('The vector must have more than 2 elements!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ind = zeros(0, dtype=int)
|
|
|
|
|
# indg=[]
|
|
|
|
|
indmiss = isnan(xn)
|
|
|
|
@ -1249,7 +1286,8 @@ def findoutliers(x, zcrit=0.0, dcrit=None, ddcrit=None, verbose=False):
|
|
|
|
|
indtr, = nonzero((diff(indzeros)))
|
|
|
|
|
indtr = indtr + 1
|
|
|
|
|
#%indices to consecutive equal points
|
|
|
|
|
if True: # removing the point before + all equal points + the point after
|
|
|
|
|
# removing the point before + all equal points + the point after
|
|
|
|
|
if True:
|
|
|
|
|
ind = hstack((ind, indtr - 1, indz, indtr, indtr + 1))
|
|
|
|
|
else: # % removing all points + the point after
|
|
|
|
|
ind = hstack((ind, indz, indtr, indtr + 1))
|
|
|
|
@ -1258,7 +1296,8 @@ def findoutliers(x, zcrit=0.0, dcrit=None, ddcrit=None, verbose=False):
|
|
|
|
|
if zcrit == 0.:
|
|
|
|
|
print('Found %d consecutive equal values' % indz.size)
|
|
|
|
|
else:
|
|
|
|
|
print('Found %d consecutive values less than %g apart.' % (indz.size, zcrit))
|
|
|
|
|
print('Found %d consecutive values less than %g apart.' %
|
|
|
|
|
(indz.size, zcrit))
|
|
|
|
|
indg = ones(xn.size, dtype=bool)
|
|
|
|
|
|
|
|
|
|
if ind.size > 1:
|
|
|
|
@ -1271,6 +1310,7 @@ def findoutliers(x, zcrit=0.0, dcrit=None, ddcrit=None, verbose=False):
|
|
|
|
|
|
|
|
|
|
return ind, indg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def common_shape(*args, ** kwds):
|
|
|
|
|
'''
|
|
|
|
|
Return the common shape of a sequence of arrays
|
|
|
|
@ -1339,8 +1379,8 @@ def common_shape(*args, ** kwds):
|
|
|
|
|
raise ValueError("shape mismatch: two or more arrays have "
|
|
|
|
|
"incompatible dimensions on axis %r." % (axis,))
|
|
|
|
|
elif len(unique) == 2:
|
|
|
|
|
# There is exactly one non-1 length. The common shape will take this
|
|
|
|
|
# value.
|
|
|
|
|
# There is exactly one non-1 length.
|
|
|
|
|
# The common shape will take this value.
|
|
|
|
|
unique.remove(1)
|
|
|
|
|
new_length = unique.pop()
|
|
|
|
|
c_shape.append(new_length)
|
|
|
|
@ -1351,6 +1391,7 @@ def common_shape(*args, ** kwds):
|
|
|
|
|
|
|
|
|
|
return tuple(c_shape)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def argsreduce(condition, * args):
|
|
|
|
|
""" Return the elements of each input array that satisfy some condition.
|
|
|
|
|
|
|
|
|
@ -1399,7 +1440,8 @@ def argsreduce(condition, * args):
|
|
|
|
|
|
|
|
|
|
def stirlerr(n):
|
|
|
|
|
'''
|
|
|
|
|
Return error of Stirling approximation, i.e., log(n!) - log( sqrt(2*pi*n)*(n/exp(1))**n )
|
|
|
|
|
Return error of Stirling approximation,
|
|
|
|
|
i.e., log(n!) - log( sqrt(2*pi*n)*(n/exp(1))**n )
|
|
|
|
|
|
|
|
|
|
Example
|
|
|
|
|
-------
|
|
|
|
@ -1430,7 +1472,6 @@ def stirlerr(n):
|
|
|
|
|
|
|
|
|
|
y = gammaln(n1 + 1) - log(sqrt(2 * pi * n1) * (n1 / exp(1)) ** n1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nn = n1 * n1
|
|
|
|
|
|
|
|
|
|
n500 = 500 < n1
|
|
|
|
@ -1446,11 +1487,16 @@ def stirlerr(n):
|
|
|
|
|
n15 = logical_and(15 < n1, n1 <= 35)
|
|
|
|
|
if any(n15):
|
|
|
|
|
nn15 = nn[n15]
|
|
|
|
|
y[n15] = (S0 - (S1 - (S2 - (S3 - S4 / nn15) / nn15) / nn15) / nn15) / n1[n15]
|
|
|
|
|
y[n15] = (
|
|
|
|
|
S0 - (S1 - (S2 - (S3 - S4 / nn15) / nn15) / nn15) / nn15) / n1[n15]
|
|
|
|
|
|
|
|
|
|
return y
|
|
|
|
|
|
|
|
|
|
def getshipchar(value=None, property="max_deadweight", **kwds): #@ReservedAssignment
|
|
|
|
|
#@ReservedAssignment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getshipchar(value=None, property="max_deadweight", # @ReservedAssignment
|
|
|
|
|
**kwds):
|
|
|
|
|
'''
|
|
|
|
|
Return ship characteristics from value of one ship-property
|
|
|
|
|
|
|
|
|
@ -1464,15 +1510,16 @@ def getshipchar(value=None, property="max_deadweight", **kwds): #@ReservedAssign
|
|
|
|
|
'propeller_diameter'.
|
|
|
|
|
The length was found from statistics of 40 vessels of size 85 to
|
|
|
|
|
100000 tonn. An exponential curve through 0 was selected, and the
|
|
|
|
|
factor and exponent that minimized the standard deviation of the relative
|
|
|
|
|
error was selected. (The error returned is the same for any ship.) The
|
|
|
|
|
servicespeed was found for ships above 1000 tonns only.
|
|
|
|
|
The propeller diameter formula is from [1]_.
|
|
|
|
|
factor and exponent that minimized the standard deviation of the
|
|
|
|
|
relative error was selected. (The error returned is the same for
|
|
|
|
|
any ship.) The servicespeed was found for ships above 1000 tonns
|
|
|
|
|
only. The propeller diameter formula is from [1]_.
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
sc : dict
|
|
|
|
|
containing estimated mean values and standard-deviations of ship characteristics:
|
|
|
|
|
containing estimated mean values and standard-deviations of ship
|
|
|
|
|
characteristics:
|
|
|
|
|
max_deadweight [kkg], (weight of cargo, fuel etc.)
|
|
|
|
|
length [m]
|
|
|
|
|
beam [m]
|
|
|
|
@ -1504,8 +1551,8 @@ def getshipchar(value=None, property="max_deadweight", **kwds): #@ReservedAssign
|
|
|
|
|
Reference
|
|
|
|
|
---------
|
|
|
|
|
.. [1] Gray and Greeley, (1978),
|
|
|
|
|
"Source level model for propeller blade rate radiation for the world's merchant
|
|
|
|
|
fleet", Bolt Beranek and Newman Technical Memorandum No. 458.
|
|
|
|
|
"Source level model for propeller blade rate radiation for the world's
|
|
|
|
|
merchant fleet", Bolt Beranek and Newman Technical Memorandum No. 458.
|
|
|
|
|
'''
|
|
|
|
|
if value is None:
|
|
|
|
|
names = kwds.keys()
|
|
|
|
@ -1522,7 +1569,8 @@ def getshipchar(value=None, property="max_deadweight", **kwds): #@ReservedAssign
|
|
|
|
|
beam=lambda x: ((x / 1.78) ** (1 / 0.27)),
|
|
|
|
|
draught=lambda x: ((x / 0.8) ** (1 / 0.24)),
|
|
|
|
|
service_speed=lambda x: ((x / 1.14) ** (1 / 0.21)),
|
|
|
|
|
propeller_diameter=lambda x: (((x / 0.12) ** (4 / 3) / 3.45) ** (2.5)))
|
|
|
|
|
propeller_diameter=lambda x: (((x / 0.12) ** (4 / 3) /
|
|
|
|
|
3.45) ** (2.5)))
|
|
|
|
|
|
|
|
|
|
max_deadweight = prop2max_dw.get(prop, lambda x: x)(value)
|
|
|
|
|
propertySTD = prop + 'STD'
|
|
|
|
@ -1540,7 +1588,6 @@ def getshipchar(value=None, property="max_deadweight", **kwds): #@ReservedAssign
|
|
|
|
|
speed = round(1.14 * max_deadweight ** 0.21 * 10) / 10
|
|
|
|
|
speed_err = speed * 0.10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_diam = 0.12 * length ** (3.0 / 4.0)
|
|
|
|
|
p_diam_err = 0.12 * length_err ** (3.0 / 4.0)
|
|
|
|
|
|
|
|
|
@ -1550,13 +1597,16 @@ def getshipchar(value=None, property="max_deadweight", **kwds): #@ReservedAssign
|
|
|
|
|
shipchar = OrderedDict(beam=beam, beamSTD=beam_err,
|
|
|
|
|
draught=draught, draughtSTD=draught_err,
|
|
|
|
|
length=length, lengthSTD=length_err,
|
|
|
|
|
max_deadweight=max_deadweight, max_deadweightSTD=max_deadweightSTD,
|
|
|
|
|
propeller_diameter=p_diam, propeller_diameterSTD=p_diam_err,
|
|
|
|
|
max_deadweight=max_deadweight,
|
|
|
|
|
max_deadweightSTD=max_deadweightSTD,
|
|
|
|
|
propeller_diameter=p_diam,
|
|
|
|
|
propeller_diameterSTD=p_diam_err,
|
|
|
|
|
service_speed=speed, service_speedSTD=speed_err)
|
|
|
|
|
|
|
|
|
|
shipchar[propertySTD] = 0
|
|
|
|
|
return shipchar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def betaloge(z, w):
|
|
|
|
|
'''
|
|
|
|
|
Natural Logarithm of beta function.
|
|
|
|
@ -1595,6 +1645,7 @@ def betaloge(z, w):
|
|
|
|
|
# (-(zpw-0.5).*log(zpw) +(w-0.5).*log(w)+(z-0.5).*log(z) +0.5*log(2*pi))
|
|
|
|
|
# return y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gravity(phi=45):
|
|
|
|
|
''' Returns the constant acceleration of gravity
|
|
|
|
|
|
|
|
|
@ -1638,7 +1689,9 @@ def gravity(phi=45):
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
phir = phi * pi / 180. # change from degrees to radians
|
|
|
|
|
return 9.78049 * (1. + 0.0052884 * sin(phir) ** 2. - 0.0000059 * sin(2 * phir) ** 2.)
|
|
|
|
|
return 9.78049 * (1. + 0.0052884 * sin(phir) ** 2. -
|
|
|
|
|
0.0000059 * sin(2 * phir) ** 2.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def nextpow2(x):
|
|
|
|
|
'''
|
|
|
|
@ -1662,6 +1715,7 @@ def nextpow2(x):
|
|
|
|
|
n = n - 1
|
|
|
|
|
return n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def discretize(fun, a, b, tol=0.005, n=5, method='linear'):
|
|
|
|
|
'''
|
|
|
|
|
Automatic discretization of function
|
|
|
|
@ -1702,13 +1756,13 @@ def discretize(fun, a, b, tol=0.005, n=5, method='linear'):
|
|
|
|
|
else:
|
|
|
|
|
return _discretize_linear(fun, a, b, tol, n)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _discretize_linear(fun, a, b, tol=0.005, n=5):
|
|
|
|
|
'''
|
|
|
|
|
Automatic discretization of function, linear gridding
|
|
|
|
|
'''
|
|
|
|
|
tiny = floatinfo.tiny
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x = linspace(a, b, n)
|
|
|
|
|
y = fun(x)
|
|
|
|
|
|
|
|
|
@ -1726,6 +1780,7 @@ def _discretize_linear(fun, a, b, tol=0.005, n=5):
|
|
|
|
|
err = 0.5 * amax(abs((y00 - y) / (abs(y00 + y) + tiny)))
|
|
|
|
|
return x, y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _discretize_adaptive(fun, a, b, tol=0.005, n=5):
|
|
|
|
|
'''
|
|
|
|
|
Automatic discretization of function, adaptive gridding.
|
|
|
|
@ -1747,7 +1802,8 @@ def _discretize_adaptive(fun, a, b, tol=0.005, n=5):
|
|
|
|
|
|
|
|
|
|
I, = where(erri > tol)
|
|
|
|
|
# double the sample rate in intervals with the most error
|
|
|
|
|
y = (vstack(((x[I] + x[I - 1]) / 2, (x[I + 1] + x[I]) / 2)).T).ravel()
|
|
|
|
|
y = (vstack(((x[I] + x[I - 1]) / 2,
|
|
|
|
|
(x[I + 1] + x[I]) / 2)).T).ravel()
|
|
|
|
|
fy = fun(y)
|
|
|
|
|
|
|
|
|
|
fy0 = interp(y, x, fx)
|
|
|
|
@ -1903,10 +1959,10 @@ def meshgrid(*xi, **kwargs):
|
|
|
|
|
sparse = kwargs.get('sparse', False)
|
|
|
|
|
indexing = kwargs.get('indexing', 'xy') # 'ij'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ndim = len(args)
|
|
|
|
|
s0 = (1,) * ndim
|
|
|
|
|
output = [x.reshape(s0[:i] + (-1,) + s0[i + 1::]) for i, x in enumerate(args)]
|
|
|
|
|
output = [x.reshape(s0[:i] + (-1,) + s0[i + 1::])
|
|
|
|
|
for i, x in enumerate(args)]
|
|
|
|
|
|
|
|
|
|
shape = [x.size for x in output]
|
|
|
|
|
|
|
|
|
@ -1938,6 +1994,7 @@ def ndgrid(*args, **kwargs):
|
|
|
|
|
kwargs['indexing'] = 'ij'
|
|
|
|
|
return meshgrid(*args, ** kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def trangood(x, f, min_n=None, min_x=None, max_x=None, max_n=inf):
|
|
|
|
|
"""
|
|
|
|
|
Make sure transformation is efficient.
|
|
|
|
@ -2004,10 +2061,10 @@ def trangood(x, f, min_n=None, min_x=None, max_x=None, max_n=inf):
|
|
|
|
|
L = float(xn - x0)
|
|
|
|
|
eps = floatinfo.eps
|
|
|
|
|
if ((nf < min_n) or (max_n < nf) or any(abs(ddx) > 10 * eps * (L))):
|
|
|
|
|
## % pab 07.01.2001: Always choose the stepsize df so that
|
|
|
|
|
## % it is an exactly representable number.
|
|
|
|
|
## % This is important when calculating numerical derivatives and is
|
|
|
|
|
## % accomplished by the following.
|
|
|
|
|
# % pab 07.01.2001: Always choose the stepsize df so that
|
|
|
|
|
# % it is an exactly representable number.
|
|
|
|
|
# % This is important when calculating numerical derivatives and is
|
|
|
|
|
# % accomplished by the following.
|
|
|
|
|
dx = L / (min(min_n, max_n) - 1)
|
|
|
|
|
dx = (dx + 2.) - 2.
|
|
|
|
|
xi = arange(x0, xn + dx / 2., dx)
|
|
|
|
@ -2033,6 +2090,7 @@ def trangood(x, f, min_n=None, min_x=None, max_x=None, max_n=inf):
|
|
|
|
|
|
|
|
|
|
return xo, fo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def tranproc(x, f, x0, *xi):
|
|
|
|
|
"""
|
|
|
|
|
Transforms process X and up to four derivatives
|
|
|
|
@ -2108,16 +2166,17 @@ def tranproc(x, f, x0, *xi):
|
|
|
|
|
y = [y0]
|
|
|
|
|
hn = xo[1] - xo[0]
|
|
|
|
|
if hn ** N < sqrt(eps):
|
|
|
|
|
print('Numerical problems may occur for the derivatives in tranproc.')
|
|
|
|
|
warnings.warn('The sampling of the transformation may be too small.')
|
|
|
|
|
msg = ('Numerical problems may occur for the derivatives in ' +
|
|
|
|
|
'tranproc.\nThe sampling of the transformation may be too small.')
|
|
|
|
|
warnings.warn(msg)
|
|
|
|
|
|
|
|
|
|
#% Transform X with the derivatives of f.
|
|
|
|
|
# Transform X with the derivatives of f.
|
|
|
|
|
fxder = zeros((N, x0.size))
|
|
|
|
|
fder = vstack((xo, fo))
|
|
|
|
|
for k in range(N): #% Derivation of f(x) using a difference method.
|
|
|
|
|
for k in range(N): # Derivation of f(x) using a difference method.
|
|
|
|
|
n = fder.shape[-1]
|
|
|
|
|
#%fder = [(fder(1:n-1,1)+fder(2:n,1))/2 diff(fder(:,2))./diff(fder(:,1))]
|
|
|
|
|
fder = vstack([(fder[0, 0:n - 1] + fder[0, 1:n]) / 2, diff(fder[1, :]) / hn])
|
|
|
|
|
fder = vstack([(fder[0, 0:n - 1] + fder[0, 1:n]) / 2,
|
|
|
|
|
diff(fder[1, :]) / hn])
|
|
|
|
|
fxder[k] = tranproc(fder[0], fder[1], x0)
|
|
|
|
|
|
|
|
|
|
# Calculate the transforms of the derivatives of X.
|
|
|
|
@ -2141,14 +2200,18 @@ def tranproc(x, f, x0, *xi):
|
|
|
|
|
# Fourth time derivative of y:
|
|
|
|
|
# y4 = f''''(x)*x1.^4+f'(x)*x4
|
|
|
|
|
# +6*f'''(x)*x1^2*x2+f''(x)*(3*x2^2+4x1*x3)
|
|
|
|
|
y4 = (fxder[3] * xi[0] ** 4. + fxder[0] * xi[3] + \
|
|
|
|
|
6. * fxder[2] * xi[0] ** 2. * xi[1] + \
|
|
|
|
|
y4 = (fxder[3] * xi[0] ** 4. + fxder[0] * xi[3] +
|
|
|
|
|
6. * fxder[2] * xi[0] ** 2. * xi[1] +
|
|
|
|
|
fxder[1] * (3. * xi[1] ** 2. + 4. * xi[0] * xi[1]))
|
|
|
|
|
y.append(y4)
|
|
|
|
|
if N > 4:
|
|
|
|
|
warnings.warn('Transformation of derivatives of order>4 not supported.')
|
|
|
|
|
warnings.warn('Transformation of derivatives of ' +
|
|
|
|
|
'order>4 not supported.')
|
|
|
|
|
return y # y0,y1,y2,y3,y4
|
|
|
|
|
def good_bins(data=None, range=None, num_bins=None, num_data=None, odd=False, loose=True): #@ReservedAssignment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def good_bins(data=None, range=None, num_bins=None, # @ReservedAssignment
|
|
|
|
|
num_data=None, odd=False, loose=True):
|
|
|
|
|
''' Return good bins for histogram
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
@ -2158,7 +2221,8 @@ def good_bins(data=None, range=None, num_bins=None, num_data=None, odd=False, lo
|
|
|
|
|
range : (float, float)
|
|
|
|
|
minimum and maximum range of bins (default data.min(), data.max())
|
|
|
|
|
num_bins : scalar integer
|
|
|
|
|
approximate number of bins wanted (default depending on num_data=len(data))
|
|
|
|
|
approximate number of bins wanted
|
|
|
|
|
(default depending on num_data=len(data))
|
|
|
|
|
odd : bool
|
|
|
|
|
placement of bins (0 or 1) (default 0)
|
|
|
|
|
loose : bool
|
|
|
|
@ -2188,7 +2252,7 @@ def good_bins(data=None, range=None, num_bins=None, num_data=None, odd=False, lo
|
|
|
|
|
num_bins = np.ceil(4 * np.sqrt(np.sqrt(num_data)))
|
|
|
|
|
|
|
|
|
|
d = float(mx - mn) / num_bins * 2
|
|
|
|
|
e = np.floor(np.log(d) / np.log(10));
|
|
|
|
|
e = np.floor(np.log(d) / np.log(10))
|
|
|
|
|
m = np.floor(d / 10 ** e)
|
|
|
|
|
if m > 5:
|
|
|
|
|
m = 5
|
|
|
|
@ -2201,7 +2265,9 @@ def good_bins(data=None, range=None, num_bins=None, num_data=None, odd=False, lo
|
|
|
|
|
limits = np.arange(mn, mx + d / 2, d)
|
|
|
|
|
return limits
|
|
|
|
|
|
|
|
|
|
def plot_histgrm(data, bins=None, range=None, normed=False, weights=None, lintype='b-'): #@ReservedAssignment
|
|
|
|
|
|
|
|
|
|
def plot_histgrm(data, bins=None, range=None, # @ReservedAssignment
|
|
|
|
|
normed=False, weights=None, lintype='b-'):
|
|
|
|
|
'''
|
|
|
|
|
Plot histogram
|
|
|
|
|
|
|
|
|
@ -2254,7 +2320,9 @@ def plot_histgrm(data, bins=None, range=None, normed=False, weights=None, lintyp
|
|
|
|
|
if bins is None:
|
|
|
|
|
bins = np.ceil(4 * np.sqrt(np.sqrt(len(x))))
|
|
|
|
|
|
|
|
|
|
bin_, limits = np.histogram(data, bins=bins, normed=normed, weights=weights) #, new=True)
|
|
|
|
|
#, new=True)
|
|
|
|
|
bin_, limits = np.histogram(
|
|
|
|
|
data, bins=bins, normed=normed, weights=weights)
|
|
|
|
|
limits.shape = (-1, 1)
|
|
|
|
|
xx = limits.repeat(3, axis=1)
|
|
|
|
|
xx.shape = (-1,)
|
|
|
|
@ -2267,6 +2335,7 @@ def plot_histgrm(data, bins=None, range=None, normed=False, weights=None, lintyp
|
|
|
|
|
yy = np.hstack((yy, 0.0))
|
|
|
|
|
return plotbackend.plot(xx, yy, lintype, limits, limits * 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def num2pistr(x, n=3):
|
|
|
|
|
'''
|
|
|
|
|
Convert a scalar to a text string in fractions of pi
|
|
|
|
@ -2303,6 +2372,7 @@ def num2pistr(x, n=3):
|
|
|
|
|
xtxt = format % x
|
|
|
|
|
return xtxt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fourier(data, t=None, T=None, m=None, n=None, method='trapz'):
|
|
|
|
|
'''
|
|
|
|
|
Returns Fourier coefficients.
|
|
|
|
@ -2314,7 +2384,8 @@ def fourier(data, t=None, T=None, m=None, n=None, method='trapz'):
|
|
|
|
|
t : array-like
|
|
|
|
|
vector with n values indexed from 1 to N.
|
|
|
|
|
T : real scalar
|
|
|
|
|
primitive period of signal, i.e., smallest period. (default T = t[-1]-t[0]
|
|
|
|
|
primitive period of signal, i.e., smallest period.
|
|
|
|
|
(default T = t[-1]-t[0]
|
|
|
|
|
m : scalar integer
|
|
|
|
|
defines no of harmonics desired (default M = N)
|
|
|
|
|
n : scalar integer
|
|
|
|
@ -2398,7 +2469,7 @@ def fourier(data, t=None, T=None, m=None, n=None, method='trapz'):
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# # Fourier coefficients by fft
|
|
|
|
|
# Fourier coefficients by fft
|
|
|
|
|
# Fcof1 = 2*ifft(x(1:N1,:),[],1);
|
|
|
|
|
# Pcor = [1; exp(sqrt(-1)*(1:M-1).'*t(1))]; % correction term to get
|
|
|
|
|
# % the correct integration limits
|
|
|
|
@ -2409,10 +2480,10 @@ def fourier(data, t=None, T=None, m=None, n=None, method='trapz'):
|
|
|
|
|
return a, b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_find_cross():
|
|
|
|
|
t = findcross([0, 0, 1, -1, 1], 0) # @UnusedVariable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_common_shape():
|
|
|
|
|
|
|
|
|
|
A = ones((4, 1))
|
|
|
|
@ -2443,18 +2514,20 @@ def _test_meshgrid():
|
|
|
|
|
yv[0, 0] = 10
|
|
|
|
|
print(xv)
|
|
|
|
|
print(yv)
|
|
|
|
|
## >>> xv
|
|
|
|
|
# >>> xv
|
|
|
|
|
## array([[ 0. , 0.5, 1. ]])
|
|
|
|
|
## >>> yv
|
|
|
|
|
## array([[ 0.],
|
|
|
|
|
## [ 1.]])
|
|
|
|
|
## array([[-1. , -0.5, 1. , 4. , 5. ],
|
|
|
|
|
# >>> yv
|
|
|
|
|
# array([[ 0.],
|
|
|
|
|
# [ 1.]])
|
|
|
|
|
# array([[-1. , -0.5, 1. , 4. , 5. ],
|
|
|
|
|
## [-1. , -0.5, 1. , 4. , 5. ],
|
|
|
|
|
## [-1. , -0.5, 1. , 4. , 5. ]])
|
|
|
|
|
##
|
|
|
|
|
## array([[ 0., 0., 0., 0., 0.],
|
|
|
|
|
# [-1. , -0.5, 1. , 4. , 5. ]])
|
|
|
|
|
#
|
|
|
|
|
# array([[ 0., 0., 0., 0., 0.],
|
|
|
|
|
## [-2., -2., -2., -2., -2.],
|
|
|
|
|
## [-5., -5., -5., -5., -5.]])
|
|
|
|
|
# [-5., -5., -5., -5., -5.]])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_tranproc():
|
|
|
|
|
import wafo.transform.models as wtm
|
|
|
|
|
tr = wtm.TrHermite()
|
|
|
|
@ -2466,14 +2539,19 @@ def _test_tranproc():
|
|
|
|
|
#>>> plot(g(:,1),[g(:,2),gder(:,2)])
|
|
|
|
|
#>>> plot(g(:,1),pdfnorm(g(:,2)).*gder(:,2),g(:,1),pdfnorm(g(:,1)))
|
|
|
|
|
#>>> legend('Transformed model','Gaussian model')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_detrend():
|
|
|
|
|
import pylab as plb
|
|
|
|
|
cos = plb.cos;randn = plb.randn
|
|
|
|
|
cos = plb.cos
|
|
|
|
|
randn = plb.randn
|
|
|
|
|
x = linspace(0, 1, 200)
|
|
|
|
|
y = exp(x) + cos(5 * 2 * pi * x) + 1e-1 * randn(x.size)
|
|
|
|
|
y0 = detrendma(y, 20);tr = y - y0
|
|
|
|
|
y0 = detrendma(y, 20)
|
|
|
|
|
tr = y - y0
|
|
|
|
|
plb.plot(x, y, x, y0, 'r', x, exp(x), 'k', x, tr, 'm')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_extrema():
|
|
|
|
|
import pylab as pb
|
|
|
|
|
from pylab import plot
|
|
|
|
@ -2485,7 +2563,6 @@ def _test_extrema():
|
|
|
|
|
_ind1 = findrfc(tp, 0.3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_discretize():
|
|
|
|
|
import pylab as plb
|
|
|
|
|
x, y = discretize(cos, 0, pi)
|
|
|
|
@ -2501,6 +2578,7 @@ def _test_stirlerr():
|
|
|
|
|
print getshipchar(1000)
|
|
|
|
|
print betaloge(3, 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_parse_kwargs():
|
|
|
|
|
opt = dict(arg1=1, arg2=3)
|
|
|
|
|
print opt
|
|
|
|
@ -2519,6 +2597,7 @@ def _test_parse_kwargs():
|
|
|
|
|
out1 = testfun(opt0['opt1'], **opt0)
|
|
|
|
|
print out1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_docstrings():
|
|
|
|
|
import doctest
|
|
|
|
|
doctest.testmod()
|
|
|
|
|