Fixed error message in Qt.py

Made scipy optional in functions and ImageItem
This commit is contained in:
Luke Campagnola 2012-10-06 16:58:35 -04:00
commit 844dbb20a5
3 changed files with 24 additions and 15 deletions

2
Qt.py
View File

@ -44,5 +44,5 @@ QtVersion = PySide.QtCore.__version__ if USE_PYSIDE else QtCore.QT_VERSION_STR
m = re.match(r'(\d+)\.(\d+).*', QtVersion) m = re.match(r'(\d+)\.(\d+).*', QtVersion)
if m is not None and map(int, m.groups()) < versionReq: if m is not None and map(int, m.groups()) < versionReq:
print map(int, m.groups()) 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))

View File

@ -24,13 +24,18 @@ SI_PREFIXES_ASCII = 'yzafpnum kMGTPEZY'
from .Qt import QtGui, QtCore from .Qt import QtGui, QtCore
import numpy as np import numpy as np
import scipy.ndimage
import decimal, re import decimal, re
try: try:
import scipy.ndimage
HAVE_SCIPY = True
try:
import scipy.weave import scipy.weave
USE_WEAVE = True USE_WEAVE = True
except: except:
USE_WEAVE = False USE_WEAVE = False
except ImportError:
HAVE_SCIPY = False
from . import debug from . import debug
@ -401,6 +406,8 @@ 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)) 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 # sanity check
if len(shape) != len(vectors): if len(shape) != len(vectors):
@ -535,6 +542,8 @@ def solve3DTransform(points1, points2):
Find a 3D transformation matrix that maps points1 onto points2 Find a 3D transformation matrix that maps points1 onto points2
points must be specified as a list of 4 Vectors. 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)]) 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)]) B = np.array([[points2[i].x(), points2[i].y(), points2[i].z(), 1] for i in range(4)])
@ -554,6 +563,8 @@ def solveBilinearTransform(points1, points2):
mapped = np.dot(matrix, [x*y, x, y, 1]) 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) ## A is 4 rows (points) x 4 columns (xy, x, y, 1)
## B is 4 rows (points) x 2 columns (x, y) ## 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)]) A = np.array([[points1[i].x()*points1[i].y(), points1[i].x(), points1[i].y(), 1] for i in range(4)])
@ -1365,6 +1376,9 @@ def invertQTransform(tr):
bugs in that method. (specifically, Qt has floating-point precision issues bugs in that method. (specifically, Qt has floating-point precision issues
when determining whether a matrix is invertible) 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] #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()]]) 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) inv = scipy.linalg.inv(arr)

View File

@ -1,11 +1,6 @@
from pyqtgraph.Qt import QtGui, QtCore from pyqtgraph.Qt import QtGui, QtCore
import numpy as np import numpy as np
import collections import collections
try:
import scipy.weave as weave
from scipy.weave import converters
except:
pass
import pyqtgraph.functions as fn import pyqtgraph.functions as fn
import pyqtgraph.debug as debug import pyqtgraph.debug as debug
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject