[GRASS-SVN] r51285 - in grass/trunk/temporal: . t.rast.aggregate.ds
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Apr 5 17:29:53 EDT 2012
Author: huhabla
Date: 2012-04-05 14:29:53 -0700 (Thu, 05 Apr 2012)
New Revision: 51285
Added:
grass/trunk/temporal/t.rast.aggregate.ds/
grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.html
grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py
grass/trunk/temporal/t.rast.aggregate.ds/test.t.rast.aggregate.ds.sh
Removed:
grass/trunk/temporal/t.rast.aggregate.ds/test.tr.aggregate.ds.sh
grass/trunk/temporal/t.rast.aggregate.ds/tr.aggregate.ds.html
grass/trunk/temporal/t.rast.aggregate.ds/tr.aggregate.ds.py
Modified:
grass/trunk/temporal/t.rast.aggregate.ds/Makefile
Log:
Using new naming scheme
Modified: grass/trunk/temporal/t.rast.aggregate.ds/Makefile
===================================================================
--- grass/trunk/temporal/tr.aggregate.ds/Makefile 2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.aggregate.ds/Makefile 2012-04-05 21:29:53 UTC (rev 51285)
@@ -1,6 +1,6 @@
MODULE_TOPDIR = ../../
-PGM = tr.aggregate.ds
+PGM = t.rast.aggregate.ds
include $(MODULE_TOPDIR)/include/Make/Script.make
Copied: grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.html (from rev 51264, grass/trunk/temporal/tr.aggregate.ds/tr.aggregate.ds.html)
===================================================================
Copied: grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py (from rev 51264, grass/trunk/temporal/tr.aggregate.ds/tr.aggregate.ds.py)
===================================================================
--- grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py (rev 0)
+++ grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py 2012-04-05 21:29:53 UTC (rev 51285)
@@ -0,0 +1,173 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE: t.rast.aggregate.ds
+# AUTHOR(S): Soeren Gebbert
+#
+# PURPOSE: Aggregated data of an existing space time raster dataset using the temporal topology of a second space time 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: Aggregated data of an existing space time raster dataset using the temporal topology of a second space time dataset
+#% keywords: temporal
+#% keywords: aggregation
+#%end
+
+#%option G_OPT_STRDS_INPUT
+#%end
+
+#%option G_OPT_STDS_INPUT
+#% key: sample
+#% description: The time intervals from this space time dataset (raster, vector or raster3d) are used for aggregation computation.
+#%end
+
+#%option G_OPT_STDS_TYPE
+#% description: Type of the aggregation space time dataset, default is strds
+#%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 peformed 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
+
+#%flag
+#% key: n
+#% description: Register Null maps
+#%end
+
+import grass.script as grass
+import grass.temporal as tgis
+
+############################################################################
+
+def main():
+
+ # Get the options
+ input = options["input"]
+ output = options["output"]
+ sampler = options["sample"]
+ base = options["base"]
+ register_null = flags["n"]
+ method = options["method"]
+ type = options["type"]
+ sampling = options["sampling"]
+
+ # 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 sampler.find("@") >= 0:
+ sampler_id = sampler
+ else:
+ sampler_id = sampler + "@" + mapset
+
+ sampler_sp = tgis.dataset_factory(type, sampler_id)
+
+ if sampler_sp.is_in_db() == False:
+ dbif.close()
+ grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
+
+ sampler_sp.select(dbif)
+
+ if sampler_sp.get_temporal_type() != sp.get_temporal_type():
+ dbif.close()
+ grass.fatal(_("Input and aggregation dataset must have the same temporal type"))
+
+ # Check if intervals are present
+ if sampler_sp.get_temporal_type() == "absolute":
+ map_time = sampler_sp.absolute_time.get_map_time()
+ else:
+ map_time = sampler_sp.relative_time.get_map_time()
+
+ if map_time != "interval":
+ dbif.close()
+ grass.fatal(_("All registered maps of the aggregation dataset must have time intervals"))
+
+ 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 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 = sampler_sp.get_registered_maps("id,start_time,end_time", None, "start_time", dbif)
+
+ if not rows:
+ dbif.close()
+ grass.fatal(_("Aggregation dataset <%s> is empty") % id)
+
+ count = 0
+ for row in rows:
+ count += 1
+ start = row["start_time"]
+ end = row["end_time"]
+
+ 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)
+
+ # 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.ds/test.t.rast.aggregate.ds.sh (from rev 51264, grass/trunk/temporal/tr.aggregate.ds/test.tr.aggregate.ds.sh)
===================================================================
--- grass/trunk/temporal/t.rast.aggregate.ds/test.t.rast.aggregate.ds.sh (rev 0)
+++ grass/trunk/temporal/t.rast.aggregate.ds/test.t.rast.aggregate.ds.sh 2012-04-05 21:29:53 UTC (rev 51285)
@@ -0,0 +1,47 @@
+# 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 = 100"
+r.mapcalc --o expr="prec_2 = 150"
+r.mapcalc --o expr="prec_3 = 250"
+r.mapcalc --o expr="prec_4 = 250"
+r.mapcalc --o expr="prec_5 = 150"
+r.mapcalc --o expr="prec_6 = 100"
+
+v.random --o -z output=soil_1 n=20 zmin=0 zmax=100 column=height
+v.random --o -z output=soil_2 n=20 zmin=0 zmax=100 column=height
+v.random --o -z output=soil_3 n=20 zmin=0 zmax=100 column=height
+
+n1=`g.tempfile pid=1 -d`
+
+cat > "${n1}" << EOF
+soil_1|2001-01-01|2001-04-01
+soil_2|2001-05-01|2001-07-01
+soil_3|2001-08-01|2001-12-01
+EOF
+
+t.create --o type=stvds temporaltype=absolute output=soil_abs1 title="A test" descr="A test"
+t.register type=vect input=soil_abs1 file="${n1}"
+
+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-03-01 00:00:00" increment="1 months"
+
+# The @test
+
+t.rast.aggregate.ds --o --v input=precip_abs1 output=precip_abs2 base=prec_sum type=stvds sample=soil_abs1 method=sum sampling=start,during
+t.info type=strds input=precip_abs2
+t.rast.list input=precip_abs2 method=deltagap
+
+# @postprocess
+t.unregister type=vect maps=soil_1,soil_2,soil_3
+t.remove type=stvds input=soil_abs1
+
+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
+g.remove vect=soil_1,soil_2,soil_3
Deleted: grass/trunk/temporal/t.rast.aggregate.ds/test.tr.aggregate.ds.sh
===================================================================
--- grass/trunk/temporal/tr.aggregate.ds/test.tr.aggregate.ds.sh 2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.aggregate.ds/test.tr.aggregate.ds.sh 2012-04-05 21:29:53 UTC (rev 51285)
@@ -1,46 +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 = 100"
-r.mapcalc --o expr="prec_2 = 150"
-r.mapcalc --o expr="prec_3 = 250"
-r.mapcalc --o expr="prec_4 = 250"
-r.mapcalc --o expr="prec_5 = 150"
-r.mapcalc --o expr="prec_6 = 100"
-
-v.random --o -z output=soil_1 n=20 zmin=0 zmax=100 column=height
-v.random --o -z output=soil_2 n=20 zmin=0 zmax=100 column=height
-v.random --o -z output=soil_3 n=20 zmin=0 zmax=100 column=height
-
-n1=`g.tempfile pid=1 -d`
-
-cat > "${n1}" << EOF
-soil_1|2001-01-01|2001-04-01
-soil_2|2001-05-01|2001-07-01
-soil_3|2001-08-01|2001-12-01
-EOF
-
-t.create --o type=stvds temporaltype=absolute output=soil_abs1 title="A test" descr="A test"
-t.register type=vect input=soil_abs1 file="${n1}"
-
-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-03-01 00:00:00" increment="1 months"
-
-# The @test
-
-tr.aggregate.ds --o --v input=precip_abs1 output=precip_abs2 base=prec_sum type=stvds sample=soil_abs1 method=sum sampling=start,during
-t.info type=strds input=precip_abs2
-tr.list input=precip_abs2 method=deltagap
-
-# @postprocess
-t.unregister type=vect maps=soil_1,soil_2,soil_3
-t.remove type=stvds input=soil_abs1
-
-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.ds/tr.aggregate.ds.html
===================================================================
Deleted: grass/trunk/temporal/t.rast.aggregate.ds/tr.aggregate.ds.py
===================================================================
--- grass/trunk/temporal/tr.aggregate.ds/tr.aggregate.ds.py 2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.aggregate.ds/tr.aggregate.ds.py 2012-04-05 21:29:53 UTC (rev 51285)
@@ -1,173 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-############################################################################
-#
-# MODULE: tr.aggregate.ds
-# AUTHOR(S): Soeren Gebbert
-#
-# PURPOSE: Aggregated data of an existing space time raster dataset using the temporal topology of a second space time 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: Aggregated data of an existing space time raster dataset using the temporal topology of a second space time dataset
-#% keywords: temporal
-#% keywords: aggregation
-#%end
-
-#%option G_OPT_STRDS_INPUT
-#%end
-
-#%option G_OPT_STDS_INPUT
-#% key: sample
-#% description: The time intervals from this space time dataset (raster, vector or raster3d) are used for aggregation computation.
-#%end
-
-#%option G_OPT_STDS_TYPE
-#% description: Type of the aggregation space time dataset, default is strds
-#%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 peformed 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
-
-#%flag
-#% key: n
-#% description: Register Null maps
-#%end
-
-import grass.script as grass
-import grass.temporal as tgis
-
-############################################################################
-
-def main():
-
- # Get the options
- input = options["input"]
- output = options["output"]
- sampler = options["sample"]
- base = options["base"]
- register_null = flags["n"]
- method = options["method"]
- type = options["type"]
- sampling = options["sampling"]
-
- # 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 sampler.find("@") >= 0:
- sampler_id = sampler
- else:
- sampler_id = sampler + "@" + mapset
-
- sampler_sp = tgis.dataset_factory(type, sampler_id)
-
- if sampler_sp.is_in_db() == False:
- dbif.close()
- grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
-
- sampler_sp.select(dbif)
-
- if sampler_sp.get_temporal_type() != sp.get_temporal_type():
- dbif.close()
- grass.fatal(_("Input and aggregation dataset must have the same temporal type"))
-
- # Check if intervals are present
- if sampler_sp.get_temporal_type() == "absolute":
- map_time = sampler_sp.absolute_time.get_map_time()
- else:
- map_time = sampler_sp.relative_time.get_map_time()
-
- if map_time != "interval":
- dbif.close()
- grass.fatal(_("All registered maps of the aggregation dataset must have time intervals"))
-
- 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 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 = sampler_sp.get_registered_maps("id,start_time,end_time", None, "start_time", dbif)
-
- if not rows:
- dbif.close()
- grass.fatal(_("Aggregation dataset <%s> is empty") % id)
-
- count = 0
- for row in rows:
- count += 1
- start = row["start_time"]
- end = row["end_time"]
-
- 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)
-
- # 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