[GRASS-SVN] r55832 - in grass/trunk: lib/python/temporal temporal/t.topology

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Apr 16 10:37:37 PDT 2013


Author: huhabla
Date: 2013-04-16 10:37:37 -0700 (Tue, 16 Apr 2013)
New Revision: 55832

Modified:
   grass/trunk/lib/python/temporal/abstract_dataset.py
   grass/trunk/lib/python/temporal/abstract_map_dataset.py
   grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
   grass/trunk/lib/python/temporal/abstract_temporal_dataset.py
   grass/trunk/lib/python/temporal/core.py
   grass/trunk/lib/python/temporal/space_time_datasets_tools.py
   grass/trunk/lib/python/temporal/temporal_extent.py
   grass/trunk/lib/python/temporal/temporal_relationships.py
   grass/trunk/temporal/t.topology/t.topology.py
Log:
Fixed temporal relationship computation. Avoid using the reserved python word "connect".


Modified: grass/trunk/lib/python/temporal/abstract_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_dataset.py	2013-04-16 10:54:03 UTC (rev 55831)
+++ grass/trunk/lib/python/temporal/abstract_dataset.py	2013-04-16 17:37:37 UTC (rev 55832)
@@ -191,7 +191,7 @@
         """!Select temporal dataset entry from database and fill 
            up the internal structure"""
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         self.base.select(dbif)
         if self.is_time_absolute():
@@ -201,7 +201,7 @@
         self.spatial_extent.select(dbif)
         self.metadata.select(dbif)
 
-        if connect:
+        if connected:
             dbif.close()
 
     def is_in_db(self, dbif=None):
@@ -226,7 +226,7 @@
                            and must be executed by the caller.
         """
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         # Build the INSERT SQL statement
         statement = self.base.get_insert_statement_mogrified(dbif)
@@ -241,11 +241,11 @@
         
         if execute:
             dbif.execute_transaction(statement)
-            if connect:
+            if connected:
                 dbif.close()
             return ""
 
-        if connect:
+        if connected:
             dbif.close()
         return statement
 
@@ -260,7 +260,7 @@
            @param ident: The identifier to be updated, useful for renaming
         """
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         # Build the UPDATE SQL statement
         statement = self.base.get_update_statement_mogrified(dbif, ident)
@@ -276,11 +276,11 @@
 
         if execute:
             dbif.execute_transaction(statement)
-            if connect:
+            if connected:
                 dbif.close()
             return ""
 
-        if connect:
+        if connected:
             dbif.close()
         return statement
 
@@ -295,7 +295,7 @@
            @param ident: The identifier to be updated, useful for renaming
         """
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         # Build the UPDATE SQL statement
         statement = self.base.get_update_all_statement_mogrified(dbif, ident)
@@ -311,11 +311,11 @@
 
         if execute:
             dbif.execute_transaction(statement)
-            if connect:
+            if connected:
                 dbif.close()
             return ""
 
-        if connect:
+        if connected:
             dbif.close()
         return statement
 

Modified: grass/trunk/lib/python/temporal/abstract_map_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_map_dataset.py	2013-04-16 10:54:03 UTC (rev 55831)
+++ grass/trunk/lib/python/temporal/abstract_map_dataset.py	2013-04-16 17:37:37 UTC (rev 55832)
@@ -344,13 +344,13 @@
            @param end_time: a datetime object specifying the end time of the map
            @param timezone: Thee timezone of the map
         """
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         self.set_absolute_time(start_time, end_time, timezone)
         self.absolute_time.update_all(dbif)
         self.base.update(dbif)
 
-        if connect:
+        if connected:
             dbif.close()
 
         self.write_timestamp_to_grass()
@@ -418,13 +418,13 @@
            @param end_time: A double value
            @param dbif: The database interface to be used
         """
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         if self.set_relative_time(start_time, end_time, unit):
             self.relative_time.update_all(dbif)
             self.base.update(dbif)
 
-        if connect:
+        if connected:
             dbif.close()
 
         self.write_timestamp_to_grass()
@@ -490,7 +490,7 @@
                    None in case of a failure
         """
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
         statement = ""
 
         if self.is_in_db(dbif):
