averagetimeseries(sb_U, column='yhead', color=colors[1], ax=ax2, alpha=0.25) averagetimeseries(ub_S, column='yhead', color=colors[2], ax=ax2, alpha=0.25) averagetimeseries(ub_U, column='yhead', color=colors[3], ax=ax2, alpha=0.25) proxylegend(colors, [ 'stable bias [stable]', 'stable bias [unstable]', 'unstable bias [stable]', 'unstable bias [unstable]' ], ax=ax2, loc='upper left') ax2.set_title('average nose trajectory') ax2.set_ylabel('nose height (cm)') ax2.set_ylim(1, 4) fig.suptitle( str.format('{0} (n = {1} trials)', name, len(stablebias) + len(unstablebias))) plt.show() # Save plot
ucract = cract.join(unstablebias, how='inner', rsuffix='R') scract.xhead = flipleftwards(scract.xhead, scract.side) ucract.xhead = flipleftwards(ucract.xhead, ucract.side) sb_S = scract.query('stepstate3') sb_U = scract.query('not stepstate3') ub_S = ucract.query('stepstate3') ub_U = ucract.query('not stepstate3') # Plot data name = namemap[name] fig = plt.figure() ax = fig.add_subplot(111, projection='3d') averagetimetrajectory(sb_S, color='b', ax=ax, alpha=0.5) averagetimetrajectory(sb_U, color='cyan', ax=ax, alpha=0.5) averagetimetrajectory(ub_S, color='orange', ax=ax, alpha=0.5) averagetimetrajectory(ub_U, color='r', ax=ax, alpha=0.5) proxylegend(['b', 'cyan', 'orange', 'r'], [ 'stable bias [stable]', 'stable bias [unstable]', 'unstable bias [stable]', 'unstable bias [unstable]' ], ax=ax, loc='upper left') # ax.set_ylim(0,3.5) ax.set_title( str.format('{0} (n = {1} trials)', name, len(stablebias) + len(unstablebias))) #plt.title(str.format('stable (n = {0} trials)',len(cr.query(stable)))) plt.show() # Save plot
cr = cr.query(selected).join(info) cr.protocol[cr.eval(stable)] = 'stable' cr.protocol[cr.eval(unstable)] = 'unstable' cr.protocol[cr.eval(restable)] = 'restable' sm = skipmeasure(cr, column) # Custom-sort by protocol protocolorder = {'stable': 0, 'unstable': 1, 'restable': 2} sm['rank'] = sm['protocol'].map(protocolorder) sm.sort(columns='rank', inplace=True) sm.drop(labels='rank', axis=1) sm = sm.groupby(['subject', 'protocol', 'skip'], sort=True)[column] ms = [d for g, d in sm] # Plot data f, ax = plt.subplots(1, 1) groupcomparison(ms, ['b', 'b', 'g', 'g', 'r', 'r'] * 100, ['o', 'x', 'o', 'x', 'o', 'x'] * 100, ['b', 'none', 'g', 'none', 'r', 'none'] * 100, s=10, ax=ax) proxylegend(['b', 'g', 'r'], ['stable', 'restable', 'unstable'], loc='upper left') ax.set_xticks(np.arange(2.5, len(ms) + 2.5, 6)) ax.set_xticklabels([namemap[name] for name in names(info)[1:]]) plt.ylabel('mean speed (cm/s)') plt.title('average speed on entry (1st third of assay)') plt.show() # Save plot
# 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) averagetimeseries(sb_S, 'xhead_speed', baseline=baseline, ax=ax2, color='b', alpha=alpha) averagetimeseries(ub_S,
for i in range(21,22): offact = crossingoffset(cract,steps,i) offact.set_index(['subject','session'],inplace=True) normalizeposition(offact,inplace=True) stablebias,unstablebias = posturebias(offact,n=2) fig, (ax1,ax2) = plt.subplots(1,2) colors = ['b','cyan','orange','r'] grouplabels = ['controls','small\nlesions','lesions','matched\ncontrols'] conditions = [offact.query('stepstate3'), offact.query('not stepstate3')] conditioncomparison('yhead', [controls,small,lesions,matched], conditions,colors=[colors[0],colors[-1]], ax=ax1) proxylegend([colors[0],colors[-1]],['stable','unstable'],ax=ax1) ax1.set_xticklabels(grouplabels) ax1.set_ylim(-1,1) conditions = [stablebias.query('stepstate3'), stablebias.query('not stepstate3'), unstablebias.query('stepstate3'), unstablebias.query('not stepstate3')] conditioncomparison('yhead', [controls,small,lesions,matched], conditions,colors=colors, ax=ax2) proxylegend(colors,['stable [R]', 'stable [W]', 'unstable [W]', 'unstable [R]'], ax=ax2)
cr = pd.read_hdf(lesionshamcache,crossings_key) cr = getballistictrials(cr) # Select data info['lesionvolume'] = lesionvolume(info) cr = cr.query(selected).join(info) cr.protocol[cr.eval(stable)] = 'stable' cr.protocol[cr.eval(unstable)] = 'unstable' cr.protocol[cr.eval(restable)] = 'restable' # Plot data sp = skipprobability(cr) sp['category'] = None sp.category[sp.eval(jumpers)] = 'jumper' sp.category[sp.eval(nonjumpers)] = 'nonjumper' sp.reset_index('subject',inplace=True) f,ax = plt.subplots(1,1) barcomparison(sp.query("protocol == 'stable'"),['b','r'], by='category',column='frequency',ax=ax) barcomparison(sp.query("protocol == 'unstable'"),['b','r'], left=3,by='category',column='frequency',ax=ax) barcomparison(sp.query("protocol == 'restable'"),['b','r'], left=6,by='category',column='frequency',ax=ax) proxylegend(['b','r'],['nonjumpers','jumpers']) ax.set_ylabel('p (skip middle steps)') ax.set_xticks([0.9,3.9,6.9]) ax.set_xticklabels(['stable','unstable','restable']) plt.show() # Save plot
# Select data cr = cr.query(selected).join(info) cr.protocol[cr.eval(unstable)] = 'unstable' sp = skipprobability(cr) sinfo = info.query('session == 0').reset_index('session') sp.reset_index('protocol', drop=True, inplace=True) sp = sp.join(sinfo) sp.age /= np.timedelta64(1, 'D') # Plot data f, ax = plt.subplots(1, 1) control(sp).plot(x='weight', y='frequency', color='b', kind='scatter', grid=False, ax=ax) anylesion(sp).plot(x='weight', y='frequency', color='r', kind='scatter', grid=False, ax=ax) ax.set_xlabel('weight (g)') ax.set_ylabel('p (skip middle steps)') ax.set_title('correlation of jumping with weight') proxylegend(['b', 'r'], ['control', 'lesion']) plt.show() # Save plot
ubtimes['duration'] = (ubtimes.timeend - ubtimes.time) / np.timedelta64(1, 's') sbtimes['bias'] = 'Z' ubtimes['bias'] = 'U' sbtimes.reset_index(inplace=True) ubtimes.reset_index(inplace=True) sbtimes.subject = sbtimes.subject.apply(lambda x: namemap[x]) ubtimes.subject = ubtimes.subject.apply(lambda x: namemap[x]) # Plot data names = sbtimes.subject.unique() names.sort() data = pd.concat([sbtimes, ubtimes]) box = data.boxplot('duration', by=['subject', 'bias'], grid=False, patch_artist=True, return_type='dict') boxes = box['duration']['boxes'] numboxes = len(boxes) colors = ['orange' if i % 2 == 0 else 'dodgerblue' for i in range(numboxes)] for patch, color in zip(boxes, colors): patch.set_facecolor(color) plt.ylabel('time (s)') plt.xticks(np.arange(1.5, len(names) * 2, 2), names) proxylegend(['orange', 'dodgerblue'], ['unstable bias', 'stable bias']) plt.title('duration of trial after learning about stable state') plt.ylim(0, 5) plt.show() # Save plot
unstable = '(9 <= session < 11)' restable = '(11 <= session < 13)' removed = "subject not in ['JPAK_20']" selected = str.format("({0} or {1} or {2}) and {3} and trial > 0", stable, unstable, restable, removed) nonjumpers = str.format("subject not in {0}", jumpers) jumpers = str.format("subject in {0}", jumpers) cr = pd.read_hdf(lesionshamcache, crossings_key) cr = getballistictrials(cr).query(selected) # Plot data f, (sx, ux, rx) = plt.subplots(1, 3) cract = pd.read_hdf(lesionshamcache, crossingactivity_stable_key) averagetrajectory(cract, cr.query(stable).query(nonjumpers), color='b', ax=sx) averagetrajectory(cract, cr.query(stable).query(jumpers), color='r', ax=sx) proxylegend(['b', 'r'], ['nonjumper', 'jumper'], ax=sx) sx.set_title(str.format('stable (n = {0} trials)', len(cr.query(stable)))) sx.set_ylabel('y (cm)') sx.set_ylim(0, 6) cract = pd.read_hdf(lesionshamcache, crossingactivity_unstable_key) averagetrajectory(cract, cr.query(unstable).query(nonjumpers), color='b', ax=ux) averagetrajectory(cract, cr.query(unstable).query(jumpers), color='r', ax=ux) ux.set_title(str.format('unstable (n = {0} trials)', len(cr.query(unstable)))) ux.set_ylabel('y (cm)') ux.set_ylim(0, 6) cract = pd.read_hdf(lesionshamcache, crossingactivity_restable_key)
stable = '(3 <= session < 5)' unstable = '(9 <= session < 11)' info = pd.read_hdf(lesionshamcache, info_key) lesionmap = lesionordermap(info) cr = pd.read_hdf(lesionshamcache, crossings_key).query('trial > 0') scract = pd.read_hdf(lesionshamcache, crossingactivity_stable_key) ucract = pd.read_hdf(lesionshamcache, crossingactivity_unstable_key) cract = pd.concat([scract, ucract]) cract.reset_index(['subject', 'session', 'crossing'], inplace=True) # Plot data def plotaverage(subject, ax): cr1 = cr.query(str.format("subject == '{0}' and {1}", subject, unstable)) cr2 = cr.query(str.format("subject == '{0}' and {1}", subject, stable)) averageposturecomparison(cract, info, cr1, cr2, ax=ax) ax.set_title(lesionmap[subject]) f, (ex1, ex2) = plt.subplots(1, 2) plotaverage('JPAK_21', ex1) plotaverage('JPAK_24', ex2) proxylegend(['g', 'r'], ['stable', 'unstable'], ax=ex1, loc='lower left', bbox_to_anchor=(0.8, 1)) plt.tight_layout() plt.show() # Save plot
uts.append(ut) # Plot data if namemap[selected] == 'Ca': ax = ax1 elif namemap[selected] == 'Lb': ax = ax2 else: ax = None if ax is not None: alpha = 0.25 boundedcurve(xpoints, st, sterr, color='b', ax=ax, alpha=alpha) boundedcurve(xpoints, ut, uterr, color='r', ax=ax, alpha=alpha) proxylegend(['b', 'r'], ['stable', 'unstable'], ax=ax, loc='upper left') ax.set_title('average speed across space') ax.set_xlabel('x (cm)') ax.set_ylabel('speed (cm/s)') ax.set_xlim(-15, 25) ax.set_ylim(-20, 30) # Create data summary names = [namemap[name] for name in group] speedup = pd.concat([ pd.DataFrame.from_items([('speedup', ut - st), ('subject', name)]) for st, ut, name in zip(sts, uts, names) ]) speedup = speedup.groupby('subject').sum() names = speedup.index.to_series()
# Select data bias = 2 group = list(names(info)) random = '(session == 13 and trial > 20) or (14 <= session < 17)' cr = cr.query(random) for name in group: selection = str.format("subject in {0}", [name]) try: scr = cr.query(selection) stablebias, unstablebias = posturebias(scr, n=bias) stablebias = getballistictrials(stablebias) unstablebias = getballistictrials(unstablebias) except Exception: continue # Plot data fig = plt.figure() ax = fig.gca() ss = stablebias.query('not stepstate3') us = unstablebias.query('not stepstate3') averagetrajectory(cract, ss, color='b', ax=ax) averagetrajectory(cract, us, color='r', ax=ax) ax.set_title(str.format('{0} (n = {1} trials)', name, len(ss) + len(us))) proxylegend(['b', 'r'], ['stable bias', 'unstable bias'], ax=ax) ax.set_ylabel('y (cm)') ax.set_ylim(0, 6) plt.show() # Save plot