I am trying to create a Gaussian random field by creating a mesh in Fourier space and then the inverse Fourier, iterating over it to get a random field. For this, the inverse Fourier transform image must be real. It seems that I get the residuals in the imaginary part of the grid of the order of 10 ^ -18 - -22, so I expected that these would be numerical errors in the FFT. The real part of the image displays a strange checkerboard pattern in pixels, although the pixels go from positive to negative. To check if the FFT is functioning properly, I tried to convert the Gaussian language, which should return another Gaussian, and again the image of the chessboard is present in the image. When you take the absolute value of the image, it looks great, but I also needso that it takes into account negative values for my Gaussian random field.
To Fourier transform the Gaussian, I use the following code:
import numpy as n
import math as m
import pyfits
def fourierplane(a):
deltakx = 2*a.kxmax/a.dimkx
deltaky = 2*a.kymax/a.dimky
plane = n.zeros([a.dimkx,a.dimky])
for y in range(n.shape(plane)[0]):
for x in range(n.shape(plane)[1]):
i1 = x - a.dimkx/2
j1 = y - a.dimky/2
kx = deltakx*i1
ky = deltaky*j1
k = m.sqrt(kx**2 + ky**2)
plane[y][x] = m.e**(-(k**2)/(2*a.sigma_k**2))
return plane
def substruct():
class fougrid:
pass
grid = fougrid()
grid.kxmax = 2.00
grid.kymax = 2.00
grid.sigma_k = (1./20.)*grid.kxmax
grid.dimkx = 1024
grid.dimky= 1024
fplane = fourierplane(grid)
implane = n.fft.ifftshift(n.fft.ifft2(fplane))
realimplane = implane.real
imagimplane = implane.imag
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)
pyfits.writeto('randomfield.fits',realimplane)
pyfits.writeto('fplane.fits',fplane)
pyfits.writeto('imranfield.fits',imagimplane)
pyfits.writeto('absranfield.fits',absimplane)
substruct()
Does anyone know how to create this template and how to solve this problem?
source
share