
from numpy import isnan


def valid_intervals(values_array_1D):
    if values_array_1D.ndim != 1:
        raise ValueError("values_array_1D must be a 1D array")
    if values_array_1D.shape[0] == 0:
        raise ValueError("values_array_1D must not be empty")

    valid_list = []
    interval = []
    for i in range(values_array_1D.shape[0]):
        if isnan(values_array_1D[i]):
            if len(interval) > 0:
                valid_list.append(interval)
                interval = []
        else:
            interval.append(i)
    else:
        if len(interval) > 0:
            valid_list.append(interval)

    intdict_list = []
    for interval in valid_list:
        if len(interval) > 1:
            int_dict = dict(start=interval[0], end=interval[-1])
            intdict_list.append(int_dict)

    return intdict_list
