Exemplo n.º 1
0
def skipprobability_subject(cr,info,ax=None):
    skip = cr.steptime3.isnull() & cr.steptime4.isnull()
    skipfreq = skip.groupby(level=['subject']).sum()
    total = cr.groupby(level=['subject']).size()
    pskip = skipfreq / total
    pskip.name = 'skipfrequency'
    pskip = activitytables.groupbylesionvolumes(pskip,info,rename=True)
    pskip.reset_index('lesion',drop=True,inplace=True)
    ax = pskip.plot(kind='bar',ax=ax,grid=False,legend=False)
    ax.set_ylabel('p (skip middle steps)')
    ax.set_ylim(0,1)
def __poolfeature__(feature,ylabel,title,fname,cr,info,path):
    if not os.path.exists(path):
        os.makedirs(path)
    
    cut = getballistictrials(cr)
    m = cut.groupby(level=['subject','session'])[feature].mean()
    e = cut.groupby(level=['subject','session'])[feature].std()
    d = activitytables.groupbylesionvolumes(pd.concat([m,e],axis=1),info)
    fig = plt.figure()
    ax = plt.gca()
    activityplots.sessionmetric(d,ax=ax,colorcycle=colorcycle)
    plt.ylabel(ylabel)
    plt.title(title)
    fpath = os.path.join(path,fname)
    plt.savefig(fpath)
    plt.close(fig)
Exemplo n.º 3
0
def __poolfeature__(feature, ylabel, title, fname, cr, info, path):
    if not os.path.exists(path):
        os.makedirs(path)

    cut = getballistictrials(cr)
    m = cut.groupby(level=['subject', 'session'])[feature].mean()
    e = cut.groupby(level=['subject', 'session'])[feature].std()
    d = activitytables.groupbylesionvolumes(pd.concat([m, e], axis=1), info)
    fig = plt.figure()
    ax = plt.gca()
    activityplots.sessionmetric(d, ax=ax, colorcycle=colorcycle)
    plt.ylabel(ylabel)
    plt.title(title)
    fpath = os.path.join(path, fname)
    plt.savefig(fpath)
    plt.close(fig)
Exemplo n.º 4
0
def figure2e(act, cr, rr, info, path):
    if not os.path.exists(path):
        os.makedirs(path)

    features = []
    cr = cr[cr.stepstate3 == False]
    for (subject, session), group in cr.groupby(level=['subject', 'session']):
        #step = activitytables.stepframeindices(act,group,4,3)
        step = activitytables.stepfeature(act, group, 4, 3).iloc[0:1, :]
        step['subject'] = subject
        step['session'] = session
        step.reset_index(inplace=True)
        step.set_index(['subject', 'session'], inplace=True)
        steprr = step.join(rr, rsuffix='reward')
        timetoreward = steprr.timereward - steprr.time
        timetoreward = timetoreward[timetoreward > 0]
        features.append((subject, timetoreward.min()))

    fig = plt.figure()
    n = [(m[1].values[0] /
          np.timedelta64(1, 's') if m[1] is not np.nan else np.nan, m[0], 5)
         for m in features]
    data = pd.DataFrame(n, columns=['timetoreward', 'subject', 'session'])
    data.set_index(['subject', 'session'], inplace=True)
    result = activitytables.groupbylesionvolumes(data, info)

    ncontrols = sum((1 for m in result.index.labels[1] if m == 0))
    nlesions = sum((1 for m in result.index.labels[1] if m == 1))
    clabels = ['C' + chr(ord('a') + i) for i in range(ncontrols)]
    llabels = ['L' + chr(ord('a') + i) for i in range(nlesions)]

    plt.bar(range(len(result)),
            result.timetoreward,
            color=['b'] * 11 + ['r'] * 11)
    plt.xlim(-1, len(result) + 1)
    plt.xticks(np.arange(len(result)) + 0.4, clabels + llabels)
    plt.xlabel('subject')
    plt.ylabel('time to reward (s)')
    plt.title('time to first reward after manipulation')
    p1 = plt.Rectangle((0, 0), 1, 1, fc="b")
    p2 = plt.Rectangle((0, 0), 1, 1, fc="r")
    plt.legend([p1, p2], ['control', 'lesion'])

    fname = str.format("manipulation_first_reward_time.png", subject)
    fpath = os.path.join(path, fname)
    plt.savefig(fpath)
    plt.close(fig)
