[GRASS-SVN] r51265 - in grass/trunk/temporal: . t.rast.aggregate

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


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

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


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

Copied: grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.html (from rev 51264, grass/trunk/temporal/tr.aggregate/tr.aggregate.html)
===================================================================
Copied: grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py (from rev 51264, grass/trunk/temporal/tr.aggregate/tr.aggregate.py)
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py	                        (rev 0)
+++ grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py	2012-04-05 20:23:52 UTC (rev 51265)
@@ -0,0 +1,176 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:	tr.aggregate
+# AUTHOR(S):	Soeren Gebbert
+#
+# PURPOSE:	Create a new space time raster dataset from the aggregated data of an existing 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: Create a new space time raster dataset from the aggregated data of an existing space time raster dataset
+#% keywords: temporal
+#% keywords: aggregation
+#%end
+
+#%option G_OPT_STRDS_INPUT
+#%end
+
+#%option G_OPT_T_WHERE
+#%end
+
+#%option
+#% key: granularity
+#% type: string
+#% description: The aggregation granularity, format absolute time "x years, x months, x weeks, x days, x hours, x minutes, x seconds" or a double value for relative time
+#% required: yes
+#% multiple: no
+#%end
+
+#%option
+#% key: output
+#% type: string
+#% description: Name of the output space time raster dataset
+#% required: yes
+#% multiple: no
+#%end
+
+#%option
+#% key: method
+#% type: string
+#% description: Aggregate operation to be performed on the raster maps
+#% required: yes
+#% multiple: no
+#% options: average,count,median,mode,minimum,min_raster,maximum,max_raster,stddev,range,sum,variance,diversity,slope,offset,detcoeff,quart1,quart3,perc90,quantile,skewness,kurtosis
+#% answer: average
+#%end
+
+#%option G_OPT_T_SAMPLE
+#%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: 2
+#%end
+
+#%flag
+#% key: n
+#% description: Register Null maps
+#%end
+
+from multiprocessing import Process
+import grass.script as grass
+import grass.temporal as tgis
+
+############################################################################
+
+def main():
+
+    # Get the options
+    input = options["input"]
+    output = options["output"]
+    where = options["where"]
+    gran = options["granularity"]
+    base = options["base"]
+    register_null = flags["n"]
+    method = options["method"]
+    sampling = options["sampling"]
+    nprocs = int(options["nprocs"])
+
+    # Make sure the temporal database exists
+    tgis.create_temporal_database()
+    # We need a database interface
+    dbif = tgis.sql_database_interface()
+    dbif.connect()
+   
+    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:
+        dbif.close()
+        grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
+
+    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(dbif):
+        if grass.overwrite() == True:
+            new_sp.delete(dbif)
+            new_sp = tgis.space_time_raster_dataset(out_id)
+        else:
+            dbif.close()
+            grass.fatal(_("Space time raster dataset <%s> is already in the database, use overwrite flag to overwrite") % 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)
+
+    rows = sp.get_registered_maps("id,start_time", where, "start_time", dbif)
+
+    if not rows:
+            dbif.close()
+            grass.fatal(_("Space time raster dataset <%s> is empty") % out_id)
+
+    # Modify the start time to fit the granularity
+
+    if sp.is_time_absolute():
+        first_start_time = tgis.adjust_datetime_to_granularity( rows[0]["start_time"], gran)
+    else:
+        first_start_time = rows[0]["start_time"]
+
+    last_start_time = rows[len(rows) - 1]["start_time"]
+    next_start_time = first_start_time
+
+    count = 0
+    proc_count = 0
+    proc_list = []
+    while next_start_time <= last_start_time:
+        start = next_start_time
+        if sp.is_time_absolute():
+            end = tgis.increment_datetime_by_string(next_start_time, gran)
+        else:
+            end = next_start_time + int(gran)
+        next_start_time = end
+
+        input_map_names = tgis.collect_map_names(sp, dbif, start, end, sampling)
+
+        if input_map_names:
+            tgis.aggregate_raster_maps(sp, new_sp, mapset, input_map_names, base, start, end, count, method, register_null, dbif)
+	    
+        count += 1
+
+    # Update the spatio-temporal extent and the raster metadata table entries
+    new_sp.update_from_registered_maps(dbif)
+        
+    dbif.close()
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()
+

