def METHOD_NAME(x, y, plot=True):
    y0 = (y[0]+y[-1])/2.
    peak = np.abs((np.max(y)-y0)) > np.abs((np.min(y)-y0))
    print('peak = ', peak, y0, np.max(y), np.min(y))
    if peak:
        A = np.max(y)-y0
        f0 = x[y[:].tolist().index(max(y[:]))]
        find_y2 = (y-y0) > A/2
    else:
        A = np.min(y)-y0
        f0 = x[y[:].tolist().index(min(y[:]))]
        find_y2 = (y-y0) < A/2
    ind_df = find_y2.tolist().index(True)
    df = 2*np.abs(x[ind_df] - f0)
    pars = fit.Parameters()
    pars.add('f', value=x, vary=False)
    pars.add('A', value=A)
    pars.add('f0', value=f0)
    pars.add('df', value=df)
    pars.add('y0', value=y0)
    fit.print_fitres(pars)
    fit.fitxy(pars, y, fn.Lorentzian)
    fit.print_fitres(pars)
    yfit = fn.Lorentzian(pars)
    if plot:
        plt.plot(x, yfit, label='fit: f0 = %.4f, df = %.1f' %
                 (pars['f0'].value, 1e3*(pars['df'].value)))
        plt.legend()
    return pars, fn.Lorentzian(pars)