def find_valley_range(vector, min_distance = 4):
    mode = "wrap"
    minima = local_minima(vector,min_distance,mode)
    maxima = local_maxima(vector,min_distance,mode)
    if len(maxima)>len(minima):
        if vector[maxima[0]] >= vector[maxima[-1]]:
            maxima=maxima[1:]
        else:
            maxima=maxima[:-1]
    if len(maxima)==len(minima):
        valley_range = numpy.asarray([minima[ii+1] - minima[ii] for ii in range(len(minima)-1)] + [len(vector)-minima[-1]+minima[0]])
        if minima[0] < maxima[0]:
            minima = numpy.asarray(list(minima) + [minima[0]])
        else:
            minima = numpy.asarray(list(minima) + [minima[-1]])       
    else:
        valley_range = numpy.asarray([minima[ii+1] - minima[ii] for ii in range(len(maxima))])
    return maxima, minima, valley_range