def peak_refinement(x, y, cands, window, refine_function, refine_args=None):
    # clean up input
    x = np.asarray(x)
    y = np.asarray(y)
    cands = np.asarray(cands, dtype=int)
    window = int(window)
    if refine_args is None:
        refine_args = dict()
    # local working variables
    out_tmp = deque()
    max_ind = len(x)

    for ind in cands:
        slc = slice(np.max([0, ind-window]),
                    np.min([max_ind, ind + window + 1]))
        try:
            ret = refine_function(x[slc], y[slc], **refine_args)
        except PeakRejection:
            # We are catching the PeakRejections raised here as
            # an indication that no suitable peak was found
            continue
        else:
            out_tmp.append(ret)

    return tuple([np.array(_) for _ in zip(*out_tmp)])
Refine candidate locations
dataset/ETHPy150Open scikit-beam/scikit-beam/skbeam/core/feature.py/peak_refinement