def figure2e(act,cr,rr,info,path):
    if not os.path.exists(path):
        os.makedirs(path)
        
    features = []
    cr = cr[cr.stepstate3 == False]
    for (subject,session),group in cr.groupby(level=['subject','session']):
        #step = activitytables.stepframeindices(act,group,4,3)
        step = activitytables.stepfeature(act,group,4,3).iloc[0:1,:]
        step['subject'] = subject
        step['session'] = session
        step.reset_index(inplace=True)
        step.set_index(['subject','session'],inplace=True)
        steprr = step.join(rr,rsuffix='reward')
        timetoreward = steprr.timereward - steprr.time
        timetoreward = timetoreward[timetoreward > 0]
        features.append((subject,timetoreward.min()))
        
    fig = plt.figure()        
    n = [(m[1].values[0]/np.timedelta64(1,'s') if m[1] is not np.nan else np.nan,
          m[0],5) for m in features]
    data = pd.DataFrame(n,columns=['timetoreward','subject','session'])
    data.set_index(['subject','session'],inplace=True)
    result = activitytables.groupbylesionvolumes(data,info)
    
    ncontrols = sum((1 for m in result.index.labels[1] if m == 0))
    nlesions = sum((1 for m in result.index.labels[1] if m == 1))
    clabels = ['C' + chr(ord('a') + i) for i in range(ncontrols)]
    llabels = ['L' + chr(ord('a') + i) for i in range(nlesions)]
    
    plt.bar(range(len(result)),result.timetoreward,color=['b']*11 + ['r']*11)
    plt.xlim(-1,len(result) + 1)
    plt.xticks(np.arange(len(result)) + 0.4,clabels+llabels)
    plt.xlabel('subject')
    plt.ylabel('time to reward (s)')
    plt.title('time to first reward after manipulation')
    p1 = plt.Rectangle((0, 0), 1, 1, fc="b")
    p2 = plt.Rectangle((0, 0), 1, 1, fc="r")
    plt.legend([p1,p2],['control', 'lesion'])
    
    fname = str.format("manipulation_first_reward_time.png",subject)
    fpath = os.path.join(path,fname)
    plt.savefig(fpath)
    plt.close(fig)
def figure2a3(act,info,path):
    if not os.path.exists(path):
        os.makedirs(path)    
    
    mframes = __getmanipulationframes__(act,info)
    mframes = mframes.join(info)
    mframes = mframes[mframes.frame != 0]
    mframes = mframes.query('subject not in ["JPAK_26","JPAK_27","JPAK_28","JPAK_29"]')
    mframes = mframes.join(activitymovies.getmoviepath(mframes))
    mframes = activitytables.groupbylesionvolumes(mframes[['path','frame','side']],mframes)
    mframes.reset_index()
    
    vidclips = __processclips__(mframes.iterrows(),ycrop=slice(320,-1))
    vidclips = [__transposeclips__(clip) for clip in vidclips]
    frames = __tileclips__(it.izip(*vidclips),len(mframes)/2,2)
    frames = __transposeclips__(frames)
    frames = __resizeclips__(frames,dsize=(1280,896))
    fname = str.format("manipulations_big_lesion.avi")
    vidpath = os.path.join(path,fname)
    activitymovies.savemovie(frames,vidpath,frames_per_second)
