Note: This document is for an older version of GRASS GIS that will be discontinued soon. You should upgrade, and read the current manual page.

**-s**- Check the spatial topology of temporally related maps and process only spatially related maps
**-n**- Register Null maps
**-g**- Use granularity sampling instead of the temporal topology approach
**-d**- Perform a dry run, compute all dependencies and module calls but don't run them
**--help**- Print usage summary
**--verbose**- Verbose module output
**--quiet**- Quiet module output
**--ui**- Force launching GUI dialog

**expression**=*string***[required]**- r.mapcalc expression for temporal and spatial analysis of space time raster datasets
**basename**=*string***[required]**- Basename of the new generated output maps
- A numerical suffix separated by an underscore will be attached to create a unique identifier
**suffix**=*string*- Suffix to add at basename: set 'gran' for granularity, 'time' for the full time format, 'num' for numerical suffix with a specific number of digits (default %05)
- Default:
*num* **nprocs**=*integer*- Number of r.mapcalc processes to run in parallel
- Default:
*1*

- DESCRIPTION
- TEMPORAL RASTER ALGEBRA
- EXAMPLES
- Computation of NDVI
- Sum of space-time raster datasets
- Sum of space-time raster datasets with temporal topology relation
- Selection of raster cells
- Selection of raster cells with temporal topology relation
- Conditional computation
- Conditional computation with temporal topology relation
- Computation with time intervals
- Computation with time intervals with temporal topology relation

- SEE ALSO
- REFERENCES
- SEE ALSO
- AUTHORS

**"result = expression"**

The statement structure is similar to that of r.mapcalc.
In this statement, **result** represents the name of the space time
raster dataset (STRDS) that will contain the result of the calculation
that is given as **expression** on the right side of the equality sign.
These expressions can be any valid or nested combination of temporal
operations and spatial overlay or buffer functions that are provided by
the temporal algebra.

The temporal raster algebra works only with space time raster datasets
(STRDS). The algebra provides methods for map selection based on their
temporal relations. It is also possible to temporally shift maps, to
create temporal buffer and to snap time instances to create a valid
temporal topology. Furthermore, expressions can be nested and evaluated
in conditional statements (if, else statements). Within if-statements,
the algebra provides temporal variables like start time, end time, day
of year, time differences or number of maps per time interval to build
up conditions.

In addition the algebra provides a subset of the spatial operations
from r.mapcalc. All these operations can be
assigned to STRDS or to the map lists resulting of operations between
STRDS.

By default, only temporal topological relations among space time datasets
(STDS) are evaluated. The **-s** flag can be used to additionally
activate the evaluation of the spatial topology based on the spatial
extent of maps.

The expression option must be passed as **quoted** expression, for
example:

t.rast.algebra expression="C = A + B" basename=result

The map **basename** for the result STRDS must always be specified.

equals A ------ B ------ during A ---- B ------ contains A ------ B ---- starts A ---- B ------ started A ------ B ---- finishs A ---- B ------ finished A ------ B ---- precedes A ---- B ---- follows A ---- B ---- overlapped A ------ B ------ overlaps A ------ B ------ over both overlaps and overlapped

Topological relations must be specified with curly brackets {}.

LEFT REFERENCE l Use the time stamp of the left space time dataset INTERSECTION i Intersection DISJOINT UNION d Disjoint union UNION u Union RIGHT REFERENCE r Use the time stamp of the right space time dataset

C = A : B

In addition, the inverse selection operator **!:** is defined as the
complement of the selection operator, hence the following expression

C = A !: B

To select parts of a STRDS using different topological relations
regarding to other STRDS, the temporal topology selection operator
can be used. This operator consists of the temporal selection operator,
the topological relations that must be separated by the logical OR
operator **|** and, the temporal extent operator. All three parts
are separated by comma and surrounded by curly brackets as follows:
{"temporal selection operator", "topological relations", "temporal operator"}.

**Examples:**

C = A {:,equals} B C = A {!:,equals} B

C = A {:,equals|during|overlaps} B

In addition, we can define the temporal extent of the resulting STRDS by adding the temporal operator.

C = A {:,during,r} B

The selection operator is implicitly contained in the temporal topology selection operator, so that the following statements are exactly the same:

C = A : B C = A {:} B C = A {:,equal} B C = A {:,equal,l} B

C = A !: B C = A {!:} B C = A {!:,equal} B C = A {!:,equal,l} B

if statement decision option temporal relations if(if, then, else) if(conditions, A) A if conditions are True; temporal topological relation between if and then is equal. if(conditions, A, B) A if conditions are True, B otherwise; temporal topological relation between if, then and else is equal. if(topologies, conditions, A) A if conditions are True; temporal topological relation between if and then is explicitly specified by topologies. if(topologies, conditions, A, B) A if conditions are True, B otherwise; temporal topological relation between if, then and else is explicitly specified by topologies.

Symbol description == equal != not equal > greater than >= greater than or equal < less than <= less than or equal && and || or

td(A) Returns a list of time intervals of STDS A start_time(A) Start time as HH::MM:SS start_date(A) Start date as yyyy-mm-DD start_datetime(A) Start datetime as yyyy-mm-DD HH:MM:SS end_time(A) End time as HH:MM:SS end_date(A) End date as yyyy-mm-DD end_datetime(A) End datetime as yyyy-mm-DD HH:MM start_doy(A) Day of year (doy) from the start time [1 - 366] start_dow(A) Day of week (dow) from the start time [1 - 7], the start of the week is Monday == 1 start_year(A) The year of the start time [0 - 9999] start_month(A) The month of the start time [1 - 12] start_week(A) Week of year of the start time [1 - 54] start_day(A) Day of month from the start time [1 - 31] start_hour(A) The hour of the start time [0 - 23] start_minute(A) The minute of the start time [0 - 59] start_second(A) The second of the start time [0 - 59] end_doy(A) Day of year (doy) from the end time [1 - 366] end_dow(A) Day of week (dow) from the end time [1 - 7], the start of the week is Monday == 1 end_year(A) The year of the end time [0 - 9999] end_month(A) The month of the end time [1 - 12] end_week(A) Week of year of the end time [1 - 54] end_day(A) Day of month from the start time [1 - 31] end_hour(A) The hour of the end time [0 - 23] end_minute(A) The minute of the end time [0 - 59] end_second(A) The second of the end time [0 - 59]

