Get start/stop indices of each `dur` length sub-glide for glides in GL

    Args
    ----
    dur: int
        Desired duration of glides
    GL: ndarray, (n, 2)
        Matrix containing the start time (first column) and end time
        (2nd column) of any glides.Times are in seconds.
    min_dur: int, default (bool False)
        Minimum number of seconds for sub-glide. Default value is `False`, which
        makes `min_dur` equal to `dur`, ignoring sub-glides smaller than `dur`.

    Attributes
    ----------
    gl_ind_diff: ndarray, (n,3)
        GL, with additional column of difference between the first two columns

    Returns
    -------
    SGL: ndarray, (n, 2)
        Matrix containing the start time (first column) and end time (2nd
        column) of the generated sub-glides. All glides must have duration equal
        to the given dur value.Times are in seconds.

def split_glides(n_samples, dur, fs_a, GL, min_dur=None):
    '''Get start/stop indices of each `dur` length sub-glide for glides in GL

    Args
    ----
    dur: int
        Desired duration of glides
    GL: ndarray, (n, 2)
        Matrix containing the start time (first column) and end time
        (2nd column) of any glides.Times are in seconds.
    min_dur: int, default (bool False)
        Minimum number of seconds for sub-glide. Default value is `False`, which
        makes `min_dur` equal to `dur`, ignoring sub-glides smaller than `dur`.

    Attributes
    ----------
    gl_ind_diff: ndarray, (n,3)
        GL, with additional column of difference between the first two columns

    Returns
    -------
    SGL: ndarray, (n, 2)
        Matrix containing the start time (first column) and end time (2nd
        column) of the generated sub-glides. All glides must have duration equal
        to the given dur value.Times are in seconds.
    '''
    import numpy

    # Convert `dur` in seconds to duration in number of samples `ndur`
    ndur = dur * fs_a

    # If minimum duration not passed, set to `min_dur` to skip slices < `dur`
    if not min_dur:
        min_ndur = dur * fs_a
    else:
        min_ndur = min_dur * fs_a

    # `GL` plus column for total duration of glide, seconds
    gl_ind_diff = numpy.vstack((GL.T, GL[:, 1] - GL[:, 0])).T

    # Split all glides in `GL`
    SGL_started = False
    for i in range(len(GL)):
        gl_ndur = gl_ind_diff[i, 2]

        # Split into sub glides if longer than duration
        if abs(gl_ndur) > ndur:

            # Make list of index lengths to start of each sub-glide
            n_sgl     = int(gl_ndur//ndur)
            sgl_ndur  = numpy.ones(n_sgl)*ndur
            sgl_start = numpy.arange(n_sgl)*(ndur+1)

            # Add remainder as a sub-glide, skips if `min_ndur` not passed
            if (gl_ndur%ndur > min_ndur):
                last_ndur = numpy.floor(gl_ndur%ndur)
                sgl_ndur  = numpy.hstack([sgl_ndur, last_ndur])

                last_start = (len(sgl_start)*ndur) + ndur
                sgl_start  = numpy.hstack([sgl_start, last_start])

            # Get start and end index positions for each sub-glide
            for k in range(len(sgl_start)):

                # starting at original glide start...
                # sgl_start_ind: add index increments of ndur+1 for next start idx
                next_start_ind = (gl_ind_diff[i, 0] + sgl_start[k]).astype(int)

                # end_glide: add `ndur` to that to get ending idx
                next_end_ind = (next_start_ind + sgl_ndur[k]).astype(int)

                # If first iteration, set equal to first set of indices
                if SGL_started == False:
                    sgl_start_ind = next_start_ind
                    sgl_end_ind   = next_end_ind
                    SGL_started = True
                else:
                    # Concatenate 1D arrays together, shape (n,)
                    sgl_start_ind = numpy.hstack((sgl_start_ind, next_start_ind))
                    sgl_end_ind   = numpy.hstack((sgl_end_ind, next_end_ind))

    # Stack and transpose indices into shape (n, 2)
    SGL = numpy.vstack((sgl_start_ind, sgl_end_ind)).T

    # Filter out sub-glides that fall outside of sensor data indices
    SGL =  SGL[(SGL[:, 0] >= 0) & (SGL[:, 1] < n_samples)]

    # check that all sub-glides have a duration of `ndur` seconds
    sgl_ndur = SGL[:, 1] - SGL[:, 0]

    # If sub-glide `min_ndur` set, make sure all above `min_ndur`, below `ndur`
    if min_dur:
        assert numpy.all((sgl_ndur <= ndur) & (sgl_ndur >= min_ndur))
    # Else make sure all sample number durations equal to `ndur`
    else:
        assert numpy.all(sgl_ndur == ndur)

    # Create `data_sgl_mask`
    data_sgl_mask = numpy.zeros(n_samples, dtype=bool)
    for start, stop in SGL.astype(int):
        data_sgl_mask[start:stop] = True

    return SGL, data_sgl_mask