Esempio n. 1
0
def __powerise10(x):
    """ Returns x as a * 10 ^ b with 0<= a <10
    """
    if x == 0: return 0, 0
    Neg = x < 0
    if Neg: x = -x
    a = 1.0 * x / 10**(floor(log10(x)))
    b = int(floor(log10(x)))
    if Neg: a = -a
    return a, b
Esempio n. 2
0
 def denoise(self, data, wavelet):
     noiseSigma = median(absolute(data - median(data))) / 0.6745
     levels = int(floor(log(len(data))))
     WC = pywt.wavedec(data, wavelet, level=levels)
     threshold = noiseSigma * sqrt(2 * log(len(data)))
     NWC = map(lambda x: pywt.thresholding.hard(x, threshold), WC)
     return pywt.waverec(NWC, wavelet)
Esempio n. 3
0
 def __pow__(self, other):
     if self.offset != 0:
         raise TypeError("cannot exponentiate units with non-zero offset")
     if type(other) is int:
         return PhysicalUnit(
             other * self.names,
             pow(self.factor, other),
             #list(map(lambda x,p=other: x*p, self.powers)))
             [x * other for x in self.powers])
     if type(other) is float:
         inv_exp = 1. / other
         rounded = int(umath.floor(inv_exp + 0.5))
         if abs(inv_exp - rounded) < 1.e-10:
             if reduce(lambda a, b: a and b,
                       map(lambda x, e=rounded: x % e == 0, self.powers)):
                 f = pow(self.factor, other)
                 p = [x / rounded for x in self.powers]
                 if reduce(
                         lambda a, b: a and b,
                         map(lambda x, e=rounded: x % e == 0,
                             self.names.values())):
                     names = self.names / rounded
                 else:
                     names = numberdict.NumberDict(default=0)
                     if f != 1.:
                         names[str(f)] = 1
                     for i in range(len(p)):
                         names[_base_names[i]] = p[i]
                 return PhysicalUnit(names, f, p)
             else:
                 raise TypeError('Illegal exponent')
     raise TypeError('Only integer and inverse integer exponents allowed')
Esempio n. 4
0
 def __pow__(self, other):
     if self.offset != 0:
         raise TypeError("cannot exponentiate units with non-zero offset")
     if type(other) is int:
         return PhysicalUnit(
             other * self.names,
             pow(self.factor, other),
             # list(map(lambda x,p=other: x*p, self.powers)))
             [x * other for x in self.powers],
         )
     if type(other) is float:
         inv_exp = 1.0 / other
         rounded = int(umath.floor(inv_exp + 0.5))
         if abs(inv_exp - rounded) < 1.0e-10:
             if reduce(lambda a, b: a and b, map(lambda x, e=rounded: x % e == 0, self.powers)):
                 f = pow(self.factor, other)
                 p = [x / rounded for x in self.powers]
                 if reduce(lambda a, b: a and b, map(lambda x, e=rounded: x % e == 0, self.names.values())):
                     names = self.names / rounded
                 else:
                     names = numberdict.NumberDict(default=0)
                     if f != 1.0:
                         names[str(f)] = 1
                     for i in range(len(p)):
                         names[_base_names[i]] = p[i]
                 return PhysicalUnit(names, f, p)
             else:
                 raise TypeError("Illegal exponent")
     raise TypeError("Only integer and inverse integer exponents allowed")
Esempio n. 5
0
def _round(x):
    if umath.greater(x, 0.):
        return umath.floor(x)
    else:
        return umath.ceil(x)
Esempio n. 6
0
def _round(x):
    if umath.greater(x, 0.0):
        return umath.floor(x)
    else:
        return umath.ceil(x)