GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
c_skew.c
Go to the documentation of this file.
1 #include <math.h>
2 
3 #include <grass/gis.h>
4 #include <grass/raster.h>
5 
6 void c_skew(DCELL * result, DCELL * values, int n, const void *closure)
7 {
8  DCELL sum, ave, sumsq, sumcb, sdev;
9  int count;
10  int i;
11 
12  sum = 0.0;
13  count = 0;
14 
15  for (i = 0; i < n; i++) {
16  if (Rast_is_d_null_value(&values[i]))
17  continue;
18 
19  sum += values[i];
20  count++;
21  }
22 
23  if (count == 0) {
24  Rast_set_d_null_value(result, 1);
25  return;
26  }
27 
28  ave = sum / count;
29 
30  sumsq = 0;
31  sumcb = 0;
32 
33  for (i = 0; i < n; i++) {
34  DCELL d;
35 
36  if (Rast_is_d_null_value(&values[i]))
37  continue;
38 
39  d = values[i] - ave;
40  sumsq += d * d;
41  sumcb += d * d * d;
42  }
43 
44  sdev = sqrt(sumsq / count);
45 
46  *result = sumcb / (count * sdev * sdev * sdev);
47 }
48 
49 void w_skew(DCELL * result, DCELL(*values)[2], int n, const void *closure)
50 {
51  DCELL sum, ave, sumsq, sumcb, sdev;
52  DCELL count;
53  int i;
54 
55  sum = 0.0;
56  count = 0;
57 
58  for (i = 0; i < n; i++) {
59  if (Rast_is_d_null_value(&values[i][0]))
60  continue;
61 
62  sum += values[i][0] * values[i][1];
63  count += values[i][1];
64  }
65 
66  if (count == 0) {
67  Rast_set_d_null_value(result, 1);
68  return;
69  }
70 
71  ave = sum / count;
72 
73  sumsq = 0;
74  sumcb = 0;
75 
76  for (i = 0; i < n; i++) {
77  DCELL d;
78 
79  if (Rast_is_d_null_value(&values[i][0]))
80  continue;
81 
82  d = values[i][0] - ave;
83  sumsq += d * d * values[i][1];
84  sumcb += d * d * d * values[i][1];
85  }
86 
87  sdev = sqrt(sumsq / count);
88 
89  *result = sumcb / (count * sdev * sdev * sdev);
90 }
void w_skew(DCELL *result, DCELL(*values)[2], int n, const void *closure)
Definition: c_skew.c:49
#define Rast_is_d_null_value(dcellVal)
Definition: defs/raster.h:420
double DCELL
Definition: gis.h:603
int count
void c_skew(DCELL *result, DCELL *values, int n, const void *closure)
Definition: c_skew.c:6
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
Definition: null_val.c:155