Skip to content

Commit

Permalink
Handle parameters and update description files (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Médéric RIBREUX committed Nov 4, 2017
1 parent 733218c commit a676db2
Show file tree
Hide file tree
Showing 318 changed files with 2,210 additions and 2,073 deletions.
83 changes: 50 additions & 33 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -27,6 +27,7 @@


__revision__ = '$Format:%H$' __revision__ = '$Format:%H$'


import sys
import os import os
import uuid import uuid
import importlib import importlib
Expand All @@ -41,29 +42,38 @@
QgsProcessingParameterDefinition, QgsProcessingParameterDefinition,
QgsProcessingException, QgsProcessingException,
QgsProcessingParameterExtent, QgsProcessingParameterExtent,
QgsProcessingParameterNumber) QgsProcessingParameterNumber,
QgsProcessingParameterString,
QgsProcessingParameterPoint,
QgsProcessingParameterBoolean,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterMultipleLayers,
QgsProcessingOutputVectorLayer,
QgsProcessingOutputRasterLayer,
QgsProcessingOutputHtml)
from qgis.utils import iface from qgis.utils import iface


#from processing.core.GeoAlgorithm import GeoAlgorithm (replaced by QgsProcessingAlgorithm) #from processing.core.GeoAlgorithm import GeoAlgorithm (replaced by QgsProcessingAlgorithm)
from processing.core.ProcessingConfig import ProcessingConfig from processing.core.ProcessingConfig import ProcessingConfig
#from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException (replaced by QgsProcessingException). #from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException (replaced by QgsProcessingException).


from processing.core.parameters import (getParameterFromString, from processing.core.parameters import (getParameterFromString)
ParameterVector, #ParameterVector,
ParameterMultipleInput, #ParameterMultipleInput,
#ParameterExtent, #ParameterExtent,
#ParameterNumber, #ParameterNumber,
#ParameterSelection, #ParameterSelection,
ParameterRaster, #ParameterRaster,
ParameterTable, #ParameterTable,
ParameterBoolean, #ParameterBoolean,
ParameterString, #ParameterString,
ParameterPoint) #ParameterPoint)
from processing.core.outputs import (getOutputFromString, #from processing.core.outputs import (getOutputFromString,
OutputRaster, # OutputRaster,
OutputVector, # OutputVector,
OutputFile, # OutputFile,
OutputHTML) # OutputHTML)


from .Grass7Utils import Grass7Utils from .Grass7Utils import Grass7Utils


Expand Down Expand Up @@ -91,6 +101,7 @@ def __init__(self, descriptionfile):
self._display_name = '' self._display_name = ''
self._group = '' self._group = ''
self.grass7Name = '' self.grass7Name = ''
self.params = []
self.hardcodedStrings = [] self.hardcodedStrings = []
self.descriptionFile = descriptionfile self.descriptionFile = descriptionfile
self.defineCharacteristicsFromFile() self.defineCharacteristicsFromFile()
Expand Down Expand Up @@ -152,6 +163,10 @@ def getParameterDescriptions(self):
except Exception: except Exception:
pass pass
return descs return descs

def initAlgorithm(self, config=None):
for p in self.params:
self.addParameter(p)


