def bin_data(jd, y, mins_jd):
    t = np.array(jd)
    split = []
    sorted_t = t
    sorted_y = y
    start = sorted_t[0]
    nextbin = sorted_t[(np.absolute((sorted_t - start)) > mins_jd)]
    while (nextbin != []):
        start = (start + mins_jd)
        ind_st = np.argmax((sorted_t > start))
        if (len(split) > 0):
            if (ind_st != split[(- 1)]):
                split.append(ind_st)
                time = sorted_t[ind_st:]
        else:
            split.append(ind_st)
            time = sorted_t[ind_st:]
        nextbin = time[(np.absolute((time - start)) > mins_jd)]
    times = np.split(sorted_t, split)
    ys = np.split(sorted_y, split)
    bins = np.zeros(len(times))
    binned_y = np.zeros(len(times))
    binned_err = np.zeros(len(times))
    for i in range(len(times)):
        if (len(ys[i]) > 0):
            try:
                bins[i] = np.nanmean(times[i])
                binned_y[i] = np.nanmean(ys[i])
                n = len(times[i])
                binned_err[i] = (np.nanstd(ys[i]) / np.sqrt(n))
            except Exception as e:
                print(e)
                pass
    bin_t = bins[(binned_y != 0)]
    bin_e = binned_err[(binned_y != 0)]
    bin_y = binned_y[(binned_y != 0)]
    return (bin_t, bin_y, bin_e)
def bin_data(jd, y, mins_jd):
    t = np.array(jd)
    split = []
    sorted_t = t
    sorted_y = y
    start = sorted_t[0]
    nextbin = sorted_t[(np.absolute((sorted_t - start)) > mins_jd)]
    while (nextbin != []):
        start = (start + mins_jd)
        ind_st = np.argmax((sorted_t > start))
        if (len(split) > 0):
            if (ind_st != split[(- 1)]):
                split.append(ind_st)
                time = sorted_t[ind_st:]
        else:
            split.append(ind_st)
            time = sorted_t[ind_st:]
        nextbin = time[(np.absolute((time - start)) > mins_jd)]
    times = np.split(sorted_t, split)
    ys = np.split(sorted_y, split)
    bins = np.zeros(len(times))
    binned_y = np.zeros(len(times))
    binned_err = np.zeros(len(times))
    for i in range(len(times)):
        if (len(ys[i]) > 0):
            try:
                bins[i] = np.nanmean(times[i])
                binned_y[i] = np.nanmean(ys[i])
                n = len(times[i])
                binned_err[i] = (np.nanstd(ys[i]) / np.sqrt(n))
            except Exception as e:
                print(e)
                pass
    bin_t = bins[(binned_y != 0)]
    bin_e = binned_err[(binned_y != 0)]
    bin_y = binned_y[(binned_y != 0)]
    return (bin_t, bin_y, bin_e)