@@ -522,7 +522,7 @@
 
         self.reset(None)
 
-        if connect:
+        if connected:
             dbif.close()
 
         if execute:
@@ -558,7 +558,7 @@
         #                 % {'type':self.get_type(), 'map':self.get_map_id()}))
 
         statement = ""
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         # Get all datasets in which this map is registered
         rows = self.get_registered_datasets(dbif)
@@ -579,7 +579,7 @@
         if execute:
             dbif.execute_transaction(statement)
 
-        if connect:
+        if connected:
             dbif.close()
 
         if execute:
@@ -594,7 +594,7 @@
 
            @param dbif: The database interface to be used
         """
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         rows = None
 
@@ -608,7 +608,7 @@
             core.error(_("Unable to select space time dataset register table "
                          "<%s>") % (self.get_stds_register()))
 
-        if connect:
+        if connected:
             dbif.close()
 
         return rows

Modified: grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2013-04-16 10:54:03 UTC (rev 55831)
+++ grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2013-04-16 17:37:37 UTC (rev 55832)
@@ -383,7 +383,7 @@
            - follows    -> allowed
            - precedes   -> allowed
 
-           - equivalent -> not allowed
+           - equal      -> not allowed
            - during     -> not allowed
            - contains   -> not allowed
            - overlaps   -> not allowed
@@ -604,7 +604,7 @@
             use_follows = False
             use_precedes = False
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         obj_list = []
         sample_maps = stds.get_registered_maps_as_objects_with_gaps(
@@ -656,7 +656,7 @@
 
             obj_list.append(copy.copy(result))
 
-        if connect:
+        if connected:
             dbif.close()
 
         return obj_list
@@ -699,7 +699,7 @@
         """
 
         
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         obj_list = []
         
@@ -839,7 +839,7 @@
 	
             start = next
 
-        if connect:
+        if connected:
             dbif.close()
             
 
@@ -867,7 +867,7 @@
            @return ordered object list, in case nothing found None is returned
         """
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         obj_list = []
 
@@ -897,7 +897,7 @@
                                                   self.get_relative_time_unit())
                         obj_list.append(copy.copy(map))
 
-        if connect:
+        if connected:
             dbif.close()
 
         return obj_list
@@ -921,13 +921,13 @@
                    In case nothing found None is returned
         """
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
         obj_list = self.get_registered_maps_as_objects(where, order, dbif)
 
         tb = TemporalTopologyBuilder()
         tb.build(obj_list)
     
-        if connect:
+        if connected:
             dbif.close()
 
         return obj_list
@@ -951,7 +951,7 @@
                    In case nothing found None is returned
         """
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         obj_list = []
 
@@ -968,7 +968,7 @@
                                           self.get_relative_time_unit())
                 obj_list.append(copy.copy(map))
 
-        if connect:
+        if connected:
             dbif.close()
 
         return obj_list
@@ -990,7 +990,7 @@
                    In case nothing found None is returned
         """
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         rows = None
 
@@ -1019,13 +1019,13 @@
                 dbif.cursor.execute(sql)
                 rows = dbif.cursor.fetchall()
             except:
-                if connect:
+                if connected:
                     dbif.close()
                 core.error(_("Unable to get map ids from register table <%s>")
                            % (self.get_map_register()))
                 raise
 
-        if connect:
+        if connected:
             dbif.close()
 
         return rows