def defineCharacteristicsFromFile(self): def defineCharacteristicsFromFile(self):
""" """
Expand Down Expand Up @@ -186,23 +201,23 @@ def defineCharacteristicsFromFile(self):
self.hardcodedStrings.append(line[len('Hardcoded|'):]) self.hardcodedStrings.append(line[len('Hardcoded|'):])
parameter = getParameterFromString(line) parameter = getParameterFromString(line)
if parameter is not None: if parameter is not None:
self.addParameter(parameter) self.params.append(parameter)
if isinstance(parameter, ParameterVector): if isinstance(parameter, QgsProcessingParameterVectorLayer):
hasVectorInput = True hasVectorInput = True
if isinstance(parameter, ParameterMultipleInput) \ if isinstance(parameter, QgsProcessingParameterMultipleLayers) \
and parameter.datatype < 3: and parameter.layerType() < 3:
hasVectorInput = True hasVectorInput = True
else: #else:
output = getOutputFromString(line) # output = Grass7Utils.getOutputFromString(line)
self.addOutput(output) # self.addOutput(output)
if isinstance(output, OutputRaster): # if isinstance(output, QgsProcessingOutputRasterLayer):
hasRasterOutput = True # hasRasterOutput = True
elif isinstance(output, OutputVector): # elif isinstance(output, QgsProcessingOutputVectorLayer):
vectorOutputs += 1 # vectorOutputs += 1
if isinstance(output, OutputHTML): # if isinstance(output, QgsProcessingOutputHtml):
self.addOutput(OutputFile("rawoutput", # self.addOutput(OutputFile("rawoutput",
self.tr("{0} (raw output)").format(output.description()), # self.tr("{0} (raw output)").format(output.description()),
"txt")) # "txt"))
line = lines.readline().strip('\n').strip() line = lines.readline().strip('\n').strip()
except Exception as e: except Exception as e:
QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line), self.tr('Processing'), QgsMessageLog.CRITICAL) QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line), self.tr('Processing'), QgsMessageLog.CRITICAL)
Expand All @@ -217,19 +232,21 @@ def defineCharacteristicsFromFile(self):
self.GRASS_REGION_CELLSIZE_PARAMETER, self.GRASS_REGION_CELLSIZE_PARAMETER,
self.tr('GRASS GIS 7 region cellsize (leave 0 for default)'), self.tr('GRASS GIS 7 region cellsize (leave 0 for default)'),
type=QgsProcessingParameterNumber.Double, type=QgsProcessingParameterNumber.Double,
minValue=0.0, maxValue=None, defaultValue=0.0) minValue=0.0, maxValue=sys.float_info.max + 1, defaultValue=0.0)
) )
if hasVectorInput: if hasVectorInput:
param = QgsProcessingParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER, param = QgsProcessingParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER,
self.tr('v.in.ogr snap tolerance (-1 = no snap)'), self.tr('v.in.ogr snap tolerance (-1 = no snap)'),
type=QgsProcessingParameterNumber.Double, type=QgsProcessingParameterNumber.Double,
minValue=-1.0, maxValue=None, defaultValue=-1.0) minValue=-1.0, maxValue=sys.float_info.max + 1,
defaultValue=-1.0)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(param) self.addParameter(param)
param = QgsProcessingParameterNumber(self.GRASS_MIN_AREA_PARAMETER, param = QgsProcessingParameterNumber(self.GRASS_MIN_AREA_PARAMETER,
self.tr('v.in.ogr min area'), self.tr('v.in.ogr min area'),
type=QgsProcessingParameterNumber.double, type=QgsProcessingParameterNumber.Double,
minValue=0.0, maxValue=None, defaultValue=0.0001) minValue=0.0, maxValue=sys.float_info.max + 1,
defaultValue=0.0001)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(param) self.addParameter(param)
if vectorOutputs == 1: if vectorOutputs == 1:
Expand Down
16 changes: 8 additions & 8 deletions python/plugins/processing/algs/grass7/description/i.albedo.txt
@@ -1,11 +1,11 @@
i.albedo i.albedo
Computes broad band albedo from surface reflectance. Computes broad band albedo from surface reflectance.
Imagery (i.*) Imagery (i.*)
ParameterMultipleInput|input|Name of input raster maps|3|False QgsProcessingParameterMultipleLayers|input|Name of input raster maps|3|None|False
ParameterBoolean|-m|MODIS (7 input bands:1,2,3,4,5,6,7)|False QgsProcessingParameterBoolean|-m|MODIS (7 input bands:1,2,3,4,5,6,7)|False
ParameterBoolean|-n|NOAA AVHRR (2 input bands:1,2)|False QgsProcessingParameterBoolean|-n|NOAA AVHRR (2 input bands:1,2)|False
ParameterBoolean|-l|Landsat 5+7 (6 input bands:1,2,3,4,5,7)|False QgsProcessingParameterBoolean|-l|Landsat 5+7 (6 input bands:1,2,3,4,5,7)|False
ParameterBoolean|-a|ASTER (6 input bands:1,3,5,6,8,9)|False QgsProcessingParameterBoolean|-a|ASTER (6 input bands:1,3,5,6,8,9)|False
ParameterBoolean|-c|Aggressive mode (Landsat)|False QgsProcessingParameterBoolean|-c|Aggressive mode (Landsat)|False
ParameterBoolean|-d|Soft mode (MODIS)|False QgsProcessingParameterBoolean|-d|Soft mode (MODIS)|False
OutputRaster|output|Albedo QgsProcessingParameterRasterDestination|output|Albedo
@@ -1,13 +1,13 @@
i.aster.toar i.aster.toar
Calculates Top of Atmosphere Radiance/Reflectance/Brightness Temperature from ASTER DN. Calculates Top of Atmosphere Radiance/Reflectance/Brightness Temperature from ASTER DN.
Imagery (i.*) Imagery (i.*)
ParameterMultipleInput|input|Names of ASTER DN layers (15 layers)|3|False QgsProcessingParameterMultipleLayers|input|Names of ASTER DN layers (15 layers)|3|None|False
ParameterNumber|dayofyear|Day of Year of satellite overpass [0-366]|0|366|0|False QgsProcessingParameterNumber|dayofyear|Day of Year of satellite overpass [0-366]|0|QgsProcessingParameterNumber.Double|False|False|0|366
ParameterNumber|sun_elevation|Sun elevation angle (degrees, < 90.0)|0.0|90.0|45.0|False QgsProcessingParameterNumber|sun_elevation|Sun elevation angle (degrees, < 90.0)|0.0|QgsProcessingParameterNumber.Double|False|False|45.0|90.0
ParameterBoolean|-r|Output is radiance (W/m2)|False QgsProcessingParameterBoolean|-r|Output is radiance (W/m2)|False
ParameterBoolean|-a|VNIR is High Gain|False QgsProcessingParameterBoolean|-a|VNIR is High Gain|False
ParameterBoolean|-b|SWIR is High Gain|False QgsProcessingParameterBoolean|-b|SWIR is High Gain|False
ParameterBoolean|-c|VNIR is Low Gain 1|False QgsProcessingParameterBoolean|-c|VNIR is Low Gain 1|False
ParameterBoolean|-d|SWIR is Low Gain 1|False QgsProcessingParameterBoolean|-d|SWIR is Low Gain 1|False
ParameterBoolean|-e|SWIR is Low Gain 2|False QgsProcessingParameterBoolean|-e|SWIR is Low Gain 2|False
OutputDirectory|output|Output Directory OutputDirectory|output|Output Directory
22 changes: 11 additions & 11 deletions python/plugins/processing/algs/grass7/description/i.atcorr.txt
@@ -1,16 +1,16 @@
i.atcorr i.atcorr
Performs atmospheric correction using the 6S algorithm. Performs atmospheric correction using the 6S algorithm.
Imagery (i.*) Imagery (i.*)
ParameterRaster|input|Name of input raster map|False QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
ParameterRange|range|Input imagery range [0,255]|0,255|True QgsProcessingParameterRange|range|Input imagery range [0,255]|0,255|True
ParameterRaster|elevation|Input altitude raster map in m (optional)|True QgsProcessingParameterRasterLayer|elevation|Input altitude raster map in m (optional)|None|True
ParameterRaster|visibility|Input visibility raster map in km (optional)|True QgsProcessingParameterRasterLayer|visibility|Input visibility raster map in km (optional)|None|True
ParameterFile|parameters|Name of input text file|False|False QgsProcessingParameterFile|parameters|Name of input text file|False|False
ParameterRange|rescale|Rescale output raster map [0,255]|0,255|True QgsProcessingParameterRange|rescale|Rescale output raster map [0,255]|0,255|True
OutputRaster|output|Atmospheric correction QgsProcessingParameterRasterDestination|output|Atmospheric correction
*ParameterBoolean|-i|Output raster map as integer|False *QgsProcessingParameterBoolean|-i|Output raster map as integer|False
*ParameterBoolean|-r|Input raster map converted to reflectance (default is radiance)|False *QgsProcessingParameterBoolean|-r|Input raster map converted to reflectance (default is radiance)|False
*ParameterBoolean|-a|Input from ETM+ image taken after July 1, 2000|False *QgsProcessingParameterBoolean|-a|Input from ETM+ image taken after July 1, 2000|False
*ParameterBoolean|-b|Input from ETM+ image taken before July 1, 2000|False *QgsProcessingParameterBoolean|-b|Input from ETM+ image taken before July 1, 2000|False




