Skip to content

Commit cce451c

Browse files
Médéric RibreuxMédéric RIBREUX
Médéric Ribreux
authored and
Médéric RIBREUX
committed
Add i.pca algorithm
1 parent a73ed12 commit cce451c

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
i.pca
2+
Principal components analysis (PCA) for image processing.
3+
Imagery (i.*)
4+
ParameterMultipleInput|input|Name of two or more input raster maps|3|False
5+
ParameterString|rescale|Rescaling range for output maps. For no rescaling use 0,0|0,255|False|True
6+
ParameterNumber|percent|Cumulative percent importance for filtering|50.0|99.0|99.0|True
7+
*ParameterBoolean|-n|Normalize (center and scale) input maps|False
8+
*ParameterBoolean|-f|Output will be filtered input bands|False
9+
OutputDirectory|output|Output Directory
10+

python/plugins/processing/algs/grass7/ext/i.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def multipleOutputDir(alg, field, basename=None):
4545
# Otherwise, export everything
4646
else:
4747
commands = ["for r in $(g.list type=rast); do".format(basename)]
48-
commands.append(" r.out.gdal -c -t input=${{r}} output={}/${{r}}.tif createopt=\"TFW=YES,COMPRESS=LZW\"".format(outputDir))
48+
commands.append(" r.out.gdal -c -t -f input=${{r}} output={}/${{r}}.tif createopt=\"TFW=YES,COMPRESS=LZW\"".format(outputDir))
4949
commands.append("done")
5050
alg.commands.extend(commands)
5151
alg.outputCommands.extend(commands)
@@ -160,7 +160,7 @@ def exportInputRasters(alg, rasterDic):
160160
for inputName, outputName in rasterDic.iteritems():
161161
inputRaster = alg.getParameterValue(inputName)
162162
outputRaster = alg.getOutputFromName(outputName)
163-
command = 'r.out.gdal -c -t --overwrite createopt="TFW=YES,COMPRESS=LZW" input={} output=\"{}\"'.format(
163+
command = 'r.out.gdal -c -t -f --overwrite createopt="TFW=YES,COMPRESS=LZW" input={} output=\"{}\"'.format(
164164
alg.exportedLayers[inputRaster],
165165
outputRaster.value
166166
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
i_pca.py
6+
--------
7+
Date : March 2016
8+
Copyright : (C) 2016 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'March 2016'
22+
__copyright__ = '(C) 2016, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from i import multipleOutputDir, verifyRasterNum
29+
from processing.core.parameters import getParameterFromString
30+
31+
32+
def checkParameterValuesBeforeExecuting(alg):
33+
return verifyRasterNum(alg, 'input', 2)
34+
35+
36+
def processCommand(alg):
37+
# Remove output
38+
output = alg.getOutputFromName('output')
39+
alg.removeOutputFromName('output')
40+
41+
# Create output parameter
42+
param = getParameterFromString("ParameterString|output|output basename|None|False|False")
43+
param.value = alg.getTempFilename()
44+
alg.addParameter(param)
45+
46+
alg.processCommand()
47+
# re-add output
48+
alg.addOutput(output)
49+
50+
51+
def processOutputs(alg):
52+
param = alg.getParameterFromName('output')
53+
multipleOutputDir(alg, 'output', param.value)
54+
55+
# Delete output parameter
56+
alg.parameters.remove(param)

0 commit comments

Comments
 (0)