def wUSV(filename,BB,ss,nm=4): fV=open(filename+'_V','w');fF=open(filename+'_F','w') fS=open(filename+'_S','w');fS.write('* INDEX S\n$ %le %le\n') BB=(BB-average(BB,0))/sqrt(len(BB)) U,S,V = svd(BB,full_matrices=0) if nm>len(U): nm=len(U); #print '# of modes =',nm F=abs(rfft(U,axis=0));F0=arange(len(F))/2.0/len(F) fV.write('* S ');fF.write('* INDEX '); for j in range(1,nm+1): fV.write('MOD_'+str(j)+' ') for j in range(1,nm+1): fF.write('MOD_'+str(j)+' ') fV.write('\n$ %le ');fF.write('\n$ %le ') for j in range(1,nm+1): fV.write('%le ') for j in range(1,nm+1): fF.write('%le ') fV.write('\n'); fF.write('\n') for k in range(len(ss)): fV.write(str(ss[k])+' ') for j in range(nm):fV.write(str(V[j,k])+' ') fV.write('\n') for k in range(len(F)): fF.write(str(F0[k])+' ') for j in range(nm):fF.write(str(F[k,j])+' ') fF.write('\n') for j in range(len(S)): fS.write(str(j)+' '+str(S[j])+'\n') fV.close();fF.close();fS.close()
def pUSV(U,V,ss,st=0,nm=4): F=abs(rfft(U,axis=0));F0=arange(len(F))/2.0/len(F) k=0;jj=arange(nm*3)+1 for j in range(st,st+nm): pylab.subplot(nm,3,jj[k]);pylab.plot(U[:,j]);k+=1 pylab.subplot(nm,3,jj[k]);pylab.plot(F0,F[:,j]);k+=1 pylab.subplot(nm,3,jj[k]);pylab.plot(V[j,:]);k+=1 pylab.show()
def fTune(BX,BY): txx=[]; tyy=[] tx=abs(rfft(BX-average(BX,0), axis=0)) ty=abs(rfft(BY-average(BY,0), axis=0)) q1=int((qx0-win)*len(tx)*2);q2=int((qx0+win)*len(tx)*2) for j in range(shape(tx)[1]): aa=argmax(tx[q1:q2,j])+q1; aa1=argmax(tx[:,j]) if aa!=aa1: print "warning, Qx outside window:",aD.H[j].name txx.append(aa/2.0/len(tx)) q1=int((qy0-win)*len(ty)*2);q2=int((qy0+win)*len(ty)*2) for j in range(shape(ty)[1]): aa=argmax(ty[q1:q2,j])+q1; aa1=argmax(ty[:,j]) if aa!=aa1: print "warning, Qy outside window:", aD.V[j].name tyy.append(aa/2.0/len(ty)) return txx, tyy