r.univar(1grass)
๐ r.univar โ the GRASS User's Manual, but make it cute ๐
okay bestie, welcome to r.univar(1grass), straight from the GRASS User's Manual ๐ซถ this is the one that does the math on your raster and tells you everything about it. grab a snack, we're going in โจ
๐ธ NAME ๐ธ
r.univar โ calculates univariate statistics from the non-null cells of a raster map ๐
and like, what stats are we talking? literally the number of cells counted, minimum and maximum cell values, range, arithmetic mean, population variance, standard deviation, coefficient of variation, and sum. the whole lil squad of numbers. periodt.
๐ KEYWORDS ๐
raster, statistics, univariate statistics, zonal statistics, parallel
โจ SYNOPSIS โจ
r.univar
r.univar --help
r.univar [-getr] map=name[,name,...] [zones=name] [output=name]
[percentile=float[,float,...]] [nprocs=integer]
[separator=character] format=name [--overwrite] [--help] [--verbose]
[--quiet] [--ui]
๐ Flags ๐
-gโ print the stats in shell script style. deprecated, bestie ๐ญ this flag is deprecated and will be removed in a future release โ useformat=shellinstead.-eโ calculate extended statistics ๐ฅ-tโ table output format instead of the standard output format. also deprecated ๐ will be removed in a future release โ useformat=csvinstead.-rโ use the native resolution and extent of the raster map, instead of the current region ๐--overwriteโ allow output files to overwrite existing files--helpโ print usage summary--verboseโ verbose module output--quietโ quiet module output--uiโ force launching GUI dialog
๐ Parameters ๐
map=name[,name,...]โ [required] name of raster map(s) ๐ธzones=nameโ raster map used for zoning, must be of typeCELLoutput=nameโ name for output file (if omitted or-output to stdout)percentile=float[,float,...]โ percentile to calculate (requires extended statistics flag)- Options:
0-100 - Default:
90
- Options:
nprocs=integerโ number of threads for parallel computing0: use OpenMP default;>0: use nprocs;<0: use MAX-nprocs- Default:
0
separator=characterโ field separator- Special characters:
pipe,comma,space,tab,newline
- Special characters:
format=nameโ [required] output format- Options:
plain,shell,csv,json - Default:
plain plain: Human readable text outputshell: shell script style text outputcsv: CSV (Comma Separated Values)json: JSON (JavaScript Object Notation)
- Options:
๐ DESCRIPTION ๐
so r.univar calculates the univariate statistics of one or several raster map(s). same list as before, no cap: the number of cells counted, minimum and maximum cell values, range, arithmetic mean, population variance, standard deviation, coefficient of variation, and sum. ๐งฎ
statistics are calculated separately for every category/zone found in the zones input map if given. iconic zonal behavior, honestly.
if you pass the -e extended statistics flag, the 1st quartile, median, 3rd quartile, and given percentile get calculated too ๐
if you pass the -g flag the results come out in a format suitable for use in a shell script. and if you pass the -t flag the results come out in tabular format with the given field separator. the table can immediately be converted to a vector attribute table, which can then be linked to a vector โ e.g. the vector that was rasterized to create the zones input raster. the way that all connects? chef's kiss ๐
when multiple input maps are given to r.univar, the overall statistics are calculated. this is useful for a time series of the same variable, as well as for the case of a segmented/tiled dataset. allowing multiple raster maps to be specified saves the user from using a temporary raster map for the result of r.series or r.patch. you're welcome ๐
๐ NOTES ๐
as with most GRASS raster modules, r.univar operates on the raster array defined by the current region settings, not the original extent and resolution of the input map. see g.region, but also the wiki page on the computational region to understand the impact of the region settings on the calculations. the vibe check here is: your region IS your answer ๐ซถ
โ ๏ธ this module can use large amounts of system memory when the-eextended statistics flag is used with a very large region setting. if the region is too large the module should exit gracefully with a memory allocation error. basic statistics can be calculated using any size input region. extended statistics can be calculated usingr.stats.quantile. so like. be careful bestie ๐ญ
without a zones input raster, the r.quantile module will be significantly more efficient for calculating percentiles with large maps. noted. โจ
for calculating univariate statistics from a raster map based on a vector polygon map and uploading statistics to new attribute columns, see v.rast.stats.
โก PERFORMANCE โก
r.univar supports parallel processing using OpenMP ๐ฅ the user can specify the number of threads to be used with the nprocs parameter. however, parallelization is disabled when the raster mask is set. yeah. it just is. ๐
due to the differences in summation order, users may encounter small floating points discrepancies when r.univar is run on very large raster files when different nprocs parameters are used. however, since the work allocation among threads is static, users should expect to have the same results when run with the same number of threads. consistency, we love to see it ๐
Figure: Benchmark shows execution time for different number of cells and cores. See benchmark scripts in source code.
๐ EXAMPLES ๐
๐ Univariate statistics
in this example, the raster map elevation in the North Carolina sample dataset is used to calculate univariate statistics:
g.region raster=elevation -p
# standard output, along with extended statistics
r.univar -e elevation percentile=98
total null and non-null cells: 2025000
total null cells: 0
Of the non-null cells:
----------------------
n: 2025000
minimum: 55.5788
maximum: 156.33
range: 100.751
mean: 110.375
mean of absolute values: 110.375
standard deviation: 20.3153
variance: 412.712
variation coefficient: 18.4057 %
sum: 223510266.558102
1st quartile: 94.79
median (even number of cells): 108.88
3rd quartile: 126.792
98th percentile: 147.727
# script style output, along with extended statistics
r.univar -ge elevation percentile=98
n=2025000
null_cells=0
cells=2025000
min=55.5787925720215
max=156.329864501953
range=100.751071929932
mean=110.375440275606
mean_of_abs=110.375440275606
stddev=20.3153233205981
variance=412.712361620436
coeff_var=18.4056555243368
sum=223510266.558102
first_quartile=94.79
median=108.88
third_quartile=126.792
percentile_98=147.727
๐ฆ Zonal statistics
in this example, the raster polygon map basins in the North Carolina sample dataset is used to calculate raster statistics for zones for the elevation raster map:
g.region raster=basins -p
this will set and print computational region in the format:
projection: 99 (Lambert Conformal Conic)
zone: 0
datum: nad83
ellipsoid: a=6378137 es=0.006694380022900787
north: 228500
south: 215000
west: 630000
east: 645000
nsres: 10
ewres: 10
rows: 1350
cols: 1500
cells: 2025000
check basin's IDs using:
r.category basins
this will print them in the format:
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
visualization of them underlying elevation map can be created as:
d.mon wx0
d.rast map=elevation
r.colors map=elevation color=grey
d.rast map=basins
r.colors map=basins color=bgyr
d.legend raster=basins use=2,4,6,8,10,12,14,16,18,20,22,24,26,28,30
d.barscale
Figure: Zones (basins, opacity: 60%) with underlying elevation map for North Carolina sample dataset.
then statistics for elevation can be calculated separately for every zone, i.e. basin found in the zones parameter:
r.univar -t map=elevation zones=basins separator=comma \
output=basin_elev_zonal.csv
this will print information in the format:
zone,label,non_null_cells,null_cells,min,max,range,mean,mean_of_abs,
stddev,variance,coeff_var,sum,sum_abs2,,116975,0,55.5787925720215,
133.147018432617,77.5682258605957,92.1196971445722,92.1196971445722,
15.1475301152556,229.447668592576,16.4433129773355,10775701.5734863,
10775701.57348634,,75480,0,61.7890930175781,110.348838806152,
48.5597457885742,83.7808205765268,83.7808205765268,11.6451777476995,
135.610164775515,13.8995747088232,6323776.33711624,6323776.33711624
6,,1137,0,66.9641571044922,83.2070922851562,16.2429351806641,
73.1900814395257,73.1900814395257,4.15733292896409,17.2834170822492,
5.68018623179036,83217.1225967407,83217.12259674078,,80506,
0,67.4670791625977,147.161514282227, ...
Comma Separated Values (CSV) file is best viewed through a spreadsheet program such as Microsoft Excel, Libre/Open Office Calc or Google Docs:
Figure: Raster statistics for zones (basins, North Carolina sample dataset) viewed through Libre/Open Office Calc.
๐ JSON Output
r.univar -e elevation percentile=98 format=json
will output the results in JSON format:
{
"n": 2025000,
"null_cells": 0,
"cells": 2025000,
"min": 55.578792572021484,
"max": 156.32986450195312,
"range": 100.75107192993164,
"mean": 110.37544027560575,
"mean_of_abs": 110.37544027560575,
"stddev": 20.315323320598083,
"variance": 412.7123616204363,
"coeff_var": 18.40565552433679,
"sum": 223510266.55810165,
"first_quartile": 94.789985656738281,
"median": 108.87990570068359,
"third_quartile": 126.79196929931641,
"percentiles": [
{
"percentile": 98,
"value": 147.7265625
}
]
}
๐ง TODO ๐ง
to be implemented mode, skewness, kurtosis. (one day, bestie. one day. ๐)
๐ SEE ALSO ๐
g.region, r3.univar, r.mode, r.quantile, r.series, r.stats, r.stats.quantile, r.stats.zonal, r.statistics, v.rast.stats, v.univar
๐ AUTHORS ๐
- Hamish Bowman, Otago University, New Zealand
- Extended statistics by Martin Landa
- Multiple input map support by Ivan Shmakov
- Zonal loop by Markus Metz
๐ฆ SOURCE CODE ๐ฆ
available at: r.univar source code (history)
latest change: Thursday Jan 22 21:46:05 2026 in commit: b166c0257c3668569cdf27cf116707c43c9088a4
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
ยฉ 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual
okay that's the whole thing, you ate it up fr fr ๐ and like, mwah ๐ this was r.univar from GRASS 8.5.0, manual page r.univar(1grass) โ go compute some stats bestie, you got this ๐โจ๐ฆ
๐ฆ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 ยท GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 ยท GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms