From ced5583ae12a314de1759f448ad5fe4bfe37b147 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 6 Oct 2012 02:23:23 -0400 Subject: [PATCH] fixed error message in Qt.py made scipy optional in functions and ImageItem --- Qt.py | 2 +- functions.py | 32 +++++++++++++++++++++++--------- graphicsItems/ImageItem.py | 5 ----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Qt.py b/Qt.py index 96703e89..43288d70 100644 --- a/Qt.py +++ b/Qt.py @@ -44,5 +44,5 @@ QtVersion = PySide.QtCore.__version__ if USE_PYSIDE else QtCore.QT_VERSION_STR m = re.match(r'(\d+)\.(\d+).*', QtVersion) if m is not None and map(int, m.groups()) < versionReq: print map(int, m.groups()) - raise Exception('pyqtgraph requires Qt version >= %d.%d (your version is %s)' % (versionReq + (QtVersion,))) + raise Exception('pyqtgraph requires Qt version >= %d.%d (your version is %s)' % (versionReq[0], versionReq[1], QtVersion)) diff --git a/functions.py b/functions.py index 85564e9f..e32b2e60 100644 --- a/functions.py +++ b/functions.py @@ -24,13 +24,18 @@ SI_PREFIXES_ASCII = 'yzafpnum kMGTPEZY' from .Qt import QtGui, QtCore import numpy as np -import scipy.ndimage import decimal, re + try: - import scipy.weave - USE_WEAVE = True -except: - USE_WEAVE = False + import scipy.ndimage + HAVE_SCIPY = True + try: + import scipy.weave + USE_WEAVE = True + except: + USE_WEAVE = False +except ImportError: + HAVE_SCIPY = False from . import debug @@ -401,7 +406,9 @@ def affineSlice(data, shape, origin, vectors, axes, order=1, returnCoords=False, affineSlice(data, shape=(20,20), origin=(40,0,0), vectors=((-1, 1, 0), (-1, 0, 1)), axes=(1,2,3)) """ - + if not HAVE_SCIPY: + raise Exception("This function requires the scipy library, but it does not appear to be importable.") + # sanity check if len(shape) != len(vectors): raise Exception("shape and vectors must have same length.") @@ -469,6 +476,8 @@ def solve3DTransform(points1, points2): Find a 3D transformation matrix that maps points1 onto points2 points must be specified as a list of 4 Vectors. """ + if not HAVE_SCIPY: + raise Exception("This function depends on the scipy library, but it does not appear to be importable.") A = np.array([[points1[i].x(), points1[i].y(), points1[i].z(), 1] for i in range(4)]) B = np.array([[points2[i].x(), points2[i].y(), points2[i].z(), 1] for i in range(4)]) @@ -488,6 +497,8 @@ def solveBilinearTransform(points1, points2): mapped = np.dot(matrix, [x*y, x, y, 1]) """ + if not HAVE_SCIPY: + raise Exception("This function depends on the scipy library, but it does not appear to be importable.") ## A is 4 rows (points) x 4 columns (xy, x, y, 1) ## B is 4 rows (points) x 2 columns (x, y) A = np.array([[points1[i].x()*points1[i].y(), points1[i].x(), points1[i].y(), 1] for i in range(4)]) @@ -505,7 +516,7 @@ def solveBilinearTransform(points1, points2): def makeARGB(data, lut=None, levels=None, useRGBA=False): - """ + """ Convert a 2D or 3D array into an ARGB array suitable for building QImages Will optionally do scaling and/or table lookups to determine final colors. @@ -531,7 +542,7 @@ def makeARGB(data, lut=None, levels=None, useRGBA=False): useRGBA - If True, the data is returned in RGBA order. The default is False, which returns in BGRA order for use with QImage. - """ + """ prof = debug.Profiler('functions.makeARGB', disabled=True) ## sanity checks @@ -1299,9 +1310,12 @@ def invertQTransform(tr): bugs in that method. (specifically, Qt has floating-point precision issues when determining whether a matrix is invertible) """ + if not USE_WEAVE: + raise Exception("This function depends on scipy.weave library, but it does not appear to be usable.") + #return tr.inverted()[0] arr = np.array([[tr.m11(), tr.m12(), tr.m13()], [tr.m21(), tr.m22(), tr.m23()], [tr.m31(), tr.m32(), tr.m33()]]) inv = scipy.linalg.inv(arr) return QtGui.QTransform(inv[0,0], inv[0,1], inv[0,2], inv[1,0], inv[1,1], inv[1,2], inv[2,0], inv[2,1]) - \ No newline at end of file + diff --git a/graphicsItems/ImageItem.py b/graphicsItems/ImageItem.py index 02fa8257..44abb887 100644 --- a/graphicsItems/ImageItem.py +++ b/graphicsItems/ImageItem.py @@ -1,11 +1,6 @@ from pyqtgraph.Qt import QtGui, QtCore import numpy as np import collections -try: - import scipy.weave as weave - from scipy.weave import converters -except: - pass import pyqtgraph.functions as fn import pyqtgraph.debug as debug from .GraphicsObject import GraphicsObject