def ReducedSpec(ar,ax=2,lenx=2*pi,leny=2*pi,lenz=2*pi):
"""
ReducedSpec(ar,ax=2,lenx=2*pi,leny=2*pi,lenz=2*pi)
Reduced spectrum of ar along axis ax
"""
if len(ar) == 0:
print 'No array provided! Exiting!'
return
ar=ar-np.mean(ar)
nx=np.shape(ar)[0];kx=nf.fftshift(nf.fftfreq(nx))*nx*(2*pi/lenx)
ny=np.shape(ar)[1];ky=nf.fftshift(nf.fftfreq(ny))*ny*(2*pi/leny)
nz=np.shape(ar)[2];kz=nf.fftshift(nf.fftfreq(nz))*nz*(2*pi/lenz)
if ax==0:
# Both are one because after the first sum, the new array as dim=2
# First sum along y, then along z
ax1=1; ax2=1
kk=kx; nn=nx
elif ax==1:
# First sum along x (0), then along z (1 for the new configuration)
ax1=0; ax2=1
kk=ky; nn=ny
elif ax==2:
# First sum along x (0), then along y (0 for the new configuration)
ax1=0; ax2=0
kk=kz; nn=nz
far = nf.fftshift(nf.fftn(ar))/(nx*ny*nz); fftea=0.5*np.abs(far)**2
ffteb=fftea.sum(axis=ax1).sum(axis=ax2)
dk = kk[1]-kk[0]
return kk[nn/2:],ffteb[nn/2:]/dk
##
## REDUCED SPECTRUM OF A VECTOR
##
评论列表
文章目录