Merge pull request #273 from campagnola/numpy-fix
Corrections for numpy API changes
This commit is contained in:
commit
fd76443458
@ -6,8 +6,18 @@ Distributed under MIT/X11 license. See license.txt for more infomation.
|
||||
"""
|
||||
|
||||
from __future__ import division
|
||||
import warnings
|
||||
import numpy as np
|
||||
import decimal, re
|
||||
import ctypes
|
||||
import sys, struct
|
||||
from .python2_3 import asUnicode, basestring
|
||||
from .Qt import QtGui, QtCore, USE_PYSIDE
|
||||
from . import getConfigOption, setConfigOptions
|
||||
from . import debug
|
||||
|
||||
|
||||
|
||||
Colors = {
|
||||
'b': QtGui.QColor(0,0,255,255),
|
||||
'g': QtGui.QColor(0,255,0,255),
|
||||
@ -27,14 +37,6 @@ SI_PREFIXES_ASCII = 'yzafpnum kMGTPEZY'
|
||||
|
||||
|
||||
|
||||
from .Qt import QtGui, QtCore, USE_PYSIDE
|
||||
from . import getConfigOption, setConfigOptions
|
||||
import numpy as np
|
||||
import decimal, re
|
||||
import ctypes
|
||||
import sys, struct
|
||||
|
||||
from . import debug
|
||||
|
||||
def siScale(x, minVal=1e-25, allowUnicode=True):
|
||||
"""
|
||||
@ -378,7 +380,8 @@ def eq(a, b):
|
||||
return True
|
||||
|
||||
try:
|
||||
e = a==b
|
||||
with warnings.catch_warnings(module=np): # ignore numpy futurewarning (numpy v. 1.10)
|
||||
e = a==b
|
||||
except ValueError:
|
||||
return False
|
||||
except AttributeError:
|
||||
@ -1374,22 +1377,17 @@ def arrayToQPath(x, y, connect='all'):
|
||||
arr[1:-1]['y'] = y
|
||||
|
||||
# decide which points are connected by lines
|
||||
if connect == 'pairs':
|
||||
connect = np.empty((n/2,2), dtype=np.int32)
|
||||
if connect.size != n:
|
||||
raise Exception("x,y array lengths must be multiple of 2 to use connect='pairs'")
|
||||
connect[:,0] = 1
|
||||
connect[:,1] = 0
|
||||
connect = connect.flatten()
|
||||
if connect == 'finite':
|
||||
connect = np.isfinite(x) & np.isfinite(y)
|
||||
arr[1:-1]['c'] = connect
|
||||
if connect == 'all':
|
||||
if eq(connect, 'all'):
|
||||
arr[1:-1]['c'] = 1
|
||||
elif eq(connect, 'pairs'):
|
||||
arr[1:-1]['c'][::2] = 1
|
||||
arr[1:-1]['c'][1::2] = 0
|
||||
elif eq(connect, 'finite'):
|
||||
arr[1:-1]['c'] = np.isfinite(x) & np.isfinite(y)
|
||||
elif isinstance(connect, np.ndarray):
|
||||
arr[1:-1]['c'] = connect
|
||||
else:
|
||||
raise Exception('connect argument must be "all", "pairs", or array')
|
||||
raise Exception('connect argument must be "all", "pairs", "finite", or array')
|
||||
|
||||
#profiler('fill array')
|
||||
# write last 0
|
||||
@ -1580,7 +1578,7 @@ def isocurve(data, level, connected=False, extendToEdge=False, path=False):
|
||||
#vertIndex = i - 2*j*i + 3*j + 4*k ## this is just to match Bourk's vertex numbering scheme
|
||||
vertIndex = i+2*j
|
||||
#print i,j,k," : ", fields[i,j,k], 2**vertIndex
|
||||
index += fields[i,j] * 2**vertIndex
|
||||
np.add(index, fields[i,j] * 2**vertIndex, out=index, casting='unsafe')
|
||||
#print index
|
||||
#print index
|
||||
|
||||
@ -2096,7 +2094,7 @@ def isosurface(data, level):
|
||||
for k in [0,1]:
|
||||
fields[i,j,k] = mask[slices[i], slices[j], slices[k]]
|
||||
vertIndex = i - 2*j*i + 3*j + 4*k ## this is just to match Bourk's vertex numbering scheme
|
||||
index += fields[i,j,k] * 2**vertIndex
|
||||
np.add(index, fields[i,j,k] * 2**vertIndex, out=index, casting='unsafe')
|
||||
|
||||
### Generate table of edges that have been cut
|
||||
cutEdges = np.zeros([x+1 for x in index.shape]+[3], dtype=np.uint32)
|
||||
@ -2165,7 +2163,7 @@ def isosurface(data, level):
|
||||
### expensive:
|
||||
verts = faceShiftTables[i][cellInds]
|
||||
#profiler()
|
||||
verts[...,:3] += cells[:,np.newaxis,np.newaxis,:] ## we now have indexes into cutEdges
|
||||
np.add(verts[...,:3], cells[:,np.newaxis,np.newaxis,:], out=verts[...,:3], casting='unsafe') ## we now have indexes into cutEdges
|
||||
verts = verts.reshape((verts.shape[0]*i,)+verts.shape[2:])
|
||||
#profiler()
|
||||
|
||||
|
@ -145,7 +145,7 @@ class SymbolAtlas(object):
|
||||
arr = fn.imageToArray(img, copy=False, transpose=False)
|
||||
else:
|
||||
(y,x,h,w) = sourceRect.getRect()
|
||||
arr = self.atlasData[x:x+w, y:y+w]
|
||||
arr = self.atlasData[int(x):int(x+w), int(y):int(y+w)]
|
||||
rendered[key] = arr
|
||||
w = arr.shape[0]
|
||||
avgWidth += w
|
||||
@ -180,10 +180,10 @@ class SymbolAtlas(object):
|
||||
self.atlasRows[-1][2] = x
|
||||
height = y + rowheight
|
||||
|
||||
self.atlasData = np.zeros((width, height, 4), dtype=np.ubyte)
|
||||
self.atlasData = np.zeros((int(width), int(height), 4), dtype=np.ubyte)
|
||||
for key in symbols:
|
||||
y, x, h, w = self.symbolMap[key].getRect()
|
||||
self.atlasData[x:x+w, y:y+h] = rendered[key]
|
||||
self.atlasData[int(x):int(x+w), int(y):int(y+h)] = rendered[key]
|
||||
self.atlas = None
|
||||
self.atlasValid = True
|
||||
self.max_width = maxWidth
|
||||
|
Loading…
Reference in New Issue
Block a user