Skip to content
Permalink
Browse files

Add i.pca algorithm

  • Loading branch information
Médéric Ribreux Médéric RIBREUX
Médéric Ribreux authored and Médéric RIBREUX committed May 2, 2016
1 parent a73ed12 commit cce451c722997b8d69e7c05a54f657221defc03e
@@ -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

@@ -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)
@@ -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
)
@@ -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.
You can’t perform that action at this time.