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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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