[GRASS-SVN] r53641 - in grass/trunk/temporal: . t.create t.rast.colors t.register t.vect.what.strds

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 1 11:29:13 PDT 2012


Author: huhabla
Date: 2012-11-01 11:29:13 -0700 (Thu, 01 Nov 2012)
New Revision: 53641

Added:
   grass/trunk/temporal/t.rast.colors/
   grass/trunk/temporal/t.rast.colors/Makefile
   grass/trunk/temporal/t.rast.colors/t.rast.colors.html
   grass/trunk/temporal/t.rast.colors/t.rast.colors.py
   grass/trunk/temporal/t.rast.colors/test.t.rast.colors.sh
Modified:
   grass/trunk/temporal/t.create/t.create.py
   grass/trunk/temporal/t.register/t.register.py
   grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py
Log:
New module to apply color tables to space time raster datasets.
Small bugfixes.


Modified: grass/trunk/temporal/t.create/t.create.py
===================================================================
--- grass/trunk/temporal/t.create/t.create.py	2012-11-01 18:21:17 UTC (rev 53640)
+++ grass/trunk/temporal/t.create/t.create.py	2012-11-01 18:29:13 UTC (rev 53641)
@@ -25,6 +25,7 @@
 #%end
 
 #%option G_OPT_STDS_TYPE
+#% description: The output type of the space time dataset
 #%end
 
 #%option G_OPT_T_TYPE

Added: grass/trunk/temporal/t.rast.colors/Makefile
===================================================================
--- grass/trunk/temporal/t.rast.colors/Makefile	                        (rev 0)
+++ grass/trunk/temporal/t.rast.colors/Makefile	2012-11-01 18:29:13 UTC (rev 53641)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../../
+
+PGM = t.rast.colors
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script $(TEST_DST)

Added: grass/trunk/temporal/t.rast.colors/t.rast.colors.html
===================================================================
--- grass/trunk/temporal/t.rast.colors/t.rast.colors.html	                        (rev 0)
+++ grass/trunk/temporal/t.rast.colors/t.rast.colors.html	2012-11-01 18:29:13 UTC (rev 53641)
@@ -0,0 +1,73 @@
+<h2>DESCRIPTION</h2>
+
+The purpose of <em>t.rast.colors</em> is to compute a 
+color table based on all registered maps of a space time 
+raster dataset and to assign this color table to each map. 
+Hence the created color table reflects the data range of 
+the space time raster dataset. This module is a simple 
+wrapper around <a href="r.colors.html">r.colors</a>. 
+All options of <em>r.colors</em> are supported.
+Internally a file with map names is created and passed 
+to the <em>file</em> option of <em>r.colors</em>.
+<p>
+Please have a look at the <a href="r.colors.html">r.colors</a> 
+manpage for further informations.
+
+<h2>EXAMPLE</h2>
+
+In this example we create 6 raster maps that will be registered in a single space time
+raster dataset named <em>precip_abs</em> using a monthly temporal granularity.
+Then we set an equilized grey color table using <em>t.rast.colors</em> and print the
+color table of the first map to stdout representing the data range of the space time raster dataset.
+
+<div class="code"><pre>
+
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+r.mapcalc --o expr="prec_1 = 100"
+r.mapcalc --o expr="prec_2 = 200"
+r.mapcalc --o expr="prec_3 = 300"
+r.mapcalc --o expr="prec_4 = 400"
+r.mapcalc --o expr="prec_5 = 500"
+r.mapcalc --o expr="prec_6 = 600"
+
+t.create --o type=strds temporaltype=absolute \
+    output=precip_abs title="Color setting example" \
+    descr="Color setting example"
+
+t.register type=rast input=precip_abs \
+    maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 \
+    start="2001-01-01" increment="1 months"
+
+# Grey color table for the full range 100 - 600
+t.rast.colors input=precip_abs color=grey.eq
+r.colors.out map=prec_1
+
+100 21:21:21
+199 21:21:21
+200 64:64:64
+299 64:64:64
+300 106:106:106
+399 106:106:106
+400 149:149:149
+499 149:149:149
+500 192:192:192
+599 192:192:192
+600 234:234:234
+nv 255:255:255
+default 255:255:255
+
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.colors.html">r.colors</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Sören Gebbert
+
+<p><i>Last changed: $Date: 2012-08-29 14:55:21 +0200 (Mi, 29. Aug 2012) $</i>
+

