def __spatialaverages__(cr,path,selector=lambda x:x.yhead,
                        ylabel='y (cm)',xlim=None,ylim=None):
    if not os.path.exists(path):
        os.makedirs(path)
    
    cut = getballistictrials(cr)
    sessions = cut[cut.trial > 0].groupby(level=['subject','session'])
    for (subject,session),group in sessions:
        fig = plt.figure()
        subjectpath = os.path.join(activitymovies.datafolder,subject)
        sact = activitytables.read_subjects(subjectpath,days=[session])
        
        x,y,yerr = activitytables.spatialaverage(sact,group,selector)
        activityplots.trajectoryplot(sact,group,alpha=0.2,flip=True,
                                     selector=selector)
        plt.fill_between(x,y-yerr,y+yerr)
        
        if xlim is not None:
            plt.xlim(xlim)
        if ylim is not None:
            plt.ylim(ylim)
        plt.xlabel('x (cm)')
        plt.ylabel(ylabel)
        plt.title(str.format('{0} (session {1})',subject,session))
        fname = str.format("{0}_session_{1}_trajectories.png",
                           subject, session)
        fpath = os.path.join(path,subject)
        if not os.path.exists(fpath):
            os.makedirs(fpath)
        fpath = os.path.join(fpath,fname)
        plt.savefig(fpath)
        plt.close(fig)
Exemplo n.º 2
0
def __spatialaveragecomparison__(cr,
                                 path,
                                 selector=lambda x: x.yhead,
                                 ylabel='y (cm)',
                                 xlim=None,
                                 ylim=None):
    if not os.path.exists(path):
        os.makedirs(path)

    cut = getballistictrials(cr)
    conditions = cut[cut.trial > 0].groupby(level=['subject'])
    for subject, group in conditions:
        fig = plt.figure()

        days = group.index.levels[1][group.index.labels[1]]
        subjectpath = os.path.join(activitymovies.datafolder, subject)
        act = activitytables.read_subjects(subjectpath, days=days)

        stact = act[act.stepstate3]
        stcr = group[group.stepstate3]
        x, y, yerr = activitytables.spatialaverage(stact, stcr, selector)
        plt.fill_between(x, y - yerr, y + yerr, color='b')

        uact = act[~act.stepstate3]
        ucr = group[~group.stepstate3]
        x, y, yerr = activitytables.spatialaverage(uact, ucr, selector)
        plt.fill_between(x, y - yerr, y + yerr, color='r')

        p1 = plt.Rectangle((0, 0), 1, 1, fc='b')
        p2 = plt.Rectangle((0, 0), 1, 1, fc='r')
        plt.legend([p1, p2], ['stable', 'unstable'])

        if xlim is not None:
            plt.xlim(xlim)
        if ylim is not None:
            plt.ylim(ylim)
        plt.xlabel('x (cm)')
        plt.ylabel(ylabel)
        plt.title(str.format('{0} trajectories', subject))
        fname = str.format("{0}_trajectories_stable_unstable.png", subject)
        fpath = os.path.join(path, fname)
        plt.savefig(fpath)
        plt.close(fig)
Exemplo n.º 3
0
def averagetimeseries(cract,column=None,baseline=None,
                      color='b',ax=None,**kwargs):
    if ax is None:
        fig = plt.figure()
        ax = fig.gca()
    
    xpoints = createspaceaxis()
    ymean,yerr = activitytables.spatialaverage(xpoints,cract,column,baseline)
    activityplots.boundedcurve(xpoints,ymean,yerr,color=color,ax=ax,**kwargs)
    ax.set_xlabel('x (cm)')
    ax.set_xlim(-15,25)
