Beispiel #1
0
def read_crossings(path, activity):
    crosses = crossings(activity)
    labelh5path = labelpath(path)
    if os.path.exists(labelh5path):
        crosses.label = pd.read_hdf(labelh5path, 'label')
    return crosses
Beispiel #2
0
def sessionsummary(path):
    labelh5path = labelpath(path)
    activity = activitytables.read_activity(path)
    crossings = activitytables.read_crossings(path, activity)
    rewards = activitytables.read_rewards(path)
    #steptimes = activitytables.steptimes(activity)
    vidpath = os.path.join(path, 'front_video.avi')
    vid = video.video(vidpath)

    selected = []

    def onselect(ind):
        selector.ind[:] = ind
        selector.updateselection()
        clearhandles(selected)
        if len(ind) <= 0:
            return

        for s in crossings.slices[ind]:
            h = axs[0, 1].plot(activity.xhead[s], activity.yhead[s], 'r')
            selected.append(h)

    markers = []

    def updateplots():
        onselect([])
        clearcollection(markers)
        valid = crossings.label == 'valid'

        axs[0, 1].clear()
        trajectoryplot(activity, crossings[valid], axs[0, 1], alpha=0.2)

        axs[1, 2].clear()
        slowdownsummary(crossings[valid], axs[1, 2])

        axs[1, 1].clear()

        invalid = crossings.label == 'invalid'
        if invalid.any():
            rows = crossings[invalid]
            pts = axs[0, 2].scatter(rows.duration,
                                    rows.yhead_max,
                                    s=20,
                                    marker='x',
                                    facecolors='none',
                                    edgecolors='r')
            markers.append(pts)
        fig.canvas.draw_idle()

    def onkeypress(evt):
        label = None
        if evt.key == 'q':
            crossings.label.to_hdf(labelh5path, 'label')
        if evt.key == 'x':
            label = 'invalid'
        if evt.key == 'c':
            label = 'valid'
        if evt.key == 'z' and len(selector.ind) == 1:
            frameslice = crossings.iloc[selector.ind[0], :].slices
            video.showmovie(vid,
                            frameslice.start,
                            fps=frames_per_second,
                            frameend=frameslice.stop)
        if label != None:
            crossings.label[selector.ind] = label
            updateplots()

    fig, axs = plt.subplots(3, 3)
    fpshist(activity, axs[0, 0])
    selector = featuresummary(crossings, axs[0, 2], onselect)
    updateplots()
    rewardrate(rewards, axs[1, 0])
    fig.canvas.mpl_connect('key_press_event', onkeypress)

    plt.tight_layout()
    return activity, crossings, rewards, selector
def sessionsummary(path):
    labelh5path = labelpath(path)
    activity = activitytables.read_activity(path)
    crossings = activitytables.read_crossings(path, activity)
    rewards = activitytables.read_rewards(path)
    # steptimes = activitytables.steptimes(activity)
    vidpath = os.path.join(path, "front_video.avi")
    vid = video.video(vidpath)

    selected = []

    def onselect(ind):
        selector.ind[:] = ind
        selector.updateselection()
        clearhandles(selected)
        if len(ind) <= 0:
            return

        for s in crossings.slices[ind]:
            h = axs[0, 1].plot(activity.xhead[s], activity.yhead[s], "r")
            selected.append(h)

    markers = []

    def updateplots():
        onselect([])
        clearcollection(markers)
        valid = crossings.label == "valid"

        axs[0, 1].clear()
        trajectoryplot(activity, crossings[valid], axs[0, 1], alpha=0.2)

        axs[1, 2].clear()
        slowdownsummary(crossings[valid], axs[1, 2])

        axs[1, 1].clear()

        invalid = crossings.label == "invalid"
        if invalid.any():
            rows = crossings[invalid]
            pts = axs[0, 2].scatter(rows.duration, rows.yhead_max, s=20, marker="x", facecolors="none", edgecolors="r")
            markers.append(pts)
        fig.canvas.draw_idle()

    def onkeypress(evt):
        label = None
        if evt.key == "q":
            crossings.label.to_hdf(labelh5path, "label")
        if evt.key == "x":
            label = "invalid"
        if evt.key == "c":
            label = "valid"
        if evt.key == "z" and len(selector.ind) == 1:
            frameslice = crossings.iloc[selector.ind[0], :].slices
            video.showmovie(vid, frameslice.start, fps=frames_per_second, frameend=frameslice.stop)
        if label != None:
            crossings.label[selector.ind] = label
            updateplots()

    fig, axs = plt.subplots(3, 3)
    fpshist(activity, axs[0, 0])
    selector = featuresummary(crossings, axs[0, 2], onselect)
    updateplots()
    rewardrate(rewards, axs[1, 0])
    fig.canvas.mpl_connect("key_press_event", onkeypress)

    plt.tight_layout()
    return activity, crossings, rewards, selector
def read_crossings(path, activity):
    crosses = crossings(activity)
    labelh5path = labelpath(path)
    if os.path.exists(labelh5path):
        crosses.label = pd.read_hdf(labelh5path, 'label')
    return crosses