# Rif: Re: horizontal two-point correlations

Date: Sat, 26 Sep 2009 16:09:31 +0200

Hi Dennis,
In the meanwhile, I have found a way to do that without the need to call external fortran routines.

Basically, I do a forward 2D Fourier transform of the 2D field w, square the result and backward transform. In this way I obtain the 2D autocorrelation function, which is symmetric both in i and j. I consider only the (1:nj/2,1:ni/2) quadrant, also ignoring the first row and column since the maximum is the element (1,1). Then I normalize the function, dividing it by its (1,1) element, to obtain the 2D autocorrelation coefficient ro_2d. At this point, I average all the elements of ro_2d characterized by the same delta=(i^2.+j^2.)^.5 and found the 1D autocorrelation coefficient ro(delta) at all angles.

I hope that this could be useful for other ncl users. It would be a good idea to include a specific function for this in the future release of ncl. This is the portion of the code I wrote:

w_fftf2=(fft2df(w))^2.

f_corr_2d =fft2db(w_fftf2)

dim_tot=dimsizes(f_corr_2d)
njt=dim_tot(0)
nit=dim_tot(1)

f_corr_2d=f_corr_2d/f_corr_2d(1,1)

ro_2d=f_corr_2d(1:floattoint((njt-1)/2.),1:floattoint((nit-1)/2.))

dim=dimsizes(ro_2d)
nj=dimcorr2(0)
ni=dimcorr2(1)

dx=50.
dy=50.
ro=new(floattoint((ni^2.+nj^2.)^.5),float)
delta=fspan(0,((ni*dx)^2.+(nj*dy)^2.)^.5,floattoint((ni^2.+nj^2.)^.5))
n_del=new(floattoint((ni^2.+nj^2.)^.5),integer)

n_del=0
ro=0.
do j=0,nj-1
do i=0,ni-1
del=floattoint((i^2.+j^2.)^.5)
ro(del)=ro(del)+ro_2d(j,i)
n_del(del)=n_del(del)+1
end do
end do
ro=ro/n_del

Franco

____________________________________________________
Eng. Franco Catalano
Ph.D. Student

D.I.T.S.
Department of Hydraulics, Transportation and Roads.
Via Eudossiana 18, 00184 Rome
Sapienza University of Rome.
tel: +390644585218

Dennis Shea <shea@ucar.edu>
25/09/2009 16:23 CST

Per   Franco Catalano <franco.catalano@uniroma1.it>
CC
CCR
Oggetto  Re: [ncl-talk] horizontal two-point correlations

---------
There are some two-point fortran programs at

http://th.nao.ac.jp/~hamanatk/OPENPRO/index.html

Franco Catalano wrote:
> Hi Dennis,
>
> I have a two-dimensional dataset z(y,x).
> I need the one-dimensional autocorrelation function f(delta), where
> f(0)=1 and delta is the increasing monotonic vector containing the
> distancies between all (y,x) in the domain.
> In your example, ra(y, delta_x) and rb(x, delta_y) are the
> autocorrelation functions obtained considering, respectively x and y
> directions alone, right?
> Thank you for your help.
>
> Franco
>
>
> Il giorno gio, 24/09/2009 alle 07.46 -0600, Dennis Shea ha scritto:
>> Buongiorno
>>
>> Perhaps I am misunderstanding the question?
>>
>>      z(t,x)    where t and x are 'named' dimensions of size nt, nx
>>
>>
>>      mxlag = 3
>>      ra    = esacr(z, mxlag)           ===> ra(nt,mxlag)
>>      rb    = esacr(z(x|:,t|:), mxlag) ; ===> rb(nx,mxlag)
>>
>> The latter uses NCL's dimension reordering
>>
>> http://www.ncl.ucar.edu/Document/Language/reorder.shtml
>>
>> More details are at:
>> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/index.shtml
>> Click on "Variables"
>> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml#NamedSubscripting
>>
>>
>>
>>
>> Franco Catalano wrote:
>>> Dear ncl developers and users,
>>> Is there a ncl function to compute the autocorrelation coefficient for a
>>> two-dimensional (x,y) dataset which considers separations delta at all
>>> angles?
>>> The function esacr considers only the rightmost dimension.
>>> Thank you for any suggestions.
>>>
>>> Franco
>>>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Sep 26 2009 - 08:09:31 MDT

This archive was generated by hypermail 2.2.0 : Sun Sep 27 2009 - 11:32:26 MDT