GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r73122
 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  sumqt = 0;
30 
31  for (i = 0; i < n; i++) {
32  DCELL d;
33 
34  if (Rast_is_d_null_value(&values[i]))
35  continue;
36 
37  d = values[i] - ave;
38  sumsq += d * d;
39  sumqt += d * d * d * d;
40  }
41 
42  var = sumsq / count;
43 
44  *result = sumqt / (count * var * var) - 3;
45 }
46 
47 void w_kurt(DCELL * result, DCELL(*values)[2], int n, const void *closure)
48 {
49  DCELL sum, ave, sumsq, sumqt, var;
50  DCELL count;
51  int i;
52 
53  sum = 0.0;
54  count = 0;
55 
56  for (i = 0; i < n; i++) {
57  if (Rast_is_d_null_value(&values[i][0]))
58  continue;
59 
60  sum += values[i][0] * values[i][1];
61  count += values[i][1];
62  }
63 
64  if (count == 0) {
65  Rast_set_d_null_value(result, 1);
66  return;
67  }
68 
69  ave = sum / count;
70 
71  sumsq = 0;
72  sumqt = 0;
73 
74  for (i = 0; i < n; i++) {
75  DCELL d;
76 
77  if (Rast_is_d_null_value(&values[i][0]))
78  continue;
79 
80  d = values[i][0] - ave;
81  sumsq += d * d * values[i][1];
82  sumqt += d * d * d * values[i][1];
83  }
84 
85  var = sumsq / count;
86 
87  *result = sumqt / (count * var * var) - 3;
88 }
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:47
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