Developing the new Semi-Automatic Classification Plugin 7: Band calc and parallel processing

The new version 7 of the Semi-Automatic Classification Plugin (SCP) for QGIS will include several updates, in particular regarding multi-threading that will allow parallel processing and reduce the computation time. 

With the new Band calc tool it will be possible to perform raster calculations with multiple parallel processes (based on system availability) where each thread performs a part of the calculation and the result is computed very rapidly (if compared to single thread).



Interface

The interface has been revamped to allow for additional settings regarding NoData values and raster data type selection (Float32 (default), Int32, Int16, UInt32, UInt16, Byte), therefore a smaller output size can be achieved.

Iterations

Several functions of iteration are available for Band sets allowing to perform multitemporal calculations on time series of images (new Band sets can include image date):
  • forbsdates: it allows for the iteration over Band sets dates (format yyyy-mm-dd, defined in Band set definition) between square brackets; forbsdates must be entered in the first line of expressions such as the following examples:

Iterating over a range of dates:

forbsdates[2020-01-01:2020-07-31]

Iterating over a list of dates:

forbsdates[2020-02-01,2020-03-11,2020-04-21]

Iterating over a list of ranges of dates:

forbsdates[2010-01-01:2010-06-31, 2010-08-01:2010-08-31, 2010-10-01:2010-12-31]
  • forbandsets: it allows for the iteration over Band sets defined between square brackets; a range of Band sets separated by colon or a list separated by commas, for instance:

    forbandsets[1:3]
    


Variables

The following variables can be used in expressions:
  • bandset#b BAND_NUMBER: bands in the active Band set can be referenced directly; the following example refers to band 1 of the active Band set:

    "bandset#b1"
    
  • bandset BANDSET_NUMBER b BAND_NUMBER: bands in the Band set can be referenced directly; the following example refers to band 1 of the Band set 1:

    "bandset1b1"
    
  • bandset#b*: list of all the bands of active Band set, which is equivalent to [bandset#b1, bandset#b2, ..., bandset#bX]; to be used in expressions that accept band lists such as the maximum value:

    max("bandset#b*")
    
  • bandset BANDSET_NUMBER b*: list of all the bands of Band set N, which is equivalent to [bandsetNb1, bandsetNb2, ..., bandsetNbX]; to be used in expressions that accept band lists such as the minimum value:

    min("bandset1b*")
    
  • bandset*b BAND_NUMBER: list of all the bands X of all the Band sets, which is equivalent to [bandset1bX, bandset2bX, ..., bandsetNbX]; to be used in expressions that accept band lists such as the mean value:

    mean("bandset*b1")
    
  • bandset{ DATE }b BAND_NUMBER: list of all the bands X of all the Band sets matching a list of dates (format yyyy-mm-dd) between curly brackets (e.g. {2019-01-01,2019-07-31}) or range of dates separated by colon (e.g. {2019-01-01:2019-07-31}) or a list of ranges of dates (e.g. {2019-01-01:2019-01-31, 2019-04-01:2019-07-31}), which is equivalent to [bandset2bX, bandset5bX, ..., bandsetNbX]; for instance:

    median("bandset{2019-01-01,2019-07-31}b1")
    
  • “#BLUE#”: the band with the center wavelength closest to 0.475 μm;

  • “#GREEN#”: the band with the center wavelength closest to 0.56 μm;

  • “#RED#”: the band with the center wavelength closest to 0.65 μm;

  • “#NIR#”: the band with the center wavelength closest to 0.85 μm; for example:

    ( "#NIR#" - "#RED#" ) / ( "#NIR#" + "#RED#" )


During the iterations, the variables related to the active Band set are replaced by the iterator, therefore the expression:

forbandsets[1:3]
"bandset#b1" @#BANDSET#

is equivalent to:

"bandset1b1" @calc1
"bandset2b1" @calc2
"bandset3b1" @calc3

Output

Output names can be defined in the expression line entering the symbol @ followed by the name, such as the following example:

"raster1" * 2 @first_calculation


It will be possible to set the output path directly by defining the output name with this structure @path@name, such as:

"raster1" * 2 @/home/user@first_calculation


It will be possible to create a temporary output (saved in the temporary directory) with @temp@ followed by output name, such as:

"raster1" * 2 @temp@first_calculation


If the output name is defined with the extension .vrt, the output will be a virtual raster referencing the single .tif files calculated by parallel processing. For instance, the following expression will calculate the raster with parallel processing and the output will be a .vrt:

"raster1" @first_calculation.vrt

Virtual file is useful to reduce calculation time of parallel processing by avoiding the writing of the entire output raster.


The new SCP 7 should be available in a few weeks.
For any comment or question, join the Facebook group about the Semi-Automatic Classification Plugin.

Newer posts Older posts