def find_peak_start(input, treshold=0.001, peak_length=15):
    input = numpy.abs(numpy.gradient(signal.bspline(input, 25)))

    # Control parameters
    input_treshold = numpy.nanmax(input) * treshold
    input_length = input.shape[0]
    recording = False
    start_x = 0
    stop_x = 0

    # Walk from start to end. When the current value exceeds threshold,
    # start recording.
    for i in range(0, input_length):
        if recording:
            if input[i] > treshold:
                stop_x = i

                if (stop_x - start_x) > peak_length:
                    return start_x
            else:
                recording = False
        else:
            if input[i] > treshold:
                start_x = i
                recording = True

    # Nothing found
    return 0
dataset/ETHPy150Open basilfx/Course-Face3D/face3d/utils.py/find_peak_start/original