[GRASS-SVN] r62125 - in grass/branches/releasebranch_7_0: . scripts/i.tasscap

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 28 13:38:05 PDT 2014


Author: neteler
Date: 2014-09-28 13:38:05 -0700 (Sun, 28 Sep 2014)
New Revision: 62125

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/scripts/i.tasscap/i.tasscap.html
   grass/branches/releasebranch_7_0/scripts/i.tasscap/i.tasscap.py
Log:
i.tasscap: use standardized option (output_prefix->basename) (trunk, r61793) + change flags to option and band options to one input option with multiple enabled (#2407, trunk r61920)


Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk:60289,60696,61269,61380,61420,61422,61480,61500,61764,61808,61829,61831,61840,61851-61854,61858,61888,61891,61905,61907,61913-61914,61916,61918,61921,61938,61967-61968,61975,61980,61986,61993,62005,62095,62099,62114,62122
   + /grass/trunk:60289,60696,61269,61380,61420,61422,61480,61500,61764,61793,61808,61829,61831,61840,61851-61854,61858,61888,61891,61905,61907,61913-61914,61916,61918,61920-61921,61938,61967-61968,61975,61980,61986,61993,62005,62095,62099,62114,62122

Modified: grass/branches/releasebranch_7_0/scripts/i.tasscap/i.tasscap.html
===================================================================
--- grass/branches/releasebranch_7_0/scripts/i.tasscap/i.tasscap.html	2014-09-28 10:34:24 UTC (rev 62124)
+++ grass/branches/releasebranch_7_0/scripts/i.tasscap/i.tasscap.html	2014-09-28 20:38:05 UTC (rev 62125)
@@ -1,7 +1,7 @@
 <h2>DESCRIPTION</h2>
 
 <em>i.tasscap</em> calculates Tasseled Cap (Kauth Thomas, TC) transformation
-for LANDSAT-TM data (TM4, TM5, TM7).
+for Landsat TM data (TM4, TM5, ETM7).<!-- add other sensors here once added -->
 
 The tasseled cap transformation is effectively a compression method to
 reduce multiple spectral data into a few bands. The method was originally

Modified: grass/branches/releasebranch_7_0/scripts/i.tasscap/i.tasscap.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/i.tasscap/i.tasscap.py	2014-09-28 10:34:24 UTC (rev 62124)
+++ grass/branches/releasebranch_7_0/scripts/i.tasscap/i.tasscap.py	2014-09-28 20:38:05 UTC (rev 62125)
@@ -11,8 +11,10 @@
 #		This program is free software under the GNU General Public
 #		License (>=v2). Read the file COPYING that comes with GRASS
 #		for details.
+#
 # TODO: Check if MODIS Tasseled Cap makes sense to be added
 #       http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1025776
+#       Add other, e.g from here: http://www.sjsu.edu/faculty/watkins/tassel.htm
 #############################################################################
 # References:
 # LANDSAT-4/LANDSAT-5:
@@ -33,54 +35,27 @@
 #############################################################################
 #
 #%Module
-#% description: Performs Tasseled Cap (Kauth Thomas) transformation for LANDSAT-TM data.
+#% description: Performs Tasseled Cap (Kauth Thomas) transformation.
 #% keywords: imagery
 #% keywords: transformation
 #% keywords: Landsat
 #% keywords: Tasseled Cap transformation
 #%end
-#%flag
-#% key: 4
-#% description: Use transformation rules for LANDSAT-4
-#%end
-#%flag
-#% key: 5
-#% description: Use transformation rules for LANDSAT-5
-#%end
-#%flag
-#% key: 7
-#% description: Use transformation rules for LANDSAT-7
-#%end
-#%option G_OPT_R_INPUT
-#% key: band1
-#% description: Name of input raster map (LANDSAT channel 1)
-#%end
-#%option G_OPT_R_INPUT
-#% key: band2
-#% description: Name of input raster map (LANDSAT channel 2)
-#%end
-#%option G_OPT_R_INPUT
-#% key: band3
-#% description: Name of input raster map (LANDSAT channel 3)
-#%end
-#%option G_OPT_R_INPUT
-#% key: band4
-#% description: Name of input raster map (LANDSAT channel 4)
-#%end
-#%option G_OPT_R_INPUT
-#% key: band5
-#% description: Name of input raster map (LANDSAT channel 5)
-#%end
-#%option G_OPT_R_INPUT
-#% key: band7
-#% description: Name of input raster map (LANDSAT channel 7)
-#%end
 #%option
-#% key: output_prefix
+#% key: satellite
 #% type: string
-#% description: Prefix for output raster maps
+#% description: Satellite sensor
 #% required: yes
+#% multiple: no
+#% options: landsat4_tm,landsat5_tm,landsat7_etm
+#% descriptions: landsat4_tm;Use transformation rules for Landsat 4 TM;landsat5_tm;Use transformation rules for Landsat 5 TM;landsat7_etm;Use transformation rules for Landsat 7 ETM
 #%end
+#%option G_OPT_R_INPUTS
+#%end
+#%option G_OPT_R_BASENAME_OUTPUT
+#% label: Name of input raster map(s)
+#% description: For Landsat 4-7, the raster maps should be the bands 1, 2, 3, 4, 5, and 7.
+#%end
 
 import sys
 import os
@@ -106,8 +81,7 @@
 	out = out, k1 = k1, k2 = k2, k3 = k3, k4 = k4, k5 = k5, k7 = k7, k0 = k0, **bands)
     grass.run_command('r.colors', map = out, color = 'grey')
 
