Difference between revisions of "TGRASS workshop at FOSS4G Europe Paris 2017"

From GRASS-Wiki
Jump to: navigation, search
(Draft workshop page (converted with pandoc))
 
(Please see: https://github.com/veroandreo/tgrass_workshop_foss4g_eu)
 
Line 1: Line 1:
[https://europe.foss4g.org/2017/ [[File:foss4g_eu_2017.png|FOSS4G EU 2017 logo]]][https://grass.osgeo.org [[Image:grassgis_logo_colorlogo_text_whitebg.png|GRASS GIS logo|200px]]]
 
 
 
= TGRASS: temporal data processing with GRASS GIS =
 
= TGRASS: temporal data processing with GRASS GIS =
  
Line 7: Line 5:
 
[https://veroandreo.wordpress.com/ Veronica Andreo], [http://www.lucadelu.org Luca Delucchi] and [https://www.mundialis.de/en/neteler/ Markus Neteler]
 
[https://veroandreo.wordpress.com/ Veronica Andreo], [http://www.lucadelu.org Luca Delucchi] and [https://www.mundialis.de/en/neteler/ Markus Neteler]
  
[[#lst-time-series-animation|[[File:figures/animation_nc_zoom.gif|NC to Wake LST animation]]]]
+
'''Please see: https://github.com/veroandreo/tgrass_workshop_foss4g_eu'''
 
 
Course outline:
 
 
 
* [[#grassgisintro|Introduction to GRASS GIS]]
 
* [[#temporalintro|Introduction to GRASS Temporal Framework]]
 
* [[#temporalhands|Hands-on to raster time series processing]]
 
 
 
Software requirements:
 
 
 
* GRASS GIS 7.2: [https://grass.osgeo.org/download/software/ download] | [https://live.osgeo.org/ OSGeo-live]
 
* GRASS GIS Add-ons: [https://grass.osgeo.org/grass72/manuals/addons/r.modis.download.html r.modis.download], [https://grass.osgeo.org/grass72/manuals/addons/r.modis.import.html r.modis.import] and [https://grass.osgeo.org/grass72/manuals/addons/v.strds.stats.html v.strds.stats]
 
* [http://www.pymodis.org pyModis] library
 
 
 
Sample data:
 
 
 
* Main dataset: [https://grass.osgeo.org/sampledata/north_carolina/nc_basic_spm_grass7.tar.gz North Carolina basic location (50 MB)]
 
** extra &quot;mapset&quot; <code>modis_lst</code>: monthly land surface temperature (LST) from MODIS sensor (MOD11B3.006) for North Carolina (2015-2016)
 
 
 
== [[GRASS GIS introduction]] ==
 
 
 
Working with GRASS GIS is not much different from any other GIS. Just a few commonly used terms need to be introduced first.
 
 
 
=== GRASS DATABASE, LOCATION and MAPSET ===
 
 
 
The '''GRASS DATABASE''' (also called &quot;GISDBASE&quot;) is an existing directory which contains all GRASS GIS projects. These projects are organized in subdirectories called LOCATIONs.<br />
 
A '''LOCATION''' is defined by its coordinate system, map projection and geographical boundaries.<br />
 
'''MAPSETs''' are subdirectories within Locations. In a '''MAPSET''' you can organize GIS maps thematically, geographically, by project or however you prefer.<br />
 
 
 
<div class="imagebox">
 
 
 
[[File:figures/grass_database.png|GRASS DATABASE, LOCATIONs, and MAPSETs]]<br />
 
GRASS DATABASE, LOCATIONs and MAPSETs
 
 
 
</div>
 
=== Raster and vector maps ===
 
 
 
GRASS GIS is able to read most GIS data formats directly (mainly done through the [http://www.gdal.org/ GDAL] library). GRASS GIS has its own internal formats to manage raster and vector data, so your data have to be imported or linked into a GRASS LOCATION/MAPSET.<br />
 
<br />
 
The '''GRASS GIS vector format is topological''', this means that adjacent geographic components in a single vector map are related to each other. For example, in a non-topological GIS if two areas share a common border that border would be digitized twice and also stored in a duplicate manner. In a topological GIS such as GRASS GIS, this border exists only once and it is shared between these two areas. The topological representation of vector data helps to produce and maintain vector maps with clean geometry. Moreover, it enables certain analyses that can not be conducted with non-topological or spaghetti data.<br />
 
 
 
<div class="imagebox">
 
 
 
[[File:figures/datatypes.png|Vector data types]]<br />
 
All vector data types in GRASS GIS
 
 
 
</div>
 
=== Modules ===
 
 
 
GRASS GIS is composed of more than 450 modules to perform any kind of GIS analysis. It is possible to analize raster, raster 3D, imagery and vector maps along with their alphanumerical attributes.<br />
 
The wealth of modules is organized by their first name in order to easily find the desired functionality. The graphical user interface offers a tree view as well as a search engine.
 
 
 
 
 
{|
 
|+ GRASS GIS module families
 
! Prefix
 
! Function class
 
! Type of command
 
! Example
 
|-
 
| [https://grass.osgeo.org/grass72/manuals/full_index.html#g g.*]
 
| general
 
| general data management
 
| [https://grass.osgeo.org/grass72/manuals/g.rename.html g.rename]: renames map
 
|-
 
| [https://grass.osgeo.org/grass72/manuals/full_index.html#d d.*]
 
| display
 
| graphical output
 
| [https://grass.osgeo.org/grass72/manuals/d.rast.html d.rast]: display raster map, d.vect: display vector map
 
|-
 
| [https://grass.osgeo.org/grass72/manuals/full_index.html#r r.*]
 
| raster
 
| raster processing
 
| [https://grass.osgeo.org/grass72/manuals/r.mapcalc.html r.mapcalc]: map algebra, r.univar: univariate statistics
 
|-
 
| [https://grass.osgeo.org/grass72/manuals/full_index.html#r v.*]
 
| vector
 
| vector processing
 
| [https://grass.osgeo.org/grass72/manuals/v.clean.html v.clean]: topological cleaning
 
|-
 
| [https://grass.osgeo.org/grass72/manuals/full_index.html#i i.*]
 
| imagery
 
| imagery processing
 
| [https://grass.osgeo.org/grass72/manuals/i.pca.html i.pca]: Principal Components Analysis on imagery group
 
|-
 
| [https://grass.osgeo.org/grass72/manuals/full_index.html#r3 r3.*]
 
| voxel
 
| 3D raster processing
 
| [https://grass.osgeo.org/grass72/manuals/r3.stats.html r3.stats]: voxel statistics
 
|-
 
| [https://grass.osgeo.org/grass72/manuals/full_index.html#db db.*]
 
| database
 
| database management
 
| [https://grass.osgeo.org/grass72/manuals/db.select.html db.select]: select value(s) from table
 
|-
 
| [https://grass.osgeo.org/grass72/manuals/full_index.html#ps ps.*]
 
| postscript
 
| map creation in PostScript format
 
| [https://grass.osgeo.org/grass72/manuals/ps.map.html ps.map]: PostScript map creation
 
|-
 
| [https://grass.osgeo.org/grass72/manuals/full_index.html#t t.*]
 
| temporal
 
| space-time datasets
 
| [https://grass.osgeo.org/grass72/manuals/t.rast.aggregate.html t.rast.aggregate]: raster time series aggregation
 
|}
 
 
 
It is also possible to install further modules, called '''Add-ons''', from a centralized [https://grass.osgeo.org/grass7/manuals/addons/ GRASS GIS Add-on repository] at OSGeo or from github using the command [https://grass.osgeo.org/grass72/manuals/g.extension.html g.extension].
 
 
 
=== Region and Mask ===
 
 
 
The '''computational (or current) region''' is the ''actual setting of the region boundaries and the actual raster resolution''.<br />
 
The raster input maps are automatically (on the fly) cropped/padded and rescaled to match the current region, the output maps have their bounds and resolution equal to those of the current computational region, while vector maps are always considered completely.
 
<div class="imagebox">
 
 
 
[[File:figures/region.png|Show computational region]]<br />
 
The red box shows the computational region currently set
 
 
 
</div>
 
''MASK'': if a mask is set, raster modules will operate only on data falling inside the masked area(s), i.e. any data falling outside of the mask are treated as if their pixel value were NULL. To set the mask you can use [https://grass.osgeo.org/grass72/manuals/r.mask.html r.mask] or create a raster called <code>MASK</code> (this raster map name is reserved for this purpose).<br />
 
 
 
<div class="imagebox">
 
 
 
[[File:figures/mask.png|Show MASK effect]]<br />
 
By setting the MASK (here based on a ZIP code) only the raster data inside the masked area are used for further analysis
 
 
 
</div>
 
=== Interfaces ===
 
 
 
GRASS GIS offers different interfaces for the interaction between user and software. Let's see them...
 
==== Graphical User Interface ====
 
 
 
The GUI is the simpler way to approach GRASS GIS. The [https://grass.osgeo.org/grass72/manuals/wxGUI.html GRASS GIS GUI] is composed of two elements, the <code>Layer Manager</code> where you can find all the GRASS GIS modules and manage your data and, the <code>Map Display</code> where you can navigate, print and query your maps. The GUI also comes with a Python shell for rapid prototyping.
 
<div class="imagebox">
 
 
 
[[File:figures/GUI_description.png|GRASS GIS GUI]]<br />
 
GRASS GIS Graphical User Interface (GUI)
 
 
 
</div>
 
Otherwise you can also use GRASS GIS inside QGIS by either using the <code>GRASS GIS plugin</code> or through <code>Processing</code>.
 
==== Command line ====
 
 
 
The command line is the traditional and, probably, the most powerful way to use GRASS GIS, used daily by many GRASS GIS power users worldwide.
 
==== Python ====
 
 
 
Python is a powerful and simple programming language, and you can use it to:
 
* interface with the functionalities offered by GRASS GIS
 
* create your own workflows chaining several GRASS GIS modules
 
* create new add-ons by using GRASS GIS modules along with a wide number of Python libraries.
 
 
 
Here's an example of Python code to run GRASS GIS modules:
 
<pre>       
 
!/usr/bin/env python
 
 
 
# simple example for pyGRASS usage: raster processing via modules approach
 
 
 
from grass.pygrass.modules.shortcuts import general as g
 
from grass.pygrass.modules.shortcuts import raster as r
 
 
 
g.message(&quot;Filter elevation map by a threshold...&quot;)
 
 
 
# set computational region
 
input = 'elevation'
 
g.region(rast=input)
 
 
 
# hardcoded:
 
# r.mapcalc('elev_100m = if(elevation &gt; 100, elevation, null())', overwrite = True)
 
 
 
# with variables
 
output = 'elev_100m'
 
thresh = 100.0
 
r.mapcalc(&quot;%s = if(%s &gt; %d, %s, null())&quot; % (output, input, thresh, input), overwrite = True)
 
r.colors(map=output, color=&quot;elevation&quot;)
 
</pre>
 
 
 
==== WPS - OGC Web Processing Service ====
 
 
 
It is possible to run GRASS GIS modules through the web using the [https://en.wikipedia.org/wiki/Web_Processing_Service Web Processing Service] (WPS is an [https://en.wikipedia.org/wiki/Open_Geospatial_Consortium OGC] standard). The Free and Open Source software [http://zoo-project.org/ ZOO-Project] and [http://pywps.org/ PyWPS] allow the user to run GRASS GIS commands in a simple way.
 
== [[Temporal GRASS GIS introduction]] ==
 
 
 
GRASS GIS is the first Open Source GIS that incorporated capabilities to manage, analyze, process and visualize spatio-temporal data, as well as the temporal relationships among time series.
 
 
 
Importantly, the '''TGRASS''' concept is based on metadata and does not duplicate any datasets. It follows a ''snapshot'' approach, i.e.: add time stamps to existent maps, to integrate time dimension to the classical spatial GIS. In GRASS GIS words, all pixels in a raster map and all elements in a vector map, share the same time stamp. A collection of time stamped maps (snapshots) of the same variable are called '''space-time datasets (STDS)''' in TGRASS. Each map in a STDS might have a different spatial and temporal extent.
 
 
 
TGRASS uses an SQL database to store the temporal and spatial extension of STDS, as well as the topological relationships among maps and among STDS.
 
 
 
=== Terminology overview ===
 
 
 
==== Temporal database ====
 
 
 
A temporal database is a mapset-specific database in which all time stamped maps are registered, i.e.: their spatial and temporal extents, unique ID and map type metadata are stored. This allows users to perform complex SQL queries using the spatio-temporal extent and metadata information for map selection (See [[#temporal_analysis|Temporal data analysis]] section).
 
==== Space-time datasets ====
 
 
 
Space-time datasets are called differently according to the map type they are formed of:
 
* Space time raster datasets ('''STRDS''') collections of time stamped raster maps.
 
* Space time 3D raster datasets ('''STR3DS''') collections of time stamped 3D raster maps.
 
* Space time vector datasets ('''STVDS''') collections of time stamped vector maps.
 
 
 
==== Spatio-temporal modules ====
 
 
 
* '''t.*''': General modules to handle STDS of all types
 
* '''t.rast.*''': Modules that specifically deal with STRDS
 
* '''t.rast3d.*''': Modules that specifically deal with STR3DS
 
* '''t.vect.*''': Modules that specifically deal with STVDS
 
 
 
==== Absolute time vs relative time ====
 
 
 
Two different time definitions are used in TGRASS:
 
 
 
{|
 
! Absolute time
 
! Relative time
 
|-
 
| Gregorian calendar (ISO 8601 time format notation)
 
| An integer and a time unit (year, month, day, hour, minute, seconds)
 
|-
 
| Example: 2013-10-15 13:00:00
 
| Example: 4 years, 90 days, 1 second
 
|}
 
 
 
==== Time intervals vs time instances ====
 
 
 
GRASS GIS supports both time intervals and time instances as map time stamps:
 
 
 
 
 
 
 
{|
 
! Time intervals
 
! Time instances
 
|-
 
| Defined by start time and end time: [start, end)
 
| Defined by start time
 
|-
 
| Support for gaps, allow overlapping, might contain time instances, might be irregularly spaced in time
 
| Punctual events
 
|}
 
 
 
==== Granularity ====
 
 
 
The granularity is the largest common divider granule of time intervals and gaps between intervals or instances from all time stamped maps that are collected in a STDS. It is represented as a number of seconds, minutes, hours, days, weeks, months or years.
 
 
 
=== Workflow overview ===
 
 
 
Now, how do we work with time series in GRASS GIS? Where do we start? Well, assuming we already have our maps in the GRASSDBASE, the first step is to set the connection to the temporal database. This is something we will need to do only once per mapset. After that, we create the STDSs, i.e.: the containers for the time series, and finally we assign time stamps to maps and register them in the STDS. After these basic steps, the following will depend on our specific objectives.
 
# Set and connect the temporal database (mapset specific): [https://grass.osgeo.org/grass72/manuals/t.connect.html t.connect]
 
# Create the STDS (raster, vector or raster 3D): [https://grass.osgeo.org/grass72/manuals/t.create.html t.create]
 
# Assign time stamps to maps and register them in the STDS: [https://grass.osgeo.org/grass72/manuals/t.register.html t.register]
 
# Check basic info, integrity and validity of STDS: [https://grass.osgeo.org/grass72/manuals/t.list.html t.list], [https://grass.osgeo.org/grass72/manuals/t.info.html t.info], [https://grass.osgeo.org/grass72/manuals/t.topology.html t.topology]
 
# Edit, update, unregister, remove maps and/or STDS: [https://grass.osgeo.org/grass72/manuals/t.rename.html t.rename], [https://grass.osgeo.org/grass72/manuals/t.remove.html t.remove], [https://grass.osgeo.org/grass72/manuals/t.support.html t.support], [https://grass.osgeo.org/grass72/manuals/t.unregister.html t.unregister]
 
# List maps, make selections, get univariate statistics: [https://grass.osgeo.org/grass72/manuals/t.rast.list.html t.rast.list], [https://grass.osgeo.org/grass72/manuals/t.vect.list.html t.vect.list], [https://grass.osgeo.org/grass72/manuals/t.select.html t.select], [https://grass.osgeo.org/grass72/manuals/t.rast.extract.html t.rast.extract], [https://grass.osgeo.org/grass72/manuals/t.vect.extract.html t.vect.extract], [https://grass.osgeo.org/grass72/manuals/t.rast.univar.html t.rast.univar], [https://grass.osgeo.org/grass72/manuals/t.vect.univar.html t.vect.univar]
 
# Spatio-temporal processing (a bit raster biased):
 
#* data aggregation: [https://grass.osgeo.org/grass72/manuals/t.rast.series.html t.rast.series], [https://grass.osgeo.org/grass72/manuals/t.rast.aggregate.html t.rast.aggregate], [https://grass.osgeo.org/grass72/manuals/t.rast.aggregate.ds.html t.rast.aggregate.ds]
 
#* data accumulation: [https://grass.osgeo.org/grass72/manuals/t.rast.accumulate.html t.rast.accumulate], [https://grass.osgeo.org/grass72/manuals/t.rast.accumulate.html t.rast.accumulate],
 
#* gap-filling and smoothing: [https://grass.osgeo.org/grass72/manuals/t.rast.gapfill.html t.rast.gapfill], [https://grass.osgeo.org/grass72/manuals/t.rast.neighbors.html t.rast.neighbors]
 
#* spatio-temporal algebra: [https://grass.osgeo.org/grass72/manuals/t.rast.mapcalc.html t.rast.mapcalc], [https://grass.osgeo.org/grass72/manuals/t.rast.algebra.html t.rast.algebra], [https://grass.osgeo.org/grass72/manuals/t.vect.algebra.html t.vect.algebra]
 
# Visualization: [https://grass.osgeo.org/grass72/manuals/g.gui.timeline.html g.gui.timeline], [https://grass.osgeo.org/grass72/manuals/g.gui.tplot.html g.gui.tplot], [https://grass.osgeo.org/grass72/manuals/g.gui.animation.html g.gui.animation], [https://grass.osgeo.org/grass72/manuals/g.gui.mapswipe.html g.gui.mapswipe]
 
 
 
== [[Hands-on to raster time series processing]] ==
 
 
 
=== Getting the MODIS satellite sensor data ===
 
 
 
MODIS is a payload scientific instrument on board the NASA Terra and the Aqua satellites with 36 spectral bands. Data are available for download upon [https://urs.earthdata.nasa.gov/users/new user registration].
 
Create the ''SETTING'' file with the following content, e.g. in the directory <code>$HOME/gisdata/</code>:<br />
 
<code> your_NASA_user your_NASA_password    </code>
 
 
 
The [https://grass.osgeo.org/grass72/manuals/addons/r.modis.download.html r.modis.download] directly downloads from the MODIS data server into a local folder previously created (for example: <code>lst_modis</code>):
 
 
 
<pre>       
 
r.modis.download -g settings=$HOME/gisdata/SETTING product=lst_terra_monthly_5600 tiles=h11v05 startday=&quot;2015-01-01&quot; endday=&quot;2016-12-31&quot; folder=$HOME/lst_monthly
 
r.modis.import -w files=$HOME/lst_monthly/listfileMOD11B3.006.txt spectral=&quot;( 1 )&quot; outfile=$HOME/lst_monthly/monthly_lst_to_register.txt
 
g.list type=raster pattern=&quot;MOD11B3*&quot;
 
 
 
 
 
# Create folder to store .hdf files
 
mkdir $HOME/lst_monthly
 
 
 
# Download data: MOD11B3 2015-2016, tile h11v05
 
r.modis.download -g settings=$HOME/gisdata/SETTING \
 
product=lst_terra_monthly_5600 \
 
tiles=h11v05 startday=&quot;2015-01-01&quot; endday=&quot;2016-12-31&quot; \
 
folder=$HOME/lst_monthly
 
 
 
# Reproject from Sinusoidal to current NC projection and import maps into NC Location (Day and Night overpasses)
 
r.modis.import -w files=$HOME/lst_monthly/listfileMOD11B3.006.txt \
 
spectral=&quot;( 1 )&quot; \
 
outfile=$HOME/lst_monthly/monthly_lst_to_register.txt
 
 
 
# Check list of imported maps
 
g.list type=raster pattern=&quot;MOD11B3*&quot;
 
 
 
 
 
# Import the needed libraries
 
import grass.pygrass.modules as gmod
 
import os
 
from subprocess import PIPE
 
 
 
# Set variables
 
# home
 
HOME=os.path.expanduser('~')
 
 
 
# Create folder to store .hdf files
 
os.makedirs(os.path.join(HOME, lst_monthly))
 
 
 
# Download data: MOD11B3 2015-2016, tile h11v05
 
gmod.Module(&quot;r.modis.download&quot;, flags=&quot;g&quot;, settings=os.path.join(HOME, 'gisdata', 'SETTING'),
 
product=&quot;lst_terra_monthly_5600&quot;, tiles=&quot;h11v05&quot;, startday=&quot;2015-01-01&quot;,
 
endday=&quot;2016-12-31&quot;, folder=os.path.join(HOME, lst_monthly)
 
 
 
# Reproject and import maps into NC Location (Day and Night)
 
gmod.Module(&quot;r.modis.import&quot;, flags=&quot;w&quot;, files=os.path.join(HOME, 'lst_monthly', 'listfileMOD11B3.006.txt'),
 
spectral=&quot;( 1 )&quot;, outfile=os.path.join(HOME, 'lst_monthly', 'monthly_lst_to_register.txt'))
 
 
 
# Check list of imported maps
 
glist = gmod.Module(&quot;g.list&quot;, type=&quot;raster&quot;, pattern=&quot;MOD11B3*&quot;, stdout_=PIPE, stderr_=PIPE)
 
print(glist.outputs[&quot;stdout&quot;].value)
 
</pre>
 
 
 
We will now visualize one of the MODIS LST images and add different map decorations. We first change the color palette from ''grey'' to ''viridis'' and set the computational region to the state of North Carolina (using <code>boundary_state</code> vector map).
 
 
 
 
 
 
 
<pre>       
 
r.colors MOD11B3.A2015060.h11v05.single_LST_Day_6km color=viridis
 
g.region -p vector=boundary_state
 
 
 
 
 
# Change color palette from grey to viridis
 
r.colors MOD11B3.A2015060.h11v05.single_LST_Day_6km color=viridis
 
 
 
# Set region to NC (g.region -d)
 
g.region -p vector=boundary_state
 
 
 
# Optionally, to the full extent of one of the raster maps
 
g.region -p raster=MOD11B3.A2015060.h11v05.single_LST_Day_6km
 
 
 
 
 
# Change color palette from grey to viridis
 
gmod.Module(&quot;r.colors&quot;, map=&quot;MOD11B3.A2015060.h11v05.single_LST_Day_6km&quot;, color=&quot;viridis&quot;)
 
 
 
# Set region to NC
 
gmod.Module(&quot;g.region&quot;, flags=&quot;p&quot;, vector=&quot;boundary_state&quot;)
 
 
 
# Optionally, to the full extent of one of the raster maps
 
gmod.Module(&quot;g.region&quot;, flags=&quot;p&quot;, raster=&quot;MOD11B3.A2015060.h11v05.single_LST_Day_6km&quot;)
 
</pre>
 
 
 
We can open a monitor and run the commands from the command line or do everything in the main GUI and copy the commands for future reference or replication. Note the ''Copy'' button in each command GUI.
 
 
 
<pre>       
 
# Open a monitor
 
d.mon wx0
 
 
 
# Display raster map
 
d.rast map=MOD11B3.A2015060.h11v05.single_LST_Day_6km
 
 
 
# Display vector map
 
d.vect map=boundary_state type=boundary
 
 
 
# Add raster legend
 
d.legend -t -s -b raster=MOD11B3.A2015060.h11v05.single_LST_Day_6km \
 
title=LST title_fontsize=20 font=sans fontsize=18
 
 
 
# Add scale bar
 
d.barscale length=200 units=kilometers segment=4 fontsize=14
 
 
 
# Add North arrow
 
d.northarrow style=1b text_color=black
 
 
 
# Add text
 
d.text -b text=&quot;LST Day from MOD11B3.006 - North Carolina - March, 2015&quot; \
 
color=black bgcolor=229:229:229 align=cc font=sans size=8
 
</pre>
 
 
 
<div class="imagebox">
 
 
 
[[File:figures/mod11b3_nc.png|display LST map with decorations]]<br />
 
MODIS LST map with decorations (scaled Kelvin pixel values)
 
 
 
</div>
 
=== Create temporal raster dataset (STRDS) ===
 
 
 
To create a space-time raster data set (STRDS) implies to create an SQLite table in the temporal database, i.e.: a container table, that will hold our raster time series and will allow us to easily handle huge amounts of maps by only using the STRDS as input in temporal commands.
 
 
 
If this is the first time you use the temporal framework, you need to create and set the connection to the temporal database by means of [https://grass.osgeo.org/grass72/manuals/t.connect.html t.connect]. As the temporal database is mapset specific, you'll need to repeat this step in each mapset in which you'll have STDSs.
 
 
 
Once the connection is set, you can create the empty STRDS, i.e.: the empty table, in which you'll put (aka: register) all your time series maps afterwards. For the creation of any STDS, we need to specify which '''type of maps''' (raster, raster3d or vector) the STDS will contain and which '''type of time''' (absolute or relative) the maps represent.
 
 
 
<pre>       
 
t.connect -d
 
t.create type=strds temporaltype=absolute output=LST_Day_monthly title=&quot;Monthly LST Day 5.6 km&quot; description=&quot;Monthly LST Day 5.6 km MOD11B3.006, 2015-2016&quot;
 
t.list type=strds
 
t.info input=LST_Day_monthly
 
 
 
 
 
# Create the temporal db connection
 
t.connect -d
 
 
 
# Create the STRDS
 
t.create type=strds temporaltype=absolute output=LST_Day_monthly \
 
title=&quot;Monthly LST Day 5.6 km&quot; \
 
description=&quot;Monthly LST Day 5.6 km MOD11B3.006, 2015-2016&quot;
 
 
 
# Check if the STRDS is created
 
t.list type=strds
 
 
 
# Get info about the STRDS
 
t.info input=LST_Day_monthly
 
 
 
 
 
import grass.temporal as tgis
 
 
 
# Create the temporal db connection using temporal library
 
gmod.Module(&quot;t.connect&quot;, flags=&quot;d&quot;)
 
 
 
# Initialize the temporal library
 
tgis.init()
 
 
 
# Create the new STRDS
 
tgis.open_new_stds(&quot;LST_Day_monthly&quot;, &quot;strds&quot;, &quot;absolute&quot;, &quot;Monthly LST Day 5.6 km&quot;,
 
                  &quot;Monthly LST Day 5.6 km MOD11B3.006, 2015-2016&quot;, &quot;mean&quot;, None, False)
 
# Connect to the SQL database interface
 
dbif = tgis.SQLDatabaseInterfaceConnection()
 
dbif.connect()
 
 
 
# Get and print the list of temporal dataset
 
stds_list = tgis.get_dataset_list(&quot;strds&quot;, &quot;absolute&quot;, dbif=dbif)
 
print(stds_list)
 
 
 
# Get and print info about the created strds
 
dataset = tgis.dataset_factory(&quot;strds&quot;, &quot;LST_Day_monthly@modis_lst&quot;)
 
dataset.select(dbif)
 
dataset.print_info()
 
</pre>
 
 
 
Once the STRDS is created, we assign time stamps to maps and add them to the STRDS, i.e.: we ''register'' maps in the STRDS. To register maps in a STDS, we need to pass the empty STDS as input and the list of maps to be registered. There are different ways to register maps in STDS. For more options, you can check the [https://grass.osgeo.org/grass72/manuals/t.register.html t.register] manual and the related [https://grasswiki.osgeo.org/wiki/Temporal_data_processing/maps_registration wiki] page.
 
 
 
<pre>       
 
t.register input=LST_Day_monthly file=$HOME/lst_monthly/monthly_lst_to_register.txt
 
 
 
 
 
# Register maps in STRDS
 
t.register input=LST_Day_monthly \
 
file=$HOME/lst_monthly/monthly_lst_to_tregister.txt
 
 
 
 
 
# Register maps using the Python function
 
gmod.Module(&quot;t.register&quot;, input=&quot;LST_Day_monthly@modis_lst&quot;,
 
            file=os.path.join(HOME, 'lst_monthly', 'monthly_lst_to_register.txt'))
 
</pre>
 
 
 
Alternatively, we could have registered our raster maps using the <code>maps</code>, <code>start</code> and <code>increment</code> options along with the <code>i</code> flag for interval creation. The command in that case would look as follows:
 
 
 
<pre>       
 
t.register -i input=LST_Day_monthly \
 
maps=`g.list type=raster pattern=MOD11B3*LST_Day* separator=comma` \
 
start=&quot;2015-01-01&quot; increment=&quot;1 months&quot;
 
</pre>
 
 
 
Let's check now the basic info again to see how it looks like and list the raster maps in our <code>LST_Day_monthly</code> STRDS:
 
 
 
<pre>       
 
t.info LST_Day_monthly
 
t.rast.list LST_Day_monthly
 
 
 
 
 
# Check info
 
t.info LST_Day_monthly
 
 
 
# Check the list of maps in the STRDS
 
t.rast.list LST_Day_monthly
 
 
 
 
 
# Get info using the modules
 
gmod.Module(&quot;t.info&quot;, input=&quot;LST_Day_monthly&quot;)
 
 
 
# Get list of raster using the Python library
 
tgis.list_maps_of_stds(&quot;strds&quot;, &quot;LST_Day_monthly@modis_lst&quot;, &quot;name,mapset,start_time,end_time&quot;,
 
                      &quot;start_time&quot;, &quot;&quot;, &quot;|&quot;, &quot;cols&quot;, True, &quot;no&quot;)
 
</pre>
 
 
 
Let's see our STRDS graphically. We will use the [https://grass.osgeo.org/grass72/manuals/g.gui.timeline.html g.gui.timeline] tool.
 
 
 
<pre>       
 
g.gui.timeline inputs=LST_Day_monthly
 
 
 
 
 
The tool g.gui.timeline is under the Temporal menu, in GUI Tools section. It can also be called from the terminal with: g.gui.timeline --ui.
 
 
 
To plot a STDS:
 
1. Choose a STRDS from the dropdown list.
 
2. Click the Draw button.
 
3. Change the margin settings as desired.
 
 
 
Alternatively, you can also get a 3D representation of the STDS (i.e.: x, y and time) by checking the 3D box.
 
 
 
 
 
 
 
Workflow for plotting STRDS with g.gui.timeline
 
 
 
 
 
<div class="imagebox">
 
 
 
[[File:figures/g_gui_timeline_lst_monthly.png|Timeline plot for LST_Day_monthly time series]]<br />
 
Timeline plot for LST_Day_monthly time series
 
 
 
</div>
 
=== [[|Temporal data analysis]] ===
 
 
 
One basic but very important function when handling hundreds or thousands of maps is the listing function, i.e.: we usually need to list maps that meet a certain condition. For example, we need maps which start month is June, maps with minimum values lower than 100, and so on. The GRASS GIS Temporal framework has different commands for that task: [https://grass.osgeo.org/grass72/manuals/t.list.html t.list] for listing STDS and maps registered in the temporal database, [https://grass.osgeo.org/grass72/manuals/t.rast.list.html t.rast.list] for maps in raster time series and, [https://grass.osgeo.org/grass72/manuals/t.vect.list.html t.vect.list] for maps in vector time series. All these commands allow us to list STDSs and/or maps according to different criteria. Let's see some examples with our <code>LST_Day_monthly</code> STRDS:
 
 
 
<pre>       
 
# Maps with minimum value lower than or equal to 14000
 
t.rast.list input=LST_Day_monthly order=min columns=name,start_time,min where=&quot;min &lt;= '14000'&quot;
 
 
 
name|start_time|min
 
MOD11B3.A2015032.h11v05.single_LST_Day_6km|2015-02-01 00:00:00|12950.0
 
MOD11B3.A2016032.h11v05.single_LST_Day_6km|2016-02-01 00:00:00|12964.0
 
MOD11B3.A2015001.h11v05.single_LST_Day_6km|2015-01-01 00:00:00|13022.0
 
 
 
# Maps with maximum value higher than 14000
 
t.rast.list input=LST_Day_monthly order=max columns=name,start_time,max where=&quot;max &gt; '14000'&quot;
 
 
 
name|start_time|max
 
MOD11B3.A2016001.h11v05.single_LST_Day_6km|2016-01-01 00:00:00|14360.0
 
MOD11B3.A2015001.h11v05.single_LST_Day_6km|2015-01-01 00:00:00|14396.0
 
MOD11B3.A2015032.h11v05.single_LST_Day_6km|2015-02-01 00:00:00|14522.0
 
 
 
# Maps between two given dates
 
t.rast.list input=LST_Day_monthly columns=name,start_time where=&quot;start_time &gt;= '2015-05' and start_time &lt;= '2015-08-01 00:00:00'&quot;
 
 
 
name|start_time
 
MOD11B3.A2015121.h11v05.single_LST_Day_6km|2015-05-01 00:00:00
 
MOD11B3.A2015152.h11v05.single_LST_Day_6km|2015-06-01 00:00:00
 
MOD11B3.A2015182.h11v05.single_LST_Day_6km|2015-07-01 00:00:00
 
MOD11B3.A2015213.h11v05.single_LST_Day_6km|2015-08-01 00:00:00
 
 
 
# Maps from January
 
t.rast.list input=LST_Day_monthly columns=name,start_time where=&quot;strftime('%m', start_time)='01'&quot;
 
 
 
name|start_time
 
MOD11B3.A2015001.h11v05.single_LST_Day_6km|2015-01-01 00:00:00
 
MOD11B3.A2016001.h11v05.single_LST_Day_6km|2016-01-01 00:00:00
 
 
 
# Maps from June, 1st
 
t.rast.list input=LST_Day_monthly columns=name,start_time where=&quot;strftime('%m-%d', start_time)='06-01'&quot;
 
 
 
name|start_time
 
MOD11B3.A2015152.h11v05.single_LST_Day_6km|2015-06-01 00:00:00
 
MOD11B3.A2016153.h11v05.single_LST_Day_6km|2016-06-01 00:00:00
 
</pre>
 
 
 
To explore a bit more our time series, we will obtain univariate statistics for the maps in the STRDS. There's a dedicated module for that: [https://grass.osgeo.org/grass72/manuals/t.rast.univar.html t.rast.univar]. There's also the possibility to obtain extended statistics such as first quartile, median value, third quartile and percentile 90 by setting the <code>e</code> flag. Let's see:
 
 
 
<pre>       
 
t.rast.univar input=LST_Day_monthly
 
 
 
id|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells
 
MOD11B3.A2015001.h11v05.single_LST_Day_6km@modis_lst|2015-01-01 00:00:00|2015-02-01 00:00:00|13920.4954589617|13022|14396|13920.4954589617|204.922713367766|41993.3184540075|1.47209353267553|329539889|51297|74970
 
MOD11B3.A2015032.h11v05.single_LST_Day_6km@modis_lst|2015-02-01 00:00:00|2015-03-01 00:00:00|13850.5832593907|12950|14522|13850.5832593907|269.511406162359|72636.3980516119|1.94584878567933|327801754|51303|74970
 
MOD11B3.A2015060.h11v05.single_LST_Day_6km@modis_lst|2015-03-01 00:00:00|2015-04-01 00:00:00|14387.8026526992|13771|14913|14387.8026526992|202.223782537869|40894.4582239235|1.40552235403321|340616840|51296|74970
 
MOD11B3.A2015091.h11v05.single_LST_Day_6km@modis_lst|2015-04-01 00:00:00|2015-05-01 00:00:00|14724.7657768016|14160|15212|14724.7657768016|127.152673621415|16167.8024090742|0.863529346060911|348594105|51296|74970
 
 
 
t.rast.univar -e input=LST_Day_monthly
 
 
 
id|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|first_quartile|median|third_quartile|percentile_90
 
MOD11B3.A2015001.h11v05.single_LST_Day_6km@modis_lst|2015-01-01 00:00:00|2015-02-01 00:00:00|14063.8152535675|13625|14289|14063.8152535675|104.326695294161|10884.0593510007|0.741809341300163|12313517190|135054|1010600|14001|14076|14148|14183
 
MOD11B3.A2015032.h11v05.single_LST_Day_6km@modis_lst|2015-02-01 00:00:00|2015-03-01 00:00:00|14040.1111911881|13532|14349|14040.1111911881|128.052778812874|16397.5141616988|0.912049606083195|12292763193|135054|1010600|13944|14059|14140|14190
 
MOD11B3.A2015060.h11v05.single_LST_Day_6km@modis_lst|2015-03-01 00:00:00|2015-04-01 00:00:00|14509.6026765013|14012|14884|14509.6026765013|128.58386990137|16533.8115988123|0.886198421612294|12703824585|135054|1010600|14417|14523|14599|14664
 
MOD11B3.A2015091.h11v05.single_LST_Day_6km@modis_lst|2015-04-01 00:00:00|2015-05-01 00:00:00|14781.4240850852|14160|15128|14781.4240850852|116.594077815457|13594.1789816369|0.788787853892261|12941816732|135054|1010600|14724|14802|14859|14907
 
 
 
t.rast.univar input=LST_Day_monthly separator=comma output=stats_LST_Day_monthly.csv
 
 
 
 
 
# Print univariate stats for maps within STRDS
 
t.rast.univar input=LST_Day_monthly
 
 
 
# Get extended statistics
 
t.rast.univar -e input=LST_Day_monthly
 
 
 
# Write the univariate stats output to a csv file
 
t.rast.univar input=LST_Day_monthly separator=comma output=stats_LST_Day_monthly.csv
 
 
 
 
 
# Print univarite statistics with the Python library
 
tgis.print_gridded_dataset_univar_statistics(&quot;strds&quot;, &quot;LST_Day_monthly@modis_lst&quot;, None, None, False, False, &quot;,&quot;, False)
 
 
 
# Print extended univarite statistics with the Python library
 
tgis.print_gridded_dataset_univar_statistics(&quot;strds&quot;, &quot;LST_Day_monthly@modis_lst&quot;, None, None, True, False, &quot;,&quot;, False)
 
 
 
 
 
</pre>
 
 
 
However, those statistics are a bit difficult to directly interpret since values are in °K*50. Let's re-scale the data to °C and run the previous command again. Then, we will set a proper color palette for the STRDS and display one map. The latter, you already know how to do.
 
 
 
To transform all the maps in our <code>LST_Day_monthly</code> time series into °C we will use the [https://grass.osgeo.org/grass72/manuals/t.rast.algebra.html t.rast.algebra] module. This module allows us to perform a very wide variety of operations in the temporal and spatial domains, as well as much of the more ''&quot;classical&quot;'' operations already available in [https://grass.osgeo.org/grass72/manuals/r.mapcalc.html r.mapcalc].
 
 
 
<pre>       
 
t.rast.algebra basename=LST_Day_monthly_celsius expression=&quot;LST_Day_monthly_celsius = LST_Day_monthly * 0.02 - 273.15&quot;
 
t.rast.univar input=LST_Day_monthly_celsius
 
t.rast.colors input=LST_Day_monthly_celsius color=celsius
 
 
 
 
 
# Re-scale data into degrees Celsius
 
t.rast.algebra basename=LST_Day_monthly_celsius \
 
expression=&quot;LST_Day_monthly_celsius = LST_Day_monthly * 0.02 - 273.15&quot;
 
 
 
# Print univariate stats
 
t.rast.univar input=LST_Day_monthly_celsius
 
 
 
# Set a dedicated color pallete
 
t.rast.colors input=LST_Day_monthly_celsius color=celsius
 
 
 
# Re-scale data into degrees Celsius
 
gmod.Module(&quot;t.rast.algebra&quot;, basename=&quot;LST_Day_monthly_celsius&quot;,
 
            expression=&quot;LST_Day_monthly_celsius = LST_Day_monthly * 0.02 - 273.15&quot;)
 
 
 
# Print univarite statistics with the Python library
 
tgis.print_gridded_dataset_univar_statistics(&quot;strds&quot;, &quot;LST_Day_monthly_celsius@modis_lst&quot;, None, None, False, False, &quot;,&quot;, False)
 
gmod.Module(&quot;t.rast.colors&quot;, input=&quot;LST_Day_monthly_celsius&quot;, color=&quot;celsius&quot;)
 
</pre>
 
 
 
<div class="imagebox">
 
[[File:figures/lst_modis_celsius.png|LST MODIS in degrees Celsius]]<br />
 
MODIS LST re-scaled to degrees Celsius
 
</div>
 
 
 
Alternatively, we could have used [https://grass.osgeo.org/grass72/manuals/t.rast.mapcalc.html t.rast.mapcalc] to perform the previous transformation. The command would look like this:
 
 
 
<pre>       
 
t.rast.mapcalc input=LST_Day_monthly output=LST_Day_monthly_celsius basename=LST_Day_monthly_celsius expression=&quot;LST_Day_monthly * 0.02 - 273.15&quot;
 
</pre>
 
 
 
=== Temporal aggregations ===
 
 
 
There are basically two dedicated modules to perform temporal aggregations in GRASS GIS. The first one that we will use is [https://grass.osgeo.org/grass72/manuals/t.rast.series.html t.rast.series]. This module is a wrapper for [https://grass.osgeo.org/grass72/manuals/r.series.html r.series] and allows us to aggregate our STRDS or parts of it with different methods. We will use it now to obtain the absolute maximum LST in the past two years.
 
 
 
<pre>       
 
t.rast.series input=LST_Day_monthly_celsius output=LST_Day_max method=maximum
 
r.colors map=LST_Day_max color=celsius
 
d.mon wx0
 
d.rast LST_Day_max
 
d.vect map=boundary_state type=boundary
 
d.legend -t -s -b raster=LST_Day_max title=LST title_fontsize=20 font=sans fontsize=18
 
d.barscale length=200 units=kilometers segment=4 fontsize=14
 
d.northarrow style=1b text_color=black
 
d.text -b text=&quot;Maximum LST in the period 2015-2016 - North Carolina&quot; color=black bgcolor=229:229:229 align=cc font=sans size=8
 
 
 
 
 
# Get maximum LST in the STRDS
 
t.rast.series input=LST_Day_monthly_celsius \
 
output=LST_Day_max method=maximum
 
 
 
# Change color pallete to celsius
 
r.colors map=LST_Day_max color=celsius
 
 
 
# Display the new map
 
d.mon wx0
 
d.rast LST_Day_max
 
d.vect map=boundary_state type=boundary
 
d.legend -t -s -b raster=LST_Day_max \
 
title=LST title_fontsize=20 font=sans fontsize=18
 
d.barscale length=200 units=kilometers segment=4 fontsize=14
 
d.northarrow style=1b text_color=black
 
d.text -b text=&quot;Maximum LST in the period 2015-2016 - North Carolina&quot; \
 
  color=black bgcolor=229:229:229 align=cc font=sans size=8
 
 
 
# Get maximum LST in the STRDS
 
gmod.Module(&quot;t.rast.series&quot;, input=&quot;LST_Day_monthly_celsius&quot;,
 
            output=&quot;LST_Day_max&quot;, method=&quot;maximum&quot;)
 
 
 
# Change color pallete to celsius
 
gmod.Module(&quot;r.colors&quot;, map=&quot;LST_Day_max&quot;, color=&quot;celsius&quot;)
 
</pre>
 
 
 
<div class="imagebox">
 
[[File:figures/max_lst.png|Maximum LST 2015-2016]]<br />
 
Maximum LST in the period 2015-2016 in North Carolina
 
</div>
 
 
 
Now, by means of the spatio-temporal map calculator, we will get the month in which the absolute maximum LST occurred. For that, we will first compare our <code>LST_Day_monthly_celsius</code> STRDS with the map of absolute maximum LST <code>LST_Day_max</code> that we just obtained before. If they coincide, we keep the month for that pixel, otherwise it will be NULL. Then, we aggregate the resulting <code>month_max_lst</code> STRDS with <code>t.rast.series method=maximum</code> and we get the map with the pixelwise month in which the absolute maximum LST has occurred in the past two years. Finally, we remove the intermediate STRDS, since we are only interested in the aggregated map.
 
 
 
<pre>       
 
t.rast.mapcalc -n inputs=LST_Day_monthly_celsius output=month_max_lst expression=&quot;if(LST_Day_monthly_celsius == LST_Day_max, start_month(), null())&quot; basename=month_max_lst
 
t.rast.series input=month_max_lst method=maximum output=max_lst_date
 
t.remove -rf inputs=month_max_lst
 
 
 
# New strds with month of overall maximum
 
t.rast.mapcalc -n inputs=LST_Day_monthly_celsius output=month_max_lst \
 
expression=&quot;if(LST_Day_monthly_celsius == LST_Day_max, start_month(), null())&quot; \
 
basename=month_max_lst
 
 
 
# Get basic info
 
t.info month_max_lst
 
 
 
# Map with month of overall maximum
 
t.rast.series input=month_max_lst method=maximum output=max_lst_date
 
 
 
# Remove month_max_lst strds (we were only interested in the resulting aggregated map)
 
t.remove -rf inputs=month_max_lst
 
 
 
# New strds with month of overall maximum
 
gmod.Module(&quot;t.rast.mapcalc&quot;, flags=&quot;n&quot;, inputs=&quot;LST_Day_monthly_celsius&quot;, output=&quot;month_max_lst&quot;,
 
            expression=&quot;if(LST_Day_monthly_celsius == LST_Day_max, start_month(), null())&quot;,
 
            basename=&quot;month_max_lst&quot;)
 
 
 
# Map with month of overall maximum
 
gmod.Module(&quot;t.rast.series&quot;, input=&quot;month_max_lst&quot;, method=&quot;maximum&quot;, output=&quot;max_lst_date&quot;)
 
 
 
# Remove month_max_lst strds
 
gmod.Module(&quot;t.remove&quot;, flags=&quot;rf&quot;, inputs=&quot;month_max_lst&quot;)
 
</pre>
 
 
 
Note that the flags <code>&quot;-rf&quot;</code> force (immediate) removal of both the STRDS (i.e.: the container table) and the maps registered in it.
 
 
 
Finally, we display the resulting map:
 
 
 
<pre>       
 
d.mon wx0
 
d.rast max_lst_date
 
d.vect map=boundary_state type=boundary
 
d.legend -t -s -b raster=max_lst_date title=LST title_fontsize=20 font=sans fontsize=18
 
d.barscale length=200 units=kilometers segment=4 fontsize=14
 
d.northarrow style=1b text_color=black
 
d.text -b text=&quot;Month of maximum LST 2015-2016&quot; color=black bgcolor=229:229:229 align=cc font=sans size=8
 
</pre>
 
 
 
<div class="imagebox">
 
[[File:figures/month_max_lst.png|Month of maximum LST]]<br />
 
Month of maximum LST for the period 2015-2016
 
</div>
 
 
 
The other module that allows us to perform temporal aggregations is [https://grass.osgeo.org/grass72/manuals/t.rast.aggregate.html t.rast.aggregate]. With this module we are able to aggregate raster maps in our STRDS with different granularities. Note that this module also has the option <code>where</code> that allows us to set specific dates for the aggregation. We will use this module to get 3-month and 6-month average LST.
 
 
 
<pre>       
 
t.rast.aggregate input=LST_Day_monthly_celsius output=LST_Day_mean_3month basename=LST_Day_mean_3month suffix=gran method=average granularity=&quot;3 months&quot;
 
t.info LST_Day_mean_3month
 
t.rast.list LST_Day_mean_3month
 
 
 
t.rast.aggregate input=LST_Day_monthly_celsius output=LST_Day_mean_6month basename=LST_Day_mean_6month suffix=gran method=average granularity=&quot;6 months&quot;
 
t.info LST_Day_mean_6month
 
t.rast.list LST_Day_mean_6month
 
 
 
# 3-month mean LST
 
t.rast.aggregate input=LST_Day_monthly_celsius \
 
output=LST_Day_mean_3month \
 
basename=LST_Day_mean_3month suffix=gran \
 
method=average granularity=&quot;3 months&quot;
 
 
 
# Print info
 
t.info LST_Day_mean_3month
 
 
 
# Print list of maps
 
t.rast.list LST_Day_mean_3month
 
 
 
# 6-month mean LST
 
t.rast.aggregate input=LST_Day_monthly_celsius \
 
output=LST_Day_mean_6month \
 
basename=LST_Day_mean_6month suffix=gran \
 
method=average granularity=&quot;6 months&quot;
 
 
 
# Print info
 
t.info LST_Day_mean_6month
 
 
 
# Print list of maps
 
t.rast.list LST_Day_mean_6month
 
 
 
# 3-month mean LST
 
gmod.Module(&quot;t.rast.aggregate&quot;, input=&quot;LST_Day_monthly_celsius&quot;, output=&quot;LST_Day_mean_3month&quot;,
 
            basename=&quot;LST_Day_mean_3month&quot;, suffix=&quot;gran&quot;, method=&quot;average&quot;, granularity=&quot;3 months&quot;)
 
 
 
# Get and print info about LST_Day_mean_3month strds in shell output format
 
dataset = tgis.dataset_factory(&quot;strds&quot;, &quot;LST_Day_mean_3month@modis_lst&quot;)
 
dataset.select(dbif)
 
dataset.print_shell_info()
 
 
 
# Print list of maps
 
tgis.list_maps_of_stds(&quot;strds&quot;, &quot;LST_Day_mean_3month@modis_lst&quot;, &quot;name,mapset,start_time,end_time&quot;,
 
                      &quot;start_time&quot;, &quot;&quot;, &quot;|&quot;, &quot;cols&quot;, True, &quot;no&quot;)
 
# 6-month mean LST
 
gmod.Module(&quot;t.rast.aggregate&quot;, input=&quot;LST_Day_monthly_celsius&quot;, output=&quot;LST_Day_mean_6month&quot;,
 
            basename=&quot;LST_Day_mean_6month&quot;, suffix=&quot;gran&quot;, method=&quot;average&quot;, granularity=&quot;6 months&quot;)
 
 
 
# Get and print info about LST_Day_mean_6month strds
 
gmod.Module(&quot;t.info&quot;, input=&quot;LST_Day_mean_6month&quot;)
 
 
 
# Print list of maps
 
gmod.Module(&quot;t.rast.list&quot;, input=&quot;LST_Day_mean_6month&quot;)
 
</pre>
 
 
 
Now, we will extract the 3-month average LST for points in a vector map. We will use the vector map <code>points_of_interest</code> that is already available in the PERMANENT mapset of NC Location. There are different commands that allow us to perform this task, but we'll use [https://grass.osgeo.org/grass72/manuals/t.rast.what.html t.rast.what]. This module samples a STRDS at specific vector point coordinates and writes the output to stdout using different layouts. You might explore the options available in the parameter <code>layout</code> to see the different ways to write the output.
 
 
 
<pre>       
 
t.rast.what points=points_of_interest strds=LST_Day_mean_6month output=trastwhat_output.csv null_value=NA separator=comma
 
 
t.rast.what points=points_of_interest strds=LST_Day_mean_6month output=trastwhat_output.csv \
 
null_value=NA separator=comma
 
 
 
gmod.Module(&quot;t.rast.what&quot;, points=&quot;points_of_interest&quot;, strds=&quot;LST_Day_mean_6month&quot;,
 
            output=&quot;trastwhat_output.csv&quot;, null_value=&quot;NA&quot;, separator=&quot;comma&quot;)
 
</pre>
 
 
 
Even though the most common is to extract raster data to points, we may also be interested in getting spatially aggregated time series data for polygons. GRASS GIS has an add-on for this: [https://grass.osgeo.org/grass72/manuals/addons/v.strds.stats.html v.strds.stats]. It calculates zonal statistics of each raster in a STRDS and writes the output to the attribute table of a new polygon vector map. We first need to install the add-on through [https://grass.osgeo.org/grass72/manuals/g.extension.html g.extension]. Then, we will extract the average, minimum and maximum monthly LST for the different geologic types in NC.
 
 
 
<pre>       
 
g.extension v.strds.stats
 
v.strds.stats input=geology strds=LST_Day_monthly_celsius output=geology_aggr_lst method=average,minimum,maximum
 
v.db.select map=geology_aggr_lst file=ts_polygons.csv
 
 
 
# Install v.strds.stats add-on
 
g.extension v.strds.stats
 
 
 
# Extract mean, max and min LST for municipalities
 
v.strds.stats input=geology strds=LST_Day_monthly_celsius \
 
output=geology_aggr_lst method=average,minimum,maximum
 
 
 
# Save the attribute table of the new vector into a csv file
 
v.db.select map=geology_aggr_lst file=ts_polygons.csv
 
 
 
# Install v.strds.stats add-on
 
gmod.Module(&quot;g.extension&quot;, extension=&quot;v.strds.stats&quot;)
 
 
 
# Extract mean, max and min LST for municipalities
 
gmod.Module(&quot;v.strds.stats&quot;, input=&quot;geology&quot;, output=&quot;geology_aggr_lst&quot;,
 
            strds=&quot;LST_Day_monthly_celsius&quot;, method=&quot;average,minimum,maximum&quot;)
 
 
 
# Save the attribute table of the new vector into a csv file
 
gmod.Module(&quot;v.db.select&quot;, map=&quot;geology_aggr_lst&quot;, file=&quot;ts_polygons.csv&quot;)
 
</pre>
 
=== Temporal data visualization ===
 
 
 
Aside from g.gui.timeline that we saw before, GRASS GIS offers different options to visualize time series data. The first one is [https://grass.osgeo.org/grass72/manuals/g.gui.mapswipe.html g.gui.mapswipe] that allows us to compare two maps from different dates for example by swiping a visibility bar. The module can be called from command line by specifying the two maps to compare or executed from the GUI as shown below in the respective tabs.
 
 
 
<pre>       
 
g.gui.mapswipe first=LST_Day_monthly_celsius_6 second=LST_Day_monthly_celsius_12
 
 
 
1. Select first and second map from the dropdown map lists.
 
2. Swipe as desired. Optionally you can change the swipe orientation or switch maps with the tools button.
 
3. Change to &quot;Mirror mode&quot; to see the exact same position in both maps.
 
</pre>
 
 
 
Another tool to visualize time series in more dynamic way and that allows us to see changes in space an time simultaneously is [https://grass.osgeo.org/grass72/manuals/g.gui.animation.html g.gui.animation]. It also allows to animate vector time series, as well as lists of raster or vector maps not specifically registered as time series. When executed from command line, options are more limited than when the module is run from the GUI, where it is possible to add different decorations and customize several options.
 
 
 
<pre>       
 
g.gui.animation strds=LST_Day_monthly_celsius@modis_lst
 
 
 
1. Add a new animation (you can add up to 4 animations).
 
2, 3, 4. Add a space time data set (vector or raster) or list of raster or vector maps.
 
5. Optionally, add vector maps such as boundaries, points of interest, etc.
 
6. Once you finished adding maps and customizing their display, click OK.
 
7. Play the animation (note that you can move forwards or backwards, pause, stop, change velocity).
 
8. Export the animation.
 
9. Add decorations such as text, time stamp, images, if desired.
 
10. Select folder and file name (Note that this step slightly varies according to the output format desired).
 
11. Click Export.
 
</pre>
 
 
 
Finally, if you want to plot the time series of our variable of interest, be it in a STRDS or a STVDS, for a specific point of your study region, GRASS GIS has [https://grass.osgeo.org/grass72/manuals/g.gui.tplot.html g.gui.tplot]. Basically, you need to set the strds or stvds and a pair of X,Y coordinates. The latter can be typed directly, copied from the map display and pasted or directly chosen from the display. See instructions below.
 
 
 
<pre>       
 
g.gui.tplot strds=LST_Day_monthly_celsius@modis_lst coordinates=419604.018913,215736.80063
 
 
 
1. Select the STRDS.
 
2. Type coordinates or select a point in the display (use the arrow at the end of the second line).
 
3. Click Draw.
 
4. Inspect values for specific dates.
 
 
 
Alternatively, you can adjust the margin settings, zoom in to different parts of the plots and save it.
 
</pre>
 
 
 
== Other (very) useful links ==
 
 
 
* GRASS intro workshop: https://ncsu-osgeorel.github.io/grass-intro-workshop/
 
* Unleash the power of GRASS GIS: https://grasswiki.osgeo.org/wiki/Unleash_the_power_of_GRASS_GIS_at_US-IALE_2017
 
* Temporal data processing wiki: https://grasswiki.osgeo.org/wiki/Temporal_data_processing
 
* GRASS GIS temporal workshop: http://ncsu-geoforall-lab.github.io/grass-temporal-workshop/
 
* GRASS GIS and R for time series processing: https://grasswiki.osgeo.org/wiki/Temporal_data_processing/GRASS_R_raster_time_series_processing
 
 
 
== References ==
 
 
 
* Gebbert, S., Pebesma, E. (2014). ''A temporal GIS for field based environmental modeling''. Environmental Modelling &amp; Software, 53, 1–12. [https://doi.org/10.1016/j.envsoft.2013.11.001 DOI]
 
* Gebbert, S., Pebesma, E. (2017). ''The GRASS GIS temporal framework''. International Journal of Geographical Information Science 31, 1273-1292. [http://dx.doi.org/10.1080/13658816.2017.1306862 DOI]
 
* Neteler, M., Bowman, M.H., Landa, M. and Metz, M. (2012): ''GRASS GIS: a multi-purpose Open Source GIS''. Environmental Modelling &amp; Software, 31: 124-130 [http://dx.doi.org/10.1016/j.envsoft.2011.11.014 DOI]
 
* Neteler, M., Mitasova, H. (2008): ''Open Source GIS: A GRASS GIS Approach''. Third edition. ed. Springer, New York. [https://grassbook.org/ Book site]
 
 
 
-----
 
 
 
''Last changed: 2017-07-17 20:17''
 
 
 
[http://grass.osgeo.org/grass72/manuals/ GRASS GIS manual main index] | [http://grass.osgeo.org/grass72/manuals/temporal.html Temporal modules index] | [http://grass.osgeo.org/grass72/manuals/topics.html Topics index] | [http://grass.osgeo.org/grass72/manuals/keywords.html Keywords Index] | [http://grass.osgeo.org/grass72/manuals/full_index.html Full index]
 
 
 
[http://creativecommons.org/licenses/by-sa/4.0/ [[File:ccbysa.png|Creative Commons License]]]<br />
 
TGRASS: temporal data processing with GRASS GIS Workshop at FOSS4G Europe 2017 by Veronica Andreo, Luca Delucchi and Markus Neteler is licensed under a '''[https://creativecommons.org/licenses/by-sa/4.0/ Creative Commons Attribution-ShareAlike 4.0 International License]''' - Thanks to [http://www4.ncsu.edu/~vpetras/index.html '''Vaclav Petras'''] for the style.
 

Latest revision as of 12:04, 20 March 2018

TGRASS: temporal data processing with GRASS GIS

FOSS4G Europe 2017 workshop

Veronica Andreo, Luca Delucchi and Markus Neteler

Please see: https://github.com/veroandreo/tgrass_workshop_foss4g_eu