Пример #1
0
    def __call__(self, value, clip=None):
        if clip is None:
            clip = self.clip

        if cbook.iterable(value):
            vtype = 'array'
            val = ma.asarray(value).astype(npy.float)
        else:
            vtype = 'scalar'
            val = ma.array([value]).astype(npy.float)

        self.autoscale_None(val)
        vmin, vmax = self.vmin, self.vmax
        if vmin > vmax:
            raise ValueError("minvalue must be less than or equal to maxvalue")
        elif vmin<=0:
            raise ValueError("values must all be positive")
        elif vmin==vmax:
            return 0.0 * val
        else:
            if clip:
                mask = ma.getmask(val)
                val = ma.array(npy.clip(val.filled(vmax), vmin, vmax),
                                mask=mask)
            result = (ma.log(val)-npy.log(vmin))/(npy.log(vmax)-npy.log(vmin))
        if vtype == 'scalar':
            result = result[0]
        return result
Пример #2
0
    def __call__(self, value, clip=None):
        if clip is None:
            clip = self.clip

        if cbook.iterable(value):
            vtype = 'array'
            val = ma.asarray(value).astype(npy.float)
        else:
            vtype = 'scalar'
            val = ma.array([value]).astype(npy.float)

        self.autoscale_None(val)
        vmin, vmax = self.vmin, self.vmax
        if vmin > vmax:
            raise ValueError("minvalue must be less than or equal to maxvalue")
        elif vmin <= 0:
            raise ValueError("values must all be positive")
        elif vmin == vmax:
            return 0.0 * val
        else:
            if clip:
                mask = ma.getmask(val)
                val = ma.array(npy.clip(val.filled(vmax), vmin, vmax),
                               mask=mask)
            result = (ma.log(val) - npy.log(vmin)) / (npy.log(vmax) -
                                                      npy.log(vmin))
        if vtype == 'scalar':
            result = result[0]
        return result
Пример #3
0
 def transform(self, a):
     sign = npy.sign(npy.asarray(a))
     masked = ma.masked_inside(a, -self.linthresh, self.linthresh, copy=False)
     log = sign * ma.log(npy.abs(masked)) / self._log_base
     if masked.mask.any():
         return npy.asarray(ma.where(masked.mask,
                                     a * self._linadjust,
                                     log))
     else:
         return npy.asarray(log)
Пример #4
0
 def transform(self, a):
     a = _mask_non_positives(a * self.base)
     if isinstance(a, MaskedArray):
         return ma.log(a) / npy.log(self.base)
     return npy.log(a) / npy.log(self.base)