@@ -1040,7 +1040,7 @@
            @param dbif: The database interface to be used
         """
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         # SELECT all needed information from the database
         self.select(dbif)
@@ -1078,7 +1078,7 @@
         # Execute the accumulated statements
         dbif.execute_transaction(statement)
         
-        if connect:
+        if connected:
             dbif.close()
     
     def delete(self, dbif=None, execute=True):
@@ -1098,13 +1098,14 @@
         # First we need to check if maps are registered in this dataset and
         # unregister them
 
-        core.verbose(_("Delete space time %s  dataset <%s> from temporal "
-                       "database") % \
-                     (self.get_new_map_instance(ident=None).get_type(), 
-                      self.get_id()))
+        # Commented because of performance issue calling g.message thousend times
+        #core.verbose(_("Delete space time %s  dataset <%s> from temporal "
+        #               "database") % \
+        #             (self.get_new_map_instance(ident=None).get_type(), 
+        #              self.get_id()))
 
         statement = ""
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         # SELECT all needed information from the database
         self.metadata.select(dbif)
@@ -1132,7 +1133,7 @@
 
         self.reset(None)
 
-        if connect:
+        if connected:
             dbif.close()
 
         if execute:
@@ -1148,11 +1149,13 @@
 
             In case the map is already registered this function 
             will break with a warning and return False.
+            
+            This method raises a ScriptError in case of a fatal error
 
            @param map: The AbstractMapDataset object that should be registered
            @param dbif: The database interface to be used
         """
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         if map.is_in_db(dbif) == False:
             dbif.close()
@@ -1237,8 +1240,6 @@
                              "<%s> and map <%s> are different") % \
                            (self.get_id(), map.get_map_id()))
 
-        #print "STDS register table", stds_register_table
-
         if stds_mapset != map_mapset:
             dbif.close()
             core.fatal(_("Only maps from the same mapset can be registered"))
@@ -1255,12 +1256,11 @@
                 dbif.cursor.execute(sql, (map_id,))
                 row = dbif.cursor.fetchone()
             except:
-                row = None
                 core.warning(_("Error in strds_register_table request"))
                 raise
 
             if row is not None and row[0] == map_id:
-                if connect == True:
+                if connected == True:
                     dbif.close()
 
                 if map.get_layer() is not None:
@@ -1270,7 +1270,7 @@
                 else:
                     core.warning(_("Map <%s> is already registered.")
                         % (map.get_map_id()))
-                return ""
+                return False
 
         # Create tables
         sql_path = get_sql_template_path()
@@ -1378,11 +1378,13 @@
         # Now execute the insert transaction
         dbif.execute_transaction(statement)
 
-        if connect:
+        if connected:
             dbif.close()
 
         # increase the counter
         self.map_counter += 1
+        
+        return True
 
     def unregister_map(self, map, dbif=None, execute=True):
         """!Unregister a map from the space time dataset.
@@ -1403,7 +1405,7 @@
 
         statement = ""
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         # First select needed data from the database
         map.metadata.select(dbif)
@@ -1443,7 +1445,7 @@
                     core.warning(_("Map <%s> is not registered in space "
                                    "time dataset <%s>") % (map.get_map_id(), 
                                                            self.base.get_id()))
-                if connect == True:
+                if connected == True:
                     dbif.close()
                 return ""
 
@@ -1470,7 +1472,7 @@
         if execute:
             dbif.execute_transaction(statement)
 
-        if connect:
+        if connected:
             dbif.close()
 
         # decrease the counter
@@ -1504,7 +1506,7 @@
         if not self.get_map_register():
             return
 
-        dbif, connect = init_dbif(dbif)
+        dbif, connected = init_dbif(dbif)
 
         map_time = None
 
@@ -1679,7 +1681,7 @@
                 self.relative_time.set_granularity(None)
             self.relative_time.update_all(dbif)
 
-        if connect:
+        if connected:
             dbif.close()
 
 ###############################################################################

Modified: grass/trunk/lib/python/temporal/abstract_temporal_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_temporal_dataset.py	2013-04-16 10:54:03 UTC (rev 55831)
+++ grass/trunk/lib/python/temporal/abstract_temporal_dataset.py	2013-04-16 17:37:37 UTC (rev 55832)
@@ -207,7 +207,7 @@
             return None
         return self._topology["PREV"]
 
-    def append_equivalent(self, map_):
+    def append_equal(self, map_):
         """!Append a map with equivalent temporal extent as this map
 
            @param map_: This object should be of type AbstractMapDataset 
@@ -217,7 +217,7 @@
             self._topology["EQUAL"] = []
         self._topology["EQUAL"].append(map_)
 
