Skip to content
Permalink
Browse files

Add r.stats.quantile algorithm

  • Loading branch information
Médéric RIBREUX
Médéric RIBREUX committed Feb 27, 2016
1 parent 960f3a9 commit 3a9846bbda9305a9bd448cc80b54ee81076187a2
@@ -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

@@ -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

@@ -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)

0 comments on commit 3a9846b

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