コード例 #1
0
def medianposture(steps,info,cropsize=(300,300),ax=None):
    if ax is None:
        fig = plt.figure()
        ax = fig.gca()
    
    xhead = activitytables.flipleftwards(steps.xhead,steps.side)
    median = steps[xhead == xhead.median()].iloc[-1,:]
    stepindex = 4 if median.side == 'leftwards' else 3
    stepcenter = steprois_crop.center[stepindex]
    info = info.ix[median.name[:2],:]
    videopath = datapath.relativepath(info,'front_video.avi')
    
    background = video.readsinglebackground(videopath,median.frame)
    background = cv2.cvtColor(background,cv2.cv.CV_GRAY2BGR)
    background *= 2.1
    
    frame = video.readsingleframe(videopath,median.frame,segmented=True)
    _,mask = cv2.threshold(frame,3,255,cv2.cv.CV_THRESH_BINARY)
    mask = mask.astype(np.bool)
    frame = cv2.cvtColor(frame,cv2.cv.CV_GRAY2BGR)
    frame *= 2.1
    
    frame[mask,...] += background[mask,...]
    fliprois = RoiSet(steprois_pixels.rois,flipxy=True)
    pts = np.array(fliprois.rois[stepindex])
    cv2.polylines(background,[pts],True,(0,0,255),2)
    background[mask,...] = frame[mask,...]
    frame = background
    
    frame = imgproc.croprect(stepcenter,cropsize,frame)
    ax.imshow(frame)
    x,y = _cmtopixel_(median.xhead,median.yhead)
    x,y = _pixelcrop_(x,y,stepcenter,cropsize)
    ax.scatter(x,y,color='r')
    ax.set_axis_off()
コード例 #2
0
def posturemean(steps,color='b',label=None,ax=None):
    if ax is None:
        fig = plt.figure()
        ax = fig.gca()
        
    xhead = activitytables.flipleftwards(steps.xhead,steps.side)
    xmean = xhead.mean()
    ymean = steps.yhead.mean()
    xerr = xhead.sem()
    yerr = steps.yhead.sem()
    ax.scatter(xmean,ymean,color=color)
    ax.errorbar(xmean,ymean,xerr=xerr,yerr=yerr,ecolor=color)
    if label is not None:
        ax.annotate(label,xy=(xmean,ymean),textcoords='offset points')
    ax.set_xlabel('progression (cm)')
    ax.set_ylabel('height (cm)')
コード例 #3
0
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)
    axScatter.legend(['stable', 'unstable'], loc=2)
    ntrials = len(steps.query(stable)) + len(steps.query(unstable))
    axHistx.set_title(str.format("n = {0} trials", ntrials))
コード例 #4
0
    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)
    unstablebias.set_index('crossing', append=True, inplace=True)
    scract = cract.join(stablebias, how='inner', rsuffix='R')
    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, (ax1, ax2) = plt.subplots(1, 2)
    colors = ['b', 'cyan', 'orange', 'r']
    averagetimeseries(sb_S, color=colors[0], ax=ax1, alpha=0.25)
    averagetimeseries(sb_U, color=colors[1], ax=ax1, alpha=0.25)
    averagetimeseries(ub_S, color=colors[2], ax=ax1, alpha=0.25)
    averagetimeseries(ub_U, color=colors[3], ax=ax1, alpha=0.25)
    ax1.set_title('average time taken across space')
コード例 #5
0
namemap = lesionordermap(info)
info = info.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)))
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)
steps.xhead = flipleftwards(steps.xhead, steps.side)
normalize(steps, mediannorm, ['xhead', 'yhead'], level=['subject'])
steps = steps.rename(columns={'index': 'time'})

# Normalize data
cract.reset_index(inplace=True)
cract.set_index(['subject', 'session', 'crossing'], inplace=True)
cract = cract.join(steps, how='inner', rsuffix='R')
cract.xhead = flipleftwards(cract.xhead, cract.side)
cract.xhead_speed[cract.side == 'leftwards'] *= -1
bias = cract.eval('xheadR >= 0')
scract = cract[bias]
ucract = cract[~bias]
sb_SA = scract.query('stepstate3')
sb_UA = scract.query('not stepstate3')
ub_SA = ucract.query('stepstate3')