-    def get_equivalent(self):
+    def get_equal(self):
         """!Return a list of map objects with equivalent temporal extent as this map
 
            @return A list of map objects or None
@@ -436,8 +436,8 @@
         return string
     
     # Set the properties
-    equivalent = property(fget=get_equivalent, 
-                                       fset=append_equivalent)
+    equal = property(fget=get_equal, 
+                                       fset=append_equal)
     follows = property(fget=get_follows, 
                                     fset=append_follows)
     precedes = property(fget=get_precedes, 
@@ -463,7 +463,7 @@
         """!Print information about this class in human readable style"""
         _next = self.next()
         _prev = self.prev()
-        _equal = self.get_equivalent()
+        _equal = self.get_equal()
         _follows = self.get_follows()
         _precedes = self.get_precedes()
         _overlaps = self.get_overlaps()
@@ -482,7 +482,7 @@
         if _prev is not None:
             print " | Previous: .................. " + str(_prev.get_id())
         if _equal is not None:
-            print " | Equivalent: ................ " + \
+            print " | Equal:...................... " + \
                 self._generate_map_list_string(_equal)
         if _follows is not None:
             print " | Follows: ................... " + \
@@ -520,7 +520,7 @@
 
         _next = self.next()
         _prev = self.prev()
-        _equal = self.get_equivalent()
+        _equal = self.get_equal()
         _follows = self.get_follows()
         _precedes = self.get_precedes()
         _overlaps = self.get_overlaps()
@@ -537,7 +537,7 @@
         if _prev is not None:
             print "prev=" + _prev.get_id()
         if _equal is not None:
-            print "equivalent=" + self._generate_map_list_string(_equal, False)
+            print "equal=" + self._generate_map_list_string(_equal, False)
         if _follows is not None:
             print "follows=" + self._generate_map_list_string(_follows, False)
         if _precedes is not None:

Modified: grass/trunk/lib/python/temporal/core.py
===================================================================
--- grass/trunk/lib/python/temporal/core.py	2013-04-16 10:54:03 UTC (rev 55831)
+++ grass/trunk/lib/python/temporal/core.py	2013-04-16 17:37:37 UTC (rev 55832)
@@ -448,10 +448,10 @@
 
             @param statement The executable SQL statement or SQL script
         """
-        connect = False
+        connected = False
         if not self.connected:
             self.connect()
-            connect = True
+            connected = True
 
         sql_script = ""
         sql_script += "BEGIN TRANSACTION;\n"
@@ -465,13 +465,13 @@
                 self.cursor.execute(statement)
             self.connection.commit()
         except:
-            if connect:
+            if connected:
                 self.close()
             core.error(_("Unable to execute transaction:\n %(sql)s" % \
                          {"sql":statement}))
             raise
 
-        if connect:
+        if connected:
             self.close()
 
 ###############################################################################

Modified: grass/trunk/lib/python/temporal/space_time_datasets_tools.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2013-04-16 10:54:03 UTC (rev 55831)
+++ grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2013-04-16 17:37:37 UTC (rev 55832)
@@ -98,7 +98,7 @@
         else:
             core.fatal(_("Unkown map type: %s") % (type))
 
-    dbif, connect = init_dbif(None)
+    dbif, connected = init_dbif(None)
 
     if name:
         # Read content from temporal database
@@ -326,7 +326,7 @@
             ds.select(dbif)
             ds.update_from_registered_maps(dbif)
 
-    if connect == True:
+    if connected == True:
         dbif.close()
 
     core.percent(num_maps, num_maps, 1)
@@ -886,10 +886,10 @@
 
     sp = dataset_factory(type, id)
 
-    dbif, connect = init_dbif(dbif)
+    dbif, connected = init_dbif(dbif)
 
     if sp.is_in_db(dbif) and overwrite == False:
-        if connect:
+        if connected:
             dbif.close()
         core.fatal(_("Space time %s dataset <%s> is already in the database. "
                       "Use the overwrite flag.") %
@@ -910,7 +910,7 @@
                           title=title, description=descr)
     sp.insert(dbif)
 
-    if connect:
+    if connected:
         dbif.close()
         
     return sp

