Skip to content
Permalink
Browse files

Handle parameters and update description files (WIP)

  • Loading branch information
Médéric RIBREUX
Médéric RIBREUX committed Sep 3, 2017
1 parent 733218c commit a676db2c0f11e1f9599809243b3e0fb4fe8ac32d
Showing 318 changed files with 2,210 additions and 2,073 deletions.
@@ -27,6 +27,7 @@

__revision__ = '$Format:%H$'

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

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

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

from .Grass7Utils import Grass7Utils

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

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

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


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

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

0 comments on commit a676db2

Please sign in to comment.
You can’t perform that action at this time.