[GRASS-SVN] r51271 - in grass/trunk/temporal: . t.rast.extract

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Apr 5 16:52:23 EDT 2012


Author: huhabla
Date: 2012-04-05 13:52:23 -0700 (Thu, 05 Apr 2012)
New Revision: 51271

Added:
   grass/trunk/temporal/t.rast.extract/
   grass/trunk/temporal/t.rast.extract/t.rast.extract.html
   grass/trunk/temporal/t.rast.extract/t.rast.extract.py
   grass/trunk/temporal/t.rast.extract/test.t.rast.extract.sh
Removed:
   grass/trunk/temporal/t.rast.extract/test.tr.extract.sh
   grass/trunk/temporal/t.rast.extract/tr.extract.html
   grass/trunk/temporal/t.rast.extract/tr.extract.py
Modified:
   grass/trunk/temporal/t.rast.extract/Makefile
Log:
Using new naming scheme


Modified: grass/trunk/temporal/t.rast.extract/Makefile
===================================================================
--- grass/trunk/temporal/tr.extract/Makefile	2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.extract/Makefile	2012-04-05 20:52:23 UTC (rev 51271)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../../
 
-PGM = tr.extract
+PGM = t.rast.extract
 
 include $(MODULE_TOPDIR)/include/Make/Script.make
 

