Example #1
0
def nan_invalid_segments(rec):
    """
    Currently a specialized signal for removing incorrect trials from data
    collected using baphy during behavior.

    TODO: Migrate to nems_db or make a more generic version
    """

    # First, select the appropriate subset of data
    rec['resp'] = rec['resp'].rasterize()
    sig = rec['resp']

    # get list of start and stop times (epoch bounds)
    epoch_indices = np.vstack(
        (ep.epoch_intersection(sig.get_epoch_bounds('HIT_TRIAL'),
                               sig.get_epoch_bounds('REFERENCE')),
         ep.epoch_intersection(sig.get_epoch_bounds('REFERENCE'),
                               sig.get_epoch_bounds('PASSIVE_EXPERIMENT'))))

    # Only takes the first of any conflicts (don't think I actually need this)
    epoch_indices = ep.remove_overlap(epoch_indices)

    epoch_indices2 = epoch_indices[0:1, :]
    for i in range(1, epoch_indices.shape[0]):
        if epoch_indices[i, 0] == epoch_indices2[-1, 1]:
            epoch_indices2[-1, 1] = epoch_indices[i, 0]
        else:
            epoch_indices2 = np.concatenate(
                (epoch_indices2, epoch_indices[i:(i + 1), :]), axis=0)

    # add adjusted signals to the recording
    newrec = rec.nan_times(epoch_indices2)

    return newrec
Example #2
0
def test_remove_overlap():
    epochs = np.array([
        [0, 10],
        [1, 15],
        [5, 10],
        [11, 32],
        [40, 50],
    ])

    expected = np.array([
        [0, 10],
        [11, 32],
        [40, 50],
    ])

    actual = remove_overlap(epochs)
    assert np.all(actual == expected)
Example #3
0
def remove_invalid_segments(rec):
    """
    Currently a specialized function for removing incorrect trials from data
    collected using baphy during behavior.

    TODO: Migrate to nems_lbhb or make a more generic version
    """

    # First, select the appropriate subset of data
    rec['resp'] = rec['resp'].rasterize()
    if 'stim' in rec.signals.keys():
        rec['stim'] = rec['stim'].rasterize()

    sig = rec['resp']

    # get list of start and stop indices (epoch bounds)
    epoch_indices = np.vstack(
        (ep.epoch_intersection(sig.get_epoch_indices('REFERENCE'),
                               sig.get_epoch_indices('HIT_TRIAL')),
         ep.epoch_intersection(sig.get_epoch_indices('REFERENCE'),
                               sig.get_epoch_indices('PASSIVE_EXPERIMENT'))))

    # Only takes the first of any conflicts (don't think I actually need this)
    epoch_indices = ep.remove_overlap(epoch_indices)

    # merge any epochs that are directly adjacent
    epoch_indices2 = epoch_indices[0:1]
    for i in range(1, epoch_indices.shape[0]):
        if epoch_indices[i, 0] == epoch_indices2[-1, 1]:
            epoch_indices2[-1, 1] = epoch_indices[i, 1]
        else:
            #epoch_indices2 = np.concatenate(
            #       (epoch_indices2, epoch_indices[i:(i + 1), :]), axis=0)
            epoch_indices2 = np.append(epoch_indices2,
                                       epoch_indices[i:(i + 1)],
                                       axis=0)

    # convert back to times
    epoch_times = epoch_indices2 / sig.fs

    # add adjusted signals to the recording
    newrec = rec.select_times(epoch_times)

    return newrec