Copied: grass/trunk/temporal/t.rast.aggregate/test.t.rast.aggregate.relative_time.sh (from rev 51264, grass/trunk/temporal/tr.aggregate/test.tr.aggregate.relative_time.sh)
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/test.t.rast.aggregate.relative_time.sh	                        (rev 0)
+++ grass/trunk/temporal/t.rast.aggregate/test.t.rast.aggregate.relative_time.sh	2012-04-05 20:23:52 UTC (rev 51265)
@@ -0,0 +1,43 @@
+# 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. 
+# 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
+# Data generation
+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=relative 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=0 unit=days increment=3
+
+# The first @test
+
+t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity=6 method=average sampling=start,during
+t.info type=strds input=precip_abs2
+r.info prec_sum_0
+r.info prec_sum_1
+r.info prec_sum_2
+t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity=9 method=maximum sampling=start,during
+t.info type=strds input=precip_abs2
+r.info prec_sum_0
+r.info prec_sum_1
+t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity=4 method=minimum sampling=start,during
+t.info type=strds input=precip_abs2
+r.info prec_sum_0
+r.info prec_sum_1
+r.info prec_sum_2
+r.info prec_sum_3
+t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity=5 method=sum sampling=start,during
+t.info type=strds input=precip_abs2
+r.info prec_sum_0
+r.info prec_sum_1
+r.info prec_sum_2
+r.info prec_sum_3
+
+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

Copied: grass/trunk/temporal/t.rast.aggregate/test.t.rast.aggregate.sh (from rev 51264, grass/trunk/temporal/tr.aggregate/test.tr.aggregate.sh)
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/test.t.rast.aggregate.sh	                        (rev 0)
+++ grass/trunk/temporal/t.rast.aggregate/test.t.rast.aggregate.sh	2012-04-05 20:23:52 UTC (rev 51265)
@@ -0,0 +1,30 @@
+# 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. 
+# 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
+# Generate data
+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-15 12:05:45" increment="14 days"
+
+# The first @test
+
+t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity="2 days" method=average sampling=start,during
+t.info type=strds input=precip_abs2
+t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity="1 months" method=maximum sampling=start,during
+t.info type=strds input=precip_abs2
+t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity="2 months" method=minimum sampling=start,during
+t.info type=strds input=precip_abs2
+t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity="3 months" method=sum sampling=start,during
+t.info type=strds input=precip_abs2
+
+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

Deleted: grass/trunk/temporal/t.rast.aggregate/test.tr.aggregate.relative_time.sh
===================================================================
--- grass/trunk/temporal/tr.aggregate/test.tr.aggregate.relative_time.sh	2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.aggregate/test.tr.aggregate.relative_time.sh	2012-04-05 20:23:52 UTC (rev 51265)
@@ -1,43 +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. 
-# 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
-# Data generation
-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=relative 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=0 unit=days increment=3
-
-# The first @test
-
-tr.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity=6 method=average sampling=start,during
-t.info type=strds input=precip_abs2
-r.info prec_sum_0
-r.info prec_sum_1
-r.info prec_sum_2
-tr.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity=9 method=maximum sampling=start,during
-t.info type=strds input=precip_abs2
-r.info prec_sum_0
-r.info prec_sum_1
-tr.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity=4 method=minimum sampling=start,during
-t.info type=strds input=precip_abs2
-r.info prec_sum_0
-r.info prec_sum_1
-r.info prec_sum_2
-r.info prec_sum_3
-tr.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity=5 method=sum sampling=start,during
-t.info type=strds input=precip_abs2
-r.info prec_sum_0
-r.info prec_sum_1
-r.info prec_sum_2
-r.info prec_sum_3
-
-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

Deleted: grass/trunk/temporal/t.rast.aggregate/test.tr.aggregate.sh
===================================================================
--- grass/trunk/temporal/tr.aggregate/test.tr.aggregate.sh	2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.aggregate/test.tr.aggregate.sh	2012-04-05 20:23:52 UTC (rev 51265)
@@ -1,30 +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. 
-# 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
-# Generate data
-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-15 12:05:45" increment="14 days"
-
-# The first @test
-
-tr.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity="2 days" method=average sampling=start,during
-t.info type=strds input=precip_abs2
-tr.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity="1 months" method=maximum sampling=start,during
-t.info type=strds input=precip_abs2
-tr.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity="2 months" method=minimum sampling=start,during
-t.info type=strds input=precip_abs2
-tr.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum granularity="3 months" method=sum sampling=start,during
-t.info type=strds input=precip_abs2
-
-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

