나는 Fourier 공간에 그리드를 만든 다음 역 푸리에 변환하여 임의의 필드를 얻으면서 Gaussian 난수 필드를 만들려고합니다. 이를 위해 역 푸리에 변환 된 이미지는 실수 값이어야합니다. 나는 10^-18 - -22의 격자의 허수 부에 잔차를 얻는 것 같아서, 나는 이것을 FFT에서 수치 오류라고 예상했다. 이미지의 실제 부분은 픽셀이 양수에서 음수로 점프하는 pixelcale에 이상한 바둑판 패턴을 표시합니다. FFT가 올바르게 작동하는지 확인하기 위해 Gaussian을 변환하려고 시도했습니다. Gaussian은 다른 Gaussian을 돌려 주어야하며 바둑판 무늬가 이미지에 나타납니다. 이미지의 절대 값을 취할 때는 괜찮아 보이지만, 가우스 임의 필드의 음수 값을 허용해야합니다. 나는 다음과 같은 코드를 사용 가우스의 푸리에 변환의 경우 FFT 후의 바둑판 패턴
:#! /usr/bin/env python
import numpy as n
import math as m
import pyfits
def fourierplane(a):
deltakx = 2*a.kxmax/a.dimkx #stepsize in k_x
deltaky = 2*a.kymax/a.dimky #stepsize in k_y
plane = n.zeros([a.dimkx,a.dimky]) #empty matrix to be filled in for the Fourier grid
for y in range(n.shape(plane)[0]):
for x in range(n.shape(plane)[1]):
#Defining coordinates centred at x = N/2, y = N/2
i1 = x - a.dimkx/2
j1 = y - a.dimky/2
#creating values to fill in in the grid:
kx = deltakx*i1 #determining value of k_x at gridpoint
ky = deltaky*j1 #determining value of k_y at gridpoint
k = m.sqrt(kx**2 + ky**2) #magnitude of k-vector
plane[y][x] = m.e**(-(k**2)/(2*a.sigma_k**2)) #gaussian
return plane
def substruct():
class fougrid:
pass
grid = fougrid()
grid.kxmax = 2.00 #maximum value k_x
grid.kymax = 2.00 #maximum value k_y
grid.sigma_k = (1./20.)*grid.kxmax #width of gaussian
grid.dimkx = 1024
grid.dimky= 1024
fplane = fourierplane(grid) #creating the Fourier grid
implane = n.fft.ifftshift(n.fft.ifft2(fplane)) #inverse Fourier transformation of the grid to get final image
##################################################################
#seperating real and imaginary part of the Fourier transformed grid
##################################################################
realimplane = implane.real
imagimplane = implane.imag
#taking the absolute value:
absimplane = n.zeros(n.shape(implane))
for a in range(n.shape(implane)[0]):
for b in range(n.shape(implane)[1]):
absimplane[a][b] = m.sqrt(implane[a][b].real**2 + implane[a][b].imag**2)
#saving images to files:
pyfits.writeto('randomfield.fits',realimplane) #real part of the image grid
pyfits.writeto('fplane.fits',fplane) #grid in fourier space
pyfits.writeto('imranfield.fits',imagimplane) #imaginary part of the image grid
pyfits.writeto('absranfield.fits',absimplane) #real part of the image grid
substruct() #running the script
사람이 패턴이 생성되고 어떻게이 문제를 해결하는 방법에 대해 어떤 생각을 가지고 있습니까?
해결되었습니다. ifft2 fplane이 수행되기 전에 코드의 는 fplane 정도로뿐만 시프트해야 : implane = n.fft.ifftshift (n.fft.ifft2 (n.fft.fftshift (fplane))) – Mizuti