Modified: grass/trunk/lib/python/temporal/temporal_extent.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_extent.py	2013-04-16 10:54:03 UTC (rev 55831)
+++ grass/trunk/lib/python/temporal/temporal_extent.py	2013-04-16 17:37:37 UTC (rev 55832)
@@ -465,15 +465,15 @@
         else:
             return False
 
-    def equivalent(self, extent):
-        """!Return True if this temporal extent (A) is equivalent to the provided 
+    def equal(self, extent):
+        """!Return True if this temporal extent (A) is equal to the provided 
            temporal extent (B)
            @verbatim
            A  |---------|
            B  |---------|
            @endverbatim
            
-           @param extent: The temporal extent object that is equivalent 
+           @param extent: The temporal extent object that is equal 
                           during this extent
            
            Usage:
@@ -482,9 +482,9 @@
            
            >>> A = AbstractTemporalExtent(start_time=5, end_time=6 )
            >>> B = AbstractTemporalExtent(start_time=5, end_time=6 )
-           >>> A.equivalent(B)
+           >>> A.equal(B)
            True
-           >>> B.equivalent(A)
+           >>> B.equal(A)
            True
            
            @endcode
@@ -578,7 +578,7 @@
            
            The following temporal relationships are supported:
            
-               - equivalent
+               - equal
                - during
                - contains
                - overlaps
@@ -609,8 +609,8 @@
         if self.D["start_time"] is None or extent.D["start_time"] is None:
             return None
 
-        if self.equivalent(extent):
-            return "equivalent"
+        if self.equal(extent):
+            return "equal"
         if self.during(extent):
             return "during"
         if self.contains(extent):

Modified: grass/trunk/lib/python/temporal/temporal_relationships.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_relationships.py	2013-04-16 10:54:03 UTC (rev 55831)
+++ grass/trunk/lib/python/temporal/temporal_relationships.py	2013-04-16 17:37:37 UTC (rev 55832)
@@ -135,7 +135,7 @@
 #                relation = maps[j].temporal_relation(maps[i])
 #
 #                # Build the next reference
-#                if relation != "equivalent" and relation != "started":
+#                if relation != "equal" and relation != "started":
 #                    maps[i].set_next(maps[j])
 #                    break
 
@@ -232,10 +232,16 @@
                 # Get the temporal relationship
                 relation = mapsB[j].temporal_relation(mapsA[i])
                 
-                if relation == "equivalent":
-                    if mapsB[j].get_id() != mapsA[i].get_id():
-                        mapsB[j].append_equivalent(mapsA[i])
-                        mapsA[i].append_equivalent(mapsB[j])
+                if relation == "equal":
+                    if mapsB[j] != mapsA[i]:
+                        if not mapsB[j].get_equal() or \
+                        (mapsB[j].get_equal() and \
+                        mapsA[i] not in mapsB[j].get_equal()):
+                            mapsB[j].append_equal(mapsA[i])
+                        if not mapsA[i].get_equal() or \
+                        (mapsA[i].get_equal() and \
+                        mapsB[j] not in mapsA[i].get_equal()):
+                            mapsA[i].append_equal(mapsB[j])
                 elif relation == "follows":
                     if not mapsB[j].get_follows() or \
                        (mapsB[j].get_follows() and \

Modified: grass/trunk/temporal/t.topology/t.topology.py
===================================================================
--- grass/trunk/temporal/t.topology/t.topology.py	2013-04-16 10:54:03 UTC (rev 55831)
+++ grass/trunk/temporal/t.topology/t.topology.py	2013-04-16 17:37:37 UTC (rev 55832)
@@ -119,9 +119,9 @@
 
     if dict_:
         for key in dict_.keys():
-            if key == "equivalent":
+            if key == "equal":
                 #      0123456789012345678901234567890
-                print " | Equivalent: ................ %s" % (dict_[key])
+                print " | Equal:...................... %s" % (dict_[key])
             if key == "during":
                 print " | During: .................... %s" % (dict_[key])
             if key == "contains":



More information about the grass-commit mailing list