[ncl-talk] NCL fft2df/fft2db conversion to Python

Christophersen, Dr. Jonathan, Contractor, Code 7532 jonathan.christophersen.ctr at nrlmry.navy.mil
Wed Feb 8 13:36:08 MST 2023


Hi NCL users,

 

Apologies if this is more of a Pythonic question than NCL, but I'm in need
of some help with converting NCL's fft2df/fft2db over to Python NumPy's (or
SciPy's) fft2/ifft2. I've gotten pretty close to a workable solution, but
there are still some conversion problems.

 

The Python (pseudo-)code that I've been able to reproduce NCL's fft2df
function with breaks the result of the 2D-FFT into components, but this is
just for investigative convenience for now :-). Code is as follows:

 

fftData = np.fft.fft2(F_x, axes=(-2, -1), norm='forward')

real_fft_tmp = np.real(fftData)

imag_fft_tmp = np.imag(fftData)

real_fft = 2*np.roll(np.flipud(real_fft_tmp), shift=1, axis=0)

imag_fft = 2*np.roll(np.flipud(imag_fft_tmp), shift=1, axis=0)

 

And if I'm only considering the data up to the Nyquist frequency (NCL's
fft2df only returns half the spectrum) then I get a pretty close match in
spectral space for both real and imaginary components. However, the
differences that are present (error within 10^-5) seem to throw off the
inverse FFT2 and I end up with large errors. Is anybody working on a 2D-FFT
conversion from NCL to Python that might be able to answer this or shed some
light on what I might be doing wrong?

 

Thanks so much for any help, and I'm happy to answer whatever questions
there might be. I'm not permitted to share my actual source code, so
apologies for any inconvenience.

Jon

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20230208/34fad143/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5477 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20230208/34fad143/attachment.p7s>


More information about the ncl-talk mailing list