def contiguous_regions(condition):
    """Finds contiguous True regions of the boolean array 'condition'.

    Args
    ----
    condition: numpy.ndarray, dtype bool
        boolean mask array, but can pass the condition itself (e.g. x > 5)

    Returns
    -------
    start_ind: numpy.ndarray, dtype int
        array with the start indices for each contiguous region
    stop_ind: numpy.ndarray, dtype int
        array with the stop indices for each contiguous region

    Notes
    -----
    This function is adpated from Joe Kington's answer on StackOverflow:
    http://stackoverflow.com/a/4495197/943773
    """
    import numpy
    if condition.ndim > 1:
        raise IndexError('contiguous_regions(): condition must be 1-D')
    idx = numpy.diff(condition).nonzero()[0]
    if condition[0]:
        idx = numpy.r_[0, idx]
    if condition[-1]:
        idx = numpy.r_[idx, condition.size]
    idx.shape = -1, 2
    start_ind = idx[:, (0)] + 1
    stop_ind = idx[:, (1)]
    good_vals = stop_ind - start_ind > 0
    start_ind = start_ind[good_vals]
    stop_ind = stop_ind[good_vals]
    return start_ind, stop_ind