The structure is similar to the select operator with the addition of an aggregation operator: {"comparison operator", "topological relations", aggregation operator, "temporal operator"}

This aggregation operator (| or &) defines the behaviour when a map is related to more than one map, e.g. for the topological relation 'contains'. Should all (&) conditions for the related maps be true or is it sufficient to have any (|) condition that is true. The resulting boolean value is then compared to the first condition by the comparison operator (|| or &&). By default, the aggregation operator is related to the comparison operator:

comparison operator -> aggregation operator:

|| -> | and && -> &

Condition 1 {||, equal, r} Condition 2 Condition 1 {&&, equal|during, l} Condition 2 Condition 1 {&&, equal|contains, |, l} Condition 2 Condition 1 {&&, equal|during, l} Condition 2 && Condition 3 Condition 1 {&&, equal|during, l} Condition 2 {&&,contains, |, r} Condition 3

A {#, contains} B

A list of integers (scalars) corresponding to the maps of A that contain maps from B will be returned.

C = if({equal}, A {#, contains} B > 2, A {:, contains} B)

Furthermore, the temporal algebra allows temporal buffering, shifting and snapping with the functions buff_t(), tshift() and tsnap(), respectively.

buff_t(A, size) Buffer STDS A with granule ("1 month" or 5) tshift(A, size) Shift STDS A with granule ("1 month" or 5) tsnap(A) Snap time instances and intervals of STDS A

tmap()

C = A {:, during} tmap(event)

Symbol description precedence % modulus 1 / division 1 * multiplication 1 + addition 2 - subtraction 2

abs(x) return absolute value of x float(x) convert x to foating point int(x) convert x to integer [ truncates ] log(x) natural log of x sqrt(x) square root of x tan(x) tangent of x (x is in degrees) round(x) round x to nearest integer sin(x) sine of x (x is in degrees) isnull(x) check if x = NULL isntnull(x) check if x is not NULL null set null value exist(x) Check if x is in the current mapset

map()

C = A * map(constant_value)

{"spatial or select operator", "list of temporal relations", "temporal operator"}

C = A {+, contains} B --> c1 = a1 + b1 + b2 + b3

**Important**: the aggregation behaviour is not symmetric

C = B {+, during} A --> c1 = b1 + a1 c2 = b2 + a1 c3 = b3 + a1

strds[2]refers to the second successor of the current map.

strds[1,2]refers to the cell one row below and two columns to the right of the current cell in the current map.

strds[1,-2,-1]refers to the cell two rows above and one column to the left of the current cell of the first successor map.

strds[-2,0,1]refers to the cell one column to the right of the current cell in the second predecessor map.

# Sentinel-2 bands are stored separately in two STDRS "S2_b4" and "S2_b8" g.region raster=sentinel2_B04_10m -p t.rast.list S2_b4 t.rast.list S2_b8 t.rast.algebra basename=ndvi expression="ndvi = float(S2_b8 - S2_b4) / ( S2_b8 + S2_b4 )" t.rast.colors input=ndvi color=ndvi

D = if(start_date(A) < "2005-01-01", A + B)

C = A + B

C = A {+,equal,l} B

C = if(A > 100 && A < 1600 && td(A) > 30, B)

C = if({equal}, A > 100 && A < 1600 {&&,equal} td(A) > 30, B)

C = if(Temp > 10.0, Prec / 3600.0 / 24.0 / td(Prec))

C = if({equal}, Temp > 10.0, Prec / 3600.0 / 24.0 {/,equal,l} td(Prec))

C = if(B {#,contain} A > 1, (B {+,contain,l} A - B) / (B {#,contain} A), A)

C = if({equal}, B {#,contain} A > 1, (B {+,contain,l} A {-,equal,l} B) {equal,=/} (B {#,contain} A), A)

# Ubuntu/Debian sudo apt-get install python3-ply # Fedora sudo dnf install python3-ply # MS-Windows (OSGeo4W: requires "python3-pip" package to be installed) python3-pip install ply

Related publications:

- Gebbert, S., Pebesma, E. 2014.
*TGRASS: A temporal GIS for field based environmental modeling*. Environmental Modelling & Software 53, 1-12 (DOI) - preprint PDF - Gebbert, S., Pebesma, E. 2017.
*The GRASS GIS temporal framework*. International Journal of Geographical Information Science 31, 1273-1292 (DOI) - Gebbert, S., Leppelt, T., Pebesma, E., 2019.
*A topology based spatio-temporal map algebra for big data analysis*. Data 4, 86. (DOI)

Available at: t.rast.algebra source code (history)

Latest change: Saturday Mar 11 22:00:31 2023 in commit: c1021236881dca395d1f6da5c4cdb55d092c13d7

Note: This document is for an older version of GRASS GIS that will be discontinued soon. You should upgrade, and read the current manual page.

Main index | Temporal index | Topics index | Keywords index | Graphical index | Full index

© 2003-2023 GRASS Development Team, GRASS GIS 7.8.9dev Reference Manual