From 2c415a8b03dc8bbb079c867d1f86d4b092bc4b79 Mon Sep 17 00:00:00 2001 From: u55 Date: Mon, 11 Jan 2016 23:02:12 -0700 Subject: [PATCH 1/7] Fix Numpy FutureWarning. Don't accidentally compare an array to string. Fixes issue #243. --- pyqtgraph/functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 3936e926..09c2fea6 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -1312,15 +1312,15 @@ def arrayToQPath(x, y, connect='all'): connect[:,0] = 1 connect[:,1] = 0 connect = connect.flatten() - if connect == 'finite': + elif connect == 'finite': connect = np.isfinite(x) & np.isfinite(y) arr[1:-1]['c'] = connect - if connect == 'all': + elif connect == 'all': arr[1:-1]['c'] = 1 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 From 2f2975212fb575d9dcea28708c31349c740833f4 Mon Sep 17 00:00:00 2001 From: u55 Date: Mon, 11 Jan 2016 23:30:23 -0700 Subject: [PATCH 2/7] Fix Numpy FutureWarning. Try again. --- pyqtgraph/functions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 09c2fea6..b5c7b0d5 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -1312,6 +1312,7 @@ def arrayToQPath(x, y, connect='all'): connect[:,0] = 1 connect[:,1] = 0 connect = connect.flatten() + arr[1:-1]['c'] = connect elif connect == 'finite': connect = np.isfinite(x) & np.isfinite(y) arr[1:-1]['c'] = connect From a41f3c362c8cc2b966ee0effa5682a6f5c6ddc01 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 30 Jan 2016 00:53:49 -0800 Subject: [PATCH 3/7] fix case where connect is ndarray --- pyqtgraph/functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index b5c7b0d5..af95e6c1 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -1305,7 +1305,7 @@ def arrayToQPath(x, y, connect='all'): arr[1:-1]['y'] = y # decide which points are connected by lines - if connect == 'pairs': + if eq(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'") @@ -1313,10 +1313,10 @@ def arrayToQPath(x, y, connect='all'): connect[:,1] = 0 connect = connect.flatten() arr[1:-1]['c'] = connect - elif connect == 'finite': + elif eq(connect, 'finite'): connect = np.isfinite(x) & np.isfinite(y) arr[1:-1]['c'] = connect - elif connect == 'all': + elif eq(connect, 'all'): arr[1:-1]['c'] = 1 elif isinstance(connect, np.ndarray): arr[1:-1]['c'] = connect From f279988916e9607944184e5621c4809d6b79d709 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 30 Jan 2016 09:08:05 -0800 Subject: [PATCH 4/7] suppress numpy futurewarning cleanups in arraytoqpath --- pyqtgraph/functions.py | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index c2a658a1..3d134feb 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -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(np): # ignore numpy futurewarning (numpy v. 1.10) + e = a==b except ValueError: return False except AttributeError: @@ -1374,19 +1377,13 @@ def arrayToQPath(x, y, connect='all'): arr[1:-1]['y'] = y # decide which points are connected by lines - if eq(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() - arr[1:-1]['c'] = connect - elif eq(connect, 'finite'): - connect = np.isfinite(x) & np.isfinite(y) - arr[1:-1]['c'] = connect - elif eq(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: From 3f03622a026f27d02bf852b822989539628d0548 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 30 Jan 2016 10:06:58 -0800 Subject: [PATCH 5/7] fix isosurface/isocurve for numpy API change --- pyqtgraph/functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 3d134feb..0b43aee7 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -1578,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 @@ -2094,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) @@ -2163,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() From d308d4515341f9c00d0e2318bda4ff5f4d8ca815 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 30 Jan 2016 12:20:05 -0800 Subject: [PATCH 6/7] avoid numpy warnings when indexing with floats --- pyqtgraph/graphicsItems/ScatterPlotItem.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index e6be9acd..89f068ce 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -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 From ee3e6212facfae899fba160e79c4c96d6af0de99 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 30 Jan 2016 12:26:23 -0800 Subject: [PATCH 7/7] correction for catch_warnings on python 3 --- pyqtgraph/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 0b43aee7..894d33e5 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -380,7 +380,7 @@ def eq(a, b): return True try: - with warnings.catch_warnings(np): # ignore numpy futurewarning (numpy v. 1.10) + with warnings.catch_warnings(module=np): # ignore numpy futurewarning (numpy v. 1.10) e = a==b except ValueError: return False