PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_band_stats()

static void test_band_stats ( )
static

Definition at line 27 of file cu_band_stats.c.

References ovdump::band, genraster::count, cu_add_band(), cu_free_raster(), rt_bandstats_t::max, rt_bandstats_t::min, PT_32BUI, PT_64BF, PT_8BUI, quantile_llist_destroy(), rtrowdump::raster, rt_band_get_histogram(), rt_band_get_nodata(), rt_band_get_quantiles(), rt_band_get_quantiles_stream(), rt_band_get_summary_stats(), rt_band_set_nodata(), rt_band_set_pixel(), rt_raster_new(), rtdealloc(), genraster::value, rt_bandstats_t::values, pixval::x, and pixval::y.

Referenced by band_stats_suite_setup().

27  {
28  rt_bandstats stats = NULL;
29  rt_histogram histogram = NULL;
30  double bin_width[] = {100};
31  double quantiles[] = {0.1, 0.3, 0.5, 0.7, 0.9};
32  double quantiles2[] = {0.66666667};
33  rt_quantile quantile = NULL;
34  uint32_t count = 0;
35 
37  rt_band band;
38  uint32_t x;
39  uint32_t xmax = 100;
40  uint32_t y;
41  uint32_t ymax = 100;
42  uint32_t max_run;
43  double nodata;
44 
45  uint32_t values[] = {0, 91, 55, 86, 76, 41, 36, 97, 25, 63, 68, 2, 78, 15, 82, 47};
46  struct quantile_llist *qlls = NULL;
47  uint32_t qlls_count;
48 
49  raster = rt_raster_new(xmax, ymax);
50  CU_ASSERT(raster != NULL);
51  band = cu_add_band(raster, PT_32BUI, 1, 0);
52  CU_ASSERT(band != NULL);
53 
54  for (x = 0; x < xmax; x++) {
55  for (y = 0; y < ymax; y++) {
56  rt_band_set_pixel(band, x, y, x + y, NULL);
57  }
58  }
59 
60  rt_band_get_nodata(band, &nodata);
61  CU_ASSERT_DOUBLE_EQUAL(nodata, 0, DBL_EPSILON);
62 
63  stats = (rt_bandstats) rt_band_get_summary_stats(band, 1, 0, 1, NULL, NULL, NULL);
64  CU_ASSERT(stats != NULL);
65  CU_ASSERT_DOUBLE_EQUAL(stats->min, 1, DBL_EPSILON);
66  CU_ASSERT_DOUBLE_EQUAL(stats->max, 198, DBL_EPSILON);
67 
68  quantile = (rt_quantile) rt_band_get_quantiles(stats, NULL, 0, &count);
69  CU_ASSERT(quantile != NULL);
70  rtdealloc(quantile);
71 
72  histogram = (rt_histogram) rt_band_get_histogram(stats, 0, NULL, 0, 0, 0, 0, &count);
73  CU_ASSERT(histogram != NULL);
74  rtdealloc(histogram);
75 
76  histogram = (rt_histogram) rt_band_get_histogram(stats, 0, NULL, 0, 1, 0, 0, &count);
77  CU_ASSERT(histogram != NULL);
78  rtdealloc(histogram);
79 
80  histogram = (rt_histogram) rt_band_get_histogram(stats, 0, bin_width, 1, 0, 0, 0, &count);
81  CU_ASSERT(histogram != NULL);
82  rtdealloc(histogram);
83 
84  rtdealloc(stats->values);
85  rtdealloc(stats);
86 
87  stats = (rt_bandstats) rt_band_get_summary_stats(band, 1, 0.1, 1, NULL, NULL, NULL);
88  CU_ASSERT(stats != NULL);
89 
90  quantile = (rt_quantile) rt_band_get_quantiles(stats, NULL, 0, &count);
91  CU_ASSERT(quantile != NULL);
92  rtdealloc(quantile);
93 
94  quantile = (rt_quantile) rt_band_get_quantiles(stats, quantiles, 5, &count);
95  CU_ASSERT(quantile != NULL);
96  CU_ASSERT_EQUAL(count, 5);
97  rtdealloc(quantile);
98 
99  histogram = (rt_histogram) rt_band_get_histogram(stats, 0, NULL, 0, 0, 0, 0, &count);
100  CU_ASSERT(histogram != NULL);
101  rtdealloc(histogram);
102 
103  rtdealloc(stats->values);
104  rtdealloc(stats);
105 
106  stats = (rt_bandstats) rt_band_get_summary_stats(band, 1, 0.15, 0, NULL, NULL, NULL);
107  CU_ASSERT(stats != NULL);
108  rtdealloc(stats);
109 
110  stats = (rt_bandstats) rt_band_get_summary_stats(band, 1, 0.2, 0, NULL, NULL, NULL);
111  CU_ASSERT(stats != NULL);
112  rtdealloc(stats);
113 
114  stats = (rt_bandstats) rt_band_get_summary_stats(band, 1, 0.25, 0, NULL, NULL, NULL);
115  CU_ASSERT(stats != NULL);
116  rtdealloc(stats);
117 
118  stats = (rt_bandstats) rt_band_get_summary_stats(band, 0, 0, 1, NULL, NULL, NULL);
119  CU_ASSERT(stats != NULL);
120  CU_ASSERT_DOUBLE_EQUAL(stats->min, 0, DBL_EPSILON);
121  CU_ASSERT_DOUBLE_EQUAL(stats->max, 198, DBL_EPSILON);
122 
123  quantile = (rt_quantile) rt_band_get_quantiles(stats, NULL, 0, &count);
124  CU_ASSERT(quantile != NULL);
125  rtdealloc(quantile);
126 
127  rtdealloc(stats->values);
128  rtdealloc(stats);
129 
130  stats = (rt_bandstats) rt_band_get_summary_stats(band, 0, 0.1, 1, NULL, NULL, NULL);
131  CU_ASSERT(stats != NULL);
132 
133  quantile = (rt_quantile) rt_band_get_quantiles(stats, NULL, 0, &count);
134  CU_ASSERT(quantile != NULL);
135  rtdealloc(quantile);
136 
137  rtdealloc(stats->values);
138  rtdealloc(stats);
139 
140  cu_free_raster(raster);
141 
142  xmax = 4;
143  ymax = 4;
144  raster = rt_raster_new(4, 4);
145  CU_ASSERT(raster != NULL);
146  band = cu_add_band(raster, PT_8BUI, 0, 0);
147  CU_ASSERT(band != NULL);
148  rt_band_set_nodata(band, 0, NULL);
149 
150  for (x = 0; x < xmax; x++) {
151  for (y = 0; y < ymax; y++) {
152  rt_band_set_pixel(band, x, y, values[(x * ymax) + y], NULL);
153  }
154  }
155 
156  rt_band_get_nodata(band, &nodata);
157  CU_ASSERT_DOUBLE_EQUAL(nodata, 0, DBL_EPSILON);
158 
160  band, 1, 1, 15,
161  &qlls, &qlls_count,
162  quantiles2, 1,
163  &count);
164  CU_ASSERT(quantile != NULL);
165  CU_ASSERT_NOT_EQUAL(count, 0);
166  CU_ASSERT_NOT_EQUAL(qlls_count, 0);
167  CU_ASSERT_DOUBLE_EQUAL(quantile[0].value, 78, DBL_EPSILON);
168  rtdealloc(quantile);
169  quantile_llist_destroy(&qlls, qlls_count);
170  qlls = NULL;
171  qlls_count = 0;
172 
173  cu_free_raster(raster);
174 
175  xmax = 100;
176  ymax = 100;
177  raster = rt_raster_new(xmax, ymax);
178  CU_ASSERT(raster != NULL);
179  band = cu_add_band(raster, PT_64BF, 0, 0);
180  CU_ASSERT(band != NULL);
181  rt_band_set_nodata(band, 0, NULL);
182 
183  for (x = 0; x < xmax; x++) {
184  for (y = 0; y < ymax; y++) {
185  rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
186  }
187  }
188 
189  rt_band_get_nodata(band, &nodata);
190  CU_ASSERT_DOUBLE_EQUAL(nodata, 0, DBL_EPSILON);
191 
192  max_run = 5;
193  for (x = 0; x < max_run; x++) {
195  band, 1, 1, xmax * ymax * max_run,
196  &qlls, &qlls_count,
197  quantiles2, 1,
198  &count);
199  CU_ASSERT(quantile != NULL);
200  CU_ASSERT_NOT_EQUAL(count, 0);
201  CU_ASSERT_NOT_EQUAL(qlls_count, 0);
202  rtdealloc(quantile);
203  }
204 
205  quantile_llist_destroy(&qlls, qlls_count);
206  qlls = NULL;
207  qlls_count = 0;
208 
209  cu_free_raster(raster);
210 }
int quantile_llist_destroy(struct quantile_llist **list, uint32_t list_count)
double quantile
Definition: librtcore.h:2345
raster
Be careful!! Zeros function&#39;s input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
band
Definition: ovdump.py:57
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:600
struct rt_quantile_t * rt_quantile
Definition: librtcore.h:152
rt_quantile rt_band_get_quantiles_stream(rt_band band, int exclude_nodata_value, double sample, uint64_t cov_count, struct quantile_llist **qlls, uint32_t *qlls_count, double *quantiles, int quantiles_count, uint32_t *rtn_count)
Compute the default set of or requested quantiles for a coverage.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1597
unsigned int uint32_t
Definition: uthash.h:78
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
rt_quantile rt_band_get_quantiles(rt_bandstats stats, double *quantiles, int quantiles_count, uint32_t *rtn_count)
Compute the default set of or requested quantiles for a set of data the quantile formula used is same...
int count
Definition: genraster.py:56
double * values
Definition: librtcore.h:2319
rt_bandstats rt_band_get_summary_stats(rt_band band, int exclude_nodata_value, double sample, int inc_vals, uint64_t *cK, double *cM, double *cQ)
Compute summary statistics for a band.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
struct rt_histogram_t * rt_histogram
Definition: librtcore.h:151
struct rt_bandstats_t * rt_bandstats
Definition: librtcore.h:150
void rtdealloc(void *mem)
Definition: rt_context.c:186
rt_histogram rt_band_get_histogram(rt_bandstats stats, int bin_count, double *bin_widths, int bin_widths_count, int right, double min, double max, uint32_t *rtn_count)
Count the distribution of data.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel&#39;s value.
Definition: rt_band.c:841
int value
Definition: genraster.py:61
Here is the call graph for this function:
Here is the caller graph for this function: