code: def integrate(func, x, args=(), offset=0, drift=0):
     
     # If it's monotonically decreasing (as is often the case here), we invert
     # it, so that our results are strictly positive
     if x[1]<x[0]:
        x = x[::-1]
     y = func(x, *args)
     # Correct for offset and drift, if those are present and specified
     # (otherwise default to 0 on both):
     y = y - offset
     y = y - drift * (x-x[0])
     # Use trapezoidal integration on the corrected function: 
     return spi.trapz(y, x)
docs: Integrate a function over the domain x
  
     Parameters
     ----------
     func : callable
         A function from the domain x to floats. The first input to this function
         has to be x, an array with values to evaluate for, running in monotonic
         order  
  
     x : float array
        The domain over which to integrate, as sampled. This can be monotonically
        decreasing or monotonically increasing.
        
     args : tuple
         The parameters of func after x.
  
     offset : 
  
     Notes
     -----
     We apply the trapezoid rule for integration here, using
     scipy.integrate.trapz.
  
     See: http://en.wikipedia.org/wiki/Trapezoidal_rule