[GRASS-SVN] r48732 - in grass/trunk/temporal: . t.info tr.aggregate
tr.extract tr.list tr.series
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Oct 11 09:51:45 EDT 2011
Author: huhabla
Date: 2011-10-11 06:51:45 -0700 (Tue, 11 Oct 2011)
New Revision: 48732
Added:
grass/trunk/temporal/tr.list/
grass/trunk/temporal/tr.list/Makefile
grass/trunk/temporal/tr.list/test.tr.list.sh
grass/trunk/temporal/tr.list/tr.list.html
grass/trunk/temporal/tr.list/tr.list.py
Modified:
grass/trunk/temporal/Makefile
grass/trunk/temporal/t.info/t.info.py
grass/trunk/temporal/tr.aggregate/test.tr.aggregate.sh
grass/trunk/temporal/tr.aggregate/tr.aggregate.py
grass/trunk/temporal/tr.extract/tr.extract.py
grass/trunk/temporal/tr.series/tr.series.py
Log:
New strds list module. Minor fixes in several temporal modules.
Modified: grass/trunk/temporal/Makefile
===================================================================
--- grass/trunk/temporal/Makefile 2011-10-11 13:26:10 UTC (rev 48731)
+++ grass/trunk/temporal/Makefile 2011-10-11 13:51:45 UTC (rev 48732)
@@ -9,6 +9,7 @@
t.time.rel \
tr.aggregate \
tr.register \
+ tr.list \
tr.series \
tr.extract \
tr3.register \
Modified: grass/trunk/temporal/t.info/t.info.py
===================================================================
--- grass/trunk/temporal/t.info/t.info.py 2011-10-11 13:26:10 UTC (rev 48731)
+++ grass/trunk/temporal/t.info/t.info.py 2011-10-11 13:51:45 UTC (rev 48732)
@@ -24,7 +24,7 @@
#% key: dataset
#% type: string
#% description: Name of an existing space time or map dataset
-#% required: yes
+#% required: no
#% multiple: no
#%end
@@ -47,6 +47,12 @@
#% description: Print temporal relation matrix for space time datasets
#%end
+#%flag
+#% key: s
+#% description: Print information about the temporal DBMI interface and exit
+#%end
+
+
import grass.script as grass
import grass.temporal as tgis
@@ -59,12 +65,25 @@
type = options["type"]
shellstyle = flags['g']
tmatrix = flags['t']
+ system = flags['s']
- # Make sure the temporal database exists
+ # Make sure the temporal database exists
tgis.create_temporal_database()
#Get the current mapset to create the id of the space time dataset
+ if system:
+ # 0123456789012345678901234567890
+ print " +------------------- Temporal DBMI backend information ----------------------+"
+ print " | DBMI Python interface:...... " + str(tgis.dbmi.__name__)
+ print " | DBMI init string:........... " + str(tgis.get_temporal_dbmi_init_string())
+ print " | SQL template path:.......... " + str(tgis.get_sql_template_path())
+ print " +----------------------------------------------------------------------------+"
+ return
+
+ if not system and not name:
+ grass.fatal(_("Please specify %s=") % ("name"))
+
if name.find("@") >= 0:
id = name
else:
Modified: grass/trunk/temporal/tr.aggregate/test.tr.aggregate.sh
===================================================================
--- grass/trunk/temporal/tr.aggregate/test.tr.aggregate.sh 2011-10-11 13:26:10 UTC (rev 48731)
+++ grass/trunk/temporal/tr.aggregate/test.tr.aggregate.sh 2011-10-11 13:51:45 UTC (rev 48732)
@@ -15,7 +15,7 @@
r.mapcalc --o expr="prec_6 = rand(0, 650)"
t.create --o type=strds temporaltype=absolute dataset=precip_abs1 gran="3 months" title="A test" descr="A test"
-tr.register -i dataset=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"
+tr.register --v -i dataset=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
# We create the space time raster datasets and register the raster maps with absolute time interval
Modified: grass/trunk/temporal/tr.aggregate/tr.aggregate.py
===================================================================
--- grass/trunk/temporal/tr.aggregate/tr.aggregate.py 2011-10-11 13:26:10 UTC (rev 48731)
+++ grass/trunk/temporal/tr.aggregate/tr.aggregate.py 2011-10-11 13:51:45 UTC (rev 48732)
@@ -82,7 +82,7 @@
print where
- rows = sp.get_registered_maps(where, "start_time", dbif)
+ rows = sp.get_registered_maps("id", where, "start_time", dbif)
if not rows:
return None
@@ -107,7 +107,10 @@
# 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:
@@ -118,11 +121,9 @@
sp = tgis.space_time_raster_dataset(id)
if sp.is_in_db() == False:
+ dbif.close()
grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
- dbif = tgis.sql_database_interface()
- dbif.connect()
-
sp.select(dbif)
if output.find("@") >= 0:
@@ -132,20 +133,22 @@
# The new space time raster dataset
new_sp = tgis.space_time_raster_dataset(out_id)
- if new_sp.is_in_db():
+ 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)
granularity, temporal_type, semantic_type, title, description = sp.get_initial_values()
new_sp.set_initial_values(gran, temporal_type, semantic_type, title, description)
new_sp.insert(dbif)
- rows = sp.get_registered_maps(where, "start_time", 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
@@ -222,8 +225,8 @@
new_sp.register_map(new_map, dbif)
- # Update the spatio-temporal extent and the raster metadata table entries
- new_sp.update_from_registered_maps(dbif)
+ # Update the spatio-temporal extent and the raster metadata table entries
+ new_sp.update_from_registered_maps(dbif)
dbif.close()
Modified: grass/trunk/temporal/tr.extract/tr.extract.py
===================================================================
--- grass/trunk/temporal/tr.extract/tr.extract.py 2011-10-11 13:26:10 UTC (rev 48731)
+++ grass/trunk/temporal/tr.extract/tr.extract.py 2011-10-11 13:51:45 UTC (rev 48732)
@@ -117,7 +117,7 @@
new_sp.set_initial_values(granularity, temporal_type, semantic_type, title, description)
new_sp.insert(dbif)
- rows = sp.get_registered_maps(where, "start_time", dbif)
+ rows = sp.get_registered_maps("id", where, "start_time", dbif)
if rows:
num_rows = len(rows)
Added: grass/trunk/temporal/tr.list/Makefile
===================================================================
--- grass/trunk/temporal/tr.list/Makefile (rev 0)
+++ grass/trunk/temporal/tr.list/Makefile 2011-10-11 13:51:45 UTC (rev 48732)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../../
+
+PGM = tr.list
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script $(TEST_DST)
Added: grass/trunk/temporal/tr.list/test.tr.list.sh
===================================================================
--- grass/trunk/temporal/tr.list/test.tr.list.sh (rev 0)
+++ grass/trunk/temporal/tr.list/test.tr.list.sh 2011-10-11 13:51:45 UTC (rev 48732)
@@ -0,0 +1,25 @@
+# This is a test to list raster maps of a space time raster dataset
+
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# raster with r.mapcalc and create a space time raster datasets
+# 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 dataset=precip_abs1 gran="1 senconds" title="A test" descr="A test"
+
+tr.register -i dataset=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="2 months"
+t.info type=strds dataset=precip_abs1
+
+# The first @test
+tr.list -c input=precip_abs1
+
+t.remove type=strds dataset=precip_abs1
+t.remove type=raster dataset=prec_1,prec_2,prec_3
+t.remove type=raster dataset=prec_4,prec_5,prec_6
Added: grass/trunk/temporal/tr.list/tr.list.html
===================================================================
Added: grass/trunk/temporal/tr.list/tr.list.py
===================================================================
--- grass/trunk/temporal/tr.list/tr.list.py (rev 0)
+++ grass/trunk/temporal/tr.list/tr.list.py 2011-10-11 13:51:45 UTC (rev 48732)
@@ -0,0 +1,142 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE: tr.list
+# AUTHOR(S): Soeren Gebbert
+#
+# PURPOSE: List registered maps of a spae 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: List registered maps of a spae time raster dataset
+#% keywords: dataset
+#% keywords: spacetime
+#% keywords: raster
+#% keywords: list
+#%end
+
+#%option
+#% key: input
+#% type: string
+#% description: Name of a space time raster dataset
+#% required: yes
+#% multiple: no
+#%end
+
+#%option
+#% key: sort
+#% type: string
+#% description: Sort the space time dataset by category. Columns number_of_maps and granularity only available fpr space time datasets
+#% required: no
+#% multiple: yes
+#% options: id, name, creator, mapset, temporal_type, creation_time, start_time, end_time, north, south, west, east, nsres, ewres, cols, rows, number_of_cells, min, max
+#% answer: start_time
+#%end
+
+#%option
+#% key: columns
+#% type: string
+#% description: Which columns should be printed to stdout. Columns number_of_maps and granularity only available fpr space time datasets
+#% required: no
+#% multiple: yes
+#% options: id, name, creator, mapset, temporal_type, creation_time, start_time, end_time, north, south, west, east, nsres, ewres, cols, rows, number_of_cells, min, max
+#% answer: name,mapset,start_time,end_time
+#%end
+
+#%option
+#% key: where
+#% type: string
+#% description: A where statement for selected listing e.g: start_time < "2001-01-01" and end_time > "2001-01-01"
+#% required: no
+#% multiple: no
+#%end
+
+#%option
+#% key: fs
+#% type: string
+#% description: The field separator character between the columns, default is tabular "\t"
+#% required: no
+#%end
+
+#%flag
+#% key: c
+#% description: Print the column names as first row
+#%end
+
+import grass.script as grass
+import grass.temporal as tgis
+
+############################################################################
+
+def main():
+
+ # Get the options
+ input = options["input"]
+ columns = options["columns"]
+ sort = options["sort"]
+ where = options["where"]
+ separator = options["fs"]
+ colhead = flags['c']
+
+ # 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:
+ dbif.close()
+ grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
+
+ sp.select()
+
+ rows = sp.get_registered_maps(columns, where, sort, None)
+
+ # Print the query result to stout
+ if rows:
+ if separator == None or separator == "":
+ separator = "\t"
+
+ # Print the column names if requested
+ if colhead == True:
+ output = ""
+ count = 0
+
+ collist = columns.split(",")
+
+ for key in collist:
+ if count > 0:
+ output += separator + str(key)
+ else:
+ output += str(key)
+ count += 1
+ print output
+
+ for row in rows:
+ output = ""
+ count = 0
+ for col in row:
+ if count > 0:
+ output += separator + str(col)
+ else:
+ output += str(col)
+ count += 1
+
+ print output
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ main()
Property changes on: grass/trunk/temporal/tr.list/tr.list.py
___________________________________________________________________
Added: svn:executable
+ *
Modified: grass/trunk/temporal/tr.series/tr.series.py
===================================================================
--- grass/trunk/temporal/tr.series/tr.series.py 2011-10-11 13:26:10 UTC (rev 48731)
+++ grass/trunk/temporal/tr.series/tr.series.py 2011-10-11 13:51:45 UTC (rev 48732)
@@ -91,7 +91,7 @@
sp.select()
- rows = sp.get_registered_maps(where, sort, None)
+ rows = sp.get_registered_maps("id", where, sort, None)
if rows:
# Create the r.series input file
More information about the grass-commit
mailing list