fixed error message in Qt.py

made scipy optional in functions and ImageItem
This commit is contained in:
Luke Campagnola 2012-10-06 02:23:23 -04:00
parent 27c90c5dd5
commit ced5583ae1
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.weave import scipy.ndimage
USE_WEAVE = True HAVE_SCIPY = True
except: try:
USE_WEAVE = False import scipy.weave
USE_WEAVE = True
except:
USE_WEAVE = False
except ImportError:
HAVE_SCIPY = False
from . import debug 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)) 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):
raise Exception("shape and vectors must have same length.") 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 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)])
@ -488,6 +497,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)])
@ -505,7 +516,7 @@ def solveBilinearTransform(points1, points2):
def makeARGB(data, lut=None, levels=None, useRGBA=False): def makeARGB(data, lut=None, levels=None, useRGBA=False):
""" """
Convert a 2D or 3D array into an ARGB array suitable for building QImages 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. 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 useRGBA - If True, the data is returned in RGBA order. The default is
False, which returns in BGRA order for use with QImage. False, which returns in BGRA order for use with QImage.
""" """
prof = debug.Profiler('functions.makeARGB', disabled=True) prof = debug.Profiler('functions.makeARGB', disabled=True)
## sanity checks ## sanity checks
@ -1299,9 +1310,12 @@ 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)
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]) 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])

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