r.univar.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <h2>DESCRIPTION</h2>
  2. <em>r.univar</em> calculates the univariate statistics of one or several raster
  3. map(s). This includes the number of cells counted, minimum and maximum cell
  4. values, range, arithmetic mean, population variance, standard deviation,
  5. coefficient of variation, and sum. Statistics are calculated separately for every
  6. category/zone found in the <b>zones</b> input map if given.
  7. If the <b>-e</b> extended statistics flag is given the 1st quartile, median,
  8. 3rd quartile, and given <b>percentile</b> are calculated.
  9. If the <b>-g</b> flag is given the results are presented in a format suitable
  10. for use in a shell script.
  11. If the <b>-t</b> flag is given the results are presented in tabular format
  12. with the given field separator. The table can immediately be converted to a
  13. vector attribute table which can then be linked to a vector, e.g. the vector
  14. that was rasterized to create the <b>zones</b> input raster.
  15. <p>
  16. When multiple input maps are given to <em>r.univar</em>, the overall statistics
  17. are calculated. This is useful for a time series of the same variable, as well as
  18. for the case of a segmented/tiled dataset. Allowing multiple raster maps to be
  19. specified saves the user from using a temporary raster map for the result of
  20. <em>r.series</em> or <em>r.patch</em>.
  21. <h2>NOTES</h2>
  22. As with most GRASS raster modules, <em>r.univar</em> operates on the raster
  23. array defined by the current region settings, not the original extent and
  24. resolution of the input map. See <em><a href="g.region.html">g.region</a></em>,
  25. but also
  26. <a href="https://grasswiki.osgeo.org/wiki/Computational_region#Understanding_the_impact_of_region_settings">
  27. the wiki page on the computational region</a> to understand the impact of the
  28. region settings on the calculations.
  29. <p>
  30. This module can use large amounts of system memory when the <b>-e</b>
  31. extended statistics flag is used with a very large region setting. If the
  32. region is too large the module should exit gracefully with a memory allocation
  33. error. Basic statistics can be calculated using any size input region.
  34. Extended statistics can be calculated using
  35. <em><a href="r.stats.quantile.html">r.stats.quantile</a></em>.
  36. <p>
  37. Without a <b>zones</b> input raster, the <em>r.quantile</em> module will
  38. be significantly more efficient for calculating percentiles with large maps.
  39. <p>
  40. For calculating univariate statistics from a raster map based on vector polygon
  41. map and uploads statistics to new attribute columns, see
  42. <em><a href="v.rast.stats.html">v.rast.stats</a></em>.
  43. <h2>EXAMPLES</h2>
  44. <h3>Univariate statistics</h3>
  45. In this example, the raster map <tt>elevation</tt> in the North
  46. Carolina sample dataset is used to calculate univariate statistics:
  47. <div class="code"><pre>
  48. g.region raster=elevation -p
  49. # standard output, along with extended statistics
  50. r.univar -e elevation percentile=98
  51. total null and non-null cells: 2025000
  52. total null cells: 0
  53. Of the non-null cells:
  54. ----------------------
  55. n: 2025000
  56. minimum: 55.5788
  57. maximum: 156.33
  58. range: 100.751
  59. mean: 110.375
  60. mean of absolute values: 110.375
  61. standard deviation: 20.3153
  62. variance: 412.712
  63. variation coefficient: 18.4057 %
  64. sum: 223510266.558102
  65. 1st quartile: 94.79
  66. median (even number of cells): 108.88
  67. 3rd quartile: 126.792
  68. 98th percentile: 147.727
  69. # script style output, along with extended statistics
  70. r.univar -ge elevation percentile=98
  71. n=2025000
  72. null_cells=0
  73. cells=2025000
  74. min=55.5787925720215
  75. max=156.329864501953
  76. range=100.751071929932
  77. mean=110.375440275606
  78. mean_of_abs=110.375440275606
  79. stddev=20.3153233205981
  80. variance=412.712361620436
  81. coeff_var=18.4056555243368
  82. sum=223510266.558102
  83. first_quartile=94.79
  84. median=108.88
  85. third_quartile=126.792
  86. percentile_98=147.727
  87. </pre></div>
  88. <h3>Zonal statistics</h3>
  89. In this example, the raster polygon map <tt>basins</tt> in the North
  90. Carolina sample dataset is used to calculate raster statistics for zones
  91. for <tt>elevation</tt> raster map:
  92. <div class="code"><pre>
  93. g.region raster=basins -p
  94. </pre></div>
  95. This will set and print computational region in the format:
  96. <div class="code"><pre>
  97. projection: 99 (Lambert Conformal Conic)
  98. zone: 0
  99. datum: nad83
  100. ellipsoid: a=6378137 es=0.006694380022900787
  101. north: 228500
  102. south: 215000
  103. west: 630000
  104. east: 645000
  105. nsres: 10
  106. ewres: 10
  107. rows: 1350
  108. cols: 1500
  109. cells: 2025000
  110. </pre></div>
  111. Check basin's IDs using:
  112. <div class="code"><pre>
  113. r.category basins
  114. </pre></div>
  115. This will print them in the format:
  116. <div class="code"><pre>
  117. 2
  118. 4
  119. 6
  120. 8
  121. 10
  122. 12
  123. 14
  124. 16
  125. 18
  126. 20
  127. 22
  128. 24
  129. 26
  130. 28
  131. 30
  132. </pre></div>
  133. Visualization of them underlying elevation map can be created as:
  134. <div class="code"><pre>
  135. d.mon wx0
  136. d.rast map=elevation
  137. r.colors map=elevation color=grey
  138. d.rast map=basins
  139. r.colors map=basins color=bgyr
  140. d.legend raster=basins use=2,4,6,8,10,12,14,16,18,20,22,24,26,28,30
  141. d.barscale
  142. </pre></div>
  143. <!--
  144. g.region -a n=227228 s=220895 w=631362 e=641170
  145. d.out.file runivar_basins.png
  146. optipng -o5 runivar_basins.png width=200px
  147. -->
  148. <div align="center" style="margin: 10px">
  149. <a href="runivar_basins.png">
  150. <img src="runivar_basins.png" width="600" alt="r.univar basins and their IDs" border=0><br>
  151. </a>
  152. <i>Figure: Zones (basins, opacity: 60%) with underlying elevation map
  153. for North Carolina sample dataset.</i>
  154. </div>
  155. <p>
  156. Then statistics for elevation can be calculated separately for every
  157. zone, i.e. basin found in the <b>zones</b> parameter:
  158. <div class="code"><pre>
  159. r.univar -t map=elevation zones=basins separator=comma \
  160. output=basin_elev_zonal.csv
  161. </pre></div>
  162. This will print information in the format:
  163. <div class="code"><pre>
  164. zone,label,non_null_cells,null_cells,min,max,range,mean,mean_of_abs,
  165. stddev,variance,coeff_var,sum,sum_abs2,,116975,0,55.5787925720215,
  166. 133.147018432617,77.5682258605957,92.1196971445722,92.1196971445722,
  167. 15.1475301152556,229.447668592576,16.4433129773355,10775701.5734863,
  168. 10775701.57348634,,75480,0,61.7890930175781,110.348838806152,
  169. 48.5597457885742,83.7808205765268,83.7808205765268,11.6451777476995,
  170. 135.610164775515,13.8995747088232,6323776.33711624,6323776.33711624
  171. 6,,1137,0,66.9641571044922,83.2070922851562,16.2429351806641,
  172. 73.1900814395257,73.1900814395257,4.15733292896409,17.2834170822492,
  173. 5.68018623179036,83217.1225967407,83217.12259674078,,80506,
  174. 0,67.4670791625977,147.161514282227, ...
  175. </pre></div>
  176. Comma Separated Values (CSV) file is best viewed through a spreadsheet
  177. program such as Microsoft Excel, Libre/Open Office Calc or Google Docs:
  178. <div align="center" style="margin: 10px">
  179. <a href="runivar_basins_elev_zonal.png">
  180. <img src="runivar_basins_elev_zonal.png" width="600" alt="r.univar raster statistics" border=0><br>
  181. </a>
  182. <i>Figure: Raster statistics for zones (basins, North Carolina sample
  183. dataset) viewed through Libre/Open Office Calc.</i>
  184. </div>
  185. <h2>TODO</h2>
  186. To be implemented <i>mode, skewness, kurtosis</i>.
  187. <h2>SEE ALSO</h2>
  188. <em>
  189. <a href="g.region.html">g.region</a>,
  190. <a href="r3.univar.html">r3.univar</a>,
  191. <a href="r.mode.html">r.mode</a>,
  192. <a href="r.quantile.html">r.quantile</a>,
  193. <a href="r.series.html">r.series</a>,
  194. <a href="r.stats.html">r.stats</a>,
  195. <a href="r.stats.quantile.html">r.stats.quantile</a>,
  196. <a href="r.stats.zonal.html">r.stats.zonal</a>,
  197. <a href="r.statistics.html">r.statistics</a>,
  198. <a href="v.rast.stats.html">v.rast.stats</a>,
  199. <a href="v.univar.html">v.univar</a>
  200. </em>
  201. <h2>AUTHORS</h2>
  202. Hamish Bowman, Otago University, New Zealand<br>
  203. Extended statistics by Martin Landa<br>
  204. Multiple input map support by Ivan Shmakov<br>
  205. Zonal loop by Markus Metz
  206. <p><i>Last changed: $Date$</i>