Find dives in depth data below a minimum dive threshold

    Args
    ----
    depths: ndarray
        Datalogger depth measurements
    min_dive_thresh: float
        Minimum depth threshold for which to classify a dive

    Returns
    -------
    dives: ndarray
        Dive summary information in a numpy record array

        *Columns*:

        * dive_id
        * start_idx
        * stop_idx
        * dive_dur
        * depth_max
        * depth_max_i
        * depth_min
        * depth_min_i
        * depth_mean
        * comp_mean

    dive_mask: ndarray
        Boolean mask array over depth data. Cells with `True` are dives and
        cells with `False` are not.

def finddives2(depths, min_dive_thresh=10):
    '''Find dives in depth data below a minimum dive threshold

    Args
    ----
    depths: ndarray
        Datalogger depth measurements
    min_dive_thresh: float
        Minimum depth threshold for which to classify a dive

    Returns
    -------
    dives: ndarray
        Dive summary information in a numpy record array

        *Columns*:

        * dive_id
        * start_idx
        * stop_idx
        * dive_dur
        * depth_max
        * depth_max_i
        * depth_min
        * depth_min_i
        * depth_mean
        * comp_mean

    dive_mask: ndarray
        Boolean mask array over depth data. Cells with `True` are dives and
        cells with `False` are not.
    '''
    import numpy
    import pandas

    from . import utils

    # Get start and stop indices for each dive above `min_dive_thresh`
    condition = depths > min_dive_thresh
    ind_start, ind_end = utils.contiguous_regions(condition)

    n_dives = len(ind_start)

    dive_mask = numpy.zeros(len(depths), dtype=bool)

    dtypes = numpy.dtype([('dive_id', int),
                          ('start_idx', int),
                          ('stop_idx', int),
                          ('dive_dur', int),
                          ('depth_max', float),
                          ('depth_max_idx', float),
                          ('depth_min', float),
                          ('depth_min_idx', float),
                          ('depth_mean', float),
                          ('comp_mean', float),])

    dive_data = numpy.zeros(n_dives, dtype=dtypes)

    for i in range(n_dives):
        dive_mask[ind_start[i]:ind_end[i]] = True
        dive_depths                   = depths[ind_start[i]:ind_end[i]]
        dive_data['dive_id'][i]       = i
        dive_data['start_idx'][i]     = ind_start[i]
        dive_data['stop_idx'][i]      = ind_end[i]
        dive_data['dive_dur'][i]      = ind_end[i] - ind_start[i]
        dive_data['depth_max'][i]     = dive_depths.max()
        dive_data['depth_max_idx'][i] = numpy.argmax(dive_depths)
        dive_data['depth_min'][i]     = dive_depths.min()
        dive_data['depth_min_idx'][i] = numpy.argmin(dive_depths)
        dive_data['depth_mean'][i]    = numpy.mean(dive_depths)
        # TODO Supposedly time of deepest dive... doesn't appear to be that
        dive_data['comp_mean'][i]     = numpy.mean(1 + (1/(0.1*dive_depths)))

    # Filter any dives with an endpoint with an index beyond bounds of array
    dive_data = dive_data[dive_data['stop_idx'] < len(depths)]

    # Create pandas data frame with following columns, init'd with nans
    dives = pandas.DataFrame(dive_data)

    return dives, dive_mask