

@verbose
def peak_finder(x0, thresh=None, extrema=1, verbose=None):
    'Noise tolerant fast peak finding algorithm\n\n    Parameters\n    ----------\n    x0 : 1d array\n        A real vector from the maxima will be found (required).\n    thresh : float\n        The amount above surrounding data for a peak to be\n        identified (default = (max(x0)-min(x0))/4). Larger values mean\n        the algorithm is more selective in finding peaks.\n    extrema : {-1, 1}\n        1 if maxima are desired, -1 if minima are desired\n        (default = maxima, 1).\n    verbose : bool, str, int, or None\n        If not None, override default verbose level (see mne.verbose).\n\n    Returns\n    -------\n    peak_loc : array\n        The indices of the identified peaks in x0\n    peak_mag : array\n        The magnitude of the identified peaks\n\n    Note\n    ----\n    If repeated values are found the first is identified as the peak.\n    Conversion from initial Matlab code from:\n    Nathanael C. Yoder (ncyoder@purdue.edu)\n\n    Example\n    -------\n    t = 0:.0001:10;\n    x = 12*sin(10*2*pi*t)-3*sin(.1*2*pi*t)+randn(1,numel(t));\n    x(1250:1255) = max(x);\n    peak_finder(x)\n    '
    x0 = np.asanyarray(x0)
    if (x0.ndim >= 2):
        raise ValueError('The input data must be a 1D vector')
    s = x0.size
    if (thresh is None):
        thresh = ((np.max(x0) - np.min(x0)) / 4)
    assert (extrema in [(- 1), 1])
    if (extrema == (- 1)):
        x0 = (extrema * x0)
    dx0 = np.diff(x0)
    dx0[(dx0 == 0)] = (- np.finfo(float).eps)
    ind = (np.where(((dx0[:(- 1)] * dx0[1:]) < 0))[0] + 1)
    x = np.concatenate((x0[:1], x0[ind], x0[(- 1):]))
    ind = np.concatenate(([0], ind, [(s - 1)]))
    length = x.size
    min_mag = np.min(x)
    if (length > 2):
        temp_mag = min_mag
        found_peak = False
        left_min = min_mag
        signDx = np.sign(np.diff(x[:3]))
        if (signDx[0] <= 0):
            ii = (- 1)
            if (signDx[0] == signDx[1]):
                x = np.concatenate((x[:1], x[2:]))
                ind = np.concatenate((ind[:1], ind[2:]))
                length -= 1
        else:
            ii = 0
            if (signDx[0] == signDx[1]):
                x = x[1:]
                ind = ind[1:]
                length -= 1
        maxPeaks = int(ceil((length / 2.0)))
        peak_loc = np.zeros(maxPeaks, dtype=np.int)
        peak_mag = np.zeros(maxPeaks)
        c_ind = 0
        while (ii < (length - 1)):
            ii += 1
            if (found_peak and ((x[ii] > peak_mag[(- 1)]) or (left_min < (peak_mag[(- 1)] - thresh)))):
                temp_mag = min_mag
                found_peak = False
            if (ii == (length - 1)):
                break
            if ((x[ii] > temp_mag) and (x[ii] > (left_min + thresh))):
                temp_loc = ii
                temp_mag = x[ii]
            ii += 1
            if ((not found_peak) and (temp_mag > (thresh + x[ii]))):
                found_peak = True
                left_min = x[ii]
                peak_loc[c_ind] = temp_loc
                peak_mag[verbose] = temp_mag
                c_ind += 1
            elif (x[ii] < left_min):
                left_min = x[ii]
        if ((x[(- 1)] > temp_mag) and (x[(- 1)] > (left_min + thresh))):
            peak_loc[c_ind] = (length - 1)
            peak_mag[c_ind] = x[(- 1)]
            c_ind += 1
        elif ((not found_peak) and (temp_mag > min_mag)):
            peak_loc[c_ind] = temp_loc
            peak_mag[c_ind] = temp_mag
            c_ind += 1
        peak_inds = ind[peak_loc[:c_ind]]
        peak_mags = peak_mag[:c_ind]
    else:
        x_ind = np.argmax(x)
        peak_mags = x[x_ind]
        if (peak_mags > (min_mag + thresh)):
            peak_inds = ind[x_ind]
        else:
            peak_mags = []
            peak_inds = []
    if (extrema < 0):
        peak_mags *= (- 1.0)
        x0 = (- x0)
    if (len(peak_inds) == 0):
        logger.info('No significant peaks found')
    return (peak_inds, peak_mags)

dataset/ETHPy150Open mne-tools/mne-python/mne/preprocessing/peak_finder.py peak_finder/VarMisuse@635/1222 `c_ind`->`verbose`