Copied: grass/trunk/temporal/t.rast.extract/t.rast.extract.html (from rev 51264, grass/trunk/temporal/tr.extract/tr.extract.html)
===================================================================
Copied: grass/trunk/temporal/t.rast.extract/t.rast.extract.py (from rev 51264, grass/trunk/temporal/tr.extract/tr.extract.py)
===================================================================
--- grass/trunk/temporal/t.rast.extract/t.rast.extract.py	                        (rev 0)
+++ grass/trunk/temporal/t.rast.extract/t.rast.extract.py	2012-04-05 20:52:23 UTC (rev 51271)
@@ -0,0 +1,233 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:	t.rast.extract
+# AUTHOR(S):	Soeren Gebbert
+#
+# PURPOSE:	Extract a subset of a 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: Extract a subset of a space time raster dataset
+#% keywords: temporal
+#% keywords: extract
+#%end
+
+#%option G_OPT_STRDS_INPUT
+#%end
+
+#%option G_OPT_T_WHERE
+#%end
+
+#%option
+#% key: expression
+#% type: string
+#% description: The r.mapcalc expression assigned to all extracted raster maps
+#% required: no
+#% multiple: no
+#%end
+
+#%option G_OPT_STRDS_OUTPUT
+#%end
+
+#%option G_OPT_R_BASE
+#%end
+
+#%option
+#% key: nprocs
+#% type: integer
+#% description: The number of r.mapcalc processes to run in parallel
+#% required: no
+#% multiple: no
+#% answer: 1
+#%end
+
+#%flag
+#% key: n
+#% description: Register Null maps
+#%end
+
+import grass.script as grass
+import grass.temporal as tgis
+from multiprocessing import Process
+
+############################################################################
+
+def main():
+
+    # Get the options
+    input = options["input"]
+    output = options["output"]
+    where = options["where"]
+    expression = options["expression"]
+    base = options["base"]
+    nprocs = int(options["nprocs"])
+    register_null = flags["n"]
+
+    # Make sure the temporal database exists
+    tgis.create_temporal_database()
+    
+    mapset =  grass.gisenv()["MAPSET"]
+
+    if input.find("@") >= 0:
+        id = input
+    else:
+        id = input + "@" + mapset
+
+    sp = tgis.space_time_raster_dataset(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))
+
+    if expression and not base:
+        grass.fatal(_("Please specify base="))
+
+    dbif = tgis.sql_database_interface()
+    dbif.connect()
+
+    sp.select(dbif)
+
+    if output.find("@") >= 0:
+        out_id = output
+    else:
+        out_id = output + "@" + mapset
+
+    # The new space time raster dataset
+    new_sp = tgis.space_time_raster_dataset(out_id)
+    if new_sp.is_in_db():
+        if grass.overwrite() == False:
+            grass.fatal(_("Space time raster dataset <%s> is already in database, use overwrite flag to overwrite") % out_id)
+            
+    rows = sp.get_registered_maps("id", where, "start_time", dbif)
+
+    new_maps = {}
+    if rows:
+	num_rows = len(rows)
+	
+	grass.percent(0, num_rows, 1)
+	
+	# Run the r.mapcalc expression
+        if expression:
+	    count = 0
+	    proc_count = 0
+	    proc_list = []
+	    for row in rows:
+		count += 1
+		
+		grass.percent(count, num_rows, 1)
+		
+		map_name = "%s_%i" % (base, count)
+
+		expr = "%s = %s" % (map_name, expression.replace(sp.get_id(), row["id"]))
+		expr = expr.replace(sp.base.get_name(), row["id"])
+
+		map_id = map_name + "@" + mapset
+
+		new_map = sp.get_new_map_instance(map_id)
+
+		# Check if new map is in the temporal database
+		if new_map.is_in_db(dbif):
+		    if grass.overwrite() == True:
+			# Remove the existing temporal database entry
+			new_map.delete(dbif)
+			new_map = sp.get_new_map_instance(map_id)
+		    else:
+			grass.error(_("Raster map <%s> is already in temporal database, use overwrite flag to overwrite"))
+			continue
+
+		grass.verbose(_("Apply r.mapcalc expression: \"%s\"") % expr)
+		
+		proc_list.append(Process(target=run_mapcalc, args=(expr,)))
+		proc_list[proc_count].start()
+		proc_count += 1
+		
+		if proc_count == nprocs:
+		    proc_count = 0
+		    exitcodes = 0
+		    for proc in proc_list:
+			proc.join()
+			exitcodes += proc.exitcode
+			
+		    if exitcodes != 0:
+			grass.fatal(_("Error while r.mapcalc computation"))
+			
+		    # Empty proc list
+		    proc_list = []
+		new_maps[row["id"]] = new_map
+	
+	grass.percent(0, num_rows, 1)
+	
+	# Insert the new space time raster dataset
+	if new_sp.is_in_db():
+	    if grass.overwrite() == True:
+		new_sp.delete(dbif)
+		new_sp = tgis.space_time_raster_dataset(out_id)
+		
+	temporal_type, semantic_type, title, description = sp.get_initial_values()
+	new_sp.set_initial_values(temporal_type, semantic_type, title, description)
+	new_sp.insert(dbif)
+	
+	# Register the maps in the database
+        count = 0
+        for row in rows:
+            count += 1
+	    
+	    grass.percent(count, num_rows, 1)
+
+            old_map = sp.get_new_map_instance(row["id"])
+            old_map.select(dbif)
+            
+            if expression:
+		
+		if new_maps.has_key(row["id"]):
+		    new_map = new_maps[row["id"]]
+
+                # Read the raster map data
+                new_map.load()
+                
+                # In case of a null map continue, do not register null maps
+                if new_map.metadata.get_min() == None and new_map.metadata.get_max() == None:
+                    if not register_null:
+                        continue
+
+                # Set the time stamp
+                if old_map.is_time_absolute():
+                    start, end, tz = old_map.get_absolute_time()
+                    new_map.set_absolute_time(start, end, tz)
+                else:
+                    start, end = old_map.get_relative_time()
+                    new_map.set_relative_time(start, end)
+
+                # Insert map in temporal database
+                new_map.insert(dbif)
+
+                new_sp.register_map(new_map, dbif)
+            else:
+                new_sp.register_map(old_map, dbif)          
+                
+        # Update the spatio-temporal extent and the raster metadata table entries
+        new_sp.update_from_registered_maps(dbif)
+	
+	grass.percent(num_rows, num_rows, 1)
+        
+    dbif.close()
+
+###############################################################################
+
+def run_mapcalc(expr):
+    """Helper function to run r.mapcalc in parallel"""
+    return grass.run_command("r.mapcalc", expression=expr, overwrite=grass.overwrite(), quiet=True)
+    
+###############################################################################
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()
+

Copied: grass/trunk/temporal/t.rast.extract/test.t.rast.extract.sh (from rev 51264, grass/trunk/temporal/tr.extract/test.tr.extract.sh)
===================================================================
--- grass/trunk/temporal/t.rast.extract/test.t.rast.extract.sh	                        (rev 0)
+++ grass/trunk/temporal/t.rast.extract/test.t.rast.extract.sh	2012-04-05 20:52:23 UTC (rev 51271)
@@ -0,0 +1,32 @@
+# Test the extraction of a subset of a space time raster input
+
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# raster with r.mapcalc and create two space time raster inputs
+# with relative and absolute time
+# 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 = rand(0, 550)"
+r.mapcalc --o expr="prec_2 = rand(0, 450)"
+r.mapcalc --o expr="prec_3 = rand(0, 320)"
+r.mapcalc --o expr="prec_4 = rand(0, 510)"
+r.mapcalc --o expr="prec_5 = rand(0, 300)"
+r.mapcalc --o expr="prec_6 = rand(0, 650)"
+
+t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
+t.register -i type=rast input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="3 months"
+
+# The first @test
+# We create the space time raster inputs and register the raster maps with absolute time interval
+
+t.rast.extract --o --v input=precip_abs1 output=precip_abs2 where="start_time > '2001-06-01'" \
+           expression=" if(precip_abs1 > 400, precip_abs1, null())" base=new_prec nprocs=2
+t.info type=strds input=precip_abs2
+
+t.rast.extract --o --v -n input=precip_abs1 output=precip_abs3 where="start_time > '2001-06-01'" \
+           expression=" if(precip_abs1 > 400, precip_abs1, null())" base=new_prec nprocs=4
+t.info type=strds input=precip_abs3
+
+t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.remove type=strds input=precip_abs1,precip_abs2,precip_abs3

