Пример #1
0
import numpy as np
import pandas as pd
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()
from shuttlingplots import averagetimeseries, proxylegend
from datapath import jumpers, lesionshamcache, crossings_key
from datapath import crossingactivity_random_key

# Load data
nonjumpers = str.format("subject not in {0}", jumpers)
info = pd.read_hdf(lesionshamcache, info_key)
namemap = lesionordermap(info)
info = info.query(nonjumpers)
cract = pd.read_hdf(lesionshamcache, crossingactivity_random_key)
cr = pd.read_hdf(lesionshamcache, crossings_key).query(nonjumpers)
cract.reset_index('time', inplace=True)

# 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])
    scr = cr.query(selection)
    stablebias, unstablebias = posturebias(scr, n=bias)
    stablebias = getballistictrials(stablebias)
    unstablebias = getballistictrials(unstablebias)
    if len(stablebias) == 0 or len(unstablebias) == 0:
        continue

    # Select data
    stablebias = stablebias.rename(columns={'index': 'crossing'})
    unstablebias = unstablebias.rename(columns={'index': 'crossing'})
    stablebias.set_index('crossing', append=True, inplace=True)
from activitytables import normalize, mediannorm, flipleftwards
from shuttlingplots import posturehistogram
from datapath import jumpers
from datapath import lesionshamcache, stepfeatures_key

# 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)
steps = pd.read_hdf(lesionshamcache, stepfeatures_key).query(nonjumpers)
info = pd.read_hdf(lesionshamcache, info_key).query(nonjumpers)

# Select data
lesioninfo = infotables.lesion(info)
lesion = str.format("subject in {0}", list(infotables.names(lesioninfo)))
control = str.format("subject in {0}", list(infotables.cagemates(lesioninfo)))
steps.xhead = flipleftwards(steps.xhead, steps.side)
normalize(steps, mediannorm, ['xhead', 'yhead'], level=['subject'])
steps = steps.query(sessions)
stepstable = steps.query(stable)
stepunstable = steps.query(unstable)

# Plot data
plt.figure()
rangex = (steps.xhead.min(), steps.xhead.max())
rangey = (steps.yhead.min(), steps.yhead.max())
axScatter = plt.subplot2grid((3, 7), (1, 0), rowspan=2, colspan=2)
axHistx = plt.subplot2grid((3, 7), (0, 0), colspan=2)
axHisty = plt.subplot2grid((3, 7), (1, 2), rowspan=2)
axes = (axScatter, axHistx, axHisty)
Пример #4
0
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
from activitytables import crossingoffset, joinstepactivity, normalizeposition
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)