<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal>Hi NCL users,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>fftData = np.fft.fft2(F_x, axes=(-2, -1), norm='forward')<o:p></o:p></p><p class=MsoNormal>real_fft_tmp = np.real(fftData)<o:p></o:p></p><p class=MsoNormal>imag_fft_tmp = np.imag(fftData)<o:p></o:p></p><p class=MsoNormal>real_fft = 2*np.roll(np.flipud(real_fft_tmp), shift=1, axis=0)<o:p></o:p></p><p class=MsoNormal>imag_fft = 2*np.roll(np.flipud(imag_fft_tmp), shift=1, axis=0)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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.<o:p></o:p></p><p class=MsoNormal>Jon<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>