Esempio n. 1
0
def amp(y, x=None, x_min=None, x_max=None, subtractBaseline=False, peak_index=False):
    y = mypy.numpy_array(y)
    x = mypy.numpy_array(x)

    (yl, xl) = clip(y, x, x_min=x_min)
    if peak_index:
        index_shift = len(y) - len(yl)
    (y, x) = clip(yl, xl, x_max=x_max)

    amp = max(y)

    if subtractBaseline:
        amp = amp - y[0]

    if peak_index:
        peak_i = numpy.argmax(y) + index_shift
        return (amp, peak_i)
    else:
        return amp
Esempio n. 2
0
def area(y, x=None, x_min=None, x_max=None, subtractBaseline=False, rule="trapezoid"):
    y = mypy.numpy_array(y)
    x = mypy.numpy_array(x)

    if rule == "trapezoid":
        f = integrate.trapz
    elif rule == "simpsons":
        f = integrate.simps
    elif rule == "rectangle":
        raise Exception("Rectangle method not yet implemented")

    (y, x) = clip(y, x, x_min, x_max)

    if subtractBaseline:
        y = y - y[0]

    if x == None:
        return f(y)
    else:
        return f(y, x)
Esempio n. 3
0
def clip(y, x=None, x_min=None, x_max=None):
    if x == None:
        return (y, x)

    if len(y) == 0:
        raise ValueError("'y' is empty.")

    if x != None and len(y) != len(x):
        raise ValueError("'y' and 'x' are not of the same length.")

    y = mypy.numpy_array(y)
    x = mypy.numpy_array(x)

    if x_min != None:
        y = y[x >= x_min]
        x = x[x >= x_min]

    if x_max != None and len(y) > 0:
        y = y[x <= x_max]
        x = x[x <= x_max]

    return (y, x)