def __spatialaveragecomparison__(cr,path,selector=lambda x:x.yhead,
                                 ylabel='y (cm)',xlim=None,ylim=None):
    if not os.path.exists(path):
        os.makedirs(path)
    
    cut = getballistictrials(cr)
    conditions = cut[cut.trial > 0].groupby(level=['subject'])
    for subject,group in conditions:
        fig = plt.figure()
        
        days = group.index.levels[1][group.index.labels[1]]
        subjectpath = os.path.join(activitymovies.datafolder,subject)
        act = activitytables.read_subjects(subjectpath,days=days)
    
        stact = act[act.stepstate3]
        stcr = group[group.stepstate3]
        x,y,yerr = activitytables.spatialaverage(stact,stcr,selector)
        plt.fill_between(x,y-yerr,y+yerr,color='b')
        
        uact = act[~act.stepstate3]
        ucr = group[~group.stepstate3]
        x,y,yerr = activitytables.spatialaverage(uact,ucr,selector)
        plt.fill_between(x,y-yerr,y+yerr,color='r')
        
        p1 = plt.Rectangle((0, 0), 1, 1, fc='b')
        p2 = plt.Rectangle((0, 0), 1, 1, fc='r')
        plt.legend([p1, p2], ['stable', 'unstable'])
        
        if xlim is not None:
            plt.xlim(xlim)
        if ylim is not None:
            plt.ylim(ylim)
        plt.xlabel('x (cm)')
        plt.ylabel(ylabel)
        plt.title(str.format('{0} trajectories',subject))
        fname = str.format("{0}_trajectories_stable_unstable.png",subject)
        fpath = os.path.join(path,fname)
        plt.savefig(fpath)
        plt.close(fig)
Exemplo n.º 5
0
def __spatialaverages__(cr,
                        path,
                        selector=lambda x: x.yhead,
                        ylabel='y (cm)',
                        xlim=None,
                        ylim=None):
    if not os.path.exists(path):
        os.makedirs(path)

    cut = getballistictrials(cr)
    sessions = cut[cut.trial > 0].groupby(level=['subject', 'session'])
    for (subject, session), group in sessions:
        fig = plt.figure()
        subjectpath = os.path.join(activitymovies.datafolder, subject)
        sact = activitytables.read_subjects(subjectpath, days=[session])

        x, y, yerr = activitytables.spatialaverage(sact, group, selector)
        activityplots.trajectoryplot(sact,
                                     group,
                                     alpha=0.2,
                                     flip=True,
                                     selector=selector)
        plt.fill_between(x, y - yerr, y + yerr)

        if xlim is not None:
            plt.xlim(xlim)
        if ylim is not None:
            plt.ylim(ylim)
        plt.xlabel('x (cm)')
        plt.ylabel(ylabel)
        plt.title(str.format('{0} (session {1})', subject, session))
        fname = str.format("{0}_session_{1}_trajectories.png", subject,
                           session)
        fpath = os.path.join(path, subject)
        if not os.path.exists(fpath):
            os.makedirs(fpath)
        fpath = os.path.join(fpath, fname)
        plt.savefig(fpath)
        plt.close(fig)
Exemplo n.º 6
0
uts = []
for selected in group:
    names = [selected]
    selection = str.format("subject in {0}", names)
    sb_S = sb_SA.query(selection)
    sb_U = sb_UA.query(selection)
    ub_S = ub_SA.query(selection)
    ub_U = ub_UA.query(selection)

    # Plot data
    alpha = 0.25
    baseline = slice(0, 28)
    xpoints = createspaceaxis()
    fig, (ax1, ax2) = plt.subplots(1, 2)
    st, sterr = spatialaverage(xpoints,
                               pd.concat([sb_S, ub_S]),
                               'xhead_speed',
                               baseline=baseline)
    ut, uterr = spatialaverage(xpoints,
                               pd.concat([sb_U, ub_U]),
                               'xhead_speed',
                               baseline=baseline)
    boundedcurve(xpoints, st, sterr, color='b', ax=ax1, alpha=alpha)
    boundedcurve(xpoints, ut, uterr, color='r', ax=ax1, alpha=alpha)
    proxylegend(['b', 'r'], ['stable', 'unstable'], ax=ax1, loc='upper left')
    ax1.set_title('average speed across space')
    ax1.set_xlabel('x (cm)')
    ax1.set_ylabel('speed (cm/s)')
    ax1.set_xlim(-15, 25)
    ax1.set_ylim(-20, 30)
    sts.append(st)
    uts.append(ut)