From 3a9846bbda9305a9bd448cc80b54ee81076187a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20RIBREUX?= Date: Sat, 27 Feb 2016 16:29:40 +0100 Subject: [PATCH] Add r.stats.quantile algorithm --- .../description/r.stats.quantile.out.txt | 12 ++++ .../description/r.stats.quantile.rast.txt | 11 ++++ .../algs/grass7/ext/r_stats_quantile_rast.py | 66 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 python/plugins/processing/algs/grass7/description/r.stats.quantile.out.txt create mode 100644 python/plugins/processing/algs/grass7/description/r.stats.quantile.rast.txt create mode 100644 python/plugins/processing/algs/grass7/ext/r_stats_quantile_rast.py diff --git a/python/plugins/processing/algs/grass7/description/r.stats.quantile.out.txt b/python/plugins/processing/algs/grass7/description/r.stats.quantile.out.txt new file mode 100644 index 00000000000..6c24c5e3ab8 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/r.stats.quantile.out.txt @@ -0,0 +1,12 @@ +r.stats.quantile +r.stats.quantile.out - Compute category quantiles using two passes and output statistics +Raster (r.*) +ParameterRaster|base|Name of base raster map|False +ParameterRaster|cover|Name of cover raster map|False +ParameterString|quantiles|Number of quantiles|None|False|True +ParameterString|percentiles|List of percentiles|None|False|True +ParameterNumber|bins|Number of bins to use|0|None|1000|True +*ParameterBoolean|-r|Create reclass map with statistics as category labels|False +Hardcoded|-p +OutputFile|output|Statistics File + diff --git a/python/plugins/processing/algs/grass7/description/r.stats.quantile.rast.txt b/python/plugins/processing/algs/grass7/description/r.stats.quantile.rast.txt new file mode 100644 index 00000000000..6bccb17cf93 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/r.stats.quantile.rast.txt @@ -0,0 +1,11 @@ +r.stats.quantile +r.stats.quantile.rast - Compute category quantiles using two passes and output rasters. +Raster (r.*) +ParameterRaster|base|Name of base raster map|False +ParameterRaster|cover|Name of cover raster map|False +ParameterNumber|quantiles|Number of quantiles|2|None|2|True +ParameterString|percentiles|List of percentiles|None|False|True +ParameterNumber|bins|Number of bins to use|0|None|1000|True +*ParameterBoolean|-r|Create reclass map with statistics as category labels|False +OutputDirectory|output_dir|Output Directory + diff --git a/python/plugins/processing/algs/grass7/ext/r_stats_quantile_rast.py b/python/plugins/processing/algs/grass7/ext/r_stats_quantile_rast.py new file mode 100644 index 00000000000..f95073378b0 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/r_stats_quantile_rast.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + r_stats_quantile_rast.py + ------------------------ + Date : February 2016 + Copyright : (C) 2016 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'February 2016' +__copyright__ = '(C) 2016, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from processing.core.parameters import getParameterFromString +import os + + +def processCommand(alg): + # We create the output sequence according to percentiles number + base = alg.getParameterValue('base') + quantiles = alg.getParameterValue('quantiles') - 1 + outputs = [] + for i in range(0, int(quantiles)): + outputs.append('output_{}'.format(i)) + + output = getParameterFromString('ParameterString|output|Output Rasters|None|False|True') + output.value = ','.join(outputs) + alg.addParameter(output) + + output_dir = alg.getOutputFromName('output_dir') + alg.removeOutputFromName('output_dir') + + # Launch the algorithm + alg.processCommand() + + # We re-add the previous output + alg.addOutput(output_dir) + + +def processOutputs(alg): + # We need to export each of the output + output_dir = alg.getOutputValue('output_dir') + outputParam = alg.getParameterFromName('output') + outputs = outputParam.value.split(',') + alg.parameters.remove(outputParam) + for output in outputs: + command = u"r.out.gdal -c createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" --overwrite".format( + output, + os.path.join(output_dir, output + '.tif') + ) + alg.commands.append(command) + alg.outputCommands.append(command)