소스 검색

replace output basename by red, green, and blue

 * compute only maps which were requested
 * avoid 'import grass.script as grass'
 * minimalize pep8 and pylint errors and warnings (tabs, unnecessary global variables)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@63796 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 10 년 전
부모
커밋
6cf39a40e6
1개의 변경된 파일37개의 추가작업 그리고 18개의 파일을 삭제
  1. 37 18
      scripts/r.rgb/r.rgb.py

+ 37 - 18
scripts/r.rgb/r.rgb.py

@@ -20,34 +20,53 @@
 #%end
 #%option G_OPT_R_INPUT
 #%end
-#%option G_OPT_R_BASENAME_OUTPUT
-#% label: Name of output basename raster map(s)
-#% description: Default: input
+#%option G_OPT_R_OUTPUT
+#% key: red
+#% description: Red channel raster map name
 #% required: no
 #%end
+#%option G_OPT_R_OUTPUT
+#% key: green
+#% description: Green channel raster map name
+#% required: no
+#%end
+#%option G_OPT_R_OUTPUT
+#% key: blue
+#% description: Blue channel raster map name
+#% required: no
+#%end
+
+import grass.script as gscript
 
-import grass.script as grass
 
 def main():
+    options, unused = gscript.parser()
     input = options['input']
-    output = options['output']
+    red = options['red']
+    green = options['green']
+    blue = options['blue']
 
-    if not grass.find_file(input)['file']:
-	grass.fatal(_("Raster map <%s> not found") % input)
+    if not gscript.find_file(input)['file']:
+        gscript.fatal(_("Raster map <%s> not found") % input)
 
-    if not output:
-	output = input.split('@')[0]
+    expressions = []
+    maps = []
+    if red:
+        expressions.append('%s = r#${input}' % red)
+        maps.append(red)
+    if green:
+        expressions.append('%s = g#${input}' % green)
+        maps.append(green)
+    if blue:
+        expressions.append('%s = b#${input}' % blue)
+        maps.append(blue)
+    expr = ';'.join(expressions)
+    gscript.mapcalc(expr, input=input)
 
-    expr = ';'.join(["${output}.r = r#${input}",
-		     "${output}.g = g#${input}",
-		     "${output}.b = b#${input}"])
-    grass.mapcalc(expr, input = input, output = output)
+    for name in maps:
+        gscript.run_command('r.colors', map=name, color='grey255')
+        gscript.raster_history(name)
 
-    for ch in ['r', 'g', 'b']:
-	name = "%s.%s" % (output, ch)
-	grass.run_command('r.colors', map = name, color = 'grey255', quiet = True)
-	grass.raster_history(name)
 
 if __name__ == "__main__":
-    options, flags = grass.parser()
     main()