def figure1n2(info,path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject','session']) for (subject,session),sinfo in sessions: fig = plt.figure() subjectpath = os.path.join(activitymovies.datafolder,subject) sact = activitytables.read_subjects(subjectpath,days=[session]) scr = activitytables.read_subjects(subjectpath,days=[session], selector = activitytables.crossings) slipframes = activitytables.slipframes(sact,scr,sinfo,3,3) side = int(np.ceil(np.sqrt(len(slipframes)))) tile = imgproc.tile(slipframes,side,side) plt.imshow(tile[0], cmap = plt.cm.Greys_r) plt.title(str.format('{0} (session {1})',subject,session)) fname = str.format("{0}_session_{1}_slip_posture.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.axis("off") plt.savefig(fpath) plt.close(fig)
def figure1k1(info,path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject','session']) for (subject,session),sinfo in sessions: subjectpath = os.path.join(activitymovies.datafolder,subject) sact = activitytables.read_subjects(subjectpath,days=[session]) scr = activitytables.read_subjects(subjectpath,days=[session], selector = activitytables.crossings) features = activitytables.stepfeature(sact,scr,4,3) leftwards = features.side == 'leftwards' features.xhead[leftwards] = max_width_cm - features.xhead[leftwards] median = np.sort(features.xhead)[len(features)/2+1] median = features[features.xhead == median].iloc[-1,:] vidpaths = activitymovies.getmoviepath(sinfo) timepaths = activitymovies.gettimepath(info) movie = [video.video(mpath,mtimepath) for mpath,mtimepath in zip(vidpaths,timepaths)][0] medianframe = movie.frame(sact.index.get_loc(median.name)) flip = median.side == 'rightwards' stepindex = 3 if flip else 4 medianframe = activitytables.cropstep(medianframe,stepindex,flip=flip) fname = str.format("{0}_session_{1}_median_step_posture.png", subject, session) fpath = os.path.join(path,subject) if not os.path.exists(fpath): os.makedirs(fpath) fpath = os.path.join(fpath,fname) cv2.imwrite(fpath,medianframe)
def figure1n2(info, path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject', 'session']) for (subject, session), sinfo in sessions: fig = plt.figure() subjectpath = os.path.join(activitymovies.datafolder, subject) sact = activitytables.read_subjects(subjectpath, days=[session]) scr = activitytables.read_subjects(subjectpath, days=[session], selector=activitytables.crossings) slipframes = activitytables.slipframes(sact, scr, sinfo, 3, 3) side = int(np.ceil(np.sqrt(len(slipframes)))) tile = imgproc.tile(slipframes, side, side) plt.imshow(tile[0], cmap=plt.cm.Greys_r) plt.title(str.format('{0} (session {1})', subject, session)) fname = str.format("{0}_session_{1}_slip_posture.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.axis("off") plt.savefig(fpath) plt.close(fig)
def figure1k3(info, path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject']) for subject, sinfo in sessions: fig = plt.figure() subjectpath = os.path.join(activitymovies.datafolder, subject) stepframes = [] stinfo = sinfo[sinfo.protocol == 'stable'] for key, group in stinfo.groupby(level=['session']): stact = activitytables.read_subjects(subjectpath, days=[key]) stcr = activitytables.read_subjects( subjectpath, days=[key], selector=activitytables.crossings) stepframes += activitytables.stepframes(stact, stcr, group, 4, 3, subtractBackground=True) stepframes = [ cv2.threshold(f, 5, 255, cv2.cv.CV_THRESH_BINARY)[1] for f in stepframes ] stavg = imgproc.average(stepframes, 1) stepframes = [] uinfo = sinfo[sinfo.protocol != 'stable'] for key, group in uinfo.groupby(level=['session']): uact = activitytables.read_subjects(subjectpath, days=[key]) ucr = activitytables.read_subjects( subjectpath, days=[key], selector=activitytables.crossings) stepframes += activitytables.stepframes(uact, ucr, group, 4, 3, subtractBackground=True) stepframes = [ cv2.threshold(f, 5, 255, cv2.cv.CV_THRESH_BINARY)[1] for f in stepframes ] uavg = imgproc.average(stepframes, 1) avg = cv2.merge((uavg, stavg, np.zeros(stavg.shape, dtype=stavg.dtype))) avg = avg.astype(np.uint8) avg = cv2.convertScaleAbs(avg, alpha=1.4, beta=0.0) plt.imshow(avg) plt.title(str.format('{0}', subject)) fname = str.format("{0}_posture_stable_unstable.png", subject) fpath = os.path.join(path, fname) plt.axis("off") plt.savefig(fpath) plt.close(fig)
def figure1j(info, path): if not os.path.exists(path): os.makedirs(path) fig = plt.figure() sessions = info.groupby(level=['subject']) xticks = [] xticklabels = [] barplotwidth = 4 for i, (subject, sinfo) in enumerate(sessions): subjectpath = os.path.join(activitymovies.datafolder, subject) days = sinfo.index.levels[1][sinfo.index.labels[1]] act = activitytables.read_subjects(subjectpath, days=days) cr = activitytables.read_subjects(subjectpath, days=days, selector=activitytables.crossings) offset = i * barplotwidth stact = act[act.stepstate3] stcr = cr[cr.stepstate3] stfeatures = activitytables.stepfeature(stact, stcr, 4, 3) stskipfrequency = 1 - float(len(stfeatures)) / len(stcr) uact = act[~act.stepstate3] ucr = cr[~cr.stepstate3] ufeatures = activitytables.stepfeature(uact, ucr, 4, 3) uskipfrequency = 1 - float(len(ufeatures)) / len(ucr) plt.bar((-1 + offset, offset), (stskipfrequency, uskipfrequency), color=['b', 'r'], width=1, hold=True) xticks.append(offset) xticklabels.append(subject.replace('JPAK_', '')) p1 = plt.Rectangle((0, 0), 1, 1, fc="b") p2 = plt.Rectangle((0, 0), 1, 1, fc="r") plt.legend([p1, p2], ['stable', 'unstable'], bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.) plt.xlabel('subject (JPAK)') plt.ylabel('p(skipping)') plt.xticks(xticks, xticklabels) plt.xlim(-2, len(sessions) * barplotwidth - 1) #plt.title(str.format('4th step contact frequency',subject)) fname = str.format("all_animals_4thstep_frequency.png", subject) fpath = os.path.join(path, fname) plt.savefig(fpath) plt.close(fig)
def figure1l(info,path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject']) for subject,sinfo in sessions: fig = plt.figure() subjectpath = os.path.join(activitymovies.datafolder,subject) days = sinfo.index.levels[1][sinfo.index.labels[1]] act = activitytables.read_subjects(subjectpath,days=days) cr = activitytables.read_subjects(subjectpath,days=days, selector=activitytables.crossings) axScatter = plt.subplot2grid((3,3),(1,0),rowspan=2,colspan=2) axHistx = plt.subplot2grid((3,3),(0,0),colspan=2) axHisty = plt.subplot2grid((3,3),(1,2),rowspan=2) axes = (axScatter,axHistx,axHisty) stepoffset = stepcenter_cm[3][1] bins = 50 xlim = (20-stepoffset,30-stepoffset) ylim = (-1,9) alpha = 0.75 stact = act[act.stepstate3] stcr = cr[cr.stepstate3] stfeatures = activitytables.stepfeature(stact,stcr,4,3) leftwards = stfeatures.side == 'leftwards' stfeatures.xhead[leftwards] = max_width_cm - stfeatures.xhead[leftwards] stfeatures.xhead -= stepoffset activityplots.scatterhist(stfeatures.xhead,stfeatures.yhead,color='b', bins=bins,axes=axes,xlim=xlim,ylim=ylim, histalpha=alpha) uact = act[~act.stepstate3] ucr = cr[~cr.stepstate3] ufeatures = activitytables.stepfeature(uact,ucr,4,3) leftwards = ufeatures.side == 'leftwards' ufeatures.xhead[leftwards] = max_width_cm - ufeatures.xhead[leftwards] ufeatures.xhead -= stepoffset activityplots.scatterhist(ufeatures.xhead,ufeatures.yhead,color='r', bins=bins,axes=axes,xlim=xlim,ylim=ylim, histalpha=alpha) axScatter.set_xlabel('x (cm)') axScatter.set_ylabel('y (cm)') axScatter.legend(['stable', 'unstable'],loc=2) axHistx.set_title(str.format('{0} nose position on contact',subject)) fname = str.format("{0}_nose_stable_unstable.png",subject) fpath = os.path.join(path,fname) plt.savefig(fpath) plt.close(fig)
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)
def figure1j(info,path): if not os.path.exists(path): os.makedirs(path) fig = plt.figure() sessions = info.groupby(level=['subject']) xticks = [] xticklabels = [] barplotwidth = 4 for i,(subject,sinfo) in enumerate(sessions): subjectpath = os.path.join(activitymovies.datafolder,subject) days = sinfo.index.levels[1][sinfo.index.labels[1]] act = activitytables.read_subjects(subjectpath,days=days) cr = activitytables.read_subjects(subjectpath,days=days, selector=activitytables.crossings) offset = i * barplotwidth stact = act[act.stepstate3] stcr = cr[cr.stepstate3] stfeatures = activitytables.stepfeature(stact,stcr,4,3) stskipfrequency = 1 - float(len(stfeatures)) / len(stcr) uact = act[~act.stepstate3] ucr = cr[~cr.stepstate3] ufeatures = activitytables.stepfeature(uact,ucr,4,3) uskipfrequency = 1 - float(len(ufeatures)) / len(ucr) plt.bar((-1 + offset,offset),(stskipfrequency,uskipfrequency), color=['b','r'],width=1,hold=True) xticks.append(offset) xticklabels.append(subject.replace('JPAK_','')) p1 = plt.Rectangle((0, 0), 1, 1, fc="b") p2 = plt.Rectangle((0, 0), 1, 1, fc="r") plt.legend([p1,p2],['stable', 'unstable'], bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.) plt.xlabel('subject (JPAK)') plt.ylabel('p(skipping)') plt.xticks(xticks,xticklabels) plt.xlim(-2,len(sessions) * barplotwidth - 1) #plt.title(str.format('4th step contact frequency',subject)) fname = str.format("all_animals_4thstep_frequency.png",subject) fpath = os.path.join(path,fname) plt.savefig(fpath) plt.close(fig)
def figure1k3(info,path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject']) for subject,sinfo in sessions: fig = plt.figure() subjectpath = os.path.join(activitymovies.datafolder,subject) stepframes = [] stinfo = sinfo[sinfo.protocol == 'stable'] for key,group in stinfo.groupby(level=['session']): stact = activitytables.read_subjects(subjectpath,days=[key]) stcr = activitytables.read_subjects(subjectpath,days=[key], selector = activitytables.crossings) stepframes += activitytables.stepframes(stact,stcr,group,4,3, subtractBackground=True) stepframes = [cv2.threshold(f, 5, 255, cv2.cv.CV_THRESH_BINARY)[1] for f in stepframes] stavg = imgproc.average(stepframes,1) stepframes = [] uinfo = sinfo[sinfo.protocol != 'stable'] for key,group in uinfo.groupby(level=['session']): uact = activitytables.read_subjects(subjectpath,days=[key]) ucr = activitytables.read_subjects(subjectpath,days=[key], selector = activitytables.crossings) stepframes += activitytables.stepframes(uact,ucr,group,4,3, subtractBackground=True) stepframes = [cv2.threshold(f, 5, 255, cv2.cv.CV_THRESH_BINARY)[1] for f in stepframes] uavg = imgproc.average(stepframes,1) avg = cv2.merge((uavg,stavg,np.zeros(stavg.shape,dtype=stavg.dtype))) avg = avg.astype(np.uint8) avg = cv2.convertScaleAbs(avg,alpha=1.4,beta=0.0) plt.imshow(avg) plt.title(str.format('{0}',subject)) fname = str.format("{0}_posture_stable_unstable.png", subject) fpath = os.path.join(path,fname) plt.axis("off") plt.savefig(fpath) plt.close(fig)
def figure1k1(info, path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject', 'session']) for (subject, session), sinfo in sessions: subjectpath = os.path.join(activitymovies.datafolder, subject) sact = activitytables.read_subjects(subjectpath, days=[session]) scr = activitytables.read_subjects(subjectpath, days=[session], selector=activitytables.crossings) features = activitytables.stepfeature(sact, scr, 4, 3) leftwards = features.side == 'leftwards' features.xhead[leftwards] = max_width_cm - features.xhead[leftwards] median = np.sort(features.xhead)[len(features) / 2 + 1] median = features[features.xhead == median].iloc[-1, :] vidpaths = activitymovies.getmoviepath(sinfo) timepaths = activitymovies.gettimepath(info) movie = [ video.video(mpath, mtimepath) for mpath, mtimepath in zip(vidpaths, timepaths) ][0] medianframe = movie.frame(sact.index.get_loc(median.name)) flip = median.side == 'rightwards' stepindex = 3 if flip else 4 medianframe = activitytables.cropstep(medianframe, stepindex, flip=flip) fname = str.format("{0}_session_{1}_median_step_posture.png", subject, session) fpath = os.path.join(path, subject) if not os.path.exists(fpath): os.makedirs(fpath) fpath = os.path.join(fpath, fname) cv2.imwrite(fpath, medianframe)
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)
def figure1n(info, path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject', 'session']) for (subject, session), sinfo in sessions: subjectpath = os.path.join(activitymovies.datafolder, subject) sact = activitytables.read_subjects(subjectpath, days=[session]) activityplots.clusterslipframes(sact, sinfo, 4, 2) plt.suptitle(str.format('{0} (session {1})', subject, session)) fname = str.format("{0}_session_{1}_slip_posture.png", subject, session) fpath = os.path.join(path, subject) if not os.path.exists(fpath): os.makedirs(fpath) fpath = os.path.join(fpath, fname) fig = plt.gcf() plt.get_current_fig_manager().resize(1090, 480) plt.savefig(fpath) plt.close(fig)
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)
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)
def figure1n(info,path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject','session']) for (subject,session),sinfo in sessions: subjectpath = os.path.join(activitymovies.datafolder,subject) sact = activitytables.read_subjects(subjectpath,days=[session]) activityplots.clusterslipframes(sact,sinfo,4,2) plt.suptitle(str.format('{0} (session {1})',subject,session)) fname = str.format("{0}_session_{1}_slip_posture.png", subject, session) fpath = os.path.join(path,subject) if not os.path.exists(fpath): os.makedirs(fpath) fpath = os.path.join(fpath,fname) fig = plt.gcf() plt.get_current_fig_manager().resize(1090,480) plt.savefig(fpath) plt.close(fig)
r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_27', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_28', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_29', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_36', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_37', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_38', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_39', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_48', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_49', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_50', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_51', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_52', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_53', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_54', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_55'] cr = activitytables.read_subjects(datafolders,days=days, selector=lambda x:activitytables.crossings(x,True,False)) rr = activitytables.read_subjects(datafolders,days=days, key=activitytables.rewards_key) info = activitytables.read_subjects(datafolders,days=days, key=activitytables.info_key) # For video analysis (4,10,12,16) days = [0] datafolders = [r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_21'] cr = activitytables.read_subjects(datafolders,days=days) rr = activitytables.read_subjects(datafolders,days=days,key=activitytables.rewards_key) info = activitytables.read_subjects(datafolders,days=days,key=activitytables.info_key) def clusterstepframes(cr,info,leftstep,rightstep): # Compute step times
def figure1l(info, path): if not os.path.exists(path): os.makedirs(path) sessions = info.groupby(level=['subject']) for subject, sinfo in sessions: fig = plt.figure() subjectpath = os.path.join(activitymovies.datafolder, subject) days = sinfo.index.levels[1][sinfo.index.labels[1]] act = activitytables.read_subjects(subjectpath, days=days) cr = activitytables.read_subjects(subjectpath, days=days, selector=activitytables.crossings) axScatter = plt.subplot2grid((3, 3), (1, 0), rowspan=2, colspan=2) axHistx = plt.subplot2grid((3, 3), (0, 0), colspan=2) axHisty = plt.subplot2grid((3, 3), (1, 2), rowspan=2) axes = (axScatter, axHistx, axHisty) stepoffset = stepcenter_cm[3][1] bins = 50 xlim = (20 - stepoffset, 30 - stepoffset) ylim = (-1, 9) alpha = 0.75 stact = act[act.stepstate3] stcr = cr[cr.stepstate3] stfeatures = activitytables.stepfeature(stact, stcr, 4, 3) leftwards = stfeatures.side == 'leftwards' stfeatures.xhead[ leftwards] = max_width_cm - stfeatures.xhead[leftwards] stfeatures.xhead -= stepoffset activityplots.scatterhist(stfeatures.xhead, stfeatures.yhead, color='b', bins=bins, axes=axes, xlim=xlim, ylim=ylim, histalpha=alpha) uact = act[~act.stepstate3] ucr = cr[~cr.stepstate3] ufeatures = activitytables.stepfeature(uact, ucr, 4, 3) leftwards = ufeatures.side == 'leftwards' ufeatures.xhead[leftwards] = max_width_cm - ufeatures.xhead[leftwards] ufeatures.xhead -= stepoffset activityplots.scatterhist(ufeatures.xhead, ufeatures.yhead, color='r', bins=bins, axes=axes, xlim=xlim, ylim=ylim, histalpha=alpha) axScatter.set_xlabel('x (cm)') axScatter.set_ylabel('y (cm)') axScatter.legend(['stable', 'unstable'], loc=2) axHistx.set_title(str.format('{0} nose position on contact', subject)) fname = str.format("{0}_nose_stable_unstable.png", subject) fpath = os.path.join(path, fname) plt.savefig(fpath) plt.close(fig)
# -*- coding: utf-8 -*- """ Created on Tue Oct 07 13:17:13 2014 @author: Gonçalo """ import activitytables import activityplots subject = r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_25' stablerange = range(4,5) randomrange = range(13,17) act1 = activitytables.read_subjects(subject, days=stablerange) act2 = activitytables.read_subjects(subject, days=randomrange) cross1 = activitytables.read_subjects(subject, days=stablerange, selector=activitytables.crossings) cross2 = activitytables.read_subjects(subject, days=randomrange, selector=activitytables.crossings) validc1 = cross1[(cross1.label == 'valid') & (cross1.stepstate3)] validc2 = cross2[(cross2.label == 'valid') & (cross2.stepstate3)] traj1 = [act1[slice(s.start,s.stop)] for s in validc1.slices] traj2 = [act2[slice(s.start,s.stop)] for s in validc2.slices]
# -*- coding: utf-8 -*- """ Created on Thu Apr 30 12:30:38 2015 @author: Gonçalo """ from activitytables import read_subjects from activitytables import visiblecrossings, fullcrossings, crossings from datapath import lesionsham, decorticate from datapath import lesionshamcache, decorticatecache from datapath import visiblecrossings_key, fullcrossings_key, crossings_key # Rebuild crossing cache print "Rebuilding lesionsham visible crossings..." cr = read_subjects(lesionsham,selector=visiblecrossings) cr.to_hdf(lesionshamcache,visiblecrossings_key) print "Rebuilding lesionsham full crossings..." cr = read_subjects(lesionsham,selector=fullcrossings) cr.to_hdf(lesionshamcache,fullcrossings_key) print "Rebuilding lesionsham crossings..." cr = read_subjects(lesionsham,selector=crossings) cr.to_hdf(lesionshamcache,crossings_key) print "Rebuilding decorticate visible crossings..." cr = read_subjects(decorticate,selector=visiblecrossings) cr.to_hdf(decorticatecache,visiblecrossings_key) print "Rebuilding decorticate full crossings..."
gioias = [ r'D:/Protocols/Shuttling/Decorticate/Data/GIOIA_01', r'D:/Protocols/Shuttling/Decorticate/Data/GIOIA_03' ] decorticates = [ r'D:/Protocols/Shuttling/Decorticate/Data/JPAK_79', r'D:/Protocols/Shuttling/Decorticate/Data/JPAK_81', r'D:/Protocols/Shuttling/Decorticate/Data/JPAK_82' ] subjects = gioias + subjects + decorticates cr = activitytables.read_subjects(subjects[1:], days=[3, 4, 9, 10, -1], selector=activitytables.crossings) info = activitytables.read_subjects(subjects[1:], days=[3, 4, 9, 10, -1], key=activitytables.info_key) # Figure 1B (Across Conditions) rr = activitytables.read_subjects(subjects, days=range(1, 5), key=activitytables.rewards_key) info = activitytables.read_subjects(subjects, days=range(1, 5), key=activitytables.info_key) fbase = r'C:\figs\figure1b' figure1.figure1b(rr, info, fbase)
# -*- coding: utf-8 -*- """ Created on Sun May 03 15:08:56 2015 @author: Gonçalo """ from activitytables import read_subjects from activitytables import stepfeatures from datapath import lesionsham, decorticate from datapath import lesionshamcache, decorticatecache from datapath import stepfeatures_key # Rebuild crossing cache print "Rebuilding lesionsham step features..." cr = read_subjects(lesionsham, selector=stepfeatures) cr.to_hdf(lesionshamcache, stepfeatures_key) print "Rebuilding decorticate step features..." cr = read_subjects(decorticate, selector=stepfeatures) cr.to_hdf(decorticatecache, stepfeatures_key)
@author: Gonçalo """ from activitytables import read_subjects from activitytables import crossingactivity from datapath import lesionsham, decorticate from datapath import lesionshamcache, decorticatecache from datapath import crossingactivity_stable_key from datapath import crossingactivity_unstable_key from datapath import crossingactivity_restable_key from datapath import crossingactivity_random_key from datapath import crossingactivity_challenge_key # Rebuild crossing trajectory cache print "Rebuilding lesionsham stable trajectories..." cr = read_subjects(lesionsham, days=slice(0, 5), selector=crossingactivity) cr.to_hdf(lesionshamcache, crossingactivity_stable_key) print "Rebuilding lesionsham unstable trajectories..." cr = read_subjects(lesionsham, days=slice(5, 11), selector=crossingactivity) cr.to_hdf(lesionshamcache, crossingactivity_unstable_key) print "Rebuilding lesionsham restable trajectories..." cr = read_subjects(lesionsham, days=slice(11, 13), selector=crossingactivity) cr.to_hdf(lesionshamcache, crossingactivity_restable_key) print "Rebuilding lesionsham random trajectories..." cr = read_subjects(lesionsham, days=slice(13, 17), selector=crossingactivity) cr.to_hdf(lesionshamcache, crossingactivity_random_key) print "Rebuilding lesionsham challenge trajectories..."
r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_50', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_51', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_52', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_53', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_54', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_55' ] decorticates = [ r'D:/Protocols/Shuttling/Decorticate/Data/JPAK_79', r'D:/Protocols/Shuttling/Decorticate/Data/JPAK_81', r'D:/Protocols/Shuttling/Decorticate/Data/JPAK_82' ] # Figure 1 rr = activitytables.read_subjects(subjects, key=activitytables.rewards_key) info = activitytables.read_subjects(subjects, key=activitytables.info_key) cr = None crd = None infod = None # Reward time over sessions selection = 'session > 0 and session < 17' shuttlingplots.timetoreward(rr.query(selection), info.query(selection)) ymin, ymax = plt.ylim() plt.vlines(5 * 3 + 0.5, ymin, ymax, linestyles='solid') plt.vlines(12 * 3 + 0.5, ymin, ymax, linestyles='solid') plt.vlines(15 * 3 + 0.5, ymin, ymax, linestyles='solid') plt.ylim(ymin, ymax) # Time to cross over sessions
# -*- coding: utf-8 -*- """ Created on Sat May 02 22:09:50 2015 @author: Gonçalo """ from activitytables import read_subjects from activitytables import info_key from datapath import ecog, ecogcache from datapath import ecoganalysis, ensurefolder # Rebuild info cache ensurefolder(ecoganalysis) print "Rebuilding ecog session info..." cr = read_subjects(ecog, key=info_key) cr.to_hdf(ecogcache, info_key)
# -*- coding: utf-8 -*- """ Created on Sun May 03 15:08:56 2015 @author: Gonçalo """ from activitytables import read_subjects from activitytables import stepfeatures from datapath import ecog, ecogcache from datapath import stepfeatures_key # Rebuild crossing cache print "Rebuilding ecog step features..." cr = read_subjects(ecog,selector=stepfeatures) cr.to_hdf(ecogcache,stepfeatures_key)
r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_29", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_36", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_37", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_38", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_39", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_48", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_49", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_50", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_51", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_52", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_53", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_54", r"D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_55", ] cr = activitytables.read_subjects(subjects[1:], days=[3, 4, 9, 10, -1], selector=activitytables.crossings) info = activitytables.read_subjects(subjects[1:], days=[3, 4, 9, 10, -1], key=activitytables.info_key) # Figure 1C (Across Conditions) alpha = 1 fbase = r"C:\figs\figure1c" scr = cr.query("session != 3 and session != 9") sinfo = info.query("session != 3 and session != 9") scr = figure1.resetsessionindex(scr, [0, 1, 2], 2) sinfo = figure1.resetsessionindex(sinfo, [0, 1, 2], 2) figure1.figure1c0(scr, fbase, alpha=alpha, fname="all_subjects_duration_maxheight_all_conditions_0.png") figure1.figure1c2(scr, fbase, alpha=alpha, fname="all_subjects_duration_maxheight_all_conditions_0a_colored.png") figure1.figure1c3(scr, sinfo, fbase, alpha=alpha, fname="all_subjects_duration_maxheight_all_conditions_1_lesion.png") figure1.figure1c4( scr, sinfo, fbase, alpha=alpha, fname="all_subjects_duration_maxheight_all_conditions_2_big_lesion.png" )
# -*- coding: utf-8 -*- """ Created on Tue Oct 07 13:17:13 2014 @author: Gonçalo """ import activitytables import activityplots subject = r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_25' stablerange = range(4, 5) randomrange = range(13, 17) act1 = activitytables.read_subjects(subject, days=stablerange) act2 = activitytables.read_subjects(subject, days=randomrange) cross1 = activitytables.read_subjects(subject, days=stablerange, selector=activitytables.crossings) cross2 = activitytables.read_subjects(subject, days=randomrange, selector=activitytables.crossings) validc1 = cross1[(cross1.label == 'valid') & (cross1.stepstate3)] validc2 = cross2[(cross2.label == 'valid') & (cross2.stepstate3)] traj1 = [act1[slice(s.start, s.stop)] for s in validc1.slices] traj2 = [act2[slice(s.start, s.stop)] for s in validc2.slices]
r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_29', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_36', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_37', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_38', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_39', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_48', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_49', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_50', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_51', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_52', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_53', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_54', r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_55' ] cr = activitytables.read_subjects( datafolders, days=days, selector=lambda x: activitytables.crossings(x, True, False)) rr = activitytables.read_subjects(datafolders, days=days, key=activitytables.rewards_key) info = activitytables.read_subjects(datafolders, days=days, key=activitytables.info_key) # For video analysis (4,10,12,16) days = [0] datafolders = [r'E:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_21'] cr = activitytables.read_subjects(datafolders, days=days) rr = activitytables.read_subjects(datafolders, days=days, key=activitytables.rewards_key)
r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_36', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_37', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_38', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_39', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_48', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_49', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_50', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_51', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_52', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_53', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_54', r'D:/Protocols/Shuttling/LightDarkServoStable/Data/JPAK_55' ] cr = activitytables.read_subjects(subjects[1:], days=[3, 4, 9, 10, -1], selector=activitytables.crossings) info = activitytables.read_subjects(subjects[1:], days=[3, 4, 9, 10, -1], key=activitytables.info_key) # Figure 1C (Across Conditions) alpha = 1 fbase = r'C:\figs\figure1c' scr = cr.query('session != 3 and session != 9') sinfo = info.query('session != 3 and session != 9') scr = figure1.resetsessionindex(scr, [0, 1, 2], 2) sinfo = figure1.resetsessionindex(sinfo, [0, 1, 2], 2) figure1.figure1c0(scr, fbase, alpha=alpha,