GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71785
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
c_kurt.c
Go to the documentation of this file.
1 #include <grass/gis.h>
2 #include <grass/raster.h>
3 
4 void c_kurt(DCELL * result, DCELL * values, int n, const void *closure)
5 {
6  DCELL sum, ave, sumsq, sumqt, var;
7  int count;
8  int i;
9 
10  sum = 0.0;
11  count = 0;
12 
13  for (i = 0; i < n; i++) {
14  if (Rast_is_d_null_value(&values[i]))
15  continue;
16 
17  sum += values[i];
18  count++;
19  }
20 
21  if (count == 0) {
22  Rast_set_d_null_value(result, 1);
23  return;
24  }
25 
26  ave = sum / count;
27 
28  sumsq = 0;
29 
30  for (i = 0; i < n; i++) {
31  DCELL d;
32 
33  if (Rast_is_d_null_value(&values[i]))
34  continue;
35 
36  d = values[i] - ave;
37  sumsq += d * d;
38  sumqt += d * d * d * d;
39  }
40 
41  var = sumsq / count;
42 
43  *result = sumqt / (count * var * var) - 3;
44 }
45 
46 void w_kurt(DCELL * result, DCELL(*values)[2], int n, const void *closure)
47 {
48  DCELL sum, ave, sumsq, sumqt, var;
49  int count;
50  int i;
51 
52  sum = 0.0;
53  count = 0;
54 
55  for (i = 0; i < n; i++) {
56  if (Rast_is_d_null_value(&values[i][0]))
57  continue;
58 
59  sum += values[i][0] * values[i][1];
60  count += values[i][1];
61  }
62 
63  if (count == 0) {
64  Rast_set_d_null_value(result, 1);
65  return;
66  }
67 
68  ave = sum / count;
69 
70  sumsq = 0;
71 
72  for (i = 0; i < n; i++) {
73  DCELL d;
74 
75  if (Rast_is_d_null_value(&values[i][0]))
76  continue;
77 
78  d = values[i][0] - ave;
79  sumsq += d * d * values[i][1];
80  sumqt += d * d * d * values[i][1];
81  }
82 
83  var = sumsq / count;
84 
85  *result = sumqt / (count * var * var) - 3;
86 }
double DCELL
Definition: gis.h:581
int count
void Rast_set_d_null_value(DCELL *dcellVals, int numVals)
To set a number of DCELL raster values to NULL.
Definition: null_val.c:155
void w_kurt(DCELL *result, DCELL(*values)[2], int n, const void *closure)
Definition: c_kurt.c:46
float var(IClass_statistics *statistics, int band1, int band2)
Helper function for computing variance.
void c_kurt(DCELL *result, DCELL *values, int n, const void *closure)
Definition: c_kurt.c:4
int Rast_is_d_null_value(const DCELL *dcellVal)
To check if a DCELL raster value is set to NULL.
Definition: null_val.c:261