source: trunk/SRC/ToBeReviewed/STATISTICS/a_correlate2d.pro @ 262

Last change on this file since 262 was 262, checked in by pinsard, 17 years ago

corrections of some headers and parameters and keywords case. change of pro2href to replace proidl

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1;+
2;
3; @file_comments
4;
5;
6; @categories
7; Statistics
8;
9; @param X {in}{required}
10; An 2 dimension Array [nx,ny]
11;
12; @param LAG {in}{required}
13; 2-element vector, in the intervals [-(nx-2), (nx-2)],[-(ny-2), (ny-2)],
14; of type integer that specifies the absolute distance(s) between
15; indexed elements of X.
16;
17; @keyword ZERO2NAN
18;
19; @keyword DOUBLE
20; If set to a non-zero value, computations are done in double precision arithmetic.
21;
22; @history
23; 28/2/2000 Sebastien Masson (smasson\@lodyc.jussieu.fr)
24; Based on the A_CORRELATE procedure of IDL
25;
26; @version
27; $Id$
28;
29;-
30;
31FUNCTION auto_cov2d, x, lag, DOUBLE = double, ZERO2NAN = zero2nan
32;
33  compile_opt idl2, strictarrsubs
34;
35   XDim = SIZE(X, /dimensions)
36   nx = XDim[0]
37   ny = XDim[1]
38;Sample autocovariance function
39   Xmean = TOTAL(X, Double = Double) / (1.*nx*ny)
40;
41   res = TOTAL( (X[0:nx-1-lag[0], 0:ny-1-lag[1]] - Xmean) * $
42                (X[lag[0]:nx-1, lag[1]:ny-1] - Xmean) $
43                , Double = Double )
44   if keyword_set(zero2nan) AND res EQ 0 then res = !values.f_nan
45   RETURN, res
46
47END
48;+
49;
50; @file_comments
51; This function computes the autocorrelation Px(K,L) or
52; autocovariance Rx(K,L) of a sample population X[nx,ny] as a
53; function of the lag (K,L).
54;
55; @categories
56; Statistics
57;
58; @param X {in}{required}
59; An 2 dimension Array [nx,ny]
60;
61; @param LAG {in}{required}
62; 2-element vector, in the intervals [-(nx-2), (nx-2)],[-(ny-2), (ny-2)],
63; of type integer that specifies the absolute distance(s) between
64; indexed elements of X.
65;
66; @keyword COVARIANCE
67; If set to a non-zero value, the sample autocovariance is computed.
68;
69; @keyword DOUBLE
70; If set to a non-zero value, computations are done in double precision arithmetic.
71;
72; @history
73; 28/2/2000 Sebastien Masson (smasson\@lodyc.jussieu.fr)
74; Based on the A_CORRELATE procedure of IDL
75;
76; @version
77; $Id$
78;
79;-
80;
81FUNCTION a_correlate2d, x, lag, COVARIANCE = covariance, DOUBLE = double
82;
83  compile_opt idl2, strictarrsubs
84;
85
86;Compute the sample-autocorrelation or autocovariance of (Xt, Xt+l)
87;as a function of the lag (l).
88
89   ON_ERROR, 2
90
91   XDim = SIZE(X, /dimensions)
92   XNDim = SIZE(X, /n_dimensions)
93   nx = XDim[0]
94   ny = XDim[1]
95   if XNDim NE 2 then $
96    ras = report("X array must contain 2 dimensions.")
97;Check length.
98   if nx lt 2 then $
99    ras = report("first dimension of X array must contain 2 or more elements.")
100   if ny lt 2 then $
101    ras = report("second dimension of X array must contain 2 or more elements.")
102   if n_elements(Lag) NE 2 THEN $
103    ras = report("Lag array must contain 2 elements.")
104   
105;If the DOUBLE keyword is not set then the internal precision and
106;result are identical to the type of input.
107   if N_ELEMENTS(Double) eq 0 then $
108    Double = (SIZE(X, /type) eq 5)
109
110   if KEYWORD_SET(Covariance) eq 0 then begin ;Compute Autocorrelation.
111      Auto = Auto_Cov2d(X, ABS(Lag), Double = Double) / $
112          Auto_Cov2d(X, [0L, 0L], Double = Double, /zero2nan)
113   endif else begin             ;Compute Autocovariance.
114      Auto = Auto_Cov2d(X, ABS(Lag), Double = Double) / n_elements(X)
115   endelse
116
117   if Double eq 0 then RETURN, FLOAT(Auto) else $
118    RETURN, Auto
119
120END
Note: See TracBrowser for help on using the repository browser.