[GRASS-SVN] r51283 - in grass/trunk/temporal: . t.rast.univar
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Apr 5 17:23:44 EDT 2012
Author: huhabla
Date: 2012-04-05 14:23:44 -0700 (Thu, 05 Apr 2012)
New Revision: 51283
Added:
grass/trunk/temporal/t.rast.univar/
grass/trunk/temporal/t.rast.univar/t.rast.univar.html
grass/trunk/temporal/t.rast.univar/t.rast.univar.py
grass/trunk/temporal/t.rast.univar/test.t.rast.univar.sh
Removed:
grass/trunk/temporal/t.rast.univar/test.tr.univar.sh
grass/trunk/temporal/t.rast.univar/tr.univar.html
grass/trunk/temporal/t.rast.univar/tr.univar.py
Modified:
grass/trunk/temporal/t.rast.univar/Makefile
Log:
Using new naming scheme
Modified: grass/trunk/temporal/t.rast.univar/Makefile
===================================================================
--- grass/trunk/temporal/tr.univar/Makefile 2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.univar/Makefile 2012-04-05 21:23:44 UTC (rev 51283)
@@ -1,6 +1,6 @@
MODULE_TOPDIR = ../../
-PGM = tr.univar
+PGM = t.rast.univar
include $(MODULE_TOPDIR)/include/Make/Script.make
Copied: grass/trunk/temporal/t.rast.univar/t.rast.univar.html (from rev 51264, grass/trunk/temporal/tr.univar/tr.univar.html)
===================================================================
Copied: grass/trunk/temporal/t.rast.univar/t.rast.univar.py (from rev 51264, grass/trunk/temporal/tr.univar/tr.univar.py)
===================================================================
--- grass/trunk/temporal/t.rast.univar/t.rast.univar.py (rev 0)
+++ grass/trunk/temporal/t.rast.univar/t.rast.univar.py 2012-04-05 21:23:44 UTC (rev 51283)
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE: t.rast.univar
+# AUTHOR(S): Soeren Gebbert
+#
+# PURPOSE: Calculates univariate statistics from the non-null cells for each registered raster map 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: Calculates univariate statistics from the non-null cells for each registered raster map of a space time raster dataset
+#% keywords: spacetime raster dataset
+#% keywords: raster
+#% keywords: statistics
+#%end
+
+#%option G_OPT_STRDS_INPUT
+#%end
+
+#%option G_OPT_T_WHERE
+#%end
+
+#%option
+#% key: fs
+#% type: string
+#% description: The field separator character between the output columns
+#% required: no
+#% answer: |
+#%end
+
+#%flag
+#% key: e
+#% description: Calculate extended statistics
+#%end
+
+#%flag
+#% key: h
+#% description: Print column names
+#%end
+
+import grass.script as grass
+import grass.temporal as tgis
+
+############################################################################
+
+def main():
+
+ # Get the options
+ input = options["input"]
+ where = options["where"]
+ extended = flags["e"]
+ header = flags["h"]
+ fs = options["fs"]
+
+ # 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(dbif) == False:
+ dbif.close()
+ grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
+
+ sp.select(dbif)
+
+ rows = sp.get_registered_maps("id,start_time,end_time", where, "start_time", dbif)
+
+ if not rows:
+ dbif.close()
+ grass.fatal(_("Space time raster dataset <%s> is empty") % out_id)
+
+ if header == True:
+ print "id" + fs + "start" + fs + "end" + fs + "mean" + fs + "min" + fs + "max" + fs,
+ print "mean_of_abs" + fs + "stddev" + fs + "variance" + fs,
+ if extended == True:
+ print "coeff_var" + fs + "sum" + fs + "null_cells" + fs + "cells" + fs,
+ print "first_quartile" + fs + "median" + fs + "third_quartile" + fs + "percentile_90"
+ else:
+ print "coeff_var" + fs + "sum" + fs + "null_cells" + fs + "cells"
+
+ for row in rows:
+ id = row["id"]
+ start = row["start_time"]
+ end = row["end_time"]
+
+ flag="g"
+
+ if extended == True:
+ flag += "e"
+
+ stats = grass.parse_command("r.univar", map=id, flags=flag)
+
+ print str(id) + fs + str(start) + fs + str(end),
+ print fs + str(stats["mean"]) + fs + str(stats["min"]) + fs + str(stats["max"]) + fs + str(stats["mean_of_abs"]),
+ print fs + str(stats["stddev"]) + fs + str(stats["variance"]) + fs + str(stats["coeff_var"]) + fs + str(stats["sum"]),
+
+ if extended == True:
+ print fs + str(stats["null_cells"]) + fs + str(stats["cells"]) + fs,
+ print str(stats["first_quartile"]) + fs + str(stats["median"]) + fs + str(stats["third_quartile"]) + fs + str(stats["percentile_90"])
+ else:
+ print fs + str(stats["null_cells"]) + fs + str(stats["cells"])
+
+ dbif.close()
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ main()
+
Copied: grass/trunk/temporal/t.rast.univar/test.t.rast.univar.sh (from rev 51264, grass/trunk/temporal/tr.univar/test.tr.univar.sh)
===================================================================
--- grass/trunk/temporal/t.rast.univar/test.t.rast.univar.sh (rev 0)
+++ grass/trunk/temporal/t.rast.univar/test.t.rast.univar.sh 2012-04-05 21:23:44 UTC (rev 51283)
@@ -0,0 +1,22 @@
+# 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=absolute output=precip_abs1 title="A test" descr="A test"
+t.register type=rast --v -i 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.univar -he input=precip_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
Deleted: grass/trunk/temporal/t.rast.univar/test.tr.univar.sh
===================================================================
--- grass/trunk/temporal/tr.univar/test.tr.univar.sh 2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.univar/test.tr.univar.sh 2012-04-05 21:23:44 UTC (rev 51283)
@@ -1,22 +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=absolute output=precip_abs1 title="A test" descr="A test"
-t.register type=rast --v -i 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.univar -he input=precip_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
Deleted: grass/trunk/temporal/t.rast.univar/tr.univar.html
===================================================================
Deleted: grass/trunk/temporal/t.rast.univar/tr.univar.py
===================================================================
--- grass/trunk/temporal/tr.univar/tr.univar.py 2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.univar/tr.univar.py 2012-04-05 21:23:44 UTC (rev 51283)
@@ -1,125 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-############################################################################
-#
-# MODULE: tr.univar
-# AUTHOR(S): Soeren Gebbert
-#
-# PURPOSE: Calculates univariate statistics from the non-null cells for each registered raster map 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: Calculates univariate statistics from the non-null cells for each registered raster map of a space time raster dataset
-#% keywords: spacetime raster dataset
-#% keywords: raster
-#% keywords: statistics
-#%end
-
-#%option G_OPT_STRDS_INPUT
-#%end
-
-#%option G_OPT_T_WHERE
-#%end
-
-#%option
-#% key: fs
-#% type: string
-#% description: The field separator character between the output columns
-#% required: no
-#% answer: |
-#%end
-
-#%flag
-#% key: e
-#% description: Calculate extended statistics
-#%end
-
-#%flag
-#% key: h
-#% description: Print column names
-#%end
-
-import grass.script as grass
-import grass.temporal as tgis
-
-############################################################################
-
-def main():
-
- # Get the options
- input = options["input"]
- where = options["where"]
- extended = flags["e"]
- header = flags["h"]
- fs = options["fs"]
-
- # 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(dbif) == False:
- dbif.close()
- grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
-
- sp.select(dbif)
-
- rows = sp.get_registered_maps("id,start_time,end_time", where, "start_time", dbif)
-
- if not rows:
- dbif.close()
- grass.fatal(_("Space time raster dataset <%s> is empty") % out_id)
-
- if header == True:
- print "id" + fs + "start" + fs + "end" + fs + "mean" + fs + "min" + fs + "max" + fs,
- print "mean_of_abs" + fs + "stddev" + fs + "variance" + fs,
- if extended == True:
- print "coeff_var" + fs + "sum" + fs + "null_cells" + fs + "cells" + fs,
- print "first_quartile" + fs + "median" + fs + "third_quartile" + fs + "percentile_90"
- else:
- print "coeff_var" + fs + "sum" + fs + "null_cells" + fs + "cells"
-
- for row in rows:
- id = row["id"]
- start = row["start_time"]
- end = row["end_time"]
-
- flag="g"
-
- if extended == True:
- flag += "e"
-
- stats = grass.parse_command("r.univar", map=id, flags=flag)
-
- print str(id) + fs + str(start) + fs + str(end),
- print fs + str(stats["mean"]) + fs + str(stats["min"]) + fs + str(stats["max"]) + fs + str(stats["mean_of_abs"]),
- print fs + str(stats["stddev"]) + fs + str(stats["variance"]) + fs + str(stats["coeff_var"]) + fs + str(stats["sum"]),
-
- if extended == True:
- print fs + str(stats["null_cells"]) + fs + str(stats["cells"]) + fs,
- print str(stats["first_quartile"]) + fs + str(stats["median"]) + fs + str(stats["third_quartile"]) + fs + str(stats["percentile_90"])
- else:
- print fs + str(stats["null_cells"]) + fs + str(stats["cells"])
-
- dbif.close()
-
-if __name__ == "__main__":
- options, flags = grass.parser()
- main()
-
More information about the grass-commit
mailing list