Skip to content

Commit

Permalink
FIX undefined elements were used at several places in the mlab module
Browse files Browse the repository at this point in the history
  • Loading branch information
NelleV committed Aug 31, 2012
1 parent cf7618c commit cf720bc
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions lib/matplotlib/mlab.py
Expand Up @@ -699,16 +699,15 @@ def entropy(y, bins):
x = mu + sigma * randn(200000) x = mu + sigma * randn(200000)
Sanalytic = 0.5 * ( 1.0 + log(2*pi*sigma**2.0) ) Sanalytic = 0.5 * ( 1.0 + log(2*pi*sigma**2.0) )
""" """
n,bins = np.histogram(y, bins) n, bins = np.histogram(y, bins)
n = n.astype(np.float_) n = n.astype(np.float_)


n = np.take(n, np.nonzero(n)[0]) # get the positive n = np.take(n, np.nonzero(n)[0]) # get the positive


p = np.divide(n, len(y)) p = np.divide(n, len(y))


delta = bins[1]-bins[0] delta = bins[1] - bins[0]
S = -1.0*np.sum(p*log(p)) + log(delta) S = -1.0 * np.sum(p * np.log(p)) + np.log(delta)
#S = -1.0*np.sum(p*log(p))
return S return S


def normpdf(x, *args): def normpdf(x, *args):
Expand All @@ -722,22 +721,20 @@ def levypdf(x, gamma, alpha):


N = len(x) N = len(x)


if N%2 != 0: if N % 2 != 0:
raise ValueError('x must be an event length array; try\n' + \ raise ValueError('x must be an event length array; try\n' + \
'x = np.linspace(minx, maxx, N), where N is even') 'x = np.linspace(minx, maxx, N), where N is even')


dx = x[1] - x[0]


dx = x[1]-x[0] f = 1/(N*dx)*np.arange(-N / 2, N / 2, np.float_)


ind = np.concatenate([np.arange(N / 2, N, int),
np.arange(0, N / 2, int)])
df = f[1] - f[0]
cfl = np.exp(-gamma * np.absolute(2 * np.pi * f) ** alpha)


f = 1/(N*dx)*np.arange(-N/2, N/2, np.float_) px = np.fft.fft(np.take(cfl, ind) * df).astype(np.float_)

ind = np.concatenate([np.arange(N/2, N, int),
np.arange(0, N/2, int)])
df = f[1]-f[0]
cfl = exp(-gamma*np.absolute(2*pi*f)**alpha)

px = np.fft.fft(np.take(cfl,ind)*df).astype(np.float_)
return np.take(px, ind) return np.take(px, ind)




Expand Down Expand Up @@ -1458,7 +1455,6 @@ def splitfunc(x):
else: else:
row = [converterseq[j](val) row = [converterseq[j](val)
for j,val in enumerate(splitfunc(line))] for j,val in enumerate(splitfunc(line))]
thisLen = len(row)
X.append(row) X.append(row)


X = np.array(X, dtype) X = np.array(X, dtype)
Expand Down Expand Up @@ -1511,7 +1507,6 @@ def splitfunc(x):
""" """


import operator
import math import math




Expand All @@ -1533,7 +1528,7 @@ def exp_safe(x):
""" """


if type(x) is np.ndarray: if type(x) is np.ndarray:
return exp(np.clip(x,exp_safe_MIN,exp_safe_MAX)) return np.exp(np.clip(x,exp_safe_MIN,exp_safe_MAX))
else: else:
return math.exp(x) return math.exp(x)


Expand Down Expand Up @@ -1817,7 +1812,6 @@ def rec_drop_fields(rec, names):
""" """


names = set(names) names = set(names)
Nr = len(rec)


newdtype = np.dtype([(name, rec.dtype[name]) for name in rec.dtype.names newdtype = np.dtype([(name, rec.dtype[name]) for name in rec.dtype.names
if name not in names]) if name not in names])
Expand Down Expand Up @@ -2146,8 +2140,6 @@ def csv2rec(fname, comments='#', skiprows=0, checkrows=0, delimiter=',',


import dateutil.parser import dateutil.parser
import datetime import datetime
parsedate = dateutil.parser.parse



fh = cbook.to_filehandle(fname) fh = cbook.to_filehandle(fname)


Expand Down Expand Up @@ -2780,6 +2772,8 @@ def griddata(x,y,z,xi,yi,interp='nn'):
if xi.ndim == 1: if xi.ndim == 1:
xi,yi = np.meshgrid(xi,yi) xi,yi = np.meshgrid(xi,yi)
# triangulate data # triangulate data
# FIXME delaunay is not imported here, and depends on the
# scipy.spatial packages; Scipy is not a dependency of matplotlib.
tri = delaunay.Triangulation(x,y) tri = delaunay.Triangulation(x,y)
# interpolate data # interpolate data
if interp == 'nn': if interp == 'nn':
Expand Down Expand Up @@ -2938,7 +2932,6 @@ def stineman_interp(xi,x,y,yp=None):
x=np.asarray(x, np.float_) x=np.asarray(x, np.float_)
y=np.asarray(y, np.float_) y=np.asarray(y, np.float_)
assert x.shape == y.shape assert x.shape == y.shape
N=len(y)


if yp is None: if yp is None:
yp = slopes(x,y) yp = slopes(x,y)
Expand Down

0 comments on commit cf720bc

Please sign in to comment.