-def calcN(options, i, n):
-    outpre = options['output_prefix']
+def calcN(outpre, bands, i, n):
     grass.message(_("LANDSAT-%d...") % n)
     for j, p in enumerate(parms[i]):
 	out = "%s.%d" % (outpre, j + 1)
@@ -117,27 +91,38 @@
 	else:
 	    name = " (%s)" % names[j]
 	grass.message(_("Calculating %s TC component %s%s ...") % (ord, out, name))
-	calc1(out, options, *p)
+	calc1(out, bands, *p)
 
+
 def main():
-    flag4 = flags['4']
-    flag5 = flags['5']
-    flag7 = flags['7']
+    options, flags = grass.parser()
+    satellite = options['satellite']
+    output_basename = options['basename']
+    inputs = options['input'].split(',')
+    num_of_bands = 6
+    if len(inputs) != num_of_bands:
+        grass.fatal(_("The number of input raster maps (bands) should be %s.") % num_of_bands)
 
-    if (flag4 and flag5) or (flag4 and flag7) or (flag5 and flag7):
-	grass.fatal(_("Select only one flag"))
+    # this is here just for the compatibility with r.mapcalc expression
+    # remove this if not really needed in new implementation
+    bands = {}
+    for i, band in enumerate(inputs):
+        band_num = i + 1
+        if band_num == 6:
+            band_num = 7
+        bands['band' + str(band_num)] = band
+    print bands
 
-    if flag4:
-	calcN(options, 0, 4)
-    elif flag5:
-	calcN(options, 1, 5)
-    elif flag7:
-	calcN(options, 2, 7)
+    if satellite == 'landsat4_tm':
+        calcN(output_basename, bands, 0, 4)
+    elif satellite == 'landsat5_tm':
+        calcN(output_basename, bands, 1, 5)
+    elif satellite == 'landsat7_etm':
+        calcN(output_basename, bands, 2, 7)
     else:
-	grass.fatal(_("Select LANDSAT satellite by flag!"))
+        raise RuntimeError("Invalid satellite: " + satellite)
 
     grass.message(_("Tasseled Cap components calculated."))
 
 if __name__ == "__main__":
-    options, flags = grass.parser()
     main()



More information about the grass-commit mailing list