14 changes: 7 additions & 7 deletions python/plugins/processing/algs/grass7/description/i.biomass.txt
@@ -1,10 +1,10 @@
i.biomass i.biomass
Computes biomass growth, precursor of crop yield calculation. Computes biomass growth, precursor of crop yield calculation.
Imagery (i.*) Imagery (i.*)
ParameterRaster|fpar|Name of fPAR raster map|False QgsProcessingParameterRasterLayer|fpar|Name of fPAR raster map|None|False
ParameterRaster|lightuse_efficiency|Name of light use efficiency raster map (UZB:cotton=1.9)|False QgsProcessingParameterRasterLayer|lightuse_efficiency|Name of light use efficiency raster map (UZB:cotton=1.9)|None|False
ParameterRaster|latitude|Name of degree latitude raster map [dd.ddd]|False QgsProcessingParameterRasterLayer|latitude|Name of degree latitude raster map [dd.ddd]|None|False
ParameterRaster|dayofyear|Name of Day of Year raster map [1-366]|False QgsProcessingParameterRasterLayer|dayofyear|Name of Day of Year raster map [1-366]|None|False
ParameterRaster|transmissivity_singleway|Name of single-way transmissivity raster map [0.0-1.0]False QgsProcessingParameterRasterLayer|transmissivity_singleway|Name of single-way transmissivity raster map [0.0-1.0]False
ParameterRaster|water_availability|Value of water availability raster map [0.0-1.0]|False QgsProcessingParameterRasterLayer|water_availability|Value of water availability raster map [0.0-1.0]|None|False
OutputRaster|output|Biomass QgsProcessingParameterRasterDestination|output|Biomass
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/grass7/description/i.cca.txt
@@ -1,6 +1,6 @@
i.cca i.cca
Canonical components analysis (CCA) program for image processing. Canonical components analysis (CCA) program for image processing.
Imagery (i.*) Imagery (i.*)
ParameterMultipleInput|input|Input rasters (2 to 8)|3|False QgsProcessingParameterMultipleLayers|input|Input rasters (2 to 8)|3|None|False
ParameterFile|signature|File containing spectral signatures|False|False QgsProcessingParameterFile|signature|File containing spectral signatures|False|False
OutputDirectory|output|Output Directory OutputDirectory|output|Output Directory
16 changes: 8 additions & 8 deletions python/plugins/processing/algs/grass7/description/i.cluster.txt
@@ -1,13 +1,13 @@
i.cluster i.cluster
Generates spectral signatures for land cover types in an image using a clustering algorithm. Generates spectral signatures for land cover types in an image using a clustering algorithm.
Imagery (i.*) Imagery (i.*)
ParameterMultipleInput|input|Input rasters|3|False QgsProcessingParameterMultipleLayers|input|Input rasters|3|None|False
ParameterNumber|classes|Initial number of classes (1-255)|1|255|1|True QgsProcessingParameterNumber|classes|Initial number of classes (1-255)|1|QgsProcessingParameterNumber.Double|True|False|1|255
ParameterFile|seed|Name of file containing initial signatures|False|True QgsProcessingParameterFile|seed|Name of file containing initial signatures|False|True
ParameterString|sample|Sampling intervals (by row and col)|None|False|True QgsProcessingParameterString|sample|Sampling intervals (by row and col)|None|False|True
ParameterNumber|iterations|Maximum number of iterations|1|None|30|True QgsProcessingParameterNumber|iterations|Maximum number of iterations|1|QgsProcessingParameterNumber.Double|True|False|30|None
ParameterNumber|convergence|Percent convergence|0.0|100.0|98.0|True QgsProcessingParameterNumber|convergence|Percent convergence|0.0|QgsProcessingParameterNumber.Double|True|False|98.0|100.0
ParameterNumber|separation|Cluster separation|0.0|None|0.0|True QgsProcessingParameterNumber|separation|Cluster separation|0.0|QgsProcessingParameterNumber.Double|True|False|0.0|None
ParameterNumber|min_size|Minimum number of pixels in a class|1|None|17|True QgsProcessingParameterNumber|min_size|Minimum number of pixels in a class|1|QgsProcessingParameterNumber.Double|True|False|17|None
OutputFile|signaturefile|Signature File OutputFile|signaturefile|Signature File
OutputFile|reportfile|Final Report File OutputFile|reportfile|Final Report File
@@ -1,15 +1,15 @@
i.colors.enhance i.colors.enhance
Performs auto-balancing of colors for RGB images. Performs auto-balancing of colors for RGB images.
Imagery (i.*) Imagery (i.*)
ParameterRaster|red|Name of red channel|False QgsProcessingParameterRasterLayer|red|Name of red channel|None|False
ParameterRaster|green|Name of green channel|False QgsProcessingParameterRasterLayer|green|Name of green channel|None|False
ParameterRaster|blue|Name of blue channel|False QgsProcessingParameterRasterLayer|blue|Name of blue channel|None|False
ParameterNumber|strength|Cropping intensity (upper brightness level)|0|100|98|True QgsProcessingParameterNumber|strength|Cropping intensity (upper brightness level)|0|QgsProcessingParameterNumber.Double|True|False|98|100
*ParameterBoolean|-f|Extend colors to full range of data on each channel|False *QgsProcessingParameterBoolean|-f|Extend colors to full range of data on each channel|False
*ParameterBoolean|-p|Preserve relative colors, adjust brightness only|False *QgsProcessingParameterBoolean|-p|Preserve relative colors, adjust brightness only|False
*ParameterBoolean|-r|Reset to standard color range|False *QgsProcessingParameterBoolean|-r|Reset to standard color range|False
*ParameterBoolean|-s|Process bands serially (default: run in parallel)|False *QgsProcessingParameterBoolean|-s|Process bands serially (default: run in parallel)|False
OutputRaster|redoutput|Enhanced Red QgsProcessingParameterRasterDestination|redoutput|Enhanced Red
OutputRaster|greenoutput|Enhanced Green QgsProcessingParameterRasterDestination|greenoutput|Enhanced Green
OutputRaster|blueoutput|Enhanced Blue QgsProcessingParameterRasterDestination|blueoutput|Enhanced Blue


