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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 11 04:31:48 PST 2014


Author: huhabla
Date: 2014-11-11 04:31:48 -0800 (Tue, 11 Nov 2014)
New Revision: 62704

Modified:
   grass/trunk/lib/python/temporal/temporal_algebra.py
Log:
temporal framework: Better error handling when enabling the temporal granularity algebra

Modified: grass/trunk/lib/python/temporal/temporal_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_algebra.py	2014-11-11 12:31:11 UTC (rev 62703)
+++ grass/trunk/lib/python/temporal/temporal_algebra.py	2014-11-11 12:31:48 UTC (rev 62704)
@@ -694,7 +694,7 @@
              space time datasets in the expression to generate the map lists.
              
              This function will analyze the expression to detect space time datasets
-             and computes are common granularity  from all granularities.
+             and computes the common granularity  from all granularities.
           
              This granularity is then be used to generate the map lists. Hence, all
              maps from all STDS will have equidistant temporal extents. The only meaningful
@@ -706,15 +706,18 @@
                                     parse the expression, default is TemporalAlgebraLexer
              
              :return: True if successful, False otherwise
-             
-             :TODO: Check for tmap and map functions in the expression to avoid
-                         problems with map names that are handled as STDS
+ 
         """
         l = lexer
         # Split the expression to ignore the left part
         expressions = expression.split("=")[1:]
         expression = " ".join(expressions)
-
+        
+        # Check if spatio-temporal operators are present in the expression
+        if "{" in expression or "}" in expression:
+            self.msgr.error(_("Spatio temporal operators are not supported in granularity algebra mode"))
+            return False
+            
         # detect all STDS
         if l is None:
             l = TemporalAlgebraLexer()
@@ -748,6 +751,7 @@
             stds = open_old_stds(name,  stdstype,  dbif)
             # We need valid temporal topology
             if stds.check_temporal_topology() is False:
+                self.msgr.error(_("All input space time datasets must have a valid temporal topology."))
                 return False
 
             grans.append(stds.get_granularity())
@@ -755,6 +759,7 @@
         
         # Only one temporal type is allowed
         if len(ttypes) > 1:
+            self.msgr.error(_("All input space time datasets must have the same temporal type."))
             return False
             
         # Compute the common granularity
@@ -767,7 +772,8 @@
         
         return True
 
-    def parse(self, expression, stdstype = 'strds', maptype = 'rast',  mapclass = RasterDataset, basename = None, overwrite=False):
+    def parse(self, expression, stdstype = 'strds', maptype = 'rast',  mapclass = RasterDataset, 
+                      basename = None, overwrite=False):
         self.lexer = TemporalAlgebraLexer()
         self.lexer.build()
         self.parser = yacc.yacc(module=self, debug=self.debug)
@@ -1264,7 +1270,8 @@
                     for boolean in relationmap.condition_value:
                         if isinstance(boolean, bool):
                             condition_value_list.append(boolean)
-                    print(str(relationmap.get_temporal_extent_as_tuple()) + str(boolean))
+                    if self.debug:
+                        print(str(relationmap.get_temporal_extent_as_tuple()) + str(boolean))
         if all(condition_value_list):
             resultbool = True
         else:
@@ -1306,9 +1313,11 @@
             condition_value_list.append(')')
         # Convert conditional list to concatenated string and evaluate booleans.
         condition_value_str = ''.join(map(str, condition_value_list))
-        print(condition_value_str)
+        if self.debug:
+            print(condition_value_str)
         resultbool = eval(condition_value_str)
-        print(resultbool)
+        if self.debug:
+            print(resultbool)
         # Add boolean value to result list.
         map_i.condition_value = [resultbool]
         
@@ -1524,10 +1533,12 @@
                                 map_i.set_relative_time(int(start), int(end), relunit)
                             resultdict[map_i.get_id()] = map_i
                 else:
-                    print('Topologic relation: ' + topo.upper() + ' not found.')
+                    if self.debug:
+                        print('Topologic relation: ' + topo.upper() + ' not found.')
                     resultdict[map_i.get_id()] = map_i
             if unchanged == True:
-                print('Leave temporal extend of result map: ' +  map_i.get_map_id() + ' unchanged.')
+                if self.debug:
+                    print('Leave temporal extend of result map: ' +  map_i.get_map_id() + ' unchanged.')
         
         resultlist = resultdict.values()
         # Sort list of maps chronological.
@@ -1861,7 +1872,8 @@
                 # Add all maps that fulfill the conditions to result list.
                 if resultbool[0]:
                     resultlist.append(map_i)
-                    print(map_i.get_map_id() + ' ' + str(map_i.condition_value))
+                    if self.debug:
+                        print(map_i.get_map_id() + ' ' + str(map_i.condition_value))
                 else:
                     inverselist.append(map_i)
         if inverse:



More information about the grass-commit mailing list