[GRASS-SVN] r49866 - grass/trunk/lib/python/temporal

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 22 15:09:13 EST 2011


Author: huhabla
Date: 2011-12-22 12:09:13 -0800 (Thu, 22 Dec 2011)
New Revision: 49866

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/aggregation.py
   grass/trunk/lib/python/temporal/metadata.py
   grass/trunk/lib/python/temporal/space_time_datasets_tools.py
Log:
Added listing of stds register.


Modified: grass/trunk/lib/python/temporal/abstract_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_dataset.py	2011-12-22 20:08:41 UTC (rev 49865)
+++ grass/trunk/lib/python/temporal/abstract_dataset.py	2011-12-22 20:09:13 UTC (rev 49866)
@@ -47,6 +47,24 @@
         """
         raise IOError("This method must be implemented in the subclasses")
 
+    def print_info(self):
+        """Print information about this class in human readable style"""
+	raise IOError("This method must be implemented in the subclasses")
+        
+    def print_shell_info(self):
+        """Print information about this class in shell style"""
+	raise IOError("This method must be implemented in the subclasses")
+ 
+    def print_self(self):
+	"""Print the content of the internal structure to stdout"""
+	self.base.print_self()
+	if self.is_time_absolute():
+	    self.absolute_time.print_self()
+        if self.is_time_relative():
+	    self.relative_time.print_self()
+	self.spatial_extent.print_self()
+	self.metadata.print_self()
+
     def get_id(self):
         return self.base.get_id()
 
@@ -223,70 +241,7 @@
 
         if connect:
             dbif.close()
- 
-    def print_self(self):
-	"""Print the content of the internal structure to stdout"""
-	self.base.print_self()
-	if self.is_time_absolute():
-	    self.absolute_time.print_self()
-        if self.is_time_relative():
-	    self.relative_time.print_self()
-	self.spatial_extent.print_self()
-	self.metadata.print_self()
 
-    def print_info(self):
-        """Print information about this class in human readable style"""
-        
-        if self.get_type() == "raster":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Raster Dataset ----------------------------------------+"
-        if self.get_type() == "raster3d":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Raster3d Dataset --------------------------------------+"
-        if self.get_type() == "vector":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Vector Dataset ----------------------------------------+"
-        if self.get_type() == "strds":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Space Time Raster Dataset -----------------------------+"
-        if self.get_type() == "str3ds":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Space Time Raster3d Dataset ---------------------------+"
-        if self.get_type() == "stvds":
-            #                1         2         3         4         5         6         7
-            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
-            print ""
-            print " +-------------------- Space Time Vector Dataset -----------------------------+"
-        print " |                                                                            |"
-	self.base.print_info()
-	if self.is_time_absolute():
-	    self.absolute_time.print_info()
-        if self.is_time_relative():
-	    self.relative_time.print_info()
-	self.spatial_extent.print_info()
-	self.metadata.print_info()
-        print " +----------------------------------------------------------------------------+"
-
-    def print_shell_info(self):
-        """Print information about this class in shell style"""
-	self.base.print_shell_info()
-	if self.is_time_absolute():
-	    self.absolute_time.print_shell_info()
-        if self.is_time_relative():
-	    self.relative_time.print_shell_info()
-	self.spatial_extent.print_shell_info()
-	self.metadata.print_shell_info()
-
     def set_time_to_absolute(self):
 	self.base.set_ttype("absolute")
 

Modified: grass/trunk/lib/python/temporal/abstract_map_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_map_dataset.py	2011-12-22 20:08:41 UTC (rev 49865)
+++ grass/trunk/lib/python/temporal/abstract_map_dataset.py	2011-12-22 20:09:13 UTC (rev 49866)
@@ -52,7 +52,67 @@
     def load(self):
         """Load the content of this object from map files"""
         raise IOError("This method must be implemented in the subclasses")
+ 
+    def print_info(self):
+        """Print information about this class in human readable style"""
+        
+        if self.get_type() == "raster":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Raster Dataset ----------------------------------------+"
+        if self.get_type() == "raster3d":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Raster3d Dataset --------------------------------------+"
+        if self.get_type() == "vector":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Vector Dataset ----------------------------------------+"
+        print " |                                                                            |"
+	self.base.print_info()
+	if self.is_time_absolute():
+	    self.absolute_time.print_info()
+        if self.is_time_relative():
+	    self.relative_time.print_info()
+	self.spatial_extent.print_info()
+	self.metadata.print_info()
+        datasets = self.get_registered_datasets()
+        count = 0
+        string = ""
+        for ds in datasets:
+            if count == 0:
+                string += ds["id"]
+            else:
+                string += ",%s" % ds["id"]
+            count += 1
+            if count > 2:
+                string += " | ............................ "
+        print " | Registered datasets ........ " + string
+        print " +----------------------------------------------------------------------------+"
 
+    def print_shell_info(self):
+        """Print information about this class in shell style"""
+	self.base.print_shell_info()
+	if self.is_time_absolute():
+	    self.absolute_time.print_shell_info()
+        if self.is_time_relative():
+	    self.relative_time.print_shell_info()
+	self.spatial_extent.print_shell_info()
+	self.metadata.print_shell_info()
+        datasets = self.get_registered_datasets()
+        count = 0
+        string = ""
+        for ds in datasets:
+            if count == 0:
+                string += ds["id"]
+            else:
+                string += ",%s" % ds["id"]
+            count += 1
+        print "registered_datasets=" + string
+
     def set_absolute_time(self, start_time, end_time=None, timezone=None):
         """Set the absolute time interval with start time and end time
         

