# GRASS - Calculate 90th percentile of a timeseries dataset

How can I calculate the 90th percentile from a registered timeseries dataset of 30 rasters in GRASS? GRASS timeseries has 2 "statistical" commands which are t.info and t.rast.univar. Unfortunately, the first one calculate, from the whole set, which is what I want, only the maximum and minimum values, not percentiles/quantile. On the opposite side, t.rast.univar calculates the percentile, togheter with other statistics (max, min, average and others) but what it does is to calculate it for every map registered, not for the whole set. Is there a way to "integrate" both commands and to calculate the 90th percentile within all raster maps?

There is a third command outside the timeseries package to analyze statistics, r.series, but it calculates quantiles only for the single cell within all input maps. What I want is the 90th percentile of the whole area of the 30 rasters I have (which is global).

The module `r.univar` can take a comma separated list of rasters as input, and calculates stats on the whole list. Does that help?

``````MAPLIST=`g.list rast pattern="rast*" separator=comma`
g.region -p \$MAPLIST
r.univar input=\${MAPLIST} percentile=90
``````
• I posted an answer instead of a comment to have the "code" mode pattern in my text May 3, 2021 at 21:21

Micha's answer is right. If instead you do a for loop with `r.univar`, you get the same result than with `t.rast.univar` which is a wrapper for r.univar for all the maps within a time series.

@Micha It seems to work. The ouput is just one list of statstic values (max, min, mean, range...). I thought that doing as you suggest would have been doing the same as doing

``````    `for maps in `g.list rast pattern="tasmax_day_MRI_CGCM3_historical_r1i1p1_19600101_19691231.36[6-9]`
do;
r.univar -ge map="\$maps";
done;
``````

But maybe it is not, as in this second case, r.univar statistics are calculated separately for each of the N rasters that compose the list. Can you confirm me that?

• From the way you worded your question: " What I want is the 90th percentile of the whole area of the 30 rasters I have (which is global)", I understood that you wanted one single value - Q90 - of all the rasters. That is what `r.univar` returns for a list of rasters. If you want the 90th percentile for each raster individually, then `t.rast.univar` would be the right approach. May 4, 2021 at 18:47