Added: grass/trunk/temporal/t.rast.colors/t.rast.colors.py
===================================================================
--- grass/trunk/temporal/t.rast.colors/t.rast.colors.py	                        (rev 0)
+++ grass/trunk/temporal/t.rast.colors/t.rast.colors.py	2012-11-01 18:29:13 UTC (rev 53641)
@@ -0,0 +1,176 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:	t.rast.colors
+# AUTHOR(S):	Soeren Gebbert
+#
+# PURPOSE:  Creates/modifies the color table associated with each raster map of the space time raster dataset.
+# COPYRIGHT:	(C) 2011 by the GRASS Development Team
+#
+#		This program is free software under the GNU General Public
+#		License (version 2). Read the file COPYING that comes with GRASS
+#		for details.
+#
+#############################################################################
+
+#%module
+#% description: Creates/modifies the color table associated with each raster map of the space time raster dataset.
+#% keywords: temporal
+#% keywords: color table
+#%end
+
+#%option G_OPT_STRDS_INPUT
+#%end
+
+#%option G_OPT_M_COLR
+#% key: color
+#% type: string
+#% description: Name of color table (see r.color help)
+#% required: no
+#% multiple: no
+#%end
+
+#%option G_OPT_R_INPUT
+#% key: raster
+#% description: Raster map from which to copy color table
+#% required: no
+#%end
+
+#%option G_OPT_R3_INPUT
+#% key: volume
+#% description: 3D raster map from which to copy color table
+#% required: no
+#%end
+
+#%option G_OPT_F_INPUT
+#% key: rules
+#% description: Path to rules file
+#% required: no
+#%end
+
+#%flag
+#% key: r
+#% description: Remove existing color table
+#%end
+
+#%flag
+#% key: w
+#% description: Only write new color table if one doesn't already exist
+#%end
+
+#%flag
+#% key: l
+#% description: List available rules then exit
+#%end
+
+#%flag
+#% key: n
+#% description: Invert colors
+#%end
+
+#%flag
+#% key: g
+#% description: Logarithmic scaling
+#%end
+
+#%flag
+#% key: a
+#% description: Logarithmic-absolute scaling
+#%end
+
+#%flag
+#% key: e
+#% description: Histogram equalization
+#%end
+
+import grass.script as grass
+import grass.temporal as tgis
+
+############################################################################
+
+
+def main():
+
+    # Get the options
+    input = options["input"]
+    color = options["color"]
+    raster = options["raster"]
+    volume = options["volume"]
+    rules = options["rules"]
+    remove = flags["r"]
+    write = flags["w"]
+    list = flags["l"]
+    invert = flags["n"]
+    log = flags["g"]
+    abslog = flags["a"]
+    equi = flags["e"]
+    
+    if raster == "":
+        raster=None
+        
+    if volume == "":
+        volume = None
+        
+    if rules == "":
+        rules = None
+        
+    if color == "":
+        color = None
+
+    # Make sure the temporal database exists
+    tgis.init()
+
+    if input.find("@") >= 0:
+        id = input
+    else:
+        mapset = grass.gisenv()["MAPSET"]
+        id = input + "@" + mapset
+
+    sp = tgis.SpaceTimeRasterDataset(id)
+
+    if sp.is_in_db() == False:
+        grass.fatal(_("Space time %s dataset <%s> not found") % (
+            sp.get_new_map_instance(None).get_type(), id))
+
+    sp.select()
+
+    rows = sp.get_registered_maps("id", None, None, None)
+
+    if rows:
+        # Create the r.colors input file
+        filename = grass.tempfile(True)
+        file = open(filename, 'w')
+
+        for row in rows:
+            string = "%s\n" % (row["id"])
+            file.write(string)
+
+        file.close()
+        
+        flags_=""
+        if(remove):
+            flags_+="r"
+        if(write):
+            flags_+="w"
+        if(list):
+            flags_+="l"
+        if(invert):
+            flags_+="n"
+        if(log):
+            flags_+="g"
+        if(abslog):
+            flags_+="a"
+        if(equi):
+            flags_+="e"
+
+        ret = grass.run_command("r.colors", flags=flags_, file=filename,
+                                color=color, raster=raster, volume=volume, 
+                                rules=rules, overwrite=grass.overwrite())
+
+        if ret != 0:
+            grass.fatal(_("Error in r.colors call"))
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()


Property changes on: grass/trunk/temporal/t.rast.colors/t.rast.colors.py
___________________________________________________________________
Added: svn:executable
   + *

Added: grass/trunk/temporal/t.rast.colors/test.t.rast.colors.sh
===================================================================
--- grass/trunk/temporal/t.rast.colors/test.t.rast.colors.sh	                        (rev 0)
+++ grass/trunk/temporal/t.rast.colors/test.t.rast.colors.sh	2012-11-01 18:29:13 UTC (rev 53641)
@@ -0,0 +1,29 @@
+#!/bin/sh
+# Simple r.series wrapper
+# We need to set a specific region in the
+# @preprocess step of this test. 
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+r.mapcalc --o expr="prec_1 = 100"
+r.mapcalc --o expr="prec_2 = 200"
+r.mapcalc --o expr="prec_3 = 300"
+r.mapcalc --o expr="prec_4 = 400"
+r.mapcalc --o expr="prec_5 = 500"
+r.mapcalc --o expr="prec_6 = 600"
+
+# @test
+t.create --o type=strds temporaltype=absolute output=precip_abs title="A test" descr="A test"
+
+t.register --o type=rast input=precip_abs maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 months"
+
+t.rast.colors input=precip_abs color=random
+r.colors.out map=prec_1
+t.rast.colors input=precip_abs color=grey.eq
+r.colors.out map=prec_2
+t.rast.colors input=precip_abs color=grey.log
+r.colors.out map=prec_3
+
+
+t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.remove type=strds input=precip_abs


Property changes on: grass/trunk/temporal/t.rast.colors/test.t.rast.colors.sh
___________________________________________________________________
Added: svn:executable
   + *

Modified: grass/trunk/temporal/t.register/t.register.py
===================================================================
--- grass/trunk/temporal/t.register/t.register.py	2012-11-01 18:21:17 UTC (rev 53640)
+++ grass/trunk/temporal/t.register/t.register.py	2012-11-01 18:29:13 UTC (rev 53641)
@@ -33,8 +33,9 @@
 #% guidependency: input,maps
 #%end
 
-#%option G_OPT_FILE_INPUT
+#%option G_OPT_F_INPUT
 #% key: file
+#% required: no
 #% description: Input file with map names, one per line. Additionally the start time and the end time can be specified per line
 #%end
 

Modified: grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py
===================================================================
--- grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py	2012-11-01 18:21:17 UTC (rev 53640)
+++ grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py	2012-11-01 18:29:13 UTC (rev 53641)
@@ -109,7 +109,7 @@
 
     if strds_sp.is_in_db() == False:
         dbif.close()
-        grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
+        grass.fatal(_("Space time raster dataset <%s> not found in temporal database") % (strds_id))
 
     strds_sp.select(dbif)
 



More information about the grass-commit mailing list