Deleted: grass/trunk/temporal/t.rast.aggregate/tr.aggregate.html
===================================================================
Deleted: grass/trunk/temporal/t.rast.aggregate/tr.aggregate.py
===================================================================
--- grass/trunk/temporal/tr.aggregate/tr.aggregate.py	2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.aggregate/tr.aggregate.py	2012-04-05 20:23:52 UTC (rev 51265)
@@ -1,176 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-############################################################################
-#
-# MODULE:	tr.aggregate
-# AUTHOR(S):	Soeren Gebbert
-#
-# PURPOSE:	Create a new space time raster dataset from the aggregated data of an existing 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: Create a new space time raster dataset from the aggregated data of an existing space time raster dataset
-#% keywords: temporal
-#% keywords: aggregation
-#%end
-
-#%option G_OPT_STRDS_INPUT
-#%end
-
-#%option G_OPT_T_WHERE
-#%end
-
-#%option
-#% key: granularity
-#% type: string
-#% description: The aggregation granularity, format absolute time "x years, x months, x weeks, x days, x hours, x minutes, x seconds" or a double value for relative time
-#% required: yes
-#% multiple: no
-#%end
-
-#%option
-#% key: output
-#% type: string
-#% description: Name of the output space time raster dataset
-#% required: yes
-#% multiple: no
-#%end
-
-#%option
-#% key: method
-#% type: string
-#% description: Aggregate operation to be performed on the raster maps
-#% required: yes
-#% multiple: no
-#% options: average,count,median,mode,minimum,min_raster,maximum,max_raster,stddev,range,sum,variance,diversity,slope,offset,detcoeff,quart1,quart3,perc90,quantile,skewness,kurtosis
-#% answer: average
-#%end
-
-#%option G_OPT_T_SAMPLE
-#%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: 2
-#%end
-
-#%flag
-#% key: n
-#% description: Register Null maps
-#%end
-
-from multiprocessing import Process
-import grass.script as grass
-import grass.temporal as tgis
-
-############################################################################
-
-def main():
-
-    # Get the options
-    input = options["input"]
-    output = options["output"]
-    where = options["where"]
-    gran = options["granularity"]
-    base = options["base"]
-    register_null = flags["n"]
-    method = options["method"]
-    sampling = options["sampling"]
-    nprocs = int(options["nprocs"])
-
-    # Make sure the temporal database exists
-    tgis.create_temporal_database()
-    # We need a database interface
-    dbif = tgis.sql_database_interface()
-    dbif.connect()
-   
-    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:
-        dbif.close()
-        grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
-
-    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(dbif):
-        if grass.overwrite() == True:
-            new_sp.delete(dbif)
-            new_sp = tgis.space_time_raster_dataset(out_id)
-        else:
-            dbif.close()
-            grass.fatal(_("Space time raster dataset <%s> is already in the database, use overwrite flag to overwrite") % 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)
-
-    rows = sp.get_registered_maps("id,start_time", where, "start_time", dbif)
-
-    if not rows:
-            dbif.close()
-            grass.fatal(_("Space time raster dataset <%s> is empty") % out_id)
-
-    # Modify the start time to fit the granularity
-
-    if sp.is_time_absolute():
-        first_start_time = tgis.adjust_datetime_to_granularity( rows[0]["start_time"], gran)
-    else:
-        first_start_time = rows[0]["start_time"]
-
-    last_start_time = rows[len(rows) - 1]["start_time"]
-    next_start_time = first_start_time
-
-    count = 0
-    proc_count = 0
-    proc_list = []
-    while next_start_time <= last_start_time:
-        start = next_start_time
-        if sp.is_time_absolute():
-            end = tgis.increment_datetime_by_string(next_start_time, gran)
-        else:
-            end = next_start_time + int(gran)
-        next_start_time = end
-
-        input_map_names = tgis.collect_map_names(sp, dbif, start, end, sampling)
-
-        if input_map_names:
-            tgis.aggregate_raster_maps(sp, new_sp, mapset, input_map_names, base, start, end, count, method, register_null, dbif)
-	    
-        count += 1
-
-    # Update the spatio-temporal extent and the raster metadata table entries
-    new_sp.update_from_registered_maps(dbif)
-        
-    dbif.close()
-
-if __name__ == "__main__":
-    options, flags = grass.parser()
-    main()
-



More information about the grass-commit mailing list