Unit 09 - Model tuning

Let’s improve our NDVI model created in Unit 08 - Modeler. The model operates in a current computation region, it would be better to define region based on user input.

NDVI values range from +1.0 to -1.0. Areas of barren rock, sand, or snow usually show very low NDVI values (less than 0.1). Sparse vegetation such as shrubs and grasslands or senescing crops may result in moderate NDVI values (approximately between 0.2 and 0.5). High NDVI values (approximately between 0.6 and 1.0) correspond to dense vegetation such as that found in temperate and tropical forests or crops at their peak growth stage. Let’s classify NDVI into 3 major classes:

  • Class 1: from -1.0 to 0.2

  • Class 2: from 0.2 to 0.6

  • Class 3: from 0.6 to 1.0

The desired output will be a simplified raster map with NDVI classes.

From GRASS perspective a computation workflow may be decomposed to the following steps:

  1. Erase cloud mask in input region (v.overlay: not operator)

  2. Set computation region based on modified input region (g.region)

  3. Set mask (r.mask)

  4. Compute NDVI values (i.vi)

  5. Reclassify NDVI values into classes (r.recode)

  6. Remove small areas (r.reclass.area)

  7. Fill holes (removed small areas) with adjacent area class (r.grow.distance)

  8. Set desired color table for NDVI classes (r.colors)

Overview of commands below:

v.overlay ainput=jena_boundary binput=MaskFeature operator=not output=region_mask
g.region vector=region_mask align=L2A_T32UPB_20170706T102021_B04_10m
r.mask -r
r.mask vector=region_mask
i.vi red=L2A_T32UPB_20170706T102021_B04_10m output=ndvi nir=L2A_T32UPB_20170706T102021_B08_10m
r.recode input=ndvi output=ndvi_class rules=reclass.txt
r.reclass.area input=ndvi_class output=ndvi_class_area mode=greater value=0.16
r.grow.distance input=ndvi_class_area value=ndvi_class_filled
r.colors map=ndvi_class_filled rules=colors.txt

Note

Small areas can be also removed by vector-based workflow:

r.to.vect -s -v input=ndvi_class output=ndvi_class type=area
v.clean input=ndvi_class output=ndvi_class_filled tool=rmarea threshold=1600
v.colors map=ndvi_class_filled raster=ndvi_class

Note that area in r.reclass.area is provided in hectares whereas in the case of v.clean it is given in square metres.

The tools can be added to the existing model by grass-module-add Add GRASS tool (module) to model. Note that newly added tools are placed at the end of a computation workflow which is not desired. Commands order can be changed in Items tab.

../_images/reorder-items.png

Fig. 58 Reorder model items (GRASS tools) by Up/Down buttons. In this case move v.overlay up to the first position.

Note

Don’t forget to align region bounds to input raster data (use align option in g.region tool).

Reclassification of floating point raster maps can be done by r.recode. An example of reclassification table:

-1:0.2:1
0.2:0.6:2
0.6:1:3

Beside predefined color tables r.colors (see Color table section) also allows to use user-defined color table by rules option. In our case a color table can be quite simple:

1 grey
2 yellow
3 green

Tip

Reclassification and color table is recommended to be stored into files otherwise it can be lost when opening model next time: reclass.txt and colors.txt

../_images/model-v2.png

Fig. 59 Extended model.

Sample model to download: ndvi-v2.gxm (note: don’t forget to fix path to reclass and colors file for r.recode and r.colors modules)

Parameterization

The model has all parameters hard-coded. User lacks possibility to control input parameters before running model.

In Graphical Modeler a user input can be defined by two mechanisms:

  • parametrization of tools parameters

  • using user-defined variables (ideal when multiple tools are sharing same user-defined input value)

In our case the model will be modified by its parametrization. Change the model in order to provide the user ability to:

  • define own area of interest (ainput option in v.overlay)

  • set threshold for small areas (value option in r.reclass.area)

To parameterize a command open its properties dialog. Option parametrization can be easily enabled by Parameterized in model checkbox as shown below.

../_images/parametrize-cmd.png

Fig. 60 Parametrization of ainput option for v.overlay command.

Note

Parameterized tools are highlighted in the model by a bold border.

After pressing grass-execute Run model the model is not run immediately. GUI dialog is shown to allow entering user-defined parameters before lauching model computation.

../_images/model-params.png

Fig. 61 Parameterized options are organized into tabs based on relevant tools.

After setting the input parameters the model can be Run.

Tip

Saved models can be run directly from Layer Manager File ‣ Run model without opening Graphical Model itself.

Task

Test the model with different settings.

../_images/ndvi-no-reduction.png

Fig. 62 NDVI classes without small area reduction.

../_images/ndvi-2000m2.png

Fig. 63 NDVI classes smaller than 2000m 2 (so 20 pixel) removed.

Task

Change computation region, eg. by buffering Jena city region (v.buffer) and run the model.

v.buffer input=jena_boundary output=jena_boundary_5km distance=5000
../_images/ndvi-jena-5km.png

Fig. 64 NDVI classes computed in 5km buffer around Jena city region.

Sample model to download: ndvi-v3.gxm