test it and at which x_value dy(x)/dx < tol for all x >= x_value, conv is true is such a x_value exists.

def determine_convergence(xs, ys, name, tol=0.0001, extra='', verbose=False, mode='extra', plots=True):
    """
    test it and at which x_value dy(x)/dx < tol for all x >= x_value, conv is true is such a x_value exists.
    """
    if len(xs) != len(ys):
        raise RuntimeError('the range of x and y are not equal')
    conv = False
    x_value = float('inf')
    y_value = None
    n_value = None
    popt = [None, None, None]
    if len(xs) > 2:
        ds = get_derivatives(xs[0:len(ys)], ys)
        try:
            if None not in ys:
                if mode == 'fit':
                    popt, pcov, func = multi_curve_fit(xs, ys, verbose)
                elif mode == 'extra':
                    res = multi_reciprocal_extra(xs, ys)
                    if res is not None:
                        popt, pcov, func = multi_reciprocal_extra(xs, ys)
                    else:
                        print(xs, ys)
                        popt, pcov = None, None
                elif mode == 'extra_noise':
                    popt, pcov, func = multi_reciprocal_extra(xs, ys, noise=True)
                else:
                    raise NotImplementedError('unknown mode for test conv')
                if func[1] > abs(tol):
                    print('warning function ', func[0], ' as the best fit but not a good fit: ', func[1])
                # todo print this to file via a method in helper, as dict
                if plots:
                    with open(name+'.fitdat', mode='a') as f:
                        f.write('{')
                        f.write('"popt": ' + str(popt) + ', ')
                        f.write('"pcov": ' + str(pcov) + ', ')
                        f.write('"data": [')
                        for n in range(0, len(ys), 1):
                            f.write('[' + str(xs[n]) + ' ' + str(ys[n]) + ']')
                        f.write(']}\n')

                    print_plot_line(func[0], popt, xs, ys, name, tol=tol, extra=extra)

        except ImportError:
            popt, pcov = None, None
        for n in range(0, len(ds), 1):
            if verbose:
                print(n, ys[n])
                print(ys)
            if tol < 0:
                if popt[0] is not None:
                    test = abs(popt[0] - ys[n])
                else:
                    test = float('inf')
            else:
                test = abs(ds[n])
            if verbose:
                print(test)
            if test < abs(tol):
                if verbose:
                    print('converged')
                conv = True
                if xs[n] < x_value:
                    x_value = xs[n]
                    y_value = ys[n]
                    n_value = n
            else:
                if verbose:
                    print('not converged')
                conv = False
                x_value = float('inf')
        if n_value is None:
            return [conv, x_value, y_value, n_value, popt[0], None]
        else:
            return [conv, x_value, y_value, n_value, popt[0], ds[n_value]]
    else:
        return [conv, x_value, y_value, n_value, popt[0], None]