Modified: grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2011-12-22 20:08:41 UTC (rev 49865)
+++ grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2011-12-22 20:09:13 UTC (rev 49866)
@@ -59,7 +59,55 @@
            @param name: The name of the register table
         """
         raise IOError("This method must be implemented in the subclasses")
+ 
+    def print_self(self):
+	"""Print the content of the internal structure to stdout"""
+	self.base.print_self()
+	if self.is_time_absolute():
+	    self.absolute_time.print_self()
+        if self.is_time_relative():
+	    self.relative_time.print_self()
+	self.spatial_extent.print_self()
+	self.metadata.print_self()
 
+    def print_info(self):
+        """Print information about this class in human readable style"""
+        
+        if self.get_type() == "strds":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Space Time Raster Dataset -----------------------------+"
+        if self.get_type() == "str3ds":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Space Time Raster3d Dataset ---------------------------+"
+        if self.get_type() == "stvds":
+            #                1         2         3         4         5         6         7
+            #      0123456789012345678901234567890123456789012345678901234567890123456789012345678
+            print ""
+            print " +-------------------- Space Time Vector Dataset -----------------------------+"
+        print " |                                                                            |"
+	self.base.print_info()
+	if self.is_time_absolute():
+	    self.absolute_time.print_info()
+        if self.is_time_relative():
+	    self.relative_time.print_info()
+	self.spatial_extent.print_info()
+	self.metadata.print_info()
+        print " +----------------------------------------------------------------------------+"
+
+    def print_shell_info(self):
+        """Print information about this class in shell style"""
+	self.base.print_shell_info()
+	if self.is_time_absolute():
+	    self.absolute_time.print_shell_info()
+        if self.is_time_relative():
+	    self.relative_time.print_shell_info()
+	self.spatial_extent.print_shell_info()
+	self.metadata.print_shell_info()
+
     def set_initial_values(self, temporal_type, semantic_type, \
                            title=None, description=None):
         """Set the initial values of the space time dataset
@@ -348,7 +396,7 @@
            "gap" map objects (id==None). Each list entry is a list of map objects
            which are potentially located in temporal relation to the actual granule of the second space time dataset.
 
-           Each entry in the object list is a dict. The actual sampler map and its temporal enxtent (the actual granule) and
+           Each entry in the object list is a dict. The actual sampler map and its temporal extent (the actual granule) and
            the list of samples are stored:
 
            list = self.sample_by_dataset_topology(stds=sampler, method=["during","overlap","contain","equal"])    
@@ -359,7 +407,8 @@
                    map.select()
                    map.print_info()
 
-           A valid temporal topology (no overlapping or inclusion allowed) is needed to get correct results. 
+           A valid temporal topology (no overlapping or inclusion allowed) is needed to get correct results in case of gaps
+           in the sample dataset. 
     
            Gaps between maps are identified as unregistered maps with id==None.
 
@@ -458,41 +507,9 @@
         for granule in sample_maps:
             start, end = granule.get_valid_time()
 
-            where = "("
+            where = create_temporal_relation_sql_where_statement(start, end, use_start, \
+                    use_during, use_overlap, use_contain, use_equal)  
 
