t.rast.algebra(1)

NAME โœจ

okay bestie, meet t.rast.algebra โ€” she applies temporal and spatial operations on space time raster datasets using temporal raster algebra. no cap, that's literally her whole thing. ๐Ÿ’…

KEYWORDS ๐ŸŽ€

temporal, algebra, raster, time


SYNOPSIS ๐Ÿ’–

t.rast.algebra
t.rast.algebra --help
t.rast.algebra [-sngd] expression=string basename=string
[suffix=string]   [nprocs=integer]   [--help]  [--verbose]  [--quiet]
[--ui]

Flags ๐Ÿšฉ

  • -s โ€” check the spatial topology of temporally related maps, and only process the maps that are spatially related ๐Ÿ—บ๏ธ
  • -n โ€” register Null maps (yes, the empty ones get an invite too) ๐Ÿ™ˆ
  • -g โ€” use granularity sampling instead of the temporal topology approach โณ
  • -d โ€” do a dry run: compute all the dependencies and module calls, but don't actually run them ๐Ÿ‘€
  • --help โ€” print usage summary
  • --verbose โ€” verbose module output
  • --quiet โ€” quiet module output
  • --ui โ€” force launching GUI dialog

Parameters ๐Ÿงš

  • expression=string [required] โ€” the 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 gets 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 ๐Ÿ’–

so t.rast.algebra performs temporal and spatial map algebra operations on space time raster datasets (STRDS) using the temporal raster algebra. that's the whole vibe.

the module expects an expression as input parameter, shaped like this:

"result = expression"

the statement structure is giving r.mapcalc energy, fr fr. in this statement, result is the name of the space time raster dataset (STRDS) that will hold the result of the calculation โ€” and that calculation is the expression sitting 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 the temporal algebra provides. โœจ

the temporal raster algebra works only with space time raster datasets (STRDS). the algebra gives you methods for map selection based on their temporal relations. it's also possible to temporally shift maps, to create temporal buffer, and to snap time instances to create a valid temporal topology. plus, expressions can be nested and evaluated in conditional statements (if, else statements). inside if-statements, the algebra hands you temporal variables like start time, end time, day of year, time differences, or number of maps per time interval โ€” all so you can build up conditions. on top of that, 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 a quoted expression, for example:

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

where C is the new space time raster dataset that will contain maps with the basename "result" and a numerical suffix separated by an underscore โ€” and those maps represent the sum of maps from the STRDS A and temporally equal maps (i.e., maps with equal temporal topology relation) from the STRDS B. slay.

the map basename for the result STRDS must always be specified. no basename, no map. periodt. ๐Ÿ’…

TEMPORAL RASTER ALGEBRA ๐ŸŒˆ

the temporal algebra provides a wide range of temporal operators and functions, and we're about to go through all of them in the following section. buckle up bestie. ๐ŸŽข

TEMPORAL RELATIONS ๐Ÿ”—

several temporal topology relations are supported between maps registered in space time datasets:

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

the relations must be read as: A is related to B, like โ€” A equals B โ€” A is during B โ€” A contains B. iykyk. ๐Ÿง 

topological relations must be specified with curly brackets {}.

TEMPORAL OPERATORS โšก

the temporal algebra defines temporal operators that can be combined with other operators to perform spatio-temporal operations. the temporal operators process the time instances and intervals of two temporally related maps and calculate the resulting temporal extent in five possible different ways:

  • 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

TEMPORAL SELECTION ๐ŸŽฏ

the temporal selection simply selects parts of a space time dataset without processing any raster or vector data. the algebra provides a selection operator : that, by default, selects parts of a space time dataset that are temporally equal to parts of a second space time dataset. this expression:

C = A : B

means: select all parts of space time dataset A that are equal to B and store them in space time dataset C. these parts are time stamped maps. ๐Ÿ’ซ

in addition, the inverse selection operator !: is defined as the complement of the selection operator, hence this expression:

C = A !: B

means: select all parts of space time time dataset A that are not equal to B and store them in space time dataset C.

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, like this: {"temporal selection operator", "topological relations", "temporal operator"}.

examples:

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

we can now define arbitrary topological relations using the OR operator "|" to connect them:

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

select all parts of A that are equal to B, during B, or overlaps B. easy. โœจ

in addition, we can define the temporal extent of the resulting STRDS by adding the temporal operator:

C = A {:,during,r} B

select all parts of A that are during B and use the temporal extents from B for C. ๐Ÿซถ

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

same for the complementary selection:

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

CONDITIONAL STATEMENTS ๐Ÿค”