Deleted: grass/trunk/temporal/t.rast.extract/test.tr.extract.sh
===================================================================
--- grass/trunk/temporal/tr.extract/test.tr.extract.sh	2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.extract/test.tr.extract.sh	2012-04-05 20:52:23 UTC (rev 51271)
@@ -1,32 +0,0 @@
-# Test the extraction of a subset of a space time raster input
-
-# We need to set a specific region in the
-# @preprocess step of this test. We generate
-# raster with r.mapcalc and create two space time raster inputs
-# with relative and absolute time
-# 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 = rand(0, 550)"
-r.mapcalc --o expr="prec_2 = rand(0, 450)"
-r.mapcalc --o expr="prec_3 = rand(0, 320)"
-r.mapcalc --o expr="prec_4 = rand(0, 510)"
-r.mapcalc --o expr="prec_5 = rand(0, 300)"
-r.mapcalc --o expr="prec_6 = rand(0, 650)"
-
-t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
-t.register -i type=rast input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="3 months"
-
-# The first @test
-# We create the space time raster inputs and register the raster maps with absolute time interval
-
-tr.extract --o --v input=precip_abs1 output=precip_abs2 where="start_time > '2001-06-01'" \
-           expression=" if(precip_abs1 > 400, precip_abs1, null())" base=new_prec nprocs=2
-t.info type=strds input=precip_abs2
-
-tr.extract --o --v -n input=precip_abs1 output=precip_abs3 where="start_time > '2001-06-01'" \
-           expression=" if(precip_abs1 > 400, precip_abs1, null())" base=new_prec nprocs=4
-t.info type=strds input=precip_abs3
-
-t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
-t.remove type=strds input=precip_abs1,precip_abs2,precip_abs3

