Skip to content

Commit

Permalink
Add i.pca algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Médéric Ribreux authored and Médéric RIBREUX committed May 29, 2016
1 parent a73ed12 commit cce451c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
10 changes: 10 additions & 0 deletions python/plugins/processing/algs/grass7/description/i.pca.txt
@@ -0,0 +1,10 @@
i.pca
Principal components analysis (PCA) for image processing.
Imagery (i.*)
ParameterMultipleInput|input|Name of two or more input raster maps|3|False
ParameterString|rescale|Rescaling range for output maps. For no rescaling use 0,0|0,255|False|True
ParameterNumber|percent|Cumulative percent importance for filtering|50.0|99.0|99.0|True
*ParameterBoolean|-n|Normalize (center and scale) input maps|False
*ParameterBoolean|-f|Output will be filtered input bands|False
OutputDirectory|output|Output Directory

4 changes: 2 additions & 2 deletions python/plugins/processing/algs/grass7/ext/i.py
Expand Up @@ -45,7 +45,7 @@ def multipleOutputDir(alg, field, basename=None):
# Otherwise, export everything
else:
commands = ["for r in $(g.list type=rast); do".format(basename)]
commands.append(" r.out.gdal -c -t input=${{r}} output={}/${{r}}.tif createopt=\"TFW=YES,COMPRESS=LZW\"".format(outputDir))
commands.append(" r.out.gdal -c -t -f input=${{r}} output={}/${{r}}.tif createopt=\"TFW=YES,COMPRESS=LZW\"".format(outputDir))
commands.append("done")
alg.commands.extend(commands)
alg.outputCommands.extend(commands)
Expand Down Expand Up @@ -160,7 +160,7 @@ def exportInputRasters(alg, rasterDic):
for inputName, outputName in rasterDic.iteritems():
inputRaster = alg.getParameterValue(inputName)
outputRaster = alg.getOutputFromName(outputName)
command = 'r.out.gdal -c -t --overwrite createopt="TFW=YES,COMPRESS=LZW" input={} output=\"{}\"'.format(
command = 'r.out.gdal -c -t -f --overwrite createopt="TFW=YES,COMPRESS=LZW" input={} output=\"{}\"'.format(
alg.exportedLayers[inputRaster],
outputRaster.value
)
Expand Down
56 changes: 56 additions & 0 deletions python/plugins/processing/algs/grass7/ext/i_pca.py
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
i_pca.py
--------
Date : March 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__ = 'March 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 i import multipleOutputDir, verifyRasterNum
from processing.core.parameters import getParameterFromString


def checkParameterValuesBeforeExecuting(alg):
return verifyRasterNum(alg, 'input', 2)


def processCommand(alg):
# Remove output
output = alg.getOutputFromName('output')
alg.removeOutputFromName('output')

# Create output parameter
param = getParameterFromString("ParameterString|output|output basename|None|False|False")
param.value = alg.getTempFilename()
alg.addParameter(param)

alg.processCommand()
# re-add output
alg.addOutput(output)


def processOutputs(alg):
param = alg.getParameterFromName('output')
multipleOutputDir(alg, 'output', param.value)

# Delete output parameter
alg.parameters.remove(param)

0 comments on commit cce451c

Please sign in to comment.