Exemplo n.º 1
0
    def __call__(self, value):

        vmin = self.vmin
        vmax = self.vmax

        if type(value) in [IntType, FloatType]:
            vtype = 'scalar'
            val = array([value])
        else:
            vtype = 'array'
            val = nx.asarray(value)

        # if both vmin is None and vmax is None, we'll automatically
        # norm the data to vmin/vmax of the actual data, so the
        # clipping step won't be needed.
        if vmin is None and vmax is None:
            needs_clipping = False
        else:
            needs_clipping = True

        if vmin is None or vmax is None:
            rval = nx.ravel(val)
            #do this if sentinels (values to ignore in data)
            if self.ignore:
                sortValues = nx.sort(rval)
                if vmin is None:
                    # find the lowest non-sentinel value
                    for thisVal in sortValues:
                        if thisVal not in self.ignore:
                            vmin = thisVal  #vmin is the lowest non-sentinel value
                            break
                    else:
                        vmin = 0.
                if vmax is None:
                    for thisVal in sortValues[::-1]:
                        if thisVal not in self.ignore:
                            vmax = thisVal  #vmax is the greatest non-sentinel value
                            break
                    else:
                        vmax = 0.
            else:
                if vmin is None: vmin = min(rval)
                if vmax is None: vmax = max(rval)
        if vmin > vmax:
            raise ValueError("minvalue must be less than or equal to maxvalue")
        elif vmin == vmax:
            return 0. * value
        else:
            if needs_clipping:
                val = nx.clip(val, vmin, vmax)
            result = (1.0 / (vmax - vmin)) * (val - vmin)

        # replace sentinels with original (non-normalized) values
        for thisIgnore in self.ignore:
            result = nx.where(val == thisIgnore, thisIgnore, result)

        if vtype == 'scalar':
            result = result[0]
        return result
        def __call__(self, value):

                vmin = self.vmin
                vmax = self.vmax

                if type(value) in [IntType, FloatType]:
                        vtype = 'scalar'
                        val = array([value])
                else:
                        vtype = 'array'
                        val = nx.asarray(value)

                # if both vmin is None and vmax is None, we'll automatically
                # norm the data to vmin/vmax of the actual data, so the
                # clipping step won't be needed.
                if vmin is None and vmax is None:
                        needs_clipping = False
                else:
                        needs_clipping = True

                if vmin is None or vmax is None:
                        rval = nx.ravel(val)
                        #do this if sentinels (values to ignore in data)
                        if self.ignore:
                                sortValues=nx.sort(rval)
                                if vmin is None: 
                                        # find the lowest non-sentinel value
                                        for thisVal in sortValues:
                                                if thisVal not in self.ignore:
                                                        vmin=thisVal #vmin is the lowest non-sentinel value
                                                        break
                                        else:
                                                vmin=0.
                                if vmax is None: 
                                        for thisVal in sortValues[::-1]:
                                                if thisVal not in self.ignore:
                                                        vmax=thisVal #vmax is the greatest non-sentinel value
                                                        break
                                        else:
                                                vmax=0.
                        else:
                                if vmin is None: vmin = min(rval)
                                if vmax is None: vmax = max(rval)
                if vmin > vmax:
                        raise ValueError("minvalue must be less than or equal to maxvalue")
                elif vmin==vmax:
                        return 0.*value
                else:
                        if needs_clipping:
                                val = nx.clip(val,vmin, vmax)
                        result = (1.0/(vmax-vmin))*(val-vmin)

                # replace sentinels with original (non-normalized) values
                for thisIgnore in self.ignore:
                        result = nx.where(val==thisIgnore,thisIgnore,result)

                if vtype == 'scalar':
                        result = result[0]
                return result
        def __call__(self, scaledImageData, alpha=1):
                # assumes the data is already normalized (ignoring sentinels)
                # clip to be on the safe side
                rgbaValues = self.cmap(nx.clip(scaledImageData, 0.,1.))

                #replace sentinel data with sentinel colors
                for sentinel,rgb in self.sentinels.items():
                        r,g,b = rgb
                        rgbaValues[:,:,0] =  nx.where(scaledImageData==sentinel, r, rgbaValues[:,:,0])
                        rgbaValues[:,:,1] =  nx.where(scaledImageData==sentinel, g, rgbaValues[:,:,1])
                        rgbaValues[:,:,2] =  nx.where(scaledImageData==sentinel, b, rgbaValues[:,:,2])
                        rgbaValues[:,:,3] =  nx.where(scaledImageData==sentinel, alpha, rgbaValues[:,:,3])

                return rgbaValues
Exemplo n.º 4
0
    def __call__(self, scaledImageData, alpha=1):
        # assumes the data is already normalized (ignoring sentinels)
        # clip to be on the safe side
        rgbaValues = self.cmap(nx.clip(scaledImageData, 0., 1.))

        #replace sentinel data with sentinel colors
        for sentinel, rgb in self.sentinels.items():
            r, g, b = rgb
            rgbaValues[:, :, 0] = nx.where(scaledImageData == sentinel, r,
                                           rgbaValues[:, :, 0])
            rgbaValues[:, :, 1] = nx.where(scaledImageData == sentinel, g,
                                           rgbaValues[:, :, 1])
            rgbaValues[:, :, 2] = nx.where(scaledImageData == sentinel, b,
                                           rgbaValues[:, :, 2])
            rgbaValues[:, :, 3] = nx.where(scaledImageData == sentinel, alpha,
                                           rgbaValues[:, :, 3])

        return rgbaValues