Deleted: grass/trunk/temporal/t.rast.extract/tr.extract.html
===================================================================
Deleted: grass/trunk/temporal/t.rast.extract/tr.extract.py
===================================================================
--- grass/trunk/temporal/tr.extract/tr.extract.py	2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.extract/tr.extract.py	2012-04-05 20:52:23 UTC (rev 51271)
@@ -1,233 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-############################################################################
-#
-# MODULE:	tr.extract
-# AUTHOR(S):	Soeren Gebbert
-#
-# PURPOSE:	Extract a subset of a 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: Extract a subset of a space time raster dataset
-#% keywords: temporal
-#% keywords: extract
-#%end
-
-#%option G_OPT_STRDS_INPUT
-#%end
-
-#%option G_OPT_T_WHERE
-#%end
-
-#%option
-#% key: expression
-#% type: string
-#% description: The r.mapcalc expression assigned to all extracted raster maps
-#% required: no
-#% multiple: no
-#%end
-
-#%option G_OPT_STRDS_OUTPUT
-#%end
-
-#%option G_OPT_R_BASE
-#%end
-
-#%option
-#% key: nprocs
-#% type: integer
-#% description: The number of r.mapcalc processes to run in parallel
-#% required: no
-#% multiple: no
-#% answer: 1
-#%end
-
-#%flag
-#% key: n
-#% description: Register Null maps
-#%end
-
-import grass.script as grass
-import grass.temporal as tgis
-from multiprocessing import Process
-
-############################################################################
-
-def main():
-
-    # Get the options
-    input = options["input"]
-    output = options["output"]
-    where = options["where"]
-    expression = options["expression"]
-    base = options["base"]
-    nprocs = int(options["nprocs"])
-    register_null = flags["n"]
-
-    # Make sure the temporal database exists
-    tgis.create_temporal_database()
-    
-    mapset =  grass.gisenv()["MAPSET"]
-
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    sp = tgis.space_time_raster_dataset(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))
-
-    if expression and not base:
-        grass.fatal(_("Please specify base="))
-
-    dbif = tgis.sql_database_interface()
-    dbif.connect()
-
-    sp.select(dbif)
-
-    if output.find("@") >= 0:
-        out_id = output
-    else:
-        out_id = output + "@" + mapset
-
-    # The new space time raster dataset
-    new_sp = tgis.space_time_raster_dataset(out_id)
-    if new_sp.is_in_db():
-        if grass.overwrite() == False:
-            grass.fatal(_("Space time raster dataset <%s> is already in database, use overwrite flag to overwrite") % out_id)
-            
-    rows = sp.get_registered_maps("id", where, "start_time", dbif)
-
-    new_maps = {}
-    if rows:
-	num_rows = len(rows)
-	
-	grass.percent(0, num_rows, 1)
-	
-	# Run the r.mapcalc expression
-        if expression:
-	    count = 0
-	    proc_count = 0
-	    proc_list = []
-	    for row in rows:
-		count += 1
-		
-		grass.percent(count, num_rows, 1)
-		
-		map_name = "%s_%i" % (base, count)
-
-		expr = "%s = %s" % (map_name, expression.replace(sp.get_id(), row["id"]))
-		expr = expr.replace(sp.base.get_name(), row["id"])
-
-		map_id = map_name + "@" + mapset
-
-		new_map = sp.get_new_map_instance(map_id)
-
-		# Check if new map is in the temporal database
-		if new_map.is_in_db(dbif):
-		    if grass.overwrite() == True:
-			# Remove the existing temporal database entry
-			new_map.delete(dbif)
-			new_map = sp.get_new_map_instance(map_id)
-		    else:
-			grass.error(_("Raster map <%s> is already in temporal database, use overwrite flag to overwrite"))
-			continue
-
-		grass.verbose(_("Apply r.mapcalc expression: \"%s\"") % expr)
-		
-		proc_list.append(Process(target=run_mapcalc, args=(expr,)))
-		proc_list[proc_count].start()
-		proc_count += 1
-		
-		if proc_count == nprocs:
-		    proc_count = 0
-		    exitcodes = 0
-		    for proc in proc_list:
-			proc.join()
-			exitcodes += proc.exitcode
-			
-		    if exitcodes != 0:
-			grass.fatal(_("Error while r.mapcalc computation"))
-			
-		    # Empty proc list
-		    proc_list = []
-		new_maps[row["id"]] = new_map
-	
-	grass.percent(0, num_rows, 1)
-	
-	# Insert the new space time raster dataset
-	if new_sp.is_in_db():
-	    if grass.overwrite() == True:
-		new_sp.delete(dbif)
-		new_sp = tgis.space_time_raster_dataset(out_id)
-		
-	temporal_type, semantic_type, title, description = sp.get_initial_values()
-	new_sp.set_initial_values(temporal_type, semantic_type, title, description)
-	new_sp.insert(dbif)
-	
-	# Register the maps in the database
-        count = 0
-        for row in rows:
-            count += 1
-	    
-	    grass.percent(count, num_rows, 1)
-
-            old_map = sp.get_new_map_instance(row["id"])
-            old_map.select(dbif)
-            
-            if expression:
-		
-		if new_maps.has_key(row["id"]):
-		    new_map = new_maps[row["id"]]
-
-                # Read the raster map data
-                new_map.load()
-                
-                # In case of a null map continue, do not register null maps
-                if new_map.metadata.get_min() == None and new_map.metadata.get_max() == None:
-                    if not register_null:
-                        continue
-
-                # Set the time stamp
-                if old_map.is_time_absolute():
-                    start, end, tz = old_map.get_absolute_time()
-                    new_map.set_absolute_time(start, end, tz)
-                else:
-                    start, end = old_map.get_relative_time()
-                    new_map.set_relative_time(start, end)
-
-                # Insert map in temporal database
-                new_map.insert(dbif)
-
-                new_sp.register_map(new_map, dbif)
-            else:
-                new_sp.register_map(old_map, dbif)          
-                
-        # Update the spatio-temporal extent and the raster metadata table entries
-        new_sp.update_from_registered_maps(dbif)
-	
-	grass.percent(num_rows, num_rows, 1)
-        
-    dbif.close()
-
-###############################################################################
-
-def run_mapcalc(expr):
-    """Helper function to run r.mapcalc in parallel"""
-    return grass.run_command("r.mapcalc", expression=expr, overwrite=grass.overwrite(), quiet=True)
-    
-###############################################################################
-
-if __name__ == "__main__":
-    options, flags = grass.parser()
-    main()
-



More information about the grass-commit mailing list