def abstrapz(y, x=None, dx=1.0):
    y = np.asanyarray(y)
if x is None:
    d = dx
else:
    x = np.asanyarray(x)
d = np.diff(x)
ret = d * (y[1:] + y[:-1]) / 2.0
return ret[ret > 0].sum()
Integration in numpy array with positive area only