python类fftshift()的实例源码

initial.py 文件源码 项目:Fingerprint-Recognition 作者: zhangzimou 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def blkwl(img):
    """Calculate wavelength  given an image block"""
    f=np.abs(fftshift(fft2(img)))
    origin=np.where(f==np.max(f));f[origin]=0;mmax=np.where(f==np.max(f))
    wl=2*img.shape[0]/(((origin[0]-mmax[0][0])*2)**2+((origin[1]-mmax[1][0])*2)**2)**0.5
    return wl
test_helper.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_definition(self):
        x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
        y = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
        assert_array_almost_equal(fft.fftshift(x), y)
        assert_array_almost_equal(fft.ifftshift(y), x)
        x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
        y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
        assert_array_almost_equal(fft.fftshift(x), y)
        assert_array_almost_equal(fft.ifftshift(y), x)
test_helper.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_inverse(self):
        for n in [1, 4, 9, 100, 211]:
            x = np.random.random((n,))
            assert_array_almost_equal(fft.ifftshift(fft.fftshift(x)), x)
test_helper.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_axes_keyword(self):
        freqs = [[0, 1, 2], [3, 4, -4], [-3, -2, -1]]
        shifted = [[-1, -3, -2], [2, 0, 1], [-4, 3, 4]]
        assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted)
        assert_array_almost_equal(fft.fftshift(freqs, axes=0),
                fft.fftshift(freqs, axes=(0,)))
        assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs)
        assert_array_almost_equal(fft.ifftshift(shifted, axes=0),
                fft.ifftshift(shifted, axes=(0,)))
AnalysisFunctions.py 文件源码 项目:TurbPlasma 作者: tulasinandan 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def vecpot(arx,ary,arz, kf, lx=2*np.pi, ly=2*np.pi, lz=2*np.pi):
   """
   Function to compute vector potential of a 3D array
   """
   nx,ny,nz=arx.shape

   #  COMPUTE THE ARRAY SIZE
   kx, ky, kz, km = create_kgrid(*arx.shape, lx=lx, ly=ly, lz=lz)
  #kx, ky, kz, k2 = kx[:,nna,nna],ky[nna,:,nna],kz[nna,nna,:], km**2
   k2=km**2
   k2[nx/2,ny/2,nz/2]=1.

   #  FOURIER TRANSFORM THE ARRAY
   farx = nf.fftshift(nf.fftn(arx))
   fary = nf.fftshift(nf.fftn(ary))
   farz = nf.fftshift(nf.fftn(arz))

   #  SET VALUES ABOVE kf AS 0+0i
   farx = (np.sign(km - kf) - 1.)/(-2.)*farx
   fary = (np.sign(km - kf) - 1.)/(-2.)*fary
   farz = (np.sign(km - kf) - 1.)/(-2.)*farz

   #  FIND THE CORRESPONDING VECTOR POTENTIAL A = -ik x B /k^2
   axf = -eye*(ky*farz-kz*fary)/k2
   ayf = -eye*(kz*farx-kx*farz)/k2
   azf = -eye*(kx*fary-ky*farx)/k2

   #  BACK TRANSFORM TO REAL SPACE
   ax  = np.real(nf.ifftn(nf.ifftshift(axf)))
   ay  = np.real(nf.ifftn(nf.ifftshift(ayf)))
   az  = np.real(nf.ifftn(nf.ifftshift(azf)))
   return ax,ay,az
