<div dir="ltr"><div><div><div>Buongiorno Guido,<br><br>I think what you are doing is correct. <br> <br></div><div>Unfortunately, I think I wrote the "pretty limited" documentation ... :-(<br>Partly, it is "pretty limited" because I don't use 'fft2d'. <br>-------------------------------------------------------------------<br><br>"I believe that fft2df is returning the real and imaginary part of the Fourier transform"<br><br></div>Yes.<br><br>---<br><br>I believe NCL is using:<br> <a href="https://www2.cisl.ucar.edu/resources/legacy/fft5">https://www2.cisl.ucar.edu/resources/legacy/fft5</a><br></div> <a href="https://www2.cisl.ucar.edu/resources/legacy/fft5/documentation">https://www2.cisl.ucar.edu/resources/legacy/fft5/documentation</a><br><br></div>NCL's fft2{f/b} are interfaces to<br><div><ul><li><a href="https://www2.cisl.ucar.edu/resources/legacy/fft5/documentation#rfft2i.html">RFFT2I</a> 2D real initialization <=== users do not see this. The interface call this<br></li><li><a href="https://www2.cisl.ucar.edu/resources/legacy/fft5/documentation#rfft2b.html">RFFT2B</a> 2D real backward <===<br></li><li><a href="https://www2.cisl.ucar.edu/resources/legacy/fft5/documentation#rfft2f.html">RFFT2F</a> 2D real forward <===<br></li></ul>------<br><div><div>The following interface software clearly shows that it is doing nothing more than calling the fortran subroutines and explicitly extracting the real and imaginary coefficients. (This latter step is necessary because NCL does not support complex variables.)<br><br>-----<br></div><div>[SNIP from NCL's C-Fortran interface.]<br><br>/*<br> * Call the Fortran routines.<br> */<br> ier = 0;<br> NGCALLF(drfft2i,DRFFT2I)(&il, &im, wsave, &ilwsave, &ier);<br> NGCALLF(drfft2f,DRFFT2F)(&ildim, &il, &im, tmp_r, wsave, &ilwsave, work, &ilwork,<br> &ier);<br> if(ier) {<br> NhlPError(NhlFATAL,NhlEUNKNOWN,"fft2df: ier = %d", ier);<br> return(NhlFATAL);<br> }<br>/*<br> * Copy tmp_r back to the appropriate locations in coef.<br> */<br> if(type_coef == NCL_float) {<br> for(i = 0; i < m; i++ ) {<br> for(j = 0; j < l21; j++ ) {<br> ic0 = i*l21 + j;<br> ic1 = ml21 + ic0;<br> ir0 = i*ldim + 2*j;<br> ir1 = ir0 + 1;<br> ((float*)coef)[ic0] = (float)tmp_r[ir0];<br> ((float*)coef)[ic1] = (float)tmp_r[ir1];<br> }<br> }<br> }<br> else {<br> for(i = 0; i < m; i++ ) {<br> for(j = 0; j < l21; j++ ) {<br> ic0 = i*l21 + j;<br> ic1 = ml21 + ic0;<br> ir0 = i*ldim + 2*j;<br> ir1 = ir0 + 1;<br> ((double*)coef)[ic0] = tmp_r[ir0];<br> ((double*)coef)[ic1] = tmp_r[ir1];<br> }<br> }<br> }<br><br></div><div>[SNIP]<br></div><div>+++++++++++++++++++++++<br>+++++++++++++++++++++++<br><br>A pic I got from 'somehere'. Sorry, I don't know the source.<br><br><a href="http://www.cgd.ucar.edu/~shea/fft2d_image_ncl">http://www.cgd.ucar.edu/~shea/fft2d_image_ncl</a><br><br></div><div>Hope all this verbal meandering is useful!<br><br></div><div>Cheers<br></div><div>D<br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 8, 2017 at 8:24 AM, Guido Cioni <span dir="ltr"><<a href="mailto:guidocioni@gmail.com" target="_blank">guidocioni@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi all,<div>I'm trying to perform a spectral analysis of surface fluxes (mainly sensible heat) in order to identify spatial scales of surface heterogeneity [Baidya Roy et al., 2003]. In order to test the method I'm first using idealized simulations where the heterogeneity is prescribed with one dry and one wet patch aligned in the x-dimension with very different fluxes. What I'd expect to find in this case is a peak at the scale of ~100km, which is the size of the patch. </div><div><br></div><div>I've been trying to use the fft2df function, but the documentation is pretty limited, so that's why I'm asking here. The idea is to go from sensible heat flux, shfl_s(time, lat, lon), to the Fourier transform F(lhfl_s)(time, k_lat, k_lon) and then somehow collapse the 2-D DFT into a one-dimensional by averaging. Since the idealized domain is limited but with periodic boundary conditions I don't think that tapering would be necessary. </div><div><br></div><div>So I first apply </div><div><br></div><div><div><font face="Menlo"> coef:=fft2df(shfl_s(:,:))</font></div><div><div><font face="Menlo"> coefmod:=sqrt(coef(0,:,:)^2+<wbr>coef(1,:,:)^2)</font></div></div><div><div><font face="Menlo"> spectrum=dim_avg_n_Wrap(<wbr>coefmod, 0)</font></div></div><div><br></div><div>I believe that fft2df is returning the real and imaginary part of the Fourier transform, so that I have to compute the absolute value and then an average to get rid of the y-coordinate, which is useless given the heterogeneity gradient in my case is everywhere parallel to the x-axis. Is the procedure correct?</div><div>I get a spectrum which is something like that (don't mind the x-axis...), but I would have expected something different...</div><div><br></div><div><img id="m_-72677858179554841468E67ECF6-3AD4-41D5-88F6-FC5A49E2FC06" src="cid:4C3AB0B5-477B-46B6-9E51-42DCFEFA9E7E@mpimet.mpg.de" height="770" width="779"></div><span class="HOEnZb"><font color="#888888"><div><br></div><div>
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br class="m_-7267785817955484146Apple-interchange-newline">Guido Cioni</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="http://guidocioni.altervista" target="_blank">http://guidocioni.altervista</a>.<wbr>org</div>
</div>
<br></font></span></div></div><br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>