Exemplo n.º 1
0
 def to_raw(self, val):
     # only handle scalar val not arrays
     func = lambda x: self.from_raw(x) - val
     a, b = self._to_raw
     # extend limits to make sure the limits are invertable
     diff = b - a
     a -= diff / 1e6
     b += diff / 1e6
     x = brentq_rootsolver(func, a, b)
     return x
Exemplo n.º 2
0
 def to_raw(self, val):
     # only handle scalar val not arrays
     func = lambda x: self.from_raw(x)-val
     a,b = self._to_raw
     # extend limits to make sure the limits are invertable
     diff = b-a
     a -= diff/1e6
     b += diff/1e6
     x = brentq_rootsolver(func, a, b)
     return x
Exemplo n.º 3
0
def fraction_to_filter(frac=0.99, n_filter=1):
    """
    Calculates the number of time constants to wait to achieve the requested
    fractional change (frac) from a step function.
    n_filter is the number of filters (all using the same time_constants non-interacting
     (buffered in between each))

    See also the inverse function filter_to_fraction
    """
    if frac <= 0. or frac >= 1:
        raise ValueError('frac is out of range need 0 < frac < 1')
    if n_filter != int(n_filter):
        old = n_filter
        n_filter = int(n_filter)
        print 'n_filter was not an integer (%r). Converted it to %i'%(old, n_filter)
    if n_filter <= 0 or n_filter > 100:
        raise ValueError('n_filter to be positive and non-zero (and not greater than 100)')
    func = lambda x: filter_to_fraction(x, n_filter)-frac
    n_time = brentq_rootsolver(func, 0, 1000)
    return n_time