import matplotlib.pyplot as plt from scipy.stats import linregress from activitytables import flipleftwards, info_key from shuttlingplots import speedhistogram, speedcorrelation, scatterhistaxes from datapath import jumpers, lesionshamcache, stepfeatures_key from infotables import names, control, lesion, smalllesion, anylesion # Load data stable = '(3 <= session < 5)' unstable = '(9 <= session < 11)' nonjumpers = str.format("subject not in {0}", jumpers) sessions = str.format("{0} or {1}", stable, unstable) info = pd.read_hdf(lesionshamcache, info_key) lesions = str.format("subject in {0}", list(names(lesion(info)))) smalllesions = str.format("subject in {0}", list(names(smalllesion(info)))) alllesions = str.format("subject in {0}", list(names(anylesion(info)))) controls = str.format("subject in {0}", list(names(control(info)))) steps = pd.read_hdf(lesionshamcache, stepfeatures_key).query(nonjumpers) steps.xhead_speed[steps.side == 'leftwards'] *= -1 steps.xhead = flipleftwards(steps.xhead, steps.side) steps = steps.query(sessions) # Plot functions rangex = (steps.xhead_speed.min(), steps.xhead_speed.max()) rangey = (steps.yhead_speed.min(), steps.yhead_speed.max()) def histogramcomparison(steps, title): axes = scatterhistaxes() axScatter, axHistx, axHisty = axes speedhistogram(steps.query(stable), rangex, rangey, color='b', axes=axes)
# 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