@@ -1,7 +1,7 @@
i.eb.eta i.eb.eta
Actual evapotranspiration for diurnal period (Bastiaanssen, 1995). Actual evapotranspiration for diurnal period (Bastiaanssen, 1995).
Imagery (i.*) Imagery (i.*)
ParameterRaster|netradiationdiurnal|Name of the diurnal net radiation map [W/m2]|False QgsProcessingParameterRasterLayer|netradiationdiurnal|Name of the diurnal net radiation map [W/m2]|None|False
ParameterRaster|evaporativefraction|Name of the evaporative fraction map|False QgsProcessingParameterRasterLayer|evaporativefraction|Name of the evaporative fraction map|None|False
ParameterRaster|temperature|Name of the surface skin temperature [K]|False QgsProcessingParameterRasterLayer|temperature|Name of the surface skin temperature [K]|None|False
OutputRaster|output|Evapotranspiration QgsProcessingParameterRasterDestination|output|Evapotranspiration
@@ -1,9 +1,9 @@
i.eb.evapfr i.eb.evapfr
Computes evaporative fraction (Bastiaanssen, 1995) and root zone soil moisture (Makin, Molden and Bastiaanssen, 2001). Computes evaporative fraction (Bastiaanssen, 1995) and root zone soil moisture (Makin, Molden and Bastiaanssen, 2001).
Imagery (i.*) Imagery (i.*)
ParameterRaster|netradiation|Name of Net Radiation raster map [W/m2]|False QgsProcessingParameterRasterLayer|netradiation|Name of Net Radiation raster map [W/m2]|None|False
ParameterRaster|soilheatflux|Name of soil heat flux raster map [W/m2]|False QgsProcessingParameterRasterLayer|soilheatflux|Name of soil heat flux raster map [W/m2]|None|False
ParameterRaster|sensibleheatflux|Name of sensible heat flux raster map [W/m2]|False QgsProcessingParameterRasterLayer|sensibleheatflux|Name of sensible heat flux raster map [W/m2]|None|False
Hardcoded|-m Hardcoded|-m
OutputRaster|evaporativefraction|Evaporative Fraction QgsProcessingParameterRasterDestination|evaporativefraction|Evaporative Fraction
OutputRaster|soilmoisture|Root Zone Soil Moisture QgsProcessingParameterRasterDestination|soilmoisture|Root Zone Soil Moisture

0 comments on commit a676db2

Please sign in to comment.