GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
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 UNUSED)
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,
48  const void *closure UNUSED)
49 {
50  DCELL sum, ave, sumsq, sumqt, var;
51  DCELL count;
52  int i;
53 
54  sum = 0.0;
55  count = 0;
56 
57  for (i = 0; i < n; i++) {
58  if (Rast_is_d_null_value(&values[i][0]))
59  continue;
60 
61  sum += values[i][0] * values[i][1];
62  count += values[i][1];
63  }
64 
65  if (count == 0) {
66  Rast_set_d_null_value(result, 1);
67  return;
68  }
69 
70  ave = sum / count;
71 
72  sumsq = 0;
73  sumqt = 0;
74 
75  for (i = 0; i < n; i++) {
76  DCELL d;
77 
78  if (Rast_is_d_null_value(&values[i][0]))
79  continue;
80 
81  d = values[i][0] - ave;
82  sumsq += d * d * values[i][1];
83  sumqt += d * d * d * values[i][1];
84  }
85 
86  var = sumsq / count;
87 
88  *result = sumqt / (count * var * var) - 3;
89 }
void w_kurt(DCELL *result, DCELL(*values)[2], int n, const void *closure UNUSED)
Definition: c_kurt.c:47
void c_kurt(DCELL *result, DCELL *values, int n, const void *closure UNUSED)
Definition: c_kurt.c:4
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
Definition: null_val.c:153
#define Rast_is_d_null_value(dcellVal)
Definition: defs/raster.h:408
double DCELL
Definition: gis.h:629
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition: gis.h:47
float var(IClass_statistics *statistics, int band1, int band2)
Helper function for computing variance.
int count