diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 2c11b647..5cbb177e 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -78,7 +78,7 @@ def siScale(x, minVal=1e-25, allowUnicode=True): pref = SI_PREFIXES_ASCII[m+8] p = .001**m - return (p, pref) + return (p, pref) def siFormat(x, precision=3, suffix='', space=True, error=None, minVal=1e-25, allowUnicode=True): @@ -1035,7 +1035,6 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False): ============== ================================================================================== """ profile = debug.Profiler() - if data.ndim not in (2, 3): raise TypeError("data must be 2D or 3D") if data.ndim == 3 and data.shape[2] > 4: @@ -1083,7 +1082,12 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False): dtype = np.ubyte else: dtype = np.min_scalar_type(lut.shape[0]-1) - + + # awkward, but fastest numpy native nan evaluation + # + nanMask = None + if data.dtype.kind == 'f' and np.isnan(data.min()): + nanMask = np.isnan(data) # Apply levels if given if levels is not None: if isinstance(levels, np.ndarray) and levels.ndim == 2: @@ -1106,10 +1110,8 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False): if minVal == maxVal: maxVal = np.nextafter(maxVal, 2*maxVal) data = rescaleData(data, scale/(maxVal-minVal), minVal, dtype=dtype) - profile() - # apply LUT if given if lut is not None: data = applyLookupTable(data, lut) @@ -1152,7 +1154,12 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False): imgData[..., 3] = 255 else: alpha = True - + + # apply nan mask through alpha channel + if nanMask is not None: + alpha = True + imgData[nanMask, 3] = 0 + profile() return imgData, alpha