source: trunk/procs/saxo_mods/skewness_4d.pro @ 27

Last change on this file since 27 was 2, checked in by post_it, 17 years ago

Initial import from ~/POST_IT/

File size: 3.5 KB
Line 
1;+
2;
3; @file_comments
4;
5;
6; @categories
7; Statistics
8;
9; @param X {in}{required}{type=array}
10; An Array which last dimension is the time dimension so
11; size n.
12;
13;
14; @param NT
15;
16;
17; @keyword DOUBLE
18; If set to a non-zero value, computations are done in
19; double precision arithmetic.
20;
21; @examples
22;
23;
24; @history
25;
26;
27; @version
28; $Id: skewness_4d.pro 232 2007-03-20 16:59:36Z pinsard $
29;
30;-
31FUNCTION Skewness_Num, X, nT, Double = Double,  NAN =  nan
32; Compute the numerator of the skewness expression
33;
34
35  compile_opt idl2, strictarrsubs
36
37  TimeDim = size(X, /n_dimensions)
38  Xmean = NAN ? TOTAL(X, TimeDim, Double = Double,  NAN =  nan) / TOTAL(FINITE(X), TimeDim) : $
39   TOTAL(X, TimeDim, Double = Double) / nT   
40  one = double ? 1.0d : 1.0
41  Xmean = Xmean[*]#replicate(one, nT)
42  res = TOTAL( (X-Xmean)^3, TimeDim, Double = Double, NAN =  nan)
43
44  RETURN, res
45 
46END
47;+
48; @file_comments
49; Same function as SKEWNESS but accept array (until 4
50; dimension) for input and perform  the skewness
51; along the time dimension which must be the last
52; one of the input array.
53;
54; @categories
55; Statistics
56;
57; @param X {in}{required}{type=array}
58; An Array which last dimension is the time dimension so
59; size n.
60;
61; @keyword DOUBLE
62; If set to a non-zero value, computations are done in
63; double precision arithmetic.
64;
65; @examples
66;
67; @history
68; 24/2/2000 Sebastien Masson (smasson\@lodyc.jussieu.fr)
69;
70; Based on the  a_timecorrelate procedure of IDL
71; INTRODUCTION TO STATISTICAL TIME SERIES
72; Wayne A. Fuller
73; ISBN 0-471-28715-6
74;
75; @version
76; $Id: skewness_4d.pro 232 2007-03-20 16:59:36Z pinsard $
77;
78;-
79
80FUNCTION skewness_4d, X, DOUBLE = Double,  NVAL =  nval
81;
82   compile_opt idl2, strictarrsubs
83;
84; Compute the skewness from 1d to 4d vectors
85@common
86
87   ON_ERROR, 2
88   
89   XDim = SIZE(X, /dimensions)
90   XNDim = SIZE(X, /n_dimensions)
91   nT = XDim[XNDim-1]
92   
93; Keyword NAN activated if needed
94; Keyword NVAL not compulsory.
95
96   NAN = ( (WHERE(FINITE(X) EQ 0 ))[0] NE -1 ) ? 1 : 0
97;We can retrieve the matrix of real lenghts of time-series   
98   nTreal = ( (WHERE(FINITE(X) EQ 0 ))[0] NE -1 ) ?  TOTAL(FINITE(X),  XNDim) : nT
99
100   IF ARG_PRESENT(NVAL) THEN nval = nTreal
101
102; Check length.
103   IF (WHERE(nTreal LE 1))[0] NE -1 THEN $
104    MESSAGE,  "Matrix of length of time-series must contain 2 or more elements"   
105     
106; If the DOUBLE keyword is not set then the internal precision and
107; result are identical to the type of input.
108   type = SIZE(X, /TYPE)
109   useDouble = (N_ELEMENTS(Double) eq 1) ? KEYWORD_SET(Double) : $
110    (type eq 5)
111   
112; Type of outputs according to the type of data input
113   case XNDim of
114      1: Skew = useDouble ? DBLARR(1) : FLTARR(1)
115      2: Skew = useDouble ? DBLARR(XDim[0]) : FLTARR(XDim[0])
116      3: Skew = useDouble ? DBLARR(XDim[0], XDim[1]) : FLTARR(XDim[0], XDim[1])
117      4: Skew = useDouble ? DBLARR(XDim[0], XDim[1], XDim[2]) : FLTARR(XDim[0], XDim[1], XDim[2])
118   endcase
119; Compute standard deviation
120; nTreal might be a matrix
121   std = a_timecorrelate(X, 0, /covariance)
122   std = sqrt(std)
123   zero = where(std EQ 0)
124
125   if zero[0] NE -1 then STOP,  $
126    'Cannot compute skewness since there are zeros in the matrix of standard deviations !'
127
128; Problem with high masked values (x^3 makes NaN when x is high)
129; Threshold put on the values of the tab
130   idx_std = WHERE (std GT 1.0e+10)
131   X = X < 1.0e+10
132   std = std < 1.0e+10
133
134; Compute skewness
135   Skew = Skewness_Num(X, nT, Double = useDouble, NAN = nan) / (nTreal*std^3)
136   IF idx_std[0] NE -1 THEN Skew[idx_std] = valmask
137   
138   return, useDouble ? Skew : FLOAT(Skew)
139   
140END
141
Note: See TracBrowser for help on using the repository browser.