Calculate summary information on glides during dive ascent/descents

    Args
    ----
    dives: (n,10)
        Numpy record array with summary information of dives in sensor data
    des: ndarray
        Boolean mask of descents over sensor data
    asc: ndarray
        Boolean mask of descents over sensor data
    glid_mask: ndarray
        Boolean mask of glides over sensor data
    depths: ndarray
        Depth values at each sensor sampling
    pitch_lf: ndarray
        Pitch in radians over the low frequency signals of acceleration

    Returns
    -------
    gl_ratio: pandas.DataFrame
        Dataframe of summary information of glides during dive descent/ascents

        *Columns*:

        * des_duration
        * des_gl_duration
        * des_gl_ratio
        * des_mean_pitch
        * des_rate
        * asc_duration
        * asc_gl_duration
        * asc_gl_ratio
        * asc_mean_pitch
        * asc_rate

def calc_glide_ratios(dives, des, asc, glide_mask, depths, pitch_lf):
    '''Calculate summary information on glides during dive ascent/descents

    Args
    ----
    dives: (n,10)
        Numpy record array with summary information of dives in sensor data
    des: ndarray
        Boolean mask of descents over sensor data
    asc: ndarray
        Boolean mask of descents over sensor data
    glid_mask: ndarray
        Boolean mask of glides over sensor data
    depths: ndarray
        Depth values at each sensor sampling
    pitch_lf: ndarray
        Pitch in radians over the low frequency signals of acceleration

    Returns
    -------
    gl_ratio: pandas.DataFrame
        Dataframe of summary information of glides during dive descent/ascents

        *Columns*:

        * des_duration
        * des_gl_duration
        * des_gl_ratio
        * des_mean_pitch
        * des_rate
        * asc_duration
        * asc_gl_duration
        * asc_gl_ratio
        * asc_mean_pitch
        * asc_rate
    '''
    import numpy
    import pandas

    # Create empty `pandas.DataFrame` for storing data, init with `nan`s
    cols = ['des_duration',
            'des_gl_duration',
            'des_gl_ratio',
            'des_mean_pitch',
            'des_rate',
            'asc_duration',
            'asc_gl_duration',
            'asc_gl_ratio',
            'asc_mean_pitch',
            'asc_rate',]

    gl_ratio = pandas.DataFrame(index=range(len(dives)), columns=cols)

    # For each dive with start/stop indices in `dives`
    for i in range(len(dives)):
        # Get indices for descent and ascent phase of dive `i`
        start_idx = dives['start_idx'][i]
        stop_idx  = dives['stop_idx'][i]
        des_ind = numpy.where(des[start_idx:stop_idx])[0]
        asc_ind = numpy.where(asc[start_idx:stop_idx])[0]

        # DESCENT
        # total duration of the descent phase (s)
        gl_ratio['des_duration'][i] = len(des_ind)

        # total glide duration during the descent phase (s)
        des_glides = numpy.where(glide_mask[des_ind])[0]
        gl_ratio['des_gl_duration'][i] = len(des_glides)

        if len(des_ind) == 0:
            gl_ratio['des_gl_ratio'][i] = 0
            gl_ratio['des_rate'][i] = 0
        else:
            # glide ratio during the descent phase
            des_gl_ratio = gl_ratio['des_gl_duration'][i] / len(des_ind)
            gl_ratio['des_gl_ratio'][i] = des_gl_ratio

            # descent rate (m/sample)
            max_depth_des = depths[des_ind].max()
            gl_ratio['des_rate'][i] = max_depth_des / len(des_ind)

        # mean pitch during the descent phase(degrees)
        des_mean_pitch = numpy.mean(numpy.rad2deg(pitch_lf[des_ind]))
        gl_ratio['des_mean_pitch'][i] = des_mean_pitch

        # ASCENT
        # total duration of the ascent phase (s)
        gl_ratio['asc_duration'][i] = len(asc_ind)

        # total glide duration during the ascent phase (s)
        asc_glides = numpy.where(glide_mask[asc_ind])[0]
        gl_ratio['asc_gl_duration'][i] = len(asc_glides)

        if len(asc_ind) == 0:
            gl_ratio['asc_gl_ratio'][i] = 0
            gl_ratio['asc_rate'][i] = 0
        else:
            # glide ratio during the ascent phase
            asc_gl_ratio = gl_ratio['asc_gl_duration'][i] / len(asc_ind)
            gl_ratio['asc_gl_ratio'][i] = asc_gl_ratio

            # ascent rate (m/sample)
            max_depth_asc = depths[asc_ind].max()
            gl_ratio['asc_rate'][i] = max_depth_asc / len(asc_ind)

        # mean pitch during the ascent phase(degrees)
        asc_mean_pitch = numpy.mean(numpy.rad2deg(pitch_lf[asc_ind]))
        gl_ratio['asc_mean_pitch'][i] = asc_mean_pitch

    return gl_ratio