Skip to content
Permalink
Browse files

Add i.landsat.acc algorithm

  • Loading branch information
Médéric Ribreux Médéric RIBREUX
Médéric Ribreux authored and Médéric RIBREUX committed May 4, 2016
1 parent 90758b5 commit 8ff07cf91acfe20fb562123f9993bbbd08363f51
@@ -0,0 +1,14 @@
i.landsat.acca
Performs Landsat TM/ETM+ Automatic Cloud Cover Assessment (ACCA).
Imagery (i.*)
ParameterMultipleInput|rasters|Landsat input rasters|3|False
ParameterNumber|b56composite|B56composite (step 6)|0|None|225|True
ParameterNumber|b45ratio|B45ratio: Desert detection (step 10)|0|None|1|True
ParameterNumber|histogram|Number of classes in the cloud temperature histogram|0|None|100|True
*ParameterBoolean|-5|Data is Landsat-5 TM|False
*ParameterBoolean|-f|Apply post-processing filter to remove small holes|False
*ParameterBoolean|-x|Always use cloud signature (step 14)|False
*ParameterBoolean|-2|Bypass second-pass processing, and merge warm (not ambiguous) and cold clouds|False
*ParameterBoolean|-s|Include a category for cloud shadows|False
OutputRaster|output|ACCA Raster

@@ -51,20 +51,24 @@ def multipleOutputDir(alg, field, basename=None):
alg.outputCommands.extend(commands)


def orderedInput(alg, inputParameter, targetParameterDef):
def orderedInput(alg, inputParameter, targetParameterDef, numSeq=None):
"""Inport multiple rasters in the order"""
rasters = alg.getParameterValue(inputParameter).split(';')
# TODO: make targetParameter
inputParameter = getParameterFromString(targetParameterDef)
rootFilename = '{}_'.format(alg.getTempFilename())
inputParameter.value = rootFilename
alg.addParameter(inputParameter)
# Handle specific range
if numSeq is None:
numSeq = range(1, len(rasters) + 1)

for idx in range(len(rasters)):
layer = rasters[idx]
if layer in alg.exportedLayers.keys():
continue
else:
destFilename = '{}{}'.format(rootFilename, idx + 1)
destFilename = '{}{}'.format(rootFilename, numSeq[idx])
alg.setSessionProjectionFromLayer(layer, alg.commands)
alg.exportedLayers[layer] = destFilename
command = 'r.external input={} band=1 output={} --overwrite -o'.format(layer, destFilename)
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
i_landsat_acca.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 verifyRasterNum, orderedInput


def checkParameterValuesBeforeExecuting(alg):
return verifyRasterNum(alg, 'rasters', 5, 5)


def processInputs(alg):
orderedInput(alg, 'rasters',
"ParameterString|input|Base name of input raster bands|None|False|False",
[2, 3, 4, 5, 61])


def processCommand(alg):
# Remove rasters parameter
rasters = alg.getParameterFromName('rasters')
alg.parameters.remove(rasters)

alg.processCommand()

# re-add rasters
alg.addParameter(rasters)
@@ -35,7 +35,8 @@ def checkParameterValuesBeforeExecuting(alg):

def processInputs(alg):
orderedInput(alg, 'rasters',
"ParameterString|input|Base name of input raster bands|None|False|False")
"ParameterString|input|Base name of input raster bands|None|False|False",
[1, 2, 3, 4, 5, 61, 62, 7, 8])


def processCommand(alg):
@@ -52,7 +53,6 @@ def processCommand(alg):
param.value = '{}_'.format(alg.getTempFilename())
alg.addParameter(param)

# Regroup rasters
alg.processCommand()

# re-add output

0 comments on commit 8ff07cf

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