AnalysisFunctions.py 文件源码 项目:TurbPlasma 作者: tulasinandan 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def Spec2D(ar,ax=2,lenx=2*pi,leny=2*pi,lenz=2*pi):
   """
      Spec2D(ar,ax=2,lenx=2*pi,leny=2*pi,lenz=2*pi)

      2D spectrum of ar perpendicular to 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:
      k1=ky; k2=kz
   elif ax==1:
      k1=kx; k2=kz
   elif ax==2:
      k1=kx; k2=ky

   far = nf.fftshift(nf.fftn(ar))/(nx*ny*nz); fftea=0.5*np.abs(far)**2
   ffteb=fftea.sum(axis=ax)
   return k1,k2,ffteb

##
## 2D SPECTRUM OF A VECTOR
##
AnalysisFunctions.py 文件源码 项目:TurbPlasma 作者: tulasinandan 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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
##
test_helper.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_definition(self):
        x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
        y = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
        assert_array_almost_equal(fft.fftshift(x), y)
        assert_array_almost_equal(fft.ifftshift(y), x)
        x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
        y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
        assert_array_almost_equal(fft.fftshift(x), y)
        assert_array_almost_equal(fft.ifftshift(y), x)
test_helper.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_inverse(self):
        for n in [1, 4, 9, 100, 211]:
            x = np.random.random((n,))
            assert_array_almost_equal(fft.ifftshift(fft.fftshift(x)), x)
test_helper.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_axes_keyword(self):
        freqs = [[0, 1, 2], [3, 4, -4], [-3, -2, -1]]
        shifted = [[-1, -3, -2], [2, 0, 1], [-4, 3, 4]]
        assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted)
        assert_array_almost_equal(fft.fftshift(freqs, axes=0),
                fft.fftshift(freqs, axes=(0,)))
        assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs)
        assert_array_almost_equal(fft.ifftshift(shifted, axes=0),
                fft.ifftshift(shifted, axes=(0,)))
test_helper.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_definition(self):
        x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
        y = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
        assert_array_almost_equal(fft.fftshift(x), y)
        assert_array_almost_equal(fft.ifftshift(y), x)
        x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
        y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
        assert_array_almost_equal(fft.fftshift(x), y)
        assert_array_almost_equal(fft.ifftshift(y), x)
test_helper.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_inverse(self):
        for n in [1, 4, 9, 100, 211]:
            x = np.random.random((n,))
            assert_array_almost_equal(fft.ifftshift(fft.fftshift(x)), x)
test_helper.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_axes_keyword(self):
        freqs = [[0, 1, 2], [3, 4, -4], [-3, -2, -1]]
        shifted = [[-1, -3, -2], [2, 0, 1], [-4, 3, 4]]
        assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted)
        assert_array_almost_equal(fft.fftshift(freqs, axes=0),
                fft.fftshift(freqs, axes=(0,)))
        assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs)
        assert_array_almost_equal(fft.ifftshift(shifted, axes=0),
                fft.ifftshift(shifted, axes=(0,)))
recon_one.py 文件源码 项目:jamespy_py3 作者: jskDr 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def ft2(g, delta):
    return fftshift(fft2(fftshift(g))) * (delta ** 2)
test_3dgauss_and_3d_plotting.py 文件源码 项目:CoherentXrayImaging 作者: susannahammarberg 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def image():
    image = misc.imread('star.bmp',flatten=True)
    circle = misc.imread('circle.png',flatten=True)
    low_values_indices = circle < 200  # Where values are low
    circle[low_values_indices] = 0  # All low values set to 0
    high_values_indices = circle > 0
    circle[high_values_indices] = 1
    #image = misc.imread('P.png',flatten=True)
    #data = abs(fft.fftshift(fft.fft2(image)))

    theta = 10*np.pi / 180 #rad
    # nä detta stämmer väl inte
    r3 = 1 + 1/np.cos(theta)    #antal pixlar som motsvarar 1 pixel i xled i xz systemet
    r1 = 1 + 1/ np.sin(theta) 
    return 0
test_helper.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_definition(self):
        x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
        y = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
        assert_array_almost_equal(fft.fftshift(x), y)
        assert_array_almost_equal(fft.ifftshift(y), x)
        x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
        y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
        assert_array_almost_equal(fft.fftshift(x), y)
        assert_array_almost_equal(fft.ifftshift(y), x)
test_helper.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_inverse(self):
        for n in [1, 4, 9, 100, 211]:
            x = np.random.random((n,))
            assert_array_almost_equal(fft.ifftshift(fft.fftshift(x)), x)
test_helper.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_axes_keyword(self):
        freqs = [[0, 1, 2], [3, 4, -4], [-3, -2, -1]]
        shifted = [[-1, -3, -2], [2, 0, 1], [-4, 3, 4]]
        assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted)
        assert_array_almost_equal(fft.fftshift(freqs, axes=0),
                fft.fftshift(freqs, axes=(0,)))
        assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs)
        assert_array_almost_equal(fft.ifftshift(shifted, axes=0),
                fft.ifftshift(shifted, axes=(0,)))


问题


面经


文章

微信
公众号

扫码关注公众号