def svmPlotExtrema(): from matustools.matusplotlib import plotGifGrid from Pixel import initPath plt.close() out=[[],[],[],[]] for nf in [[0,''],[1,''],[1,'3'],[1,'2']]: dat=svmPlotExtrRep(nf[0],suf=nf[1],plot=True) for vp in range(4): out[vp].extend([dat[vp][1],dat[vp][5]]) path,inpath,figpath=initPath(1,0) plotGifGrid(out,fn=figpath+'svmExtrema'+FMT,bcgclr=0.5,F=34,P=32, duration=0.2,plottime=True,snapshot=True)
def pcAddition(MOVIE=True): #BP S1 out=[] for vp in [1,0]: path=inpath+'vp%03d/E%d/'%(vp+1,97) coeff=np.load(path+'X/coeff.npy') pc1=_getPC(coeff,0) if pc1.mean()>=0.4: pc1=1-pc1 pc2=_getPC(coeff,1) if pc2.mean()>=0.4: pc2=1-pc2 out.append([]) out[-1].append(pc1) out[-1].append(pc2) out[-1].append((pc1-pc2+1)/2.) #out[-1].append((pc1+pc2)/2.) if False: out.append([]) out[-1].append(pc1) out[-1].append(1-pc2) out[-1].append((pc1+pc2)/2.) if MOVIE: plotGifGrid(out,fn=figpath+'Pixel/pcAddition'+FMT,bcgclr=1,snapshot=2, plottime=True,text=[['A',20,12,-10],['B',20,84,-10]]) bla print out[0][0].shape cols=5;fs=np.linspace(0,out[0][0].shape[0]-1,cols) ps=np.arange(out[0][0].shape[1]) for i in range(len(out)): for j in range(len(out[0])): for fi in range(cols): plt.subplot(3,cols,j*cols+fi+1) plt.pcolor(ps,ps,out[i][j][fs[fi],:,:],cmap='gray') #plt.grid() plt.savefig(figpath+'Pixel'+os.path.sep+'pcAddition', dpi=DPI,bbox_inches='tight')
def plotTrack(MOVIE=True): plt.close() vp,ev,path=initVP(4,1) D=np.load(path+'trackPF.npy') count=np.load(path+'trackPFcount.npy') FFs=[] for vp in range(D.shape[0]): FFs.append([[],[],[]]) Fs=[] for g in range(D.shape[2]): Fs=[]; for vp in range(D.shape[0]): Fs.append([]) temp=np.float32(np.max(count[vp,:,g,:],1)) if not g:print 'vp=%d, nrags=%d, prop=%.3f'%(vp+1,2,temp[2]/temp[1:].sum()) for h in range(1,D.shape[1]): denom=[0.003,0.15,0.05,0.05][h] temp=D[vp,h,g,:,:,:]/denom Fs[-1].append(temp) temp[temp>1]=1 if h==2:FFs[vp][[0,2,1][g]]=temp lbl=[] for i in range(4):lbl.append([FIG[6][2]+str(i+1),20,65+i*137,FIG[6][3]]) for i in range(3):lbl.append([['1','2','>2'][i],20,-10,85+i*135]) if MOVIE: plotGifGrid(Fs,fn=figpath+'Coord/'+['trackPFforw', 'trackPFback','trackPFmid'][g]+FMT, bcgclr=1,plottime=True,text=lbl,P=129,F=85) lbl=[] for i in range(4):lbl.append([FIG[6][2]+str(i+1),20,65+i*137,FIG[6][3]]) lbl.extend([[FIG[6][1][0],20,-10,40],[FIG[6][1][1],20,-10,190],[FIG[6][1][2],20,-10,330]]) if MOVIE: plotGifGrid(FFs,fn=figpath+'Coord/trackPF'+FMT,bcgclr=1, forclr=0,plottime=True,P=129,F=85,text=lbl) figure(size=3,aspect=1) for g in range(D.shape[2]): for vp in range(4): d=D[vp,2,[0,2,1][g],60:68,:,:].mean(0) T=d.shape[1];P=d.shape[0] ax=subplot(4,3,g+3*vp+1) t=[np.linspace(-T*1000/85,0,T), np.linspace(-T/2*1000/85,T/2*1000/85,T), np.linspace(0,T*1000/85,T)][g] if not g:plt.ylabel(FIG[6][2]+str(vp+1),size=18) if not vp:plt.title(FIG[6][1][g],size=18) p=np.linspace(-5,5,P) plt.pcolor(p,t,d.T,cmap='gray',vmax=0.05) plt.xlim([p[0],p[-1]]) #if g: ax.set_yticklabels([]) if vp<3: ax.set_xticklabels([]) if g==1: plt.ylim([-500,500]) ax.set_yticks([-500,-250,0,250,500]) elif g==0: ax.set_yticks([-1000,-750,-500,-250,0]) else: ax.set_yticks([0,250,500,750,1000]) ax.set_axisbelow(False);plt.grid(True) ax.set_xticks([-5,-2.5,0,2.5,5]) plt.savefig(figpath+FIG[6][0],dpi=DPI,bbox_inches='tight')
def plotBTmean(MAX=16): from matustools.matusplotlib import plotGifGrid dat=[] for vp in range(1,5): dat.append([]) for event in range(-6,0): fn=inpath+'vp%03d/E%d/'%(vp,100+event)+'PF/PF000.npy' d=np.squeeze(np.load(fn)) #print np.max(d.mean(axis=0)),np.min(d.mean(axis=0)) dat[-1].append(d.mean(axis=0)/float(MAX)) lbl=[] #for i in range(4):lbl.append([FIG[6][1][3]+str(i+1),20,32+i*72,-15]) for i in range(4):lbl.append([FIG[3][3]+str(i+1),20,32+i*72,FIG[3][4]]) #for i in range(6):lbl.append([str([500,400,300,200,100,50][i]),20,-10,30+i*72]) for i in range(6):lbl.append([str([500,400,300,200,100,50][i]),20,-10,FIG[3][5]+i*FIG[3][6]]) plotGifGrid(dat,fn=figpath+'buttonPressMean'+FMT,bcgclr=1, text=lbl,plottime=True) return dat
def plotCoeff(event,rows=8,cols=5,pcs=10): '''event - id of the catch-up saccade, 0=exploration saccade rows - nr rows in the movie cols - nr columns in the movie pcs - number of principal components that will be displayed''' plt.close() panels=[];small=[] for vp in range(1,5): small.append([]) path=inpath+'vp%03d/E%d/'%(vp,event) coeff=np.load(path+'X/coeff.npy') offset=8 # nr pixels for border padding R=np.ones((69,(64+offset)*rows,(64+offset)*cols),dtype=np.float32) for h in range(coeff.shape[1]): if h>=rows*cols:continue c= h%cols;r= h/cols s=((offset+64)*r+offset/2,(offset+64)*c+offset/2) pc= _getPC(coeff,h) if pc.mean()>=0.4: pc= 1-pc R[1:,s[0]:s[0]+64,s[1]:s[1]+64]= pc if h<pcs: small[-1].append(pc.T) panels.append(np.copy(R)) lbl=[] for i in range(4):lbl.append([FIG[6][1][3]+str(i+1),20,32+i*72,FIG[6][1][5]]) for i in range(10):lbl.append([FIG[6][1][4]+str(i+1),20,-10,FIG[6][1][6]+i*FIG[6][1][7]]) lbl[-1][3]-=10 plotGifGrid(small, fn=figpath+'Pixel/pcE%ds'%(event)+FMT,tpL=True, duration=0.1,text=lbl,plottime=True,snapshot=1,bcgclr=1) pad=20 a,b,c=R.shape T=np.ones((a,(b+pad)*2,c*2+pad)) T[:,pad:(b+pad),:c]=panels[0] T[:,pad:(b+pad),(c+pad):(2*c+pad)]=panels[1] T[:,(b+2*pad):(2*b+2*pad),:c]=panels[2] T[:,(b+2*pad):(2*b+2*pad),(c+pad):(2*c+pad)]=panels[3] labels=[] for i in range(4): labels.append(str2img('ABCD'[i],20)) T[:,:labels[0].shape[0],:labels[0].shape[1]]-=labels[0] T[:,:labels[1].shape[0],(c+pad):(c+pad+labels[1].shape[1])]-=labels[1] T[:,(b+pad):(b+pad+labels[2].shape[0]),:labels[2].shape[1]]-=labels[2] T[:,(b+pad):(b+pad+labels[3].shape[0]), (c+pad):(c+pad+labels[3].shape[1])]-=labels[3] ndarray2gif(figpath+'Pixel/pcE%d'%(event)+FMT, T,duration=0.1,plottime=True,snapshot=True)
def pcAddition(): #BP S1 out=[] for vp in [1,0]: path=inpath+'vp%03d/E%d/'%(vp+1,97) coeff=np.load(path+'X/coeff.npy') pc1=_getPC(coeff,0) if pc1.mean()>=0.4: pc1=1-pc1 pc2=_getPC(coeff,1) if pc2.mean()>=0.4: pc2=1-pc2 out.append([]) out[-1].append(pc1) out[-1].append(pc2) out[-1].append((pc1-pc2+1)/2.) #out[-1].append((pc1+pc2)/2.) if False: out.append([]) out[-1].append(pc1) out[-1].append(1-pc2) out[-1].append((pc1+pc2)/2.) plotGifGrid(out,fn=figpath+'Pixel/pcAddition'+FMT,bcgclr=1, plottime=True,text=[['A',20,12,-10],['B',20,84,-10]])
def svmPlotExtrRep(event=0,plot=True,suf=''): from Pixel import initPath if plot: plt.close() P=32;F=34 dat=[] for vp in range(1,5): path,inpath,figpath=initPath(vp,event) fn= inpath+'svm%s/hc/hcWorker'%suf dat.append([]) for g in range(2): for k in range(4): try:temp=np.load(fn+'%d.npy'%(k*2+g)) except IOError: print 'File missing: ',vp,event,suf temp=np.zeros(P*P*F,dtype=np.bool8) temp=np.reshape(temp,[P,P,F]) dat[-1].append(np.bool8(g-1**g *temp)) lbl=[] for i in range(4):lbl.append([FIG[7][0]+str(i+1),20,18+i*40,FIG[7][1]]) lbl.append([FIG[7][2],20,-10,70]);lbl.append([FIG[7][3],20,-10,245]) if plot: plotGifGrid(dat,fn=figpath+'svm%sExtremaE%d'%(suf,event)+FMT, F=34,P=32,text=lbl,bcgclr=0.5) return dat
def plotBTavg(MAX=16,MOVIE=True): from matustools.matusplotlib import plotGifGrid dat=[];T=68;P=64;est=[] t=np.linspace(-0.8,0,T);p=np.linspace(-5,5,P) figure(size=3,aspect=1) for vp in range(1,5): dat.append([]) for event in range(-6,0): fn=inpath+'vp%03d/E%d/'%(vp,100+event)+'PF/PF000.npy' d=np.squeeze(np.load(fn)) #print np.max(d.mean(axis=0)),np.min(d.mean(axis=0)) dat[-1].append(d.mean(axis=0)/float(MAX)) inc=0#[-2,2,0,0,0,0][i+1] D= (d.mean(axis=0)/float(MAX)) D=np.rollaxis(D,1) D=D[:,(31+inc):(33+inc),:].mean(1);D/=D.sum(); j=vp-1; i=event+6 subplot(6,4,i*4+j+1) plt.pcolor(p,t,D.T,cmap='gray') # below we set the initial guess if i==3: if vp==1: x0=np.array((0.5,-12,0.3)) else: x0=np.array((3,-12,0.2,-0.5,-12,0.2)) xopt=fmin(func=_fun,x0=x0,args=(D,t,p,False)) est.append(xopt.tolist()) plt.plot(xopt[0]-xopt[1]*t,t,'r',lw=1,alpha=0.4) if vp!=1: plt.plot(xopt[3]-xopt[4]*t,t,'r',lw=1,alpha=0.4) else:est[-1].extend([np.nan]*3) plt.grid(True,'both'); plt.xlim([p[0],p[-1]]);plt.ylim([t[0],t[-1]]); ax=plt.gca();ax.set_axisbelow(False) ax.set_xticks([-4,-2,0,2,4]) ytck=np.linspace(-0.8,0,5)[1:] ax.set_yticks(ytck) if j>0: ax.set_yticklabels([]) else: ax.set_yticklabels(ytck-[0.5,0.4,0.3,0.2,0.1,0.05][i]) #if i==1: plt.text(2,-1,FIG[3][2],size=8) if i<5: ax.set_xticklabels([]) #else: plt.ylabel('subject %d'%(i+1)) #if i==0: plt.title(str(m[j]*2+2)) # if i==0: plt.title(FIG[3][3]+str(j+1)) plt.subplot(6,4,5) plt.text(-9,-0.5,FIG[3][1],rotation='vertical') plt.subplot(6,4,22) plt.text(-2,-1.2,FIG[3][2]) plt.subplots_adjust(wspace=-1) plt.savefig(figpath+FIG[3][0]+'avg',dpi=DPI,bbox_inches='tight') est=np.array(est) print est.ndim, est if est.ndim>2: est=np.squeeze(est) print ndarray2latextable(est,decim=2) if not MOVIE: return dat lbl=[] #for i in range(4):lbl.append([FIG[6][1][3]+str(i+1),20,32+i*72,-15]) for i in range(4):lbl.append([FIG[3][3]+str(i+1),20,32+i*72,FIG[3][4]]) #for i in range(6):lbl.append([str([500,400,300,200,100,50][i]),20,-10,30+i*72]) for i in range(6):lbl.append([str([500,400,300,200,100,50][i]),20,-10,FIG[3][5]+i*FIG[3][6]]) plotGifGrid(dat,fn=figpath+'buttonPressMean'+FMT,bcgclr=1, text=lbl,plottime=True) return dat