colormap no longer requires scipy.interpolate
This commit is contained in:
parent
b398ccd0ce
commit
18ddff76f0
@ -63,8 +63,8 @@ class ColorMap(object):
|
|||||||
ignored. By default, the mode is entirely RGB.
|
ignored. By default, the mode is entirely RGB.
|
||||||
=============== ==============================================================
|
=============== ==============================================================
|
||||||
"""
|
"""
|
||||||
self.pos = pos
|
self.pos = np.array(pos)
|
||||||
self.color = color
|
self.color = np.array(color)
|
||||||
if mode is None:
|
if mode is None:
|
||||||
mode = np.ones(len(pos))
|
mode = np.ones(len(pos))
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
@ -83,11 +83,6 @@ class ColorMap(object):
|
|||||||
qcolor Values are returned as an array of QColor objects.
|
qcolor Values are returned as an array of QColor objects.
|
||||||
=========== ===============================================================
|
=========== ===============================================================
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
import scipy.interpolate
|
|
||||||
except:
|
|
||||||
raise Exception("Colormap.map() requires the package scipy.interpolate, but it could not be imported.")
|
|
||||||
|
|
||||||
if isinstance(mode, basestring):
|
if isinstance(mode, basestring):
|
||||||
mode = self.enumMap[mode.lower()]
|
mode = self.enumMap[mode.lower()]
|
||||||
|
|
||||||
@ -96,15 +91,24 @@ class ColorMap(object):
|
|||||||
else:
|
else:
|
||||||
pos, color = self.getStops(mode)
|
pos, color = self.getStops(mode)
|
||||||
|
|
||||||
data = np.clip(data, pos.min(), pos.max())
|
# don't need this--np.interp takes care of it.
|
||||||
|
#data = np.clip(data, pos.min(), pos.max())
|
||||||
|
|
||||||
if not isinstance(data, np.ndarray):
|
# Interpolate
|
||||||
interp = scipy.interpolate.griddata(pos, color, np.array([data]))[0]
|
# TODO: is griddata faster?
|
||||||
|
# interp = scipy.interpolate.griddata(pos, color, data)
|
||||||
|
if np.isscalar(data):
|
||||||
|
interp = np.empty((color.shape[1],), dtype=color.dtype)
|
||||||
else:
|
else:
|
||||||
interp = scipy.interpolate.griddata(pos, color, data)
|
|
||||||
|
|
||||||
if mode == self.QCOLOR:
|
|
||||||
if not isinstance(data, np.ndarray):
|
if not isinstance(data, np.ndarray):
|
||||||
|
data = np.array(data)
|
||||||
|
interp = np.empty(data.shape + (color.shape[1],), dtype=color.dtype)
|
||||||
|
for i in range(color.shape[1]):
|
||||||
|
interp[...,i] = np.interp(data, pos, color[:,i])
|
||||||
|
|
||||||
|
# Convert to QColor if requested
|
||||||
|
if mode == self.QCOLOR:
|
||||||
|
if np.isscalar(data):
|
||||||
return QtGui.QColor(*interp)
|
return QtGui.QColor(*interp)
|
||||||
else:
|
else:
|
||||||
return [QtGui.QColor(*x) for x in interp]
|
return [QtGui.QColor(*x) for x in interp]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user