def __poolfeatureconditions__(feature,conditions,ylabel,title,fname,cr,info,path):
    if not os.path.exists(path):
        os.makedirs(path)
    
    labels = range(len(conditions))
    cr = resetsessionindex(cr,labels,labels[-1])
    info = resetsessionindex(info,labels,labels[-1])
    cut = getballistictrials(cr)
    m = cut.groupby(level=['subject','session'])[feature].mean()
    e = cut.groupby(level=['subject','session'])[feature].std()
    d = activitytables.groupbylesionvolumes(pd.concat([m,e],axis=1),info)
    fig = plt.figure()
    ax = plt.gca()
    activityplots.sessionmetric(d,ax=ax,colorcycle=colorcycle,connect=False)
    plt.xlabel('')
    plt.xticks(labels,conditions)
    plt.ylabel(ylabel)
    plt.title(title)
    fpath = os.path.join(path,fname)
    plt.savefig(fpath)
    plt.close(fig)
Exemplo n.º 8
0
def __poolfeatureconditions__(feature, conditions, ylabel, title, fname, cr,
                              info, path):
    if not os.path.exists(path):
        os.makedirs(path)

    labels = range(len(conditions))
    cr = resetsessionindex(cr, labels, labels[-1])
    info = resetsessionindex(info, labels, labels[-1])
    cut = getballistictrials(cr)
    m = cut.groupby(level=['subject', 'session'])[feature].mean()
    e = cut.groupby(level=['subject', 'session'])[feature].std()
    d = activitytables.groupbylesionvolumes(pd.concat([m, e], axis=1), info)
    fig = plt.figure()
    ax = plt.gca()
    activityplots.sessionmetric(d, ax=ax, colorcycle=colorcycle, connect=False)
    plt.xlabel('')
    plt.xticks(labels, conditions)
    plt.ylabel(ylabel)
    plt.title(title)
    fpath = os.path.join(path, fname)
    plt.savefig(fpath)
    plt.close(fig)
Exemplo n.º 9
0
def figure2a3(act, info, path):
    if not os.path.exists(path):
        os.makedirs(path)

    mframes = __getmanipulationframes__(act, info)
    mframes = mframes.join(info)
    mframes = mframes[mframes.frame != 0]
    mframes = mframes.query(
        'subject not in ["JPAK_26","JPAK_27","JPAK_28","JPAK_29"]')
    mframes = mframes.join(activitymovies.getmoviepath(mframes))
    mframes = activitytables.groupbylesionvolumes(
        mframes[['path', 'frame', 'side']], mframes)
    mframes.reset_index()

    vidclips = __processclips__(mframes.iterrows(), ycrop=slice(320, -1))
    vidclips = [__transposeclips__(clip) for clip in vidclips]
    frames = __tileclips__(it.izip(*vidclips), len(mframes) / 2, 2)
    frames = __transposeclips__(frames)
    frames = __resizeclips__(frames, dsize=(1280, 896))
    fname = str.format("manipulations_big_lesion.avi")
    vidpath = os.path.join(path, fname)
    activitymovies.savemovie(frames, vidpath, frames_per_second)
Exemplo n.º 10
0
def figure1b(rr,info,path):
    if not os.path.exists(path):
        os.makedirs(path)
    
    rr = rr.query('session > 0')
    info = info.query('session > 0')
    rrdiff = rr.groupby(level=[0,1]).diff()
    nulldiff = rrdiff.time.isnull()
    firstrr = rr.time[nulldiff] - info.starttime
    rrdiff.time[nulldiff] = firstrr
    rrsec = rrdiff.time.map(lambda x:x / np.timedelta64(1, 's'))
    rrdata = rrsec.groupby(level=[0,1]).mean()
    rryerr = rrsec.groupby(level=[0,1]).std()
    rrgdata = activitytables.groupbylesionvolumes(pd.concat([rrdata,rryerr],axis=1),info)
    
    fig = plt.figure()
    activityplots.sessionmetric(rrgdata)
    plt.ylabel('time between rewards (s)')
    plt.title('performance curve')
    fname = 'performance_curve.png'
    fpath = os.path.join(path,fname)
    plt.savefig(fpath)
    plt.close(fig)