selection operations can be evaluated within conditional statements, as shown below. note that A and B can be either space time datasets or expressions. the temporal relationship between the conditions and the conclusions can be defined at the beginning of the if statement (third and fourth examples below). the relationship between then and else conclusion must be always equal. ๐Ÿ‘‘

  • 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.

the conditions are comparison expressions that are used to evaluate space time datasets. specific values of temporal variables are compared by logical operators and evaluated for each map of the STRDS.

Important: the conditions are evaluated from left to right. don't forget it bestie. ๐Ÿ˜ญ

Logical operators ๐Ÿงฎ

  • == โ€” equal
  • != โ€” not equal
  • > โ€” greater than
  • >= โ€” greater than or equal
  • < โ€” less than
  • <= โ€” less than or equal
  • && โ€” and
  • || โ€” or

๐ŸŒธ Temporal functions ๐ŸŒธ

Okay bestie, these ones are a little โœจspecialโœจ โ€” they only get evaluated for the STDS you pass them in parenthesis. No parenthesis, no function, periodt. ๐Ÿ’…

  • 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]

Now here's the lil plot twist ๐Ÿซถ โ€” to actually use those numbers from the last block up there, you gotta add an offset value. Like, start_doy(A, 0) would return the DOY of the current map in STDS A. And end_hour(A, -1) would return the end hour of the previous map in STDS A. The way that offset just slides you through timeโ€ฆ iconic honestly. ๐Ÿ˜ญ


๐Ÿ”ฅ Comparison operator ๐Ÿ”ฅ

As mentioned above (iykyk), the conditions are comparison expressions that are used to evaluate space time datasets. Specific values of temporal variables are compared by logical operators and evaluated for each map of the STDS and (optionally) related maps. For complex relations, the comparison operator can be used to combine conditions. ๐Ÿ’ซ

The structure is similar to the select operator, except there's an extra aggregation operator in the mix:

{"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 && -> &

Examples, bestie โ€” study these, they're giving exam energy ๐Ÿ“šโœจ:

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

#๏ธโƒฃ Hash operator #๏ธโƒฃ

BONUS FEATURE, and it's a good one ๐ŸŽ€ โ€” the number of maps in intervals can be computed and used in conditional statements with the hash (#) operator.

A {#, contains} B

This expression computes the number of maps from space time dataset B which are during the time intervals of maps from space time dataset A. 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)

This expression selects all maps from A that temporally contain at least 2 maps from B and stores them in space time dataset C. The leading equal statement in the if condition specifies the temporal relation between the if and then part of the if expression. This is very important, so we do not need to specify a global time reference (a space time dataset) for temporal processing. ๐Ÿ‘‘

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

๐Ÿ• Single map with temporal extent ๐Ÿ•

Plot twist number two ๐Ÿ™ˆ โ€” the temporal algebra can also handle single maps with time stamps, via the tmap() function.

tmap()

For example:

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

This statement selects all maps from space time data set A that are during the temporal extent of the single map 'event'. Little guy, big influence. ๐Ÿ’…


๐Ÿงฎ Spatial raster operators ๐Ÿงฎ

The module supports the following raster operations (precedence included, because order matters bestie):

  • % โ€” modulus, precedence 1
  • / โ€” division, precedence 1
  • * โ€” multiplication, precedence 1
  • + โ€” addition, precedence 2
  • - โ€” subtraction, precedence 2

And raster functions:

  • 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

๐Ÿ—บ๏ธ Single raster map ๐Ÿ—บ๏ธ

The temporal raster algebra features also a function to integrate single raster maps without time stamps into the expressions. No timestamp, no problem. ๐Ÿซถ

map()

For example:

C = A * map(constant_value)

This statement multiplies all raster maps from space time raster data set A with the raster map 'constant_value'.


๐ŸŒˆ Combinations of temporal, raster and select operators ๐ŸŒˆ

The user can combine the temporal topology relations, the temporal operators and the spatial/select operators to create spatio-temporal operators as follows:

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

For multiple topological relations or several related maps the spatio-temporal operators feature implicit aggregation. The algebra evaluates the stated STDS by their temporal topologies and apply the given spatio-temporal operators in a aggregated form. So if we have two STDS A and B, and B has three maps: b1, b2, b3 that are all during the temporal extent of the single map a1 of A, then the following arithmetic calculations would implicitly aggregate all maps of B into one result map for a1 of A:

 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

๐ŸŽ€ Temporal neighbourhood modifier ๐ŸŽ€

The neighbourhood modifier of r.mapcalc is extended for the temporal raster algebra with the temporal dimension. The format is strds[t,r,c], where t is the temporal offset, r is the row offset and c is the column offset. A single neighborhood modifier is interpreted as temporal offset [t], while two neighborhood modifiers are interpreted as row and column offsets [r,c].

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. โช

The way you can just move through space AND time in one little bracketโ€ฆ that's main character energy fr fr. ๐Ÿ’œ

โœจ EXAMPLES โœจ

Bestie, this is the part where it all clicks. Grab a strawberry ๐Ÿ“, these are chef's kiss.

๐Ÿ’– Computation of NDVI ๐Ÿ’–

Okay so real talk โ€” Sentinel-2 bands live in separate space time raster datasets, S2_b4 and S2_b8, and we're about to make them kiss and produce an NDVI. Watch:

# 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

First you set the region, then you peek at both STRDS, then the algebra does the whole float(S2_b8 - S2_b4) / ( S2_b8 + S2_b4 ) moment, and then t.rast.colors gives it the NDVI palette. Iconic. ๐Ÿ‘‘

๐Ÿฆ‹ Sum of space-time raster datasets ๐Ÿฆ‹

Sum maps from STRDS A with maps from STRDS B which have equal time stamps and are temporally before Jan. 1. 2005 and store them in STRDS D:

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

And to create the sum of all maps from STRDS A and B that have equal time stamps and store the new maps in STRDS C:

C = A + B

๐ŸŒธ Sum of space-time raster datasets with temporal topology relation ๐ŸŒธ

Same expression, but now you spell out the temporal topology relation and temporal operators yourself, out loud, like a main character:

C = A {+,equal,l} B

โœจ Selection of raster cells โœจ

Select all cells from STRDS B with equal temporal relations to STRDS A, if the cells of A are in the range [100.0, 1600] of time intervals that have more than 30 days (Jan, Mar, May, Jul, Aug, Oct, Dec):

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

๐Ÿ’… Selection of raster cells with temporal topology relation ๐Ÿ’…

Same expression with the temporal topology relation and temporal operators written out explicitly:

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

๐ŸŽ€ Conditional computation ๐ŸŽ€

Compute the recharge in meters per second for all cells of precipitation STRDS "Prec" if the mean temperature specified in STRDS "Temp" is higher than 10 degrees. Computation is performed if STRDS "Prec" and "Temp" have equal time stamps. The number of days or fraction of days per interval is computed using the td() function that has as argument the STRDS "Prec":

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

๐Ÿ’œ Conditional computation with temporal topology relation ๐Ÿ’œ

Same expression with explicit definition of the temporal topology relation and temporal operators:

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

๐ŸŒˆ Computation with time intervals ๐ŸŒˆ

Compute the mean value of all maps from STRDS A that are located during time intervals of STRDS B if more than one map of A is contained in an interval of B, use A otherwise. The resulting time intervals are either from B or A:

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

โญ Computation with time intervals with temporal topology relation โญ

Same expression with explicit definition of the temporal topology relation and temporal operators:

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

๐Ÿ”ฅ Compute DOY for spatio-temporal conditions ๐Ÿ”ฅ

Compute the DOY for all maps from STRDS A where conditions are met at three consecutive time intervals (e.g. temperature > 0):

B = if(A > 0.0 && A[-1] > 0.0 && A[-2] > 0.0, start_doy(A, -1), 0)"

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

  • r.mapcalc
  • t.vect.algebra
  • t.rast3d.algebra
  • t.select
  • t.rast3d.mapcalc
  • t.rast.mapcalc
  • Temporal data processing Wiki

๐Ÿงš REFERENCES ๐Ÿงš

The use of this module requires the following software to be installed: PLY(Python-Lex-Yacc)

# 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)

๐ŸŒธ SEE ALSO ๐ŸŒธ

  • v.overlay
  • v.buffer
  • v.patch
  • r.mapcalc

๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

Thomas Leppelt, Sรถren Gebbert, Thรผnen Institute of Climate-Smart Agriculture


๐Ÿ’พ SOURCE CODE ๐Ÿ’พ

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

Accessed: Saturday Jan 17 05:41:53 2026

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

ยฉ 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual


and that's the whole page, bestie ๐Ÿ’– no cap, you just read the entire t.rast.algebra manual โ€” this is GRASS GIS version 8.4.2, page t.rast.algebra(1), and it was accessed Saturday Jan 17 05:41:53 2026. go forth and algebra โœจ๐Ÿฆ‹๐ŸŽ€

๐Ÿ“ฆ where this page comes from