Unit 22 - Spatio-temporal basic analysis

Map algebra

Digital numbers (DN) need to be converted into Celsius scale similarly as done in Unit 24. Instead of running r.mapcalc repeatedly there is a specialized temporal command t.rast.mapcalc which applies map algebra to all the maps registered in input space time dataset.


Many temporal data processing modules (t.*) support parallelization (see nproc option).

t.rast.mapcalc input=modis output=modis_c nproc=3 basename=modis_celsius \
expression="if(modis != 0, modis * 0.02 - 273.15, null())"


Compared to expression used in Unit 24, raster map name is replaced by spatio-temporal dataset name.

Alternatively t.rast.algebra could be used to perform the DN transformation, see command below.

t.rast.algebra basename=modis_celsius expression="modis_c = modis * 0.02 - 273.15"

Color table for all the maps in a spatio-temporal raster dataset can be easily set by t.rast.colors similarly as r.colors does for a single raster map.

t.rast.colors input=modis_c color=celsius

Data aggregation

The temporal framework enables the user to perform data aggregation in a really simple way. The command to be used is t.rast.aggregate. Based on specified granularity a new temporal dataset with aggregated data is created.

t.rast.aggregate input=modis_c output=modis_cm basename=cm granularity="1 months" nproc=3

Statistics can be computed by t.rast.univar.

t.rast.univar modis_cm
cm_2017_01@modis|2017-01-01 00:00:00|2017-02-01 00:00:00|-9.44159183015945|-24.37|5.09000000000003|...
cm_2017_02@modis|2017-02-01 00:00:00|2017-03-01 00:00:00|-9.53477082170954|-21.0066666666666|5.41000000000003|...

Another aggregation method is based on t.rast.series, it allows to aggregate spatio-temporal raster dataset or part of it by various methods. The module returns a single raster map as output and not a temporal dataset as by t.rast.aggregate. In example below annual average temperature is computed.

t.rast.series input=modis_c output=modis_avg method=average

Univariate statistics of created raster map with average temperature values can be calculated by r.univar.

r.univar modis_avg
minimum: -10.8297
maximum: 15.9633
range: 26.7931
mean: -0.876881

Fig. 118 Average temperature in Norway for 2017.

Data visualization

In addition to g.gui.timeline introduced in Unit 21 there are other two GRASS tools for temporal data visualization: g.gui.animation (Temporal ‣ GUI tools ‣ Animation tool) and g.gui.tplot (Temporal ‣ GUI tools ‣ Temporal plot tool).

Tool g.gui.animation allows creating animations in different formats, the example below showing the monthly average values.

g.gui.animation strds=modis_cm

Fig. 119 Monthly average dataset animation with celsius color table applied.

The second tool, g.gui.tplot, allows plotting the time series of defined variable of interest for a specific point or area of a study region. In example below coordinates of Studenterhytta venue are used.

g.gui.tplot strds=modis_c coordinates=258121.68627886,6662114.92897065

Fig. 120 The plot of MODIS monthly average temperature @ Studenterhytta