Exemplo n.º 11
0
def figure1b(rr, info, path):
    if not os.path.exists(path):
        os.makedirs(path)

    rr = rr.query('session > 0')
    info = info.query('session > 0')
    rrdiff = rr.groupby(level=[0, 1]).diff()
    nulldiff = rrdiff.time.isnull()
    firstrr = rr.time[nulldiff] - info.starttime
    rrdiff.time[nulldiff] = firstrr
    rrsec = rrdiff.time.map(lambda x: x / np.timedelta64(1, 's'))
    rrdata = rrsec.groupby(level=[0, 1]).mean()
    rryerr = rrsec.groupby(level=[0, 1]).std()
    rrgdata = activitytables.groupbylesionvolumes(
        pd.concat([rrdata, rryerr], axis=1), info)

    fig = plt.figure()
    activityplots.sessionmetric(rrgdata)
    plt.ylabel('time between rewards (s)')
    plt.title('performance curve')
    fname = 'performance_curve.png'
    fpath = os.path.join(path, fname)
    plt.savefig(fpath)
    plt.close(fig)
#tiles = imgproc.tile(frames,6,3)
#activitymovies.showmovie(tiles)

# Showing a video clip
#video.showmovie(videos[0],93571)

# Compute time to next reward (including first trial)
rrdiff = rr.groupby(level=[0, 1]).diff()
nulldiff = rrdiff.time.isnull()
firstrr = rr.time[nulldiff] - info.starttime
rrdiff.time[nulldiff] = firstrr
rrsec = rrdiff.time.map(lambda x: x / np.timedelta64(1, 's'))

rrdata = rrsec.groupby(level=[0, 1]).mean()
rryerr = rrsec.groupby(level=[0, 1]).std()
rrgdata = activitytables.groupbylesionvolumes(
    pd.concat([rrdata, rryerr], axis=1), info)

data = cr.groupby(level=[0, 1])['duration'].mean()
yerr = cr.groupby(level=[0, 1])['duration'].std()
lesionvolume = info['lesionleft'] + info['lesionright']
lesionvolume.name = 'lesionvolume'
g = pd.concat([data, yerr, lesionvolume, info['cagemate']], axis=1)
lesionorder = g[g['lesionvolume'] > 0].sort('lesionvolume', ascending=False)
controls = lesionorder.groupby('cagemate', sort=False).median().index
controlorder = g.reset_index().set_index('subject').ix[controls]
controlorder.set_index('session', append=True, inplace=True)
result = pd.concat([controlorder, lesionorder])
result['lesion'] = [
    'lesion' if v > 0 else 'control' for v in result['lesionvolume']
]
result.reset_index(inplace=True)
#tiles = imgproc.tile(frames,6,3)
#activitymovies.showmovie(tiles)

# Showing a video clip
#video.showmovie(videos[0],93571)
                              
# Compute time to next reward (including first trial)
rrdiff = rr.groupby(level=[0,1]).diff()
nulldiff = rrdiff.time.isnull()
firstrr = rr.time[nulldiff] - info.starttime
rrdiff.time[nulldiff] = firstrr
rrsec = rrdiff.time.map(lambda x:x / np.timedelta64(1, 's'))

rrdata = rrsec.groupby(level=[0,1]).mean()
rryerr = rrsec.groupby(level=[0,1]).std()
rrgdata = activitytables.groupbylesionvolumes(pd.concat([rrdata,rryerr],axis=1),info)

data = cr.groupby(level=[0,1])['duration'].mean()
yerr = cr.groupby(level=[0,1])['duration'].std()
lesionvolume = info['lesionleft'] + info['lesionright']
lesionvolume.name = 'lesionvolume'
g = pd.concat([data,yerr,lesionvolume,info['cagemate']],axis=1)
lesionorder = g[g['lesionvolume'] > 0].sort('lesionvolume',ascending=False)
controls = lesionorder.groupby('cagemate',sort=False).median().index
controlorder = g.reset_index().set_index('subject').ix[controls]
controlorder.set_index('session',append=True,inplace=True)
result = pd.concat([controlorder,lesionorder])
result['lesion'] = ['lesion' if v > 0 else 'control'
                    for v in result['lesionvolume']]
result.reset_index(inplace=True)
result.sort(['session','lesion'],inplace=True)