-            if use_start:
-                where += "(start_time >= '%s' and start_time < '%s') " % (start, end)
-
-            if use_during:
-                if use_start:
-                    where += " OR "
-                where += "((start_time > '%s' and end_time < '%s') OR " % (start, end)
-                where += "(start_time >= '%s' and end_time < '%s') OR " % (start, end)
-                where += "(start_time > '%s' and end_time <= '%s'))" % (start, end)
-
-            if use_overlap:
-                if use_start or use_during:
-                    where += " OR "
-
-                where += "((start_time < '%s' and end_time > '%s' and end_time < '%s') OR " % (start, start, end)
-                where += "(start_time < '%s' and start_time > '%s' and end_time > '%s'))" % (end, start, end)
-
-            if use_contain:
-                if use_start or use_during or use_overlap:
-                    where += " OR "
-
-                where += "((start_time < '%s' and end_time > '%s') OR " % (start, end)
-                where += "(start_time <= '%s' and end_time > '%s') OR " % (start, end)
-                where += "(start_time < '%s' and end_time >= '%s'))" % (start, end)
-
-            if use_equal:
-                if use_start or use_during or use_overlap or use_contain:
-                    where += " OR "
-
-                where += "(start_time = '%s' and end_time = '%s')" % (start, end)
-
-            where += ")"
-
             rows = self.get_registered_maps("id", where, "start_time", dbif)
 
             result = {}
@@ -1225,3 +1242,80 @@
 
         if connect == True:
             dbif.close()
+
+###############################################################################
+
+def create_temporal_relation_sql_where_statement(start, end, use_start=True, use_during=False, 
+                                        use_overlap=False, use_contain=False, use_equal=False):
+    """ Create a SQL WHERE statement for temporal relation selection of maps in space time datastes
+
+        @param start: The start time
+        @param end: The end time
+        @param use_start: Select maps of which the start time is located in the selection granule
+                         map    :        s
+                         granule:  s-----------------e
+
+                         map    :        s--------------------e
+                         granule:  s-----------------e
+
+                         map    :        s--------e
+                         granule:  s-----------------e
+
+        @param use_during: during: Select maps which are temporal during the selection granule
+                         map    :     s-----------e
+                         granule:  s-----------------e
+
+        @param use_overlap: Select maps which temporal overlap the selection granule
+                         map    :     s-----------e
+                         granule:        s-----------------e
+
+                         map    :     s-----------e
+                         granule:  s----------e
+
+        @param use_contain: Select maps which temporally contain the selection granule
+                         map    :  s-----------------e
+                         granule:     s-----------e
+
+        @param use_equal: Select maps which temporally equal to the selection granule
+                         map    :  s-----------e
+                         granule:  s-----------e
+    """
+
+    where = "("
+
+    if use_start:
+        where += "(start_time >= '%s' and start_time < '%s') " % (start, end)
+
+    if use_during:
+        if use_start:
+            where += " OR "
+        where += "((start_time > '%s' and end_time < '%s') OR " % (start, end)
+        where += "(start_time >= '%s' and end_time < '%s') OR " % (start, end)
+        where += "(start_time > '%s' and end_time <= '%s'))" % (start, end)
+
+    if use_overlap:
+        if use_start or use_during:
+            where += " OR "
+
+        where += "((start_time < '%s' and end_time > '%s' and end_time < '%s') OR " % (start, start, end)
+        where += "(start_time < '%s' and start_time > '%s' and end_time > '%s'))" % (end, start, end)
+
+    if use_contain:
+        if use_start or use_during or use_overlap:
+            where += " OR "
+
+        where += "((start_time < '%s' and end_time > '%s') OR " % (start, end)
+        where += "(start_time <= '%s' and end_time > '%s') OR " % (start, end)
+        where += "(start_time < '%s' and end_time >= '%s'))" % (start, end)
+
+    if use_equal:
+        if use_start or use_during or use_overlap or use_contain:
+            where += " OR "
+
+        where += "(start_time = '%s' and end_time = '%s')" % (start, end)
+
+    where += ")"
+
+    return where
+
+

Modified: grass/trunk/lib/python/temporal/aggregation.py
===================================================================
--- grass/trunk/lib/python/temporal/aggregation.py	2011-12-22 20:08:41 UTC (rev 49865)
+++ grass/trunk/lib/python/temporal/aggregation.py	2011-12-22 20:09:13 UTC (rev 49866)
@@ -24,12 +24,39 @@
 
 from space_time_datasets import *
 
-def collect_map_names(sp, dbif, start, end):
+def collect_map_names(sp, dbif, start, end, sampling):
     
-    where = " start_time >= \'%s\' and start_time < \'%s\'" % (start, end)
+    use_start = False
+    use_during = False
+    use_overlap = False
+    use_contain = False
+    use_equal = False
 
-    print where
-    
+    # Inititalize the methods
+    if sampling:
+        for name in sampling.split(","):
+            if name == "start":
+                use_start = True
+            if name == "during":
+                use_during = True
+            if name == "overlap":
+                use_overlap = True
+            if name == "contain":
+                use_contain = True
+            if name == "equal":
+                use_equal = True
+    else:
+        use_start = True
+
+    if sp.get_map_time() != "interval":
+        use_start = True
+        use_during = False
+        use_overlap = False
+        use_contain = False
+        use_equal = False
+
+    where = create_temporal_relation_sql_where_statement(start, end, use_start, use_during, use_overlap, use_contain, use_equal)
+   
     rows = sp.get_registered_maps("id", where, "start_time", dbif)
 
     if not rows:
@@ -41,7 +68,6 @@
 
     return names    
 
-
 def aggregate_raster_maps(dataset, mapset, inputs, base, start, end, count, method, register_null, dbif):
 
     core.verbose(_("Aggregate %s raster maps") %(len(inputs)))

Modified: grass/trunk/lib/python/temporal/metadata.py
===================================================================
--- grass/trunk/lib/python/temporal/metadata.py	2011-12-22 20:08:41 UTC (rev 49865)
+++ grass/trunk/lib/python/temporal/metadata.py	2011-12-22 20:09:13 UTC (rev 49866)
@@ -199,12 +199,13 @@
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
+        raster_metadata_base.print_info(self)
         print " | STRDS register table ....... " + str(self.get_strds_register())
-        raster_metadata_base.print_info(self)
 
     def print_shell_info(self):
         """Print information about this class in shell style"""
         raster_metadata_base.print_shell_info(self)
+        print "strds_register=" + str(self.get_strds_register())
 
 ###############################################################################
 
@@ -258,17 +259,18 @@
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
-        print " | STR3DS register table ...... " + str(self.get_str3ds_register())
         raster_metadata_base.print_info(self)
         #      0123456789012345678901234567890
         print " | Number of depths:........... " + str(self.get_depths())
         print " | Top-Bottom resolution:...... " + str(self.get_tbres())
+        print " | STR3DS register table ...... " + str(self.get_str3ds_register())
 
     def print_shell_info(self):
         """Print information about this class in shell style"""
-        raster_metadata_base.print_shell_info(self)
+        print "str3ds_register=" + str(self.get_str3ds_register())
         print "depths=" + str(self.get_depths())
         print "tbres=" + str(self.get_tbres())
+        raster_metadata_base.print_shell_info(self)
         
 ###############################################################################
 
@@ -541,12 +543,13 @@
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
+        stds_raster_metadata_base.print_info(self)
         print " | Raster register table:...... " + str(self.get_raster_register())
-        stds_raster_metadata_base.print_info(self)
 
     def print_shell_info(self):
         """Print information about this class in shell style"""
         stds_raster_metadata_base.print_shell_info(self)
+        print "raster_register=" + str(self.get_raster_register())
 
 ###############################################################################
 
@@ -594,17 +597,18 @@
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
-        print " | Raster3d register table:.... " + str(self.get_raster3d_register())
         stds_raster_metadata_base.print_info(self)
         #      0123456789012345678901234567890
         print " | Top-bottom resolution min:.. " + str(self.get_ewres_min())
         print " | Top-bottom resolution max:.. " + str(self.get_ewres_max())
+        print " | Raster3d register table:.... " + str(self.get_raster3d_register())
 
     def print_shell_info(self):
         """Print information about this class in shell style"""
         stds_raster_metadata_base.print_shell_info(self)
         print "tbres_min=" + str(self.get_tbres_min())
         print "tbres_max=" + str(self.get_tbres_max())
+        print "raster3d_register=" + str(self.get_raster3d_register())
 
 ###############################################################################
 
@@ -632,9 +636,12 @@
         """Print information about this class in human readable style"""
         print " +-------------------- Metadata information ----------------------------------+"
         #      0123456789012345678901234567890
+        stds_metadata_base.print_info(self)
         print " | Vector register table:...... " + str(self.get_vector_register())
-        stds_metadata_base.print_info(self)
 
     def print_shell_info(self):
         """Print information about this class in shell style"""
         stds_metadata_base.print_shell_info(self)
+        print "vector_register=" + str(self.get_vector_register())
+
+

Modified: grass/trunk/lib/python/temporal/space_time_datasets_tools.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2011-12-22 20:08:41 UTC (rev 49865)
+++ grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2011-12-22 20:09:13 UTC (rev 49866)
@@ -676,6 +676,7 @@
                         
                     print output
 
+###############################################################################
 
 def sample_stds_by_stds_topology(intype, sampletype, input, sampler, header, separator, method):
     """ Sample the input space time dataset with a sample space time dataset and print the result to stdout
@@ -773,3 +774,4 @@
             print string
 
     dbif.close()
+



More information about the grass-commit mailing list