|
|
|
@ -14,6 +14,7 @@ from numpy import (abs, amax, any, logical_and, arange, linspace, atleast_1d,
|
|
|
|
|
from scipy.special import gammaln
|
|
|
|
|
import types
|
|
|
|
|
import warnings
|
|
|
|
|
from wafo import plotbackend
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import wafo.c_library as clib
|
|
|
|
@ -26,7 +27,7 @@ __all__ = ['JITImport', 'DotDict', 'Bunch', 'printf', 'sub_dict_select',
|
|
|
|
|
'parse_kwargs', 'ecross', 'findtc', 'findtp', 'findcross',
|
|
|
|
|
'findextrema', 'findrfc', 'rfcfilter', 'common_shape', 'argsreduce',
|
|
|
|
|
'stirlerr', 'getshipchar', 'betaloge', 'gravity', 'nextpow2',
|
|
|
|
|
'discretize', 'pol2cart', 'cart2pol', 'ndgrid', 'meshgrid']
|
|
|
|
|
'discretize', 'pol2cart', 'cart2pol', 'ndgrid', 'meshgrid', 'histgrm']
|
|
|
|
|
|
|
|
|
|
class JITImport(object):
|
|
|
|
|
'''
|
|
|
|
@ -1849,6 +1850,66 @@ def tranproc(x, f, x0, *xi):
|
|
|
|
|
warnings.warn('Transformation of derivatives of order>4 not supported.')
|
|
|
|
|
return y #y0,y1,y2,y3,y4
|
|
|
|
|
|
|
|
|
|
def histgrm(data, n=None, odd=False, scale=False, lintype='b-'):
|
|
|
|
|
'''HISTGRM Plot histogram
|
|
|
|
|
|
|
|
|
|
CALL: binwidth = histgrm(x,N,odd,scale)
|
|
|
|
|
binwidth = the width of each bin
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
-----------
|
|
|
|
|
x = the data
|
|
|
|
|
n = approximate number of bins wanted
|
|
|
|
|
(default depending on length(x))
|
|
|
|
|
odd = placement of bins (0 or 1) (default 0)
|
|
|
|
|
scale = argument for scaling (default 0)
|
|
|
|
|
scale = 1 yields the area 1 under the histogram
|
|
|
|
|
lintype : specify color and lintype, see PLOT for possibilities.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
R=rndgumb(2,2,1,100);
|
|
|
|
|
histgrm(R,20,0,1)
|
|
|
|
|
hold on
|
|
|
|
|
x=linspace(-3,16,200);
|
|
|
|
|
plot(x,pdfgumb(x,2,2),'r')
|
|
|
|
|
hold off
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
x = np.atleast_1d(data)
|
|
|
|
|
if n is None:
|
|
|
|
|
n = np.ceil(4 * np.sqrt(np.sqrt(len(x))))
|
|
|
|
|
|
|
|
|
|
mn = x.min()
|
|
|
|
|
mx = x.max()
|
|
|
|
|
d = (mx - mn) / n * 2
|
|
|
|
|
e = np.floor(np.log(d) / np.log(10));
|
|
|
|
|
m = np.floor(d / 10 ** e)
|
|
|
|
|
if m > 5:
|
|
|
|
|
m = 5
|
|
|
|
|
elif m > 2:
|
|
|
|
|
m = 2
|
|
|
|
|
|
|
|
|
|
d = m * 10 ** e
|
|
|
|
|
mn = (np.floor(mn / d) - 1) * d - odd * d / 2
|
|
|
|
|
mx = (np.ceil(mx / d) + 1) * d + odd * d / 2
|
|
|
|
|
limits = np.arange(mn, mx, d)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bin, limits = np.histogram(data, bins=limits, normed=scale) #, new=True)
|
|
|
|
|
limits.shape = (-1, 1)
|
|
|
|
|
xx = limits.repeat(3, axis=1)
|
|
|
|
|
xx.shape = (-1,)
|
|
|
|
|
xx = xx[1:-1]
|
|
|
|
|
bin.shape = (-1, 1)
|
|
|
|
|
yy = bin.repeat(3, axis=1)
|
|
|
|
|
#yy[0,0] = 0.0 # pdf
|
|
|
|
|
yy[:, 0] = 0.0 # histogram
|
|
|
|
|
yy.shape = (-1,)
|
|
|
|
|
yy = np.hstack((yy, 0.0))
|
|
|
|
|
plotbackend.plotbackend.plot(xx, yy, lintype, limits, limits * 0)
|
|
|
|
|
binwidth = d
|
|
|
|
|
return binwidth
|
|
|
|
|
|
|
|
|
|
def _test_find_cross():
|
|
|
|
|
t = findcross([0, 0, 1, -1, 1], 0)
|
|
|
|
|