Intro to GRASS GIS

Basic notions, interfaces and temporal framework

Author

Veronica Andreo

Published

July 1, 2024

Open GRASS for the first time

When you open GRASS you’ll get both the terminal and the graphical user interface (GUI). You can use GRASS tools in either. It’s a matter of taste, task on hand and habit, too.

GRASS GUI has a single window layout by default, but it is also possible to minimize and/or dock/undock the panels. On the right, you can find the data browser which allows you to navigate through your projects and data, and the layers panel showing displayed layers. The panel in the middle is the map display. You can add additional ones if you need. Finally, on the right there are multiple tabs where you can find a searchable tools’ tree similar to the Processing toolbox in QGIS, a console where you can type GRASS commands, the history of executed commands in case you want to re-run a task and a simple Python console where you can use the GRASS Python API.

From the data panel you can manage several actions and, if you do not yet have imported data into your GRASS project, the software creates a project with demo data automatically.

Database

  • GRASS database (directory with projects): When running GRASS GIS for the first time, a folder named grassdata is automatically created. Depending on the operating system, it can be found in $HOME (*nix) or My Documents (MS Windows).
  • Project: GRASS projects are simply folders storing your geospatial data with common coordinate reference system (CRS), ensuring consistency of your data.
  • Mapset: Data is further organized into subprojects called mapsets, which you can use to manage different subregions or analyses within a project. When creating a new project, GRASS GIS automatically creates a special mapset called PERMANENT which is used to store source datasets for your analysis that can be easily accessed from other mapsets.

Computational region

A very useful concept when working with raster data is that of the computational region. It refers to the boundaries and spatial resolution of the analysis area. The computational region can be defined and modified with the tool g.region to the extent of a vector map, a raster or manually to some area of interest. The output raster maps will have an extent and spatial resolution equal to the computational region, while vector maps are always processed at their original extent.

Note

For more details, see the wiki on Computational Region.

Tools

GRASS has more than 500 tools for the most varied tasks:

Prefix Function class Type of command Example
g.* general general data management g.rename: renames map
d.* display graphical output d.rast: display raster map
r.* raster raster processing r.mapcalc: map algebra
v.* vector vector processing v.clean: topological cleaning
i.* imagery imagery processing i.pca: Principal Components Analysis on imagery group
r3.* voxel 3D raster processing r3.stats: voxel statistics
db.* database database management db.select: select value(s) from table
ps.* postscript PostScript map creation ps.map: PostScript map creation
t.* temporal space-time datasets t.rast.aggregate: raster time series aggregation

Extensions or add-ons can be installed from the central GitHub repository or from other users’ GitHub (or similar repositories) using the command g.extension. For example:

 # install an extension from the GRASS GIS repository
 g.extension extension=r.hants
 
 # install an extension from another GitHub repository
 g.extension extension=r.change.stats \
   url=https://github.com/mundialis/r.change.stats

GRASS +

There are different Python libraries delivered with GRASS GIS, we’ll use 2 of them:

  • grass.script which provides Python interface to launch GRASS GIS modules in scripts
  • grass.jupyter which offers classes and setup functions for running GRASS GIS in Jupyter Notebooks

Other Python libraries delivered with GRASS GIS include: pygrass, the temporal framework, the testing framework, among others.

We can use Python within GRASS GUI, within Jupyter notebooks, or from our preferred IDE. See the options within the GUI:

GRASS + through rgrass package

We can use R within a GRASS GIS session or use GRASS GIS within an R session. We’ll explore this further in the last part of this session.

Demo session overview

Habitat suitability mapping for the Asian tiger mosquito in Northern Italy based on variables derived from daily LST data

  • GRASS
    • Import species records
    • Create random background points
    • Create different environmental layers from daily LST data
  • R
    • Read data from GRASS into R
    • Model species distribution
    • Model evaluation
    • Visualization of results

Data for the session

  • Records of Aedes albopictus (Asian tiger mosquito) in Northern Italy downloaded from GBIF
  • Average daily MODIS LST reconstructed by mundialis GmbH & Co. KG based on Metz et al. (2017):
    • 1 km spatial resolution
    • Converted to Celsius degrees

Get the sample project

  • Create a folder named grass_foss4geu_2024
  • Within grass_foss4geu_2024 create a folder named grassdata
  • Download the eu_laea project with LST mapset and unzip it within your grassdata folder
  • Download mosquito data and drop it within grass_foss4geu_2024

The grass_foss4geu_2024 folder’s tree should look like this:

  grass_foss4geu_2024/
  ├── aedes_albopictus.gpkg
  └── grassdata
      └── eu_laea
          ├── italy_LST_daily
          └── PERMANENT

GRASS GIS HELP!!!

References

Metz, M., Andreo, V., and Neteler, M. (2017), “A New Fully Gap-Free Time Series of Land Surface Temperature from MODIS LST Data,” Remote Sensing, 9, 1333. https://doi.org/10.3390/rs9121333.

:::