<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 &quot;pretty limited&quot; documentation ... :-(<br>Partly, it is &quot;pretty limited&quot; because I don&#39;t use &#39;fft2d&#39;. <br>-------------------------------------------------------------------<br><br>&quot;I believe that fft2df is returning the real and imaginary part of the Fourier transform&quot;<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&#39;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   &lt;=== 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     &lt;===<br></li><li><a href="https://www2.cisl.ucar.edu/resources/legacy/fft5/documentation#rfft2f.html">RFFT2F</a> 2D real forward         &lt;===<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&#39;s  C-Fortran interface.]<br><br>/*<br> * Call the Fortran routines.<br> */<br>  ier = 0;<br>  NGCALLF(drfft2i,DRFFT2I)(&amp;il, &amp;im, wsave, &amp;ilwsave, &amp;ier);<br>  NGCALLF(drfft2f,DRFFT2F)(&amp;ildim, &amp;il, &amp;im, tmp_r, wsave, &amp;ilwsave, work, &amp;ilwork,<br>                             &amp;ier);<br>  if(ier) {<br>    NhlPError(NhlFATAL,NhlEUNKNOWN,&quot;fft2df: ier = %d&quot;, 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 &lt; m; i++ ) {<br>      for(j = 0; j &lt; 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 &lt; m; i++ ) {<br>      for(j = 0; j &lt; 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 &#39;somehere&#39;. Sorry, I don&#39;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">&lt;<a href="mailto:guidocioni@gmail.com" target="_blank">guidocioni@gmail.com</a>&gt;</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&#39;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&#39;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&#39;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&#39;ve been trying to use the fft2df function, but the documentation is pretty limited, so that&#39;s why I&#39;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&#39;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&#39;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>