from shuttlingplots import conditioncomparison, proxylegend
from datapath import jumpers, lesionshamcache, stepfeatures_key
from datapath import crossingactivity_random_key, crossings_key

# Load data
nonjumpers = str.format("subject not in {0}",jumpers)
steps = pd.read_hdf(lesionshamcache,stepfeatures_key).query(nonjumpers)
cr = pd.read_hdf(lesionshamcache,crossings_key).query(nonjumpers)
cract = pd.read_hdf(lesionshamcache,crossingactivity_random_key)
cract.reset_index(['subject','session','crossing'],inplace=True)
info = pd.read_hdf(lesionshamcache, info_key).query(nonjumpers)
info = info.query("subject != 'JPAK_20'")

# Select data
group = list(names(info))
controls = list(names(control(info)))
lesions = list(names(lesion(info)))
matched = list(cagemates(lesion(info)))
small = list(names(smalllesion(info)))
selection = str.format("subject in {0}",group)
random = '(session == 13 and trial > 20) or (14 <= session < 17)'
steps = steps.query(random).query(selection)
cr = cr.query(random).query(selection)
steps = joinstepactivity(steps,cr,cract)
steps = getballistictrials(steps)

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)
示例#2
0
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)
    speedhistogram(steps.query(unstable), rangex, rangey, color='r', axes=axes)
cr = getballistictrials(cr)

# 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