[GRASS-SVN] r57480 - in grass/trunk/temporal: t.create t.info t.merge t.rast.aggregate t.rast.aggregate.ds t.rast.colors t.rast.gapfill t.rast.neighbors t.rast.out.vtk t.rast.series t.rast.to.rast3 t.remove t.shift t.snap t.support t.topology t.unregister t.vect.db.select t.vect.observe.strds t.vect.what.strds

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 21 11:57:06 PDT 2013


Author: huhabla
Date: 2013-08-21 11:57:06 -0700 (Wed, 21 Aug 2013)
New Revision: 57480

Modified:
   grass/trunk/temporal/t.create/t.create.py
   grass/trunk/temporal/t.info/t.info.py
   grass/trunk/temporal/t.info/test.t.info.sh
   grass/trunk/temporal/t.merge/t.merge.py
   grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py
   grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py
   grass/trunk/temporal/t.rast.colors/t.rast.colors.py
   grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py
   grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
   grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.py
   grass/trunk/temporal/t.rast.series/t.rast.series.py
   grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py
   grass/trunk/temporal/t.remove/t.remove.py
   grass/trunk/temporal/t.shift/t.shift.py
   grass/trunk/temporal/t.snap/t.snap.py
   grass/trunk/temporal/t.support/t.support.py
   grass/trunk/temporal/t.topology/t.topology.py
   grass/trunk/temporal/t.unregister/t.unregister.py
   grass/trunk/temporal/t.vect.db.select/t.vect.db.select.py
   grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py
   grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py
Log:
Replaced lots of code with the new open functions for space time datasets.


Modified: grass/trunk/temporal/t.create/t.create.py
===================================================================
--- grass/trunk/temporal/t.create/t.create.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.create/t.create.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -75,8 +75,8 @@
 
     tgis.init()
     
-    tgis.create_space_time_dataset(name, type, temporaltype, title, descr, 
-                                   semantic, None, grass.overwrite())
+    tgis.open_new_space_time_dataset(name, type, temporaltype, title, descr, 
+                                     semantic, None, grass.overwrite())
 
 if __name__ == "__main__":
     options, flags = grass.parser()

Modified: grass/trunk/temporal/t.info/t.info.py
===================================================================
--- grass/trunk/temporal/t.info/t.info.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.info/t.info.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -42,7 +42,7 @@
 
 #%flag
 #% key: h
-#% description: Print history information in human readable shell style
+#% description: Print history information in human readable shell style for space time datasets
 #%end
 
 #%flag
@@ -61,7 +61,7 @@
 def main():
 
     name = options["input"]
-    type = options["type"]
+    type_ = options["type"]
     shellstyle = flags['g']
     system = flags['s']
     history = flags['h']
@@ -100,26 +100,25 @@
         grass.fatal(_("Please specify %s=") % ("name"))
 
     if name.find("@") >= 0:
-        id = name
+        id_ = name
     else:
-        mapset = grass.gisenv()["MAPSET"]
-        id = name + "@" + mapset
+        id_ = name + "@" + grass.gisenv()["MAPSET"]
 
-    ds = tgis.dataset_factory(type, id)
+    dataset = tgis.dataset_factory(type_, id_)
 
-    if ds.is_in_db() == False:
-        grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
+    if dataset.is_in_db() == False:
+        grass.fatal(_("Dataset <%s> not found in temporal database") % (id_))
 
-    ds.select()
+    dataset.select()
 
-    if history == True:
-        ds.print_history()
+    if history == True and type in ["strds", "stvds", "str3ds"]:
+        dataset.print_history()
         return
 
     if shellstyle == True:
-        ds.print_shell_info()
+        dataset.print_shell_info()
     else:
-        ds.print_info()
+        dataset.print_info()
 
 if __name__ == "__main__":
     options, flags = grass.parser()

Modified: grass/trunk/temporal/t.info/test.t.info.sh
===================================================================
--- grass/trunk/temporal/t.info/test.t.info.sh	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.info/test.t.info.sh	2013-08-21 18:57:06 UTC (rev 57480)
@@ -34,6 +34,7 @@
 t.register --o type=rast -i input=precip_abs2 maps=prec_1,prec_2 start="2001-01-01" increment="20 years"
 t.info type=strds input=precip_abs2
 t.info -g type=strds input=precip_abs2
+t.info -h type=strds input=precip_abs2
 t.info type=rast input=prec_1
 t.info -g type=rast input=prec_1
 t.info type=rast input=prec_2
@@ -47,6 +48,7 @@
 t.register --o type=rast3d -i input=precip_abs2 maps=prec_1,prec_2 start="2001-01-01" increment="20 years"
 t.info type=str3ds input=precip_abs2
 t.info -g type=str3ds input=precip_abs2
+t.info -h type=str3ds input=precip_abs2
 t.info type=rast3 input=prec_1
 t.info -g type=rast3 input=prec_1
 t.info type=rast3 input=prec_2

Modified: grass/trunk/temporal/t.merge/t.merge.py
===================================================================
--- grass/trunk/temporal/t.merge/t.merge.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.merge/t.merge.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -74,13 +74,7 @@
     first = None
 
     for id in input_ids:
-        stds = tgis.dataset_factory(type, id)
-        if stds.is_in_db(dbif=dbif) == False:
-            dbif.close()
-            grass.fatal(_("Space time %s dataset <%s> not found") % (
-                stds.get_new_map_instance(None).get_type(), id))
-
-        stds.select(dbif=dbif)
+        stds = tgis.open_old_space_time_dataset(id, type, dbif)
         if first is None:
             first = stds
 
@@ -106,7 +100,7 @@
                       (stds.get_new_map_instance(None).get_type(), output_id))
 
     if not output_exists:
-        output_stds = tgis.create_space_time_dataset(output, type,
+        output_stds = tgis.open_new_space_time_dataset(output, type,
                                    first.get_temporal_type(),
                                    "Merged space time dataset",
                                    "Merged space time dataset",

Modified: grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -58,7 +58,6 @@
 #% description: Register Null maps
 #%end
 
-from multiprocessing import Process
 import grass.script as grass
 import grass.temporal as tgis
 
@@ -83,47 +82,17 @@
     dbif = tgis.SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    mapset = grass.gisenv()["MAPSET"]
-
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    sp = tgis.SpaceTimeRasterDataset(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.SpaceTimeRasterDataset(out_id)
-    if new_sp.is_in_db(dbif):
-        if grass.overwrite() == True:
-            new_sp.delete(dbif)
-            new_sp = tgis.SpaceTimeRasterDataset(out_id)
-        else:
-            dbif.close()
-            grass.fatal(_("Space time raster dataset <%s> is already in the "
-                          "database, use overwrite flag to overwrite") % out_id)
-
+    sp = tgis.open_old_space_time_dataset(input, "strds", dbif)
     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)
+    new_sp = tgis.open_new_space_time_dataset(output, "strds", temporal_type,
+                                              title, description, semantic_type,
+                                              dbif, grass.overwrite())
 
     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)
+        grass.fatal(_("Space time raster dataset <%s> is empty") % input)
 
     # Modify the start time to fit the granularity
 

Modified: grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -81,35 +81,9 @@
     dbif = tgis.SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    mapset = grass.gisenv()["MAPSET"]
+    sp = tgis.open_old_space_time_dataset(input, "strds", dbif)
+    sampler_sp = tgis.open_old_space_time_dataset(sampler, type, dbif)
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    sp = tgis.SpaceTimeRasterDataset(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 "
@@ -121,25 +95,10 @@
         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.SpaceTimeRasterDataset(out_id)
-    if new_sp.is_in_db(dbif):
-        if grass.overwrite() == True:
-            new_sp.delete(dbif)
-            new_sp = tgis.SpaceTimeRasterDataset(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)
+    new_sp = tgis.open_new_space_time_dataset(output, "strds", temporal_type,
+                                              title, description, semantic_type,
+                                              dbif, grass.overwrite())
 
     rows = sampler_sp.get_registered_maps(
         "id,start_time,end_time", None, "start_time", dbif)
@@ -159,7 +118,7 @@
 
         if input_map_names:
             new_map = tgis.aggregate_raster_maps(input_map_names, base,
-                                                 start, end, count, method, 
+                                                 start, end, count, method,
                                                  register_null, dbif)
 
             if new_map:

Modified: grass/trunk/temporal/t.rast.colors/t.rast.colors.py
===================================================================
--- grass/trunk/temporal/t.rast.colors/t.rast.colors.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.rast.colors/t.rast.colors.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -115,36 +115,24 @@
     log = flags["g"]
     abslog = flags["a"]
     equi = flags["e"]
-    
+
     if raster == "":
         raster=None
-        
+
     if volume == "":
         volume = None
-        
+
     if rules == "":
         rules = None
-        
+
     if color == "":
         color = None
 
     # Make sure the temporal database exists
     tgis.init()
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        mapset = grass.gisenv()["MAPSET"]
-        id = input + "@" + mapset
+    sp = tgis.open_old_space_time_dataset(input, "strds")
 
-    sp = tgis.SpaceTimeRasterDataset(id)
-
-    if sp.is_in_db() == False:
-        grass.fatal(_("Space time %s dataset <%s> not found") % (
-            sp.get_new_map_instance(None).get_type(), id))
-
-    sp.select()
-
     rows = sp.get_registered_maps("id", None, None, None)
 
     if rows:
@@ -157,7 +145,7 @@
             file.write(string)
 
         file.close()
-        
+
         flags_=""
         if(remove):
             flags_+="r"
@@ -175,7 +163,7 @@
             flags_+="e"
 
         ret = grass.run_command("r.colors", flags=flags_, file=filename,
-                                color=color, raster=raster, volume=volume, 
+                                color=color, raster=raster, volume=volume,
                                 rules=rules, overwrite=grass.overwrite())
 
         if ret != 0:

Modified: grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py
===================================================================
--- grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -49,7 +49,6 @@
 #%end
 
 from multiprocessing import Process
-import copy
 import grass.script as grass
 import grass.temporal as tgis
 
@@ -64,27 +63,17 @@
     where = options["where"]
     nprocs = options["nprocs"]
 
+    mapset = grass.gisenv()["MAPSET"]
+
     # Make sure the temporal database exists
     tgis.init()
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        mapset = grass.gisenv()["MAPSET"]
-        id = input + "@" + mapset
-
     # We need a database interface
     dbif = tgis.SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    sp = tgis.SpaceTimeRasterDataset(id)
+    sp = tgis.open_old_space_time_dataset(input, "strds")
 
-    if sp.is_in_db(dbif) == False:
-        grass.fatal(_("Space time %s dataset <%s> not found") %
-                    (sp.get_new_map_instance(None).get_type(), id))
-
-    sp.select(dbif)
-
     maps = sp.get_registered_maps_as_objects_with_gaps(where, dbif)
 
     num = len(maps)
@@ -107,8 +96,8 @@
                 else:
                     if _map.is_in_db(dbif):
                         overwrite_flags[_id] = True
-                        
 
+
             gap_list.append(_map)
 
     if len(gap_list) == 0:

Modified: grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
===================================================================
--- grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -92,34 +92,14 @@
 
     mapset = grass.gisenv()["MAPSET"]
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    sp = tgis.SpaceTimeRasterDataset(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)
+    sp = tgis.open_old_space_time_dataset(input, "strds", dbif)
     dummy = sp.get_new_map_instance(None)
 
-    if output.find("@") >= 0:
-        out_id = output
-    else:
-        out_id = output + "@" + mapset
+    temporal_type, semantic_type, title, description = sp.get_initial_values()
+    new_sp = tgis.open_new_space_time_dataset(output, "strds", sp.get_temporal_type(),
+                                              title, description, semantic_type,
+                                              dbif, grass.overwrite(), dry=True)
 
-    # The new space time raster dataset
-    new_sp = tgis.SpaceTimeRasterDataset(out_id)
-    if new_sp.is_in_db(dbif):
-        if not grass.overwrite():
-            dbif.close()
-            grass.fatal(_("Space time raster dataset <%s> is already in the "
-                          "database, use overwrite flag to overwrite") % out_id)
-
     rows = sp.get_registered_maps("id,start_time", where, "start_time", dbif)
 
     if not rows:
@@ -129,10 +109,10 @@
     count = 0
     proc_count = 0
     proc_list = []
-    
+
     num_rows = len(rows)
     new_maps = {}
-    
+
     for row in rows:
         count += 1
 
@@ -162,7 +142,7 @@
         proc_list[proc_count].start()
         proc_count += 1
 
-        # Join processes if the maximum number of processes are 
+        # Join processes if the maximum number of processes are
         # reached or the end of the loop is reached
         if proc_count == nprocs or proc_count == num_rows:
             proc_count = 0
@@ -180,23 +160,19 @@
 
         # Store the new maps
         new_maps[row["id"]] = new_map
-    
+
     grass.percent(0, num_rows, 1)
-    
-    # Insert the new space time dataset
-    if new_sp.is_in_db(dbif):
-        if grass.overwrite():
-            new_sp.delete(dbif)
-            new_sp = sp.get_new_instance(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)
-    
+
+    new_sp = tgis.open_new_space_time_dataset(output, "strds",
+                                              sp.get_temporal_type(),
+                                              title, description,
+                                              semantic_type,
+                                              dbif, grass.overwrite(),
+                                              dry=False)
+
     # collect empty maps to remove them
     empty_maps = []
-    
+
     # Register the maps in the database
     count = 0
     for row in rows:
@@ -218,7 +194,7 @@
 
             old_map = sp.get_new_map_instance(row["id"])
             old_map.select(dbif)
-            
+
             # Set the time stamp
             if old_map.is_time_absolute():
                 start, end, tz = old_map.get_absolute_time()
@@ -230,11 +206,11 @@
             # Insert map in temporal database
             new_map.insert(dbif)
             new_sp.register_map(new_map, dbif)
-    
+
     # Update the spatio-temporal extent and the metadata table entries
     new_sp.update_from_registered_maps(dbif)
     grass.percent(num_rows, num_rows, 1)
-    
+
     # Remove empty maps
     if len(empty_maps) > 0:
         names = ""
@@ -245,16 +221,16 @@
             else:
                 names += ",%s" % (map.get_name())
             count += 1
-            
+
         grass.run_command("g.remove", rast=names, quiet=True)
 
-                
+
     dbif.close()
 
 def run_neighbors(input, output, method, size):
     """Helper function to run r.neighbors in parallel"""
-    return grass.run_command("r.neighbors", input=input, output=output, 
-                            method=method, size=size, overwrite=grass.overwrite(), 
+    return grass.run_command("r.neighbors", input=input, output=output,
+                            method=method, size=size, overwrite=grass.overwrite(),
                             quiet=True)
 
 

Modified: grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.py
===================================================================
--- grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -91,21 +91,8 @@
 
     os.chdir(expdir)
 
-    mapset = grass.gisenv()["MAPSET"]
+    sp = tgis.open_old_space_time_dataset(input, "strds")
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    sp = tgis.SpaceTimeRasterDataset(id)
-
-    if sp.is_in_db() == False:
-        grass.fatal(_("Space time %s dataset <%s> not found") % (
-            sp.get_new_map_instance(None).get_type(), id))
-
-    sp.select()
-
     if use_granularity:
         # Attention: A list of lists of maps will be returned
         maps = sp.get_registered_maps_as_objects_by_granularity()
@@ -115,7 +102,7 @@
     else:
         maps = sp.get_registered_maps_as_objects(where, "start_time", None)
 
-    # To have scalar values with the same name, we need to copy the 
+    # To have scalar values with the same name, we need to copy the
     # raster maps using a single name
     map_name = "%s_%i" % (sp.base.get_name(), os.getpid())
 
@@ -131,7 +118,7 @@
             if id is None:
                 id = null_map
 
-            grass.run_command("g.copy", rast="%s,%s" % (id, map_name), 
+            grass.run_command("g.copy", rast="%s,%s" % (id, map_name),
                               overwrite=True)
             out_name = "%6.6i_%s.vtk" % (count, sp.base.get_name())
 
@@ -143,17 +130,16 @@
 
             # Export the raster map with r.out.vtk
             if elevation:
-                ret = grass.run_command("r.out.vtk", flags=mflags, null=null, 
-                                        input=map_name, elevation=elevation, 
-                                        output=out_name, 
+                ret = grass.run_command("r.out.vtk", flags=mflags, null=null,
+                                        input=map_name, elevation=elevation,
+                                        output=out_name,
                                         overwrite=grass.overwrite())
             else:
-                ret = grass.run_command("r.out.vtk", flags=mflags, null=null, 
-                                        input=map_name, output=out_name, 
+                ret = grass.run_command("r.out.vtk", flags=mflags, null=null,
+                                        input=map_name, output=out_name,
                                         overwrite=grass.overwrite())
-
             if ret != 0:
-                grass.fatal(_("Unable to export raster map <%s>" % name))
+                grass.fatal(_("Unable to export raster map <%s>" % map_name))
 
             count += 1
 

Modified: grass/trunk/temporal/t.rast.series/t.rast.series.py
===================================================================
--- grass/trunk/temporal/t.rast.series/t.rast.series.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.rast.series/t.rast.series.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -5,7 +5,8 @@
 # MODULE:	t.rast.series
 # AUTHOR(S):	Soeren Gebbert
 #
-# PURPOSE:	Perform different aggregation algorithms from r.series on all or a selected subset of raster maps in a space time raster dataset
+# PURPOSE:	Perform different aggregation algorithms from r.series on all or a
+#          selected subset of raster maps in a space time raster dataset
 # COPYRIGHT:	(C) 2011 by the GRASS Development Team
 #
 #		This program is free software under the GNU General Public
@@ -73,20 +74,8 @@
     # Make sure the temporal database exists
     tgis.init()
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        mapset = grass.gisenv()["MAPSET"]
-        id = input + "@" + mapset
+    sp = tgis.open_old_space_time_dataset(input, "strds")
 
-    sp = tgis.SpaceTimeRasterDataset(id)
-
-    if sp.is_in_db() == False:
-        grass.fatal(_("Space time %s dataset <%s> not found") % (
-            sp.get_new_map_instance(None).get_type(), id))
-
-    sp.select()
-
     rows = sp.get_registered_maps("id", where, order, None)
 
     if rows:
@@ -101,7 +90,7 @@
         file.close()
 
         ret = grass.run_command("r.series", flags="z", file=filename,
-                                output=output, overwrite=grass.overwrite(), 
+                                output=output, overwrite=grass.overwrite(),
                                 method=method)
 
         if ret == 0 and not add_time:

Modified: grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py
===================================================================
--- grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -46,19 +46,8 @@
 
     mapset = grass.gisenv()["MAPSET"]
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
+    sp = tgis.open_old_space_time_dataset(input, "strds")
 
-    sp = tgis.SpaceTimeRasterDataset(id)
-
-    if sp.is_in_db() == False:
-        grass.fatal(_("Space time %s dataset <%s> not found") % (
-            sp.get_new_map_instance(None).get_type(), id))
-
-    sp.select()
-
     grass.use_temp_region()
 
     maps = sp.get_registered_maps_as_objects_by_granularity()
@@ -70,12 +59,12 @@
     # This is the reference time to scale the z coordinate
     reftime = datetime(1900, 1, 1)
 
-    # We set top and bottom according to the start time in relation 
+    # We set top and bottom according to the start time in relation
     # to the date 1900-01-01 00:00:00
-    # In case of days, hours, minutes and seconds, a double number 
+    # In case of days, hours, minutes and seconds, a double number
     # is used to represent days and fracs of a day
 
-    # Space time voxel cubes with montly or yearly granularity can not be 
+    # Space time voxel cubes with montly or yearly granularity can not be
     # mixed with other temporal units
 
     # Compatible temporal units are : days, hours, minutes and seconds
@@ -85,7 +74,7 @@
     if sp.is_time_absolute():
         unit = granularity.split(" ")[1]
         granularity = float(granularity.split(" ")[0])
-        
+
         print "Gran from stds %0.15f"%(granularity)
 
         if unit == "years" or unit == "year":
@@ -155,7 +144,7 @@
 
     # Set the unit
     ret = grass.run_command("r3.support", map=output, vunit=unit,
-                            title=title, description=descr, 
+                            title=title, description=descr,
                             overwrite=grass.overwrite())
 
     # Register the space time voxel cube in the temporal GIS

Modified: grass/trunk/temporal/t.remove/t.remove.py
===================================================================
--- grass/trunk/temporal/t.remove/t.remove.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.remove/t.remove.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -104,28 +104,14 @@
             dataset_name = line_list[0]
             dataset_list.append(dataset_name)
 
-    mapset = grass.gisenv()["MAPSET"]
-
     statement = ""
 
     for name in dataset_list:
         name = name.strip()
-        # Check for the mapset in name
-        if name.find("@") < 0:
-            id = name + "@" + mapset
-        else:
-            id = name
+        sp = tgis.open_old_space_time_dataset(name, type, dbif)
 
-        sp = tgis.dataset_factory(type, 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))
-
         if recursive and force:
             grass.message(_("Removing registered maps"))
-            sp.select(dbif)
             maps = sp.get_registered_maps_as_objects(dbif=dbif)
             map_statement = ""
             count = 1

Modified: grass/trunk/temporal/t.shift/t.shift.py
===================================================================
--- grass/trunk/temporal/t.shift/t.shift.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.shift/t.shift.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -57,33 +57,21 @@
 
     # Make sure the temporal database exists
     tgis.init()
-    
+
     dbif = tgis.SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    if name.find("@") >= 0:
-        id = name
-    else:
-        mapset = grass.gisenv()["MAPSET"]
-        id = name + "@" + mapset
-
-    stds = tgis.dataset_factory(type, id)
-
-    if stds.is_in_db(dbif) == False:
-        dbif.close()
-        grass.fatal(_("Space time dataset <%s> not found in temporal database") % (id))
-
-    stds.select(dbif)
+    stds = tgis.open_old_space_time_dataset(name, type, dbif)
     check = stds.shift(gran=gran, dbif=dbif)
 
     if check == False:
         dbif.close()
         grass.fatal(_("Unable to temporally shift the space time %s dataset <%s>") % \
                      (stds.get_new_map_instance(None).get_type(), id))
-        
+
     stds.update_command_string(dbif=dbif)
     dbif.close()
-    
+
 if __name__ == "__main__":
     options, flags = grass.parser()
     main()

Modified: grass/trunk/temporal/t.snap/t.snap.py
===================================================================
--- grass/trunk/temporal/t.snap/t.snap.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.snap/t.snap.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -48,28 +48,16 @@
 
     # Make sure the temporal database exists
     tgis.init()
-    
+
     dbif = tgis.SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    if name.find("@") >= 0:
-        id = name
-    else:
-        mapset = grass.gisenv()["MAPSET"]
-        id = name + "@" + mapset
-
-    stds = tgis.dataset_factory(type, id)
-
-    if stds.is_in_db(dbif) == False:
-        dbif.close()
-        grass.fatal(_("Space time dataset <%s> not found in temporal database") % (id))
-
-    stds.select(dbif)
+    stds = tgis.open_old_space_time_dataset(name, type, dbif)
     stds.snap(dbif=dbif)
-        
+
     stds.update_command_string(dbif=dbif)
     dbif.close()
-    
+
 if __name__ == "__main__":
     options, flags = grass.parser()
     main()

Modified: grass/trunk/temporal/t.support/t.support.py
===================================================================
--- grass/trunk/temporal/t.support/t.support.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.support/t.support.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -83,26 +83,11 @@
     # Make sure the temporal database exists
     tgis.init()
 
-    #Get the current mapset to create the id of the space time dataset
-    mapset = grass.gisenv()["MAPSET"]
-
-    if name.find("@") >= 0:
-        id = name
-    else:
-        id = name + "@" + mapset
-
     dbif = tgis.SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    stds = tgis.dataset_factory(type, id)
+    stds = tgis.open_old_space_time_dataset(name, type, dbif)
 
-    if stds.is_in_db(dbif=dbif) == False:
-        dbif.close()
-        grass.fatal(_("Space time %s dataset <%s> not found") % (
-            stds.get_new_map_instance(None).get_type(), id))
-
-    stds.select(dbif=dbif)
-
     update = False
     if title:
         stds.metadata.set_title(title=title)
@@ -163,7 +148,7 @@
 
     if map_update or update:
         stds.update_from_registered_maps(dbif=dbif)
-    
+
     stds.update_command_string(dbif=dbif)
 
     dbif.close()

Modified: grass/trunk/temporal/t.topology/t.topology.py
===================================================================
--- grass/trunk/temporal/t.topology/t.topology.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.topology/t.topology.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -59,28 +59,14 @@
     # Make sure the temporal database exists
     tgis.init()
 
-    #Get the current mapset to create the id of the space time dataset
-    if name.find("@") >= 0:
-        id = name
-    else:
-        mapset = grass.gisenv()["MAPSET"]
-        id = name + "@" + mapset
+    sp = tgis.open_old_space_time_dataset(name, type)
 
-    sp = tgis.dataset_factory(type, id)
-
-    if sp.is_in_db() == False:
-        grass.fatal(_("Space time %s dataset <%s> not found") % (
-            sp.get_new_map_instance(None).get_type(), id))
-
-    # Insert content from db
-    sp.select()
-
     # Get ordered map list
     maps = sp.get_registered_maps_as_objects(
         where=where, order="start_time", dbif=None)
-    
+
     spatial = None
-    
+
     if spatio_temporal_relations:
         if sp.get_type() == "strds":
             spatial = "2D"

Modified: grass/trunk/temporal/t.unregister/t.unregister.py
===================================================================
--- grass/trunk/temporal/t.unregister/t.unregister.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.unregister/t.unregister.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -72,24 +72,8 @@
 
     # In case a space time dataset is specified
     if input:
-        # Check if the dataset name contains the mapset as well
-        if input.find("@") < 0:
-            id = input + "@" + mapset
-        else:
-            id = input
+        sp = tgis.open_old_space_time_dataset(input, type, dbif)
 
-        if type == "rast":
-            sp = tgis.dataset_factory("strds", id)
-        if type == "rast3d":
-            sp = tgis.dataset_factory("str3ds", id)
-        if type == "vect":
-            sp = tgis.dataset_factory("stvds", 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))
-
     maplist = []
 
     dummy = tgis.RasterDataset(None)
@@ -139,7 +123,6 @@
         if map.is_in_db(dbif) == True:
             # Unregister from a single dataset
             if input:
-                sp.metadata.select(dbif)
                 # Collect SQL statements
                 statement += sp.unregister_map(
                     map=map, dbif=dbif, execute=False)
@@ -170,23 +153,13 @@
     # Update space time datasets
     grass.message(_("Unregister maps from space time dataset(s)"))
     if input:
-        sp.metadata.select(dbif)
         sp.update_from_registered_maps(dbif)
         sp.update_command_string(dbif=dbif)
     elif len(update_dict) > 0:
         count = 0
         for key in update_dict.keys():
             id = update_dict[key]
-            if type == "rast":
-                sp = tgis.dataset_factory("strds", id)
-            elif type == "rast3d":
-                sp = tgis.dataset_factory("str3ds", id)
-            elif type == "vect":
-                sp = tgis.dataset_factory("stvds", id)
-            else:
-                break
-
-            sp.metadata.select(dbif)
+            sp = tgis.open_old_space_time_dataset(id, type, dbif)
             sp.update_from_registered_maps(dbif)
             grass.percent(count, len(update_dict), 1)
             count += 1

Modified: grass/trunk/temporal/t.vect.db.select/t.vect.db.select.py
===================================================================
--- grass/trunk/temporal/t.vect.db.select/t.vect.db.select.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.vect.db.select/t.vect.db.select.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -45,7 +45,6 @@
 
 import grass.script as grass
 import grass.temporal as tgis
-import grass.script.raster as raster
 
 ############################################################################
 
@@ -69,21 +68,8 @@
     # Make sure the temporal database exists
     tgis.init()
 
-    mapset = grass.gisenv()["MAPSET"]
+    sp = tgis.open_old_space_time_dataset(input, "stvds")
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    sp = tgis.SpaceTimeVectorDataset(id)
-
-    if sp.is_in_db() == False:
-        grass.fatal(_("Space time %s dataset <%s> not found") % (
-            sp.get_new_map_instance(None).get_type(), id))
-
-    sp.select()
-
     rows = sp.get_registered_maps("name,layer,mapset,start_time,end_time",
                                   tempwhere, "start_time", None)
 
@@ -91,13 +77,13 @@
     if rows:
         for row in rows:
             vector_name = "%s@%s" % (row["name"], row["mapset"])
-            # In case a layer is defined in the vector dataset, 
+            # In case a layer is defined in the vector dataset,
             # we override the option layer
             if row["layer"]:
                 layer = row["layer"]
 
-            select = grass.read_command("v.db.select", map=vector_name, 
-                                        layer=layer, columns=columns, 
+            select = grass.read_command("v.db.select", map=vector_name,
+                                        layer=layer, columns=columns,
                                         separator="%s" % (fs), where=where)
 
             if not select:
@@ -117,7 +103,7 @@
                             print col_names
                     else:
                         if row["end_time"]:
-                            print "%s%s%s%s%s" % (row["start_time"], fs, 
+                            print "%s%s%s%s%s" % (row["start_time"], fs,
                                                   row["end_time"], fs, entry)
                         else:
                             print "%s%s%s%s" % (row["start_time"],

Modified: grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py
===================================================================
--- grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -80,37 +80,21 @@
 
     mapset = grass.gisenv()["MAPSET"]
 
-    if strds.find("@") >= 0:
-        strds_id = strds
-    else:
-        strds_id = strds + "@" + mapset
+    strds_sp = tgis.open_old_space_time_dataset(strds, "strds", dbif)
 
-    strds_sp = tgis.SpaceTimeRasterDataset(strds_id)
 
-    if strds_sp.is_in_db() == False:
-        dbif.close()
-        grass.fatal(_("Space time raster dataset <%s> not found") % (strds_id))
+    title = _("Observaion of space time raster dataset <%s>") % (strds_sp.get_id())
+    description= _("Observation of space time raster dataset <%s>"
+                                " with vector map <%s>") % (strds_sp.get_id(),
+                                                            input)
 
-    strds_sp.select(dbif)
+    out_sp = tgis.open_new_space_time_dataset(output, "stvds",
+                                              strds_sp.get_temporal_type(),
+                                              title, description,
+                                              strds_sp.get_semantic_type(),
+                                              dbif,
+                                              grass.overwrite(), dry=True)
 
-    if output.find("@") >= 0:
-        id = output
-    else:
-        id = output + "@" + mapset
-
-    out_sp = tgis.SpaceTimeVectorDataset(id)
-
-    if out_sp.is_in_db(dbif) == True and grass.overwrite() == False:
-        dbif.close()
-        grass.fatal(_("Dataset <%s> found in temporal database, "
-                      "use the overwrite flag to overwrite") % (id))
-
-    # Overwrite existing stvds
-    if out_sp.is_in_db(dbif) == True and grass.overwrite() == True:
-        out_sp.select(dbif)
-        out_sp.delete(dbif)
-        out_sp = tgis.SpaceTimeVectorDataset(id)
-
     # Select the raster maps
     rows = strds_sp.get_registered_maps(
         "name,mapset,start_time,end_time", tempwhere, "start_time", dbif)
@@ -149,25 +133,23 @@
 
     # We create a new vector map using the categories of the original map
     ret = grass.run_command("v.category", input=input, layer=layers,
-                            output=vectmap, option="transfer", 
+                            output=vectmap, option="transfer",
                             overwrite=grass.overwrite())
     if ret != 0:
         grass.fatal(_("Unable to create new layers for vector map <%s>")
                     % (vectmap))
 
     # Create the output space time vector dataset
-    out_sp.set_initial_values(strds_sp.get_temporal_type(),
-                              strds_sp.get_semantic_type(),
-                              _("Observaion of space time raster "
-                                "dataset <%s>") % (strds_id),
-                              _("Observation of space time raster dataset <%s>"
-                                " with vector map <%s>") % (strds_id, input))
+    out_sp = tgis.open_new_space_time_dataset(output, "stvds",
+                                              strds_sp.get_temporal_type(),
+                                              title, description,
+                                              strds_sp.get_semantic_type(),
+                                              dbif, grass.overwrite(),
+                                              dry=False)
 
-    out_sp.insert(dbif)
-
     dummy = out_sp.get_new_map_instance(None)
 
-    # Sample the space time raster dataset with the vector 
+    # Sample the space time raster dataset with the vector
     # map at specific layer with v.what.rast
     count = 1
     for row in rows:
@@ -178,7 +160,7 @@
         if column:
             col_name = column
         else:
-            # Create a new column with name of the 
+            # Create a new column with name of the
             # sampled space time raster dataset
             col_name = row["name"]
 
@@ -190,9 +172,9 @@
 
         # Try to add a column
         if vector_db and count in vector_db and vector_db[count]["table"]:
-            ret = grass.run_command("v.db.addcolumn", map=vectmap, 
-                                    layer=count, 
-                                    column="%s %s" % (col_name, coltype), 
+            ret = grass.run_command("v.db.addcolumn", map=vectmap,
+                                    layer=count,
+                                    column="%s %s" % (col_name, coltype),
                                     overwrite=grass.overwrite())
             if ret != 0:
                 dbif.close()
@@ -201,8 +183,8 @@
         else:
             # Try to add a new table
             grass.message("Add table to layer %i" % (count))
-            ret = grass.run_command("v.db.addtable", map=vectmap, layer=count, 
-                                    columns="%s %s" % (col_name, coltype), 
+            ret = grass.run_command("v.db.addtable", map=vectmap, layer=count,
+                                    columns="%s %s" % (col_name, coltype),
                                     overwrite=grass.overwrite())
             if ret != 0:
                 dbif.close()
@@ -211,7 +193,7 @@
 
         # Call v.what.rast
         ret = grass.run_command("v.what.rast", map=vectmap,
-                                layer=count, raster=rastmap, 
+                                layer=count, raster=rastmap,
                                 column=col_name, where=where)
         if ret != 0:
             dbif.close()
@@ -219,7 +201,7 @@
                           "with layer %i and raster map <%s>") % \
                         (vectmap, count, rastmap))
 
-        vect = out_sp.get_new_map_instance(dummy.build_id(vectmap, 
+        vect = out_sp.get_new_map_instance(dummy.build_id(vectmap,
                                                           mapset, str(count)))
         vect.load()
 

Modified: grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py
===================================================================
--- grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py	2013-08-21 18:54:55 UTC (rev 57479)
+++ grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py	2013-08-21 18:57:06 UTC (rev 57480)
@@ -84,35 +84,9 @@
     dbif = tgis.SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    mapset = grass.gisenv()["MAPSET"]
+    sp = tgis.open_old_space_time_dataset(input, "stvds", dbif)
+    strds_sp = tgis.open_old_space_time_dataset(strds, "strds", dbif)
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    sp = tgis.SpaceTimeVectorDataset(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 strds.find("@") >= 0:
-        strds_id = strds
-    else:
-        strds_id = strds + "@" + mapset
-
-    strds_sp = tgis.SpaceTimeRasterDataset(strds_id)
-
-    if strds_sp.is_in_db() == False:
-        dbif.close()
-        grass.fatal(_("Space time raster dataset <%s> not found in temporal database") % (strds_id))
-
-    strds_sp.select(dbif)
-
     if strds_sp.get_temporal_type() != sp.get_temporal_type():
         dbif.close()
         grass.fatal(_("Input and aggregation dataset must "
@@ -131,7 +105,6 @@
 
     rows = sp.get_registered_maps("name,layer,mapset,start_time,end_time",
                                   tempwhere, "start_time", dbif)
-    dummy = tgis.VectorDataset(None)
 
     if not rows:
         dbif.close()
@@ -143,7 +116,6 @@
         end = row["end_time"]
         vectmap = row["name"] + "@" + row["mapset"]
         layer = row["layer"]
-        count = 0
 
         raster_maps = tgis.collect_map_names(
             strds_sp, dbif, start, end, sampling)
@@ -156,9 +128,9 @@
                 # Generate the temporary map name
                 aggreagated_map_name = "aggreagated_map_name_" + \
                     str(os.getpid())
-                new_map = tgis.aggregate_raster_maps(raster_maps, 
-                                                     aggreagated_map_name, 
-                                                     start, end, 0, method, 
+                new_map = tgis.aggregate_raster_maps(raster_maps,
+                                                     aggreagated_map_name,
+                                                     start, end, 0, method,
                                                      False, dbif)
                 aggreagated_map_name = aggreagated_map_name + "_0"
                 if new_map is None:
@@ -171,7 +143,7 @@
                 if column:
                     col_name = column
                 else:
-                    # Create a new column with the SQL compliant 
+                    # Create a new column with the SQL compliant
                     # name of the sampled raster map
                     col_name = rastermap.split("@")[0].replace(".", "_")
 
@@ -182,13 +154,13 @@
                     coltype = "INT"
 
                 if layer:
-                    ret = grass.run_command("v.db.addcolumn", 
-                                            map=vectmap, layer=layer, 
-                                            column="%s %s" % (col_name, coltype), 
+                    ret = grass.run_command("v.db.addcolumn",
+                                            map=vectmap, layer=layer,
+                                            column="%s %s" % (col_name, coltype),
                                             overwrite=grass.overwrite())
                 else:
-                    ret = grass.run_command("v.db.addcolumn", map=vectmap, 
-                                            column="%s %s" % (col_name, coltype), 
+                    ret = grass.run_command("v.db.addcolumn", map=vectmap,
+                                            column="%s %s" % (col_name, coltype),
                                             overwrite=grass.overwrite())
 
                 if ret != 0:
@@ -198,17 +170,17 @@
 
                 # Call v.what.rast
                 if layer:
-                    ret = grass.run_command("v.what.rast", map=vectmap, 
-                                            layer=layer, raster=rastermap, 
+                    ret = grass.run_command("v.what.rast", map=vectmap,
+                                            layer=layer, raster=rastermap,
                                             column=col_name, where=where)
                 else:
-                    ret = grass.run_command("v.what.rast", map=vectmap, 
-                                            raster=rastermap, column=col_name, 
+                    ret = grass.run_command("v.what.rast", map=vectmap,
+                                            raster=rastermap, column=col_name,
                                             where=where)
                 if ret != 0:
                     dbif.close()
                     grass.fatal(_("Unable to run v.what.rast for vector map "
-                                  "<%s> and raster map <%s>") % (vectmap, 
+                                  "<%s> and raster map <%s>") % (vectmap,
                                                                  rastermap))
 
                 if aggreagated_map_name:



More information about the grass-commit mailing list