def plotFishPositionVsTime(jsonData, startState=1, endState=0, smooth=5, axis=0, fmt='b-',wid=1): state = jsonData['stateinfo'] midLine = (jsonData['tankSize_mm'][axis])/2.0 st,_,nS,_ = aba.state_to_time(jsonData,startState) _,et,_,nE = aba.state_to_time(jsonData,endState) tracking = aba.getTracking(jsonData) tracking = tracking[np.logical_and(tracking[:,0] > st, tracking[:,0] < et),:].copy() frametime = tracking[:,0] - st position = tracking[:,axis+1] if 'OMRinfo' in jsonData.keys(): results = aba.getOMRinfo(jsonData, tankLength =midLine*2) color = {-1:'red', 1:'blue'} hatch = {-1:'\\', 1:'/'} os = results['omrResults']['st'] oe = results['omrResults']['et'] od = results['omrResults']['dir'] for n in range(len(os)): p1 = mpl.patches.Rectangle((os[n]-st,0), width=oe[n]-os[n], height=midLine*2,alpha=0.5, color=[.5,1,.5],hatch=hatch[od[n]]) pyplot.gca().add_patch(p1) #pyplot.text(os[n]-st+(oe[n]-os[n])/3, 45, '%0.2f'%results['omrResults']['maxdist'][n]) pyplot.plot(frametime, position, fmt, lw=1) if smooth>0: import scipy pyplot.plot(frametime, scipy.convolve(position,np.ones(smooth)/smooth, mode='same')) pyplot.ylim([0,midLine*2]) pyplot.xlim([0,et-st]) if axis==0: pyplot.ylabel('') else: pyplot.ylabel('') pyplot.xlabel('Time (s)')
def getmintime(d): tracking = aba.getTracking(d) frametime = tracking[:,0] mintime = max(frametime)-min(frametime) return mintime
whichndx = [1,2,3,4,5,6,7] compare = [[d_pre[whichndx],d_veh[whichndx]],[d_veh[whichndx], d_sch[whichndx]]] trange = [[[1000,1700],[0,360]], [[1000,1700],[0,360]]] titles = ['Vehicle','Schreckstoff'] labels = [['Baseline','Vehicle_Start'],['Vehicle_End','Schreckstoff_Start']] bins = np.linspace(0,300,50) f = pyplot.figure(7) f.set_facecolor('w') mmperpixel=35.0/300 center=(150,150) center_rad = 100 for compnum,comp in enumerate(compare): timeInCenter = np.zeros([len(comp),len(comp[0])]) for condnum, cond in enumerate(comp): for fishnum, fish in enumerate(cond): tracking = aba.getTracking(fish) tracking[:,1]-=tracking[:,1].min() tracking[:,2]-=tracking[:,2].min() trel = trange[compnum][condnum] + tracking[0,0] tndx = np.logical_and(tracking[:,0]>=trel[0], tracking[:,0]<trel[1]) heatmap, xedges, yedges = np.histogram2d(tracking[tndx,1],tracking[tndx,2],bins=bins,normed=True) xx,yy = np.meshgrid([x1+x2/2.0 for x1, x2 in itertools.izip(xedges[1:], xedges)], [y1+y2/2.0 for y1, y2 in itertools.izip(yedges[1:], yedges)]) xxndx,yyndx = np.meshgrid(range(len(xedges)-1),range(len(yedges)-1)) centerndx = np.nonzero(np.sqrt(pow(xx-center[0],2)+pow(yy-center[1],2))<center_rad) timeInCenter[condnum][fishnum] = heatmap[xxndx[centerndx],yyndx[centerndx]].sum() / heatmap.sum() print timeInCenter (t,p) = scipy.stats.ttest_rel(timeInCenter[0,:],timeInCenter[1,:]) pyplot.subplot(1,len(compare),1+compnum) pyplot.plot(range(len(comp)),timeInCenter,'o-b') pyplot.xlim([-0.5,len(comp)-0.5])