Debian Codegraph @

raster/r.univar/r.univar.html

raw symbols SCIP
1 <h2>DESCRIPTION</h2>
2
3 <em>r.univar</em> calculates the univariate statistics of one or several raster
4 map(s). This includes the number of cells counted, minimum and maximum cell
5 values, range, arithmetic mean, population variance, standard deviation,
6 coefficient of variation, and sum. Statistics are calculated separately for every
7 category/zone found in the <b>zones</b> input map if given.
8 If the <b>-e</b> extended statistics flag is given the 1st quartile, median,
9 3rd quartile, and given <b>percentile</b> are calculated.
10 If the <b>-g</b> flag is given the results are presented in a format suitable
11 for use in a shell script.
12 If the <b>-t</b> flag is given the results are presented in tabular format
13 with the given field separator. The table can immediately be converted to a
14 vector attribute table which can then be linked to a vector, e.g. the vector
15 that was rasterized to create the <b>zones</b> input raster.
16
17 <p>
18 When multiple input maps are given to <em>r.univar</em>, the overall statistics
19 are calculated. This is useful for a time series of the same variable, as well as
20 for the case of a segmented/tiled dataset. Allowing multiple raster maps to be
21 specified saves the user from using a temporary raster map for the result of
22 <em>r.series</em> or <em>r.patch</em>.
23
24 <h2>NOTES</h2>
25
26 As with most GRASS raster modules, <em>r.univar</em> operates on the raster
27 array defined by the current region settings, not the original extent and
28 resolution of the input map. See <em><a href="g.region.html">g.region</a></em>,
29 but also
30 <a href="https://grasswiki.osgeo.org/wiki/Computational_region#Understanding_the_impact_of_region_settings">
31 the wiki page on the computational region</a> to understand the impact of the
32 region settings on the calculations.
33
34 <p>
35 This module can use large amounts of system memory when the <b>-e</b>
36 extended statistics flag is used with a very large region setting. If the
37 region is too large the module should exit gracefully with a memory allocation
38 error. Basic statistics can be calculated using any size input region.
39 Extended statistics can be calculated using
40 <em><a href="r.stats.quantile.html">r.stats.quantile</a></em>.
41
42 <p>
43 Without a <b>zones</b> input raster, the <em>r.quantile</em> module will
44 be significantly more efficient for calculating percentiles with large maps.
45
46 <p>
47 For calculating univariate statistics from a raster map based on vector polygon
48 map and uploads statistics to new attribute columns, see
49 <em><a href="v.rast.stats.html">v.rast.stats</a></em>.
50
51 <h3>PERFORMANCE</h3>
52
53 <p>
54 <em>r.univar</em> supports parallel processing using OpenMP. The user
55 can specify the number of threads to be used with the <b>nprocs</b> parameter.
56 However, parallelization is disabled when the raster mask is set.
57
58 <p>
59 Due to the differences in summation order, users may encounter small floating points
60 discrepancies when <em>r.univar</em> is run on very large raster files when different
61 <b>nprocs</b> parameters are used. However, since the work allocation among threads
62 is static, users should expect to have the same results when run with the same
63 number of threads.
64
65 <div align="center" style="margin: 10px">
66 <img src="r_univar_benchmark_size.png" alt="benchmark for number of cells" border="0">
67 <br>
68 <i>Figure: Benchmark shows execution time for different
69 number of cells and cores. See benchmark scripts in source code. </i>
70 </div>
71
72 <h2>EXAMPLES</h2>
73
74 <h3>Univariate statistics</h3>
75
76 In this example, the raster map <code>elevation</code> in the North
77 Carolina sample dataset is used to calculate univariate statistics:
78
79 <div class="code"><pre>
80 g.region raster=elevation -p
81
82 # standard output, along with extended statistics
83 r.univar -e elevation percentile=98
84 total null and non-null cells: 2025000
85 total null cells: 0
86
87 Of the non-null cells:
88 ----------------------
89 n: 2025000
90 minimum: 55.5788
91 maximum: 156.33
92 range: 100.751
93 mean: 110.375
94 mean of absolute values: 110.375
95 standard deviation: 20.3153
96 variance: 412.712
97 variation coefficient: 18.4057 %
98 sum: 223510266.558102
99 1st quartile: 94.79
100 median (even number of cells): 108.88
101 3rd quartile: 126.792
102 98th percentile: 147.727
103
104
105 # script style output, along with extended statistics
106 r.univar -ge elevation percentile=98
107 n=2025000
108 null_cells=0
109 cells=2025000
110 min=55.5787925720215
111 max=156.329864501953
112 range=100.751071929932
113 mean=110.375440275606
114 mean_of_abs=110.375440275606
115 stddev=20.3153233205981
116 variance=412.712361620436
117 coeff_var=18.4056555243368
118 sum=223510266.558102
119 first_quartile=94.79
120 median=108.88
121 third_quartile=126.792
122 percentile_98=147.727
123 </pre></div>
124
125 <h3>Zonal statistics</h3>
126 In this example, the raster polygon map <code>basins</code> in the North
127 Carolina sample dataset is used to calculate raster statistics for zones
128 for <code>elevation</code> raster map:
129
130 <div class="code"><pre>
131 g.region raster=basins -p
132 </pre></div>
133
134 This will set and print computational region in the format:
135
136 <div class="code"><pre>
137 projection: 99 (Lambert Conformal Conic)
138 zone: 0
139 datum: nad83
140 ellipsoid: a=6378137 es=0.006694380022900787
141 north: 228500
142 south: 215000
143 west: 630000
144 east: 645000
145 nsres: 10
146 ewres: 10
147 rows: 1350
148 cols: 1500
149 cells: 2025000
150 </pre></div>
151
152 Check basin's IDs using:
153
154 <div class="code"><pre>
155 r.category basins
156 </pre></div>
157
158 This will print them in the format:
159
160 <div class="code"><pre>
161 2
162 4
163 6
164 8
165 10
166 12
167 14
168 16
169 18
170 20
171 22
172 24
173 26
174 28
175 30
176 </pre></div>
177
178 Visualization of them underlying elevation map can be created as:
179
180 <div class="code"><pre>
181 d.mon wx0
182 d.rast map=elevation
183 r.colors map=elevation color=grey
184 d.rast map=basins
185 r.colors map=basins color=bgyr
186 d.legend raster=basins use=2,4,6,8,10,12,14,16,18,20,22,24,26,28,30
187 d.barscale
188 </pre></div>
189
190 <!--
191 g.region -a n=227228 s=220895 w=631362 e=641170
192 d.out.file runivar_basins.png
193 optipng -o5 runivar_basins.png width=200px
194 -->
195
196
197 <div align="center" style="margin: 10px">
198 <a href="runivar_basins.png">
199 <img src="runivar_basins.png" width="600" height="446" alt="r.univar basins and their IDs" border="0"><br>
200 </a>
201 <i>Figure: Zones (basins, opacity: 60%) with underlying elevation map
202 for North Carolina sample dataset.</i>
203 </div>
204
205 <p>
206 Then statistics for elevation can be calculated separately for every
207 zone, i.e. basin found in the <b>zones</b> parameter:
208
209 <div class="code"><pre>
210 r.univar -t map=elevation zones=basins separator=comma \
211 output=basin_elev_zonal.csv
212 </pre></div>
213
214 This will print information in the format:
215
216 <div class="code"><pre>
217 zone,label,non_null_cells,null_cells,min,max,range,mean,mean_of_abs,
218 stddev,variance,coeff_var,sum,sum_abs2,,116975,0,55.5787925720215,
219 133.147018432617,77.5682258605957,92.1196971445722,92.1196971445722,
220 15.1475301152556,229.447668592576,16.4433129773355,10775701.5734863,
221 10775701.57348634,,75480,0,61.7890930175781,110.348838806152,
222 48.5597457885742,83.7808205765268,83.7808205765268,11.6451777476995,
223 135.610164775515,13.8995747088232,6323776.33711624,6323776.33711624
224 6,,1137,0,66.9641571044922,83.2070922851562,16.2429351806641,
225 73.1900814395257,73.1900814395257,4.15733292896409,17.2834170822492,
226 5.68018623179036,83217.1225967407,83217.12259674078,,80506,
227 0,67.4670791625977,147.161514282227, ...
228 </pre></div>
229
230 Comma Separated Values (CSV) file is best viewed through a spreadsheet
231 program such as Microsoft Excel, Libre/Open Office Calc or Google Docs:
232
233 <div align="center" style="margin: 10px">
234 <a href="runivar_basins_elev_zonal.png">
235 <img src="runivar_basins_elev_zonal.png" width="600" height="121" alt="r.univar raster statistics" border="0"><br>
236 </a>
237 <i>Figure: Raster statistics for zones (basins, North Carolina sample
238 dataset) viewed through Libre/Open Office Calc.</i>
239 </div>
240
241 <h3>JSON Output</h3>
242 <div class="code"><pre>
243 r.univar -e elevation percentile=98 format=json
244 </pre></div>
245 will output the results in JSON format:
246
247 <div class="code"><pre>
248 {
249 "n": 2025000,
250 "null_cells": 0,
251 "cells": 2025000,
252 "min": 55.578792572021484,
253 "max": 156.32986450195312,
254 "range": 100.75107192993164,
255 "mean": 110.37544027560575,
256 "mean_of_abs": 110.37544027560575,
257 "stddev": 20.315323320598083,
258 "variance": 412.7123616204363,
259 "coeff_var": 18.40565552433679,
260 "sum": 223510266.55810165,
261 "first_quartile": 94.789985656738281,
262 "median": 108.87990570068359,
263 "third_quartile": 126.79196929931641,
264 "percentiles": [
265 {
266 "percentile": 98,
267 "value": 147.7265625
268 }
269 ]
270 }
271 </pre></div>
272
273 <h2>TODO</h2>
274
275 To be implemented <i>mode, skewness, kurtosis</i>.
276
277 <h2>SEE ALSO</h2>
278
279 <em>
280 <a href="g.region.html">g.region</a>,
281 <a href="r3.univar.html">r3.univar</a>,
282 <a href="r.mode.html">r.mode</a>,
283 <a href="r.quantile.html">r.quantile</a>,
284 <a href="r.series.html">r.series</a>,
285 <a href="r.stats.html">r.stats</a>,
286 <a href="r.stats.quantile.html">r.stats.quantile</a>,
287 <a href="r.stats.zonal.html">r.stats.zonal</a>,
288 <a href="r.statistics.html">r.statistics</a>,
289 <a href="v.rast.stats.html">v.rast.stats</a>,
290 <a href="v.univar.html">v.univar</a>
291 </em>
292
293 <h2>AUTHORS</h2>
294
295 Hamish Bowman, Otago University, New Zealand<br>
296 Extended statistics by Martin Landa<br>
297 Multiple input map support by Ivan Shmakov<br>
298 Zonal loop by Markus Metz