[GRASS-SVN] r48594 - in grass/trunk: lib/python/temporal
temporal/t.info temporal/t.list temporal/t.time.abs
temporal/t.time.rel temporal/tr.extract temporal/tr.register
temporal/tr.series temporal/tr3.register temporal/tv.register
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Oct 1 20:00:15 EDT 2011
Author: huhabla
Date: 2011-10-01 17:00:15 -0700 (Sat, 01 Oct 2011)
New Revision: 48594
Modified:
grass/trunk/lib/python/temporal/abstract_datasets.py
grass/trunk/lib/python/temporal/base.py
grass/trunk/lib/python/temporal/space_time_datasets.py
grass/trunk/lib/python/temporal/temporal_extent.py
grass/trunk/temporal/t.info/t.info.py
grass/trunk/temporal/t.list/t.list.py
grass/trunk/temporal/t.time.abs/t.time.abs.py
grass/trunk/temporal/t.time.abs/test.t.time.abs.sh
grass/trunk/temporal/t.time.rel/t.time.rel.py
grass/trunk/temporal/t.time.rel/test.t.time.rel.sh
grass/trunk/temporal/tr.extract/tr.extract.py
grass/trunk/temporal/tr.register/test.tr.register.sh
grass/trunk/temporal/tr.register/tr.register.py
grass/trunk/temporal/tr.series/test.tr.series.sh
grass/trunk/temporal/tr.series/tr.series.py
grass/trunk/temporal/tr3.register/test.tr3.register.sh
grass/trunk/temporal/tr3.register/tr3.register.py
grass/trunk/temporal/tv.register/test.tv.register.sh
grass/trunk/temporal/tv.register/tv.register.py
Log:
Better support for single points of time. Implemented temporal relation matrix in t.info.
Modified: grass/trunk/lib/python/temporal/abstract_datasets.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_datasets.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/lib/python/temporal/abstract_datasets.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -20,6 +20,7 @@
@author Soeren Gebbert
"""
import uuid
+import copy
from temporal_extent import *
from spatial_extent import *
from metadata import *
@@ -265,7 +266,7 @@
connect = True
self.set_absolute_time(start_time, end_time, timezone)
- self.absolute_time.update(dbif)
+ self.absolute_time.update_all(dbif)
self.base.update(dbif)
if connect == True:
@@ -307,7 +308,7 @@
connect = True
self.set_relative_time(start_time, end_time)
- self.relative_time.update(dbif)
+ self.relative_time.update_all(dbif)
self.base.update(dbif)
if connect == True:
@@ -464,8 +465,9 @@
self.metadata.set_title(title)
self.metadata.set_description(description)
- def get_registered_maps(self, dbif=None, where = None):
- """Return sqlite rows with ids of all registered maps. In case nothing found None is returned"""
+ def get_temporal_relation_matrix(self, dbif=None):
+ """Return the temporal relation matrix between all registered maps
+ """
connect = False
@@ -474,17 +476,96 @@
dbif.connect()
connect = True
+ matrix = []
+
+ maps = self.get_registered_maps_as_objects(dbif=dbif, where=None, order="start_time")
+
+ # Create the temporal relation matrix
+ # Add the map names first
+ row = []
+ for map in maps:
+ row.append(map.get_id())
+ matrix.append(row)
+
+ for mapA in maps:
+ row = []
+ for mapB in maps:
+ row.append(mapA.temporal_relation(mapB))
+ matrix.append(row)
+
+ if connect == True:
+ dbif.close()
+
+ return matrix
+
+ def get_registered_maps_as_objects(self, dbif=None, where = None, order = None):
+ """Return all registered maps as ordered object list
+
+ Each row includes all columns specified in the datatype specific view
+
+ In case nothing found None is returned
+ """
+
+ connect = False
+
+ if dbif == None:
+ dbif = sql_database_interface()
+ dbif.connect()
+ connect = True
+
+ obj_list = []
+
+ rows = self.get_registered_maps(dbif, where, order)
+
+ if rows:
+ for row in rows:
+ map = self.get_new_map_instance(row["id"])
+ map.select(dbif)
+ obj_list.append(copy.copy(map))
+
+ if connect == True:
+ dbif.close()
+
+ return obj_list
+
+ def get_registered_maps(self, dbif=None, where = None, order = None):
+ """Return sqlite rows of all registered maps.
+
+ Each row includes all columns specified in the datatype specific view
+
+ In case nothing found None is returned
+ """
+
+ connect = False
+
+ if dbif == None:
+ dbif = sql_database_interface()
+ dbif.connect()
+ connect = True
+
rows = None
if self.get_map_register():
- sql = "SELECT id FROM " + self.get_map_register()
+ # Use the correct temporal table
+ if self.get_temporal_type() == "absolute":
+ map_view = self.get_new_map_instance(None).get_type() + "_view_abs_time"
+ else:
+ map_view = self.get_new_map_instance(None).get_type() + "_view_rel_time"
+
+ sql = "SELECT * FROM %s WHERE %s.id IN (SELECT id FROM %s)" % (map_view, map_view, self.get_map_register())
+
if where:
- sql += " WHERE %s" % (where)
+ sql += " AND %s" % (where)
+ if order:
+ sql += " ORDER BY %s" % (order)
+
+ print sql
+
try:
dbif.cursor.execute(sql)
rows = dbif.cursor.fetchall()
except:
- core.error("Unable to get map ids from register table <" + self.get_map_register() + ">")
+ core.error(_("Unable to get map ids from register table <%s>") % (self.get_map_register()))
raise
if connect == True:
@@ -497,7 +578,7 @@
# First we need to check if maps are registered in this dataset and
# unregister them
- core.verbose("Delete space time " + self.get_new_map_instance(ident=None).get_type() + " dataset <" + self.get_id() + "> from temporal database")
+ core.verbose(_("Delete space time %s dataset <%s> from temporal database") % (self.get_new_map_instance(ident=None).get_type(), self.get_id()))
connect = False
@@ -519,7 +600,7 @@
sql = "DROP TABLE " + self.get_map_register()
dbif.cursor.execute(sql)
except:
- core.error("Unable to drop table <" + self.get_map_register() + ">")
+ core.error(_("Unable to drop table <%s>") % (self.get_map_register()))
raise
# Remove the primary key, the foreign keys will be removed by trigger
Modified: grass/trunk/lib/python/temporal/base.py
===================================================================
--- grass/trunk/lib/python/temporal/base.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/lib/python/temporal/base.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -85,7 +85,7 @@
if where:
sql += where
- # Create update statement
+ # Create update statement for existing entries
if type =="UPDATE":
count = 0
sql += 'UPDATE ' + table + ' SET '
@@ -101,6 +101,20 @@
if where:
sql += where
+ # Create update statement
+ if type =="UPDATE ALL":
+ count = 0
+ sql += 'UPDATE ' + table + ' SET '
+ for key in self.D.keys():
+ if count == 0:
+ sql += ' %s = ? ' % key
+ else:
+ sql += ' ,%s = ? ' % key
+ count += 1
+ args.append(self.D[key])
+ if where:
+ sql += where
+
return sql, tuple(args)
def deserialize(self, row):
@@ -264,6 +278,24 @@
self.cursor.execute(sql, args)
self.close()
+ def get_update_all_statement(self):
+ return self.serialize("UPDATE ALL", self.get_table_name(), "WHERE id = \"" + str(self.ident) + "\"")
+
+ def update_all(self, dbif=None):
+ if self.ident == None:
+ raise IOError("Missing identifer");
+
+ sql, args = self.get_update_all_statement()
+ #print sql
+ #print args
+
+ if dbif:
+ dbif.cursor.execute(sql, args)
+ else:
+ self.connect()
+ self.cursor.execute(sql, args)
+ self.close()
+
###############################################################################
class dataset_base(sql_database_interface):
Modified: grass/trunk/lib/python/temporal/space_time_datasets.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/lib/python/temporal/space_time_datasets.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -373,7 +373,7 @@
###############################################################################
-def register_maps_in_space_time_dataset(type, name, maps, start=None, increment=None, dbif = None):
+def register_maps_in_space_time_dataset(type, name, maps, start=None, increment=None, dbif = None, interval=False):
"""Use this method to register maps in space time datasets. This function is generic and
can handle raster, vector and raster3d maps as well as there space time datasets.
@@ -388,6 +388,8 @@
@maps A comma separated list of map names
@start The start date and time of the first raster map, in case the map has no date (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd", format relative 5.0)
@increment Time increment between maps for time stamp creation (format absolute: NNN seconds, minutes, hours, days, weeks, months, years; format relative: 1.0)
+ @dbif The database interface to use for sql queries
+ @interval If True, time intervals are created in case the start time and an increment is provided
"""
# We may need the mapset
@@ -458,7 +460,7 @@
# Set the valid time
if start:
- assign_valid_time_to_map(ttype=sp.get_temporal_type(), map=map, start=start, end=None, increment=increment, mult=count, dbif=dbif)
+ assign_valid_time_to_map(ttype=sp.get_temporal_type(), map=map, start=start, end=None, increment=increment, mult=count, dbif=dbif, interval=interval)
# Finally Register map in the space time dataset
sp.register_map(map, dbif)
@@ -544,7 +546,7 @@
###############################################################################
-def assign_valid_time_to_maps(type, maps, ttype, start, end=None, increment=None, dbif = None):
+def assign_valid_time_to_maps(type, maps, ttype, start, end=None, increment=None, dbif = None, interval=False):
"""Use this method to assign valid time (absolute or relative) to raster,
raster3d and vector datasets.
@@ -558,6 +560,8 @@
@start The start date and time of the first raster map (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd", format relative 5.0)
@end The end date and time of the first raster map (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd", format relative 5.0)
@increment Time increment between maps for time stamp creation (format absolute: NNN seconds, minutes, hours, days, weeks, months, years; format relative: 1.0)
+ @dbif The database interface to use for sql queries
+ @interval If True, time intervals are created in case the start time and an increment is provided
"""
if end and increment:
@@ -614,7 +618,7 @@
splist[dataset["id"]] = True
# Set the valid time
- assign_valid_time_to_map(ttype=ttype, map=map, start=start, end=end, increment=increment, mult=count, dbif=dbif)
+ assign_valid_time_to_map(ttype=ttype, map=map, start=start, end=end, increment=increment, mult=count, dbif=dbif, interval=interval)
count += 1
@@ -630,7 +634,7 @@
###############################################################################
-def assign_valid_time_to_map(ttype, map, start, end, increment=None, mult=1, dbif = None):
+def assign_valid_time_to_map(ttype, map, start, end, increment=None, mult=1, dbif = None, interval=False):
"""Assign the valid time to a map dataset
@ttype The temporal type which should be assigned and which the time format is of
@@ -639,6 +643,8 @@
@end The end date and time of the first raster map (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd", format relative 5.0)
@increment Time increment between maps for time stamp creation (format absolute: NNN seconds, minutes, hours, days, weeks, months, years; format relative: 1.0)
@multi A multiplier for the increment
+ @dbif The database interface to use for sql queries
+ @interval If True, time intervals are created in case the start time and an increment is provided
"""
connect = False
@@ -656,29 +662,30 @@
time_format = "%Y-%m-%d"
start_time = datetime.strptime(start, time_format)
+ end_time = None
+
if end:
end_time = datetime.strptime(end, time_format)
- else:
- end_time = None
# Add the increment
if increment:
start_time = increment_datetime_by_string(start_time, increment, mult)
- end_time = increment_datetime_by_string(start_time, increment, 1)
+ if interval:
+ end_time = increment_datetime_by_string(start_time, increment, 1)
core.verbose(_("Set absolute valid time for map <%s> to %s - %s") % (map.get_id(), str(start_time), str(end_time)))
map.update_absolute_time(start_time, end_time, None, dbif)
else:
start_time = float(start)
+ end_time = None
if end:
end_time = float(end)
- else:
- end_time = None
if increment:
start_time = start_time + mult * float(increment)
- end_time = start_time + float(increment)
+ if interval:
+ end_time = start_time + float(increment)
core.verbose(_("Set relative valid time for map <%s> to %f - %s") % (map.get_id(), start_time, str(end_time)))
map.update_relative_time(start_time, end_time, dbif)
Modified: grass/trunk/lib/python/temporal/temporal_extent.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_extent.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/lib/python/temporal/temporal_extent.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -35,132 +35,197 @@
self.set_end_time(end_time)
def starts(self, map):
- """Return True if this absolute time object starts at the start of the provided absolute time object and finishes within it
+ """Return True if this time object starts at the start of the provided time object and finishes within it
A |-----|
B |---------|
"""
+ if self.D["end_time"] == None or map.D["end_time"] == None :
+ return False
+
if self.D["start_time"] == map.D["start_time"] and self.D["end_time"] < map.D["end_time"]:
return True
else:
return False
def started(self, map):
- """Return True if this absolute time object is started at the start of the provided absolute time object
+ """Return True if this time object is started at the start of the provided time object
A |---------|
B |-----|
"""
+ if self.D["end_time"] == None or map.D["end_time"] == None :
+ return False
+
if self.D["start_time"] == map.D["start_time"] and self.D["end_time"] > map.D["end_time"]:
return True
else:
return False
def finishes(self, map):
- """Return True if this absolute time object finishes at the end and within of the provided absolute time object
+ """Return True if this time object finishes at the end and within of the provided time object
A |-----|
B |---------|
"""
+ if self.D["end_time"] == None or map.D["end_time"] == None :
+ return False
+
if self.D["end_time"] == map.D["end_time"] and self.D["start_time"] > map.D["start_time"] :
return True
else:
return False
def finished(self, map):
- """Return True if this absolute time object finished at the end of the provided absolute time object
+ """Return True if this time object finished at the end of the provided time object
A |---------|
B |-----|
"""
+ if self.D["end_time"] == None or map.D["end_time"] == None :
+ return False
+
if self.D["end_time"] == map.D["end_time"] and self.D["start_time"] < map.D["start_time"] :
return True
else:
return False
def after(self, map):
- """Return True if this absolute time object is temporal located after the provided absolute time object
+ """Return True if this time object is temporal located after the provided time object
A |---------|
B |---------|
"""
+ if map.D["end_time"] == None:
+ if self.D["start_time"] > map.D["start_time"]:
+ return True
+ else:
+ return False
+
if self.D["start_time"] > map.D["end_time"]:
return True
else:
return False
def before(self, map):
- """Return True if this absolute time object is temporal located bevor the provided absolute time object
+ """Return True if this time object is temporal located bevor the provided time object
A |---------|
B |---------|
"""
+ if self.D["end_time"] == None:
+ if self.D["start_time"] < map.D["start_time"]:
+ return True
+ else:
+ return False
+
if self.D["end_time"] < map.D["start_time"]:
return True
else:
return False
def adjacent(self, map):
- """Return True if this absolute time object is a meeting neighbour the provided absolute time object
+ """Return True if this time object is a meeting neighbour the provided time object
A |---------|
B |---------|
A |---------|
B |---------|
"""
+ if self.D["end_time"] == None and map.D["end_time"] == None :
+ return False
+
if (self.D["start_time"] == map.D["end_time"]) or (self.D["end_time"] == map.D["start_time"]):
return True
else:
return False
def follows(self, map):
- """Return True if this absolute time object is temporal follows the provided absolute time object
+ """Return True if this time object is temporal follows the provided time object
A |---------|
B |---------|
"""
+ if map.D["end_time"] == None :
+ return False
+
if self.D["start_time"] == map.D["end_time"]:
return True
else:
return False
def precedes(self, map):
- """Return True if this absolute time object is temporal precedes the provided absolute time object
+ """Return True if this time object is temporal precedes the provided time object
A |---------|
B |---------|
"""
+ if self.D["end_time"] == None:
+ return False
+
if self.D["end_time"] == map.D["start_time"]:
return True
else:
return False
def during(self, map):
- """Return True if this absolute time object is temporal located during the provided absolute time object
+ """Return True if this time object is temporal located during the provided time object
A |-------|
B |---------|
"""
+ if self.D["end_time"] == None and map.D["end_time"] == None :
+ return False
+
+ # Check single point of time in interval
+ if self.D["end_time"] == None:
+ if self.D["start_time"] > map.D["start_time"] and self.D["start_time"] < map.D["end_time"]:
+ return True
+ else:
+ return False
+
if self.D["start_time"] > map.D["start_time"] and self.D["end_time"] < map.D["end_time"]:
return True
else:
return False
def contains(self, map):
- """Return True if this absolute time object is temporal located during the provided absolute time object
+ """Return True if this time object contains the provided time object
A |---------|
B |-------|
"""
+ if self.D["end_time"] == None and map.D["end_time"] == None :
+ return False
+
+ # Check single point of time in interval
+ if map.D["end_time"] == None:
+ if self.D["start_time"] < map.D["start_time"] and self.D["end_time"] > map.D["start_time"]:
+ return True
+ else:
+ return False
+
if self.D["start_time"] < map.D["start_time"] and self.D["end_time"] > map.D["end_time"]:
return True
else:
return False
def equivalent(self, map):
- """Return True if this absolute time object is temporal located equivalent the provided absolute time object
+ """Return True if this time object is temporal located equivalent the provided time object
A |---------|
B |---------|
"""
+ if self.D["end_time"] == None and map.D["end_time"] == None :
+ if self.D["start_time"] == map.D["start_time"]:
+ return True
+ else:
+ return False
+
+ if self.D["end_time"] == None or map.D["end_time"] == None :
+ return False
+
if self.D["start_time"] == map.D["start_time"] and self.D["end_time"] == map.D["end_time"]:
return True
else:
return False
def overlaps(self, map):
- """Return True if this absolute time object is temporal overlaps the provided absolute time object
+ """Return True if this time object is temporal overlaps the provided time object
A |---------|
B |---------|
"""
+ if self.D["end_time"] == None or map.D["end_time"] == None :
+ return False
+
if self.D["start_time"] < map.D["start_time"] and self.D["end_time"] < map.D["end_time"] and\
self.D["end_time"] > map.D["start_time"]:
return True
@@ -168,10 +233,13 @@
return False
def overlapped(self, map):
- """Return True if this absolute time object is temporal overlaped by the provided absolute time object
+ """Return True if this time object is temporal overlaped by the provided time object
A |---------|
B |---------|
"""
+ if self.D["end_time"] == None or map.D["end_time"] == None :
+ return False
+
if self.D["start_time"] > map.D["start_time"] and self.D["end_time"] > map.D["end_time"] and\
self.D["start_time"] < map.D["end_time"]:
return True
@@ -179,7 +247,7 @@
return False
def temporal_relation(self, map):
- """Returns the temporal relation between absolute time temporal objects
+ """Returns the temporal relation between temporal objects
Temporal relationsships are implemented after [Allen and Ferguson 1994 Actions and Events in Interval Temporal Logic]
"""
if self.equivalent(map):
Modified: grass/trunk/temporal/t.info/t.info.py
===================================================================
--- grass/trunk/temporal/t.info/t.info.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/t.info/t.info.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -42,6 +42,11 @@
#% description: Print information in shell style
#%end
+#%flag
+#% key: t
+#% description: Print temporal relation matrix for space time datasets
+#%end
+
import grass.script as grass
import grass.temporal as tgis
@@ -53,6 +58,7 @@
name = options["dataset"]
type = options["type"]
shellstyle = flags['g']
+ tmatrix = flags['t']
# Make sure the temporal database exists
tgis.create_temporal_database()
@@ -73,10 +79,13 @@
sp = tgis.space_time_vector_dataset(id)
if type == "raster":
sp = tgis.raster_dataset(id)
+ tmatrix = False
if type == "raster3d":
sp = tgis.raster3d_dataset(id)
+ tmatrix = False
if type == "vector":
sp = tgis.vector_dataset(id)
+ tmatrix = False
if sp.is_in_db() == False:
grass.fatal("Dataset <" + name + "> not found in temporal database")
@@ -84,6 +93,15 @@
# Insert content from db
sp.select()
+ if tmatrix:
+ matrix = sp.get_temporal_relation_matrix()
+
+ for row in matrix:
+ for col in row:
+ print col,
+ print " "
+ print " "
+
if shellstyle == True:
sp.print_shell_info()
else:
Modified: grass/trunk/temporal/t.list/t.list.py
===================================================================
--- grass/trunk/temporal/t.list/t.list.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/t.list/t.list.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -46,7 +46,7 @@
#% 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, number_of_maps, creation_time, modification_time, revision, start_time, end_time, interval, north, south, west, east, granularity, all
+#% options: id, name, creator, mapset, number_of_maps, creation_time, modification_time, revision, start_time, end_time, north, south, west, east, granularity, all
#% answer: id
#%end
Modified: grass/trunk/temporal/t.time.abs/t.time.abs.py
===================================================================
--- grass/trunk/temporal/t.time.abs/t.time.abs.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/t.time.abs/t.time.abs.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -55,6 +55,11 @@
#% multiple: no
#%end
+#%flag
+#% key: i
+#% description: Create an interval (start and end time) in case an increment is provided
+#%end
+
import grass.script as grass
import grass.temporal as tgis
@@ -67,12 +72,14 @@
start = options["start"]
end = options["end"]
increment = options["increment"]
+ interval = flags["i"]
# Make sure the temporal database exists
tgis.create_temporal_database()
# Set valid absolute time to maps
tgis.assign_valid_time_to_maps(type="raster", maps=maps, ttype="absolute", \
- start=start, end=end, increment=increment, dbif=None)
+ start=start, end=end, increment=increment, \
+ dbif=None, interval=interval)
if __name__ == "__main__":
options, flags = grass.parser()
Modified: grass/trunk/temporal/t.time.abs/test.t.time.abs.sh
===================================================================
--- grass/trunk/temporal/t.time.abs/test.t.time.abs.sh 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/t.time.abs/test.t.time.abs.sh 2011-10-02 00:00:15 UTC (rev 48594)
@@ -29,6 +29,10 @@
t.time.abs --v maps=prec_1,prec_2,prec_3 start="2011-01-01" increment="1 months"
t.info type=strds dataset=precip_abs1
+# Check if the space time datasets are updated correctly
+t.time.abs --v -i maps=prec_1,prec_2,prec_3 start="2011-01-01" increment="1 months"
+t.info type=strds dataset=precip_abs1
+
t.time.abs --v maps=prec_4,prec_5 start="2001-01-01" end="2002-01-01"
t.info type=raster dataset=prec_4
t.info type=raster dataset=prec_5
Modified: grass/trunk/temporal/t.time.rel/t.time.rel.py
===================================================================
--- grass/trunk/temporal/t.time.rel/t.time.rel.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/t.time.rel/t.time.rel.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -55,6 +55,11 @@
#% multiple: no
#%end
+#%flag
+#% key: i
+#% description: Create an interval (start and end time) in case an increment is provided
+#%end
+
import grass.script as grass
import grass.temporal as tgis
@@ -67,12 +72,14 @@
start = options["start"]
end = options["end"]
increment = options["increment"]
+ interval = flags["i"]
# Make sure the temporal database exists
tgis.create_temporal_database()
# Set valid relative time to maps
tgis.assign_valid_time_to_maps(type="raster", maps=maps, ttype="relative", \
- start=start, end=end, increment=increment, dbif=None)
+ start=start, end=end, increment=increment, \
+ dbif=None, interval=interval)
if __name__ == "__main__":
options, flags = grass.parser()
Modified: grass/trunk/temporal/t.time.rel/test.t.time.rel.sh
===================================================================
--- grass/trunk/temporal/t.time.rel/test.t.time.rel.sh 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/t.time.rel/test.t.time.rel.sh 2011-10-02 00:00:15 UTC (rev 48594)
@@ -29,6 +29,9 @@
t.time.rel --v maps=prec_1,prec_2,prec_3 start=0 increment=1000
t.info type=strds dataset=precip_rel1
+t.time.rel --v maps=prec_1,prec_2,prec_3 start=0 increment=1000 -i
+t.info type=strds dataset=precip_rel1
+
t.time.rel --v maps=prec_4,prec_5 start=5000 end=6000
t.info type=raster dataset=prec_4
t.info type=raster dataset=prec_5
Modified: grass/trunk/temporal/tr.extract/tr.extract.py
===================================================================
--- grass/trunk/temporal/tr.extract/tr.extract.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/tr.extract/tr.extract.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -15,7 +15,7 @@
#############################################################################
#%module
-#% description: Register raster maps in a space time raster dataset
+#% description: Extract a subset of a space time raster dataset
#% keywords: spacetime raster dataset
#% keywords: raster
#% keywords: extract
@@ -48,7 +48,15 @@
#% multiple: no
#%end
+#%option
+#% key: base
+#% type: string
+#% description: Base name of the new created raster maps
+#% required: yes
+#% multiple: no
+#%end
+
import grass.script as grass
import grass.temporal as tgis
@@ -64,6 +72,41 @@
# Make sure the temporal database exists
tgis.create_temporal_database()
+
+ if input.find("@") >= 0:
+ id = input
+ else:
+ mapset = grass.gisenv()["MAPSET"]
+ id = input + "@" + mapset
+
+ sp = tgis.space_time_raster_dataset(id)
+
+ if sp.is_in_db() == False:
+ grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
+
+ sp.select()
+
+ rows = sp.get_registered_maps(None, where, sort)
+
+ if rows:
+ inputs = ""
+
+ count = 0
+ for row in rows:
+ if count == 0:
+ inputs += row["id"]
+ else:
+ inputs += "," + row["id"]
+ count += 1
+
+ print inputs
+
+ if grass.overwrite() == True:
+ grass.run_command("r.mapcalc", expression=expression, overwrite=True)
+ else:
+ grass.run_command("r.mapcalc", expression=expression, overwrite=False)
+
+
if __name__ == "__main__":
options, flags = grass.parser()
main()
Modified: grass/trunk/temporal/tr.register/test.tr.register.sh
===================================================================
--- grass/trunk/temporal/tr.register/test.tr.register.sh 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/tr.register/test.tr.register.sh 2011-10-02 00:00:15 UTC (rev 48594)
@@ -28,16 +28,19 @@
t.create --v --o type=strds temporaltype=absolute dataset=precip_abs6 gran="1 months" title="A test" descr="A test"
t.create --v --o type=strds temporaltype=absolute dataset=precip_abs7 gran="1 years" title="A test" descr="A test"
-tr.register --v dataset=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 seconds"
+tr.register --v -i dataset=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 seconds"
t.info type=strds dataset=precip_abs1
+t.info -t type=strds dataset=precip_abs1
tr.unregister --v dataset=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
t.info type=strds dataset=precip_abs1
-tr.register --v dataset=precip_abs2 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="20 seconds, 5 minutes"
+tr.register --v -i dataset=precip_abs2 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="20 seconds, 5 minutes"
t.info type=strds dataset=precip_abs2
+t.info -t type=strds dataset=precip_abs2
-tr.register --v dataset=precip_abs3 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="8 hours"
+tr.register --v -i dataset=precip_abs3 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="8 hours"
t.info type=strds dataset=precip_abs3
+t.info -t type=strds dataset=precip_abs3
tr.unregister --v maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
t.info type=strds dataset=precip_abs3
@@ -52,9 +55,15 @@
tr.register dataset=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="20 years, 3 months, 1 days, 4 hours"
t.info type=strds dataset=precip_abs7
+t.info -t type=strds dataset=precip_abs7
# Register with different valid time again
tr.register dataset=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours"
t.info type=strds dataset=precip_abs7
+t.info -t type=strds dataset=precip_abs7
+# Register with different valid time again creating an interval
+tr.register -i dataset=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours"
+t.info type=strds dataset=precip_abs7
+t.info -t type=strds dataset=precip_abs7
t.remove --v type=raster dataset=prec_1,prec_2,prec_3
t.remove --v type=strds dataset=precip_abs1,precip_abs2,precip_abs3,precip_abs4,precip_abs5,precip_abs6,precip_abs7
Modified: grass/trunk/temporal/tr.register/tr.register.py
===================================================================
--- grass/trunk/temporal/tr.register/tr.register.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/tr.register/tr.register.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -52,6 +52,11 @@
#% multiple: no
#%end
+#%flag
+#% key: i
+#% description: Create an interval (start and end time) in case an increment is provided
+#%end
+
import grass.script as grass
import grass.temporal as tgis
@@ -64,11 +69,12 @@
maps = options["maps"]
start = options["start"]
increment = options["increment"]
+ interval = flags["i"]
# Make sure the temporal database exists
tgis.create_temporal_database()
# Register maps
- tgis.register_maps_in_space_time_dataset("raster", name, maps, start, increment)
+ tgis.register_maps_in_space_time_dataset("raster", name, maps, start, increment, None, interval)
if __name__ == "__main__":
options, flags = grass.parser()
Modified: grass/trunk/temporal/tr.series/test.tr.series.sh
===================================================================
--- grass/trunk/temporal/tr.series/test.tr.series.sh 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/tr.series/test.tr.series.sh 2011-10-02 00:00:15 UTC (rev 48594)
@@ -24,9 +24,14 @@
tr.register --v dataset=precip_abs maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 months"
-tr.series --o input=precip_abs method=average output=prec_average
-tr.series --o input=precip_abs method=maximum output=prec_max
-tr.series --o input=precip_abs method=quantile output=prec_quant quantile=0.9
+tr.series --o input=precip_abs method=average output=prec_average where='start_time > "2001-03-01"'
+tr.series --o input=precip_abs method=maximum output=prec_max sort=north
+tr.series --o input=precip_abs method=sum output=prec_sum
+#tr.series --o input=precip_abs method=quantile output=prec_quant quantile=0.9
-#t.remove --v type=raster dataset=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
-#t.remove --v type=strds dataset=precip_abs
+t.remove --v type=raster dataset=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.remove --v type=strds dataset=precip_abs
+
+r.info prec_average
+r.info prec_max
+r.info prec_sum
Modified: grass/trunk/temporal/tr.series/tr.series.py
===================================================================
--- grass/trunk/temporal/tr.series/tr.series.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/tr.series/tr.series.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -32,7 +32,7 @@
#%option
#% key: method
#% type: string
-#% description: Aggregate operation
+#% description: Aggregate operation on all raster maps of a space time raster dataset
#% 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
@@ -40,18 +40,21 @@
#%end
#%option
-#% key: quantile
+#% key: sort
#% type: string
-#% description: Quantile to calculate for method=quantile
+#% description: Sort the maps by category.
#% required: no
-#% multiple: no
-#% options: 0.0-1.0
+#% multiple: yes
+#% options: id, name, creator, mapset, creation_time, modification_time, start_time, end_time, north, south, west, east, min, max
+#% answer: id
#%end
+#%option G_OPT_DB_WHERE
+#%end
+
#%option G_OPT_R_OUTPUT
#%end
-
import grass.script as grass
import grass.temporal as tgis
@@ -62,8 +65,9 @@
# Get the options
input = options["input"]
output = options["output"]
- quantile = options["quantile"]
method = options["method"]
+ sort = options["sort"]
+ where = options["where"]
# Make sure the temporal database exists
tgis.create_temporal_database()
@@ -77,11 +81,11 @@
sp = tgis.space_time_raster_dataset(id)
if sp.is_in_db() == False:
- grass.fatal("Dataset <%s> not found in temporal database" % (id))
+ grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
sp.select()
- rows = sp.get_registered_maps()
+ rows = sp.get_registered_maps(None, where, sort)
if rows:
inputs = ""
@@ -97,9 +101,9 @@
print inputs
if grass.overwrite() == True:
- grass.run_command("r.series", input=inputs, output=output, overwrite=True, method=method, quantile=quantile)
+ grass.run_command("r.series", input=inputs, output=output, overwrite=True, method=method)
else:
- grass.run_command("r.series", input=inputs, output=output, overwrite=False, method=method, quantile=quantile)
+ grass.run_command("r.series", input=inputs, output=output, overwrite=False, method=method)
if __name__ == "__main__":
Modified: grass/trunk/temporal/tr3.register/test.tr3.register.sh
===================================================================
--- grass/trunk/temporal/tr3.register/test.tr3.register.sh 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/tr3.register/test.tr3.register.sh 2011-10-02 00:00:15 UTC (rev 48594)
@@ -28,15 +28,15 @@
t.create --v --o type=str3ds temporaltype=absolute dataset=volume_abs6 gran="1 months" title="A test" descr="A test"
t.create --v --o type=str3ds temporaltype=absolute dataset=volume_abs7 gran="1 years" title="A test" descr="A test"
-tr3.register --v dataset=volume_abs1 maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6 start="2001-01-01" increment="1 seconds"
+tr3.register --v -i dataset=volume_abs1 maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6 start="2001-01-01" increment="1 seconds"
t.info type=str3ds dataset=volume_abs1
tr3.unregister --v dataset=volume_abs1 maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6
t.info type=str3ds dataset=volume_abs1
-tr3.register --v dataset=volume_abs2 maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6 start="2001-01-01" increment="20 seconds, 5 minutes"
+tr3.register --v -i dataset=volume_abs2 maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6 start="2001-01-01" increment="20 seconds, 5 minutes"
t.info type=str3ds dataset=volume_abs2
-tr3.register --v dataset=volume_abs3 maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6 start="2001-01-01" increment="8 hours"
+tr3.register --v -i dataset=volume_abs3 maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6 start="2001-01-01" increment="8 hours"
t.info type=str3ds dataset=volume_abs3
tr3.unregister --v maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6
t.info type=str3ds dataset=volume_abs3
@@ -55,6 +55,9 @@
# Register with different valid time again
tr3.register dataset=volume_abs7 maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours"
t.info type=str3ds dataset=volume_abs7
+# Register with different valid time again creating intervals
+tr3.register -i dataset=volume_abs7 maps=volume_1,volume_2,volume_3,volume_4,volume_5,volume_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours"
+t.info type=str3ds dataset=volume_abs7
t.remove --v type=raster3d dataset=volume_1,volume_2,volume_3
t.remove --v type=str3ds dataset=volume_abs1,volume_abs2,volume_abs3,volume_abs4,volume_abs5,volume_abs6,volume_abs7
Modified: grass/trunk/temporal/tr3.register/tr3.register.py
===================================================================
--- grass/trunk/temporal/tr3.register/tr3.register.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/tr3.register/tr3.register.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -52,6 +52,12 @@
#% multiple: no
#%end
+#%flag
+#% key: i
+#% description: Create an interval (start and end time) in case an increment is provided
+#%end
+
+
import grass.script as grass
import grass.temporal as tgis
@@ -64,11 +70,12 @@
maps = options["maps"]
start = options["start"]
increment = options["increment"]
+ interval = flags["i"]
# Make sure the temporal database exists
tgis.create_temporal_database()
# Register maps
- tgis.register_maps_in_space_time_dataset("raster3d", name, maps, start, increment)
+ tgis.register_maps_in_space_time_dataset("raster3d", name, maps, start, increment, None, interval)
if __name__ == "__main__":
options, flags = grass.parser()
Modified: grass/trunk/temporal/tv.register/test.tv.register.sh
===================================================================
--- grass/trunk/temporal/tv.register/test.tv.register.sh 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/tv.register/test.tv.register.sh 2011-10-02 00:00:15 UTC (rev 48594)
@@ -28,15 +28,15 @@
t.create --v --o type=stvds temporaltype=absolute dataset=lidar_abs_ds6 gran="1 months" title="A test" descr="A test"
t.create --v --o type=stvds temporaltype=absolute dataset=lidar_abs_ds7 gran="1 years" title="A test" descr="A test"
-tv.register --v dataset=lidar_abs_ds1 maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6 start="2001-01-01" increment="1 seconds"
+tv.register --v -i dataset=lidar_abs_ds1 maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6 start="2001-01-01" increment="1 seconds"
t.info type=stvds dataset=lidar_abs_ds1
tv.unregister --v dataset=lidar_abs_ds1 maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6
t.info type=stvds dataset=lidar_abs_ds1
-tv.register --v dataset=lidar_abs_ds2 maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6 start="2001-01-01" increment="20 seconds, 5 minutes"
+tv.register --v -i dataset=lidar_abs_ds2 maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6 start="2001-01-01" increment="20 seconds, 5 minutes"
t.info type=stvds dataset=lidar_abs_ds2
-tv.register --v dataset=lidar_abs_ds3 maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6 start="2001-01-01" increment="8 hours"
+tv.register --v -i dataset=lidar_abs_ds3 maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6 start="2001-01-01" increment="8 hours"
t.info type=stvds dataset=lidar_abs_ds3
tv.unregister --v maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6
t.info type=stvds dataset=lidar_abs_ds3
@@ -55,6 +55,9 @@
# Register with different valid time again
tv.register dataset=lidar_abs_ds7 maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours"
t.info type=stvds dataset=lidar_abs_ds7
+# Register with different valid time again creating an interval
+tv.register -i dataset=lidar_abs_ds7 maps=lidar_abs_1,lidar_abs_2,lidar_abs_3,lidar_abs_4,lidar_abs_5,lidar_abs_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours"
+t.info type=stvds dataset=lidar_abs_ds7
t.remove --v type=vector dataset=lidar_abs_1,lidar_abs_2,lidar_abs_3
t.remove --v type=stvds dataset=lidar_abs_ds1,lidar_abs_ds2,lidar_abs_ds3,lidar_abs_ds4,lidar_abs_ds5,lidar_abs_ds6,lidar_abs_ds7
Modified: grass/trunk/temporal/tv.register/tv.register.py
===================================================================
--- grass/trunk/temporal/tv.register/tv.register.py 2011-10-01 22:09:11 UTC (rev 48593)
+++ grass/trunk/temporal/tv.register/tv.register.py 2011-10-02 00:00:15 UTC (rev 48594)
@@ -52,6 +52,12 @@
#% multiple: no
#%end
+#%flag
+#% key: i
+#% description: Create an interval (start and end time) in case an increment is provided
+#%end
+
+
import grass.script as grass
import grass.temporal as tgis
@@ -64,11 +70,12 @@
maps = options["maps"]
start = options["start"]
increment = options["increment"]
+ interval = flags["i"]
# Make sure the temporal database exists
tgis.create_temporal_database()
# Register maps
- tgis.register_maps_in_space_time_dataset("vector", name, maps, start, increment)
+ tgis.register_maps_in_space_time_dataset("vector", name, maps, start, increment, None, interval)
if __name__ == "__main__":
options, flags = grass.parser()
More information about the grass-commit
mailing list