[GRASS-SVN] r67485 - in grass/trunk/lib/python/temporal: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 4 16:10:15 PST 2016


Author: huhabla
Date: 2016-01-04 16:10:15 -0800 (Mon, 04 Jan 2016)
New Revision: 67485

Modified:
   grass/trunk/lib/python/temporal/temporal_algebra.py
   grass/trunk/lib/python/temporal/temporal_granularity.py
   grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra_grs.py
Log:
temporal framework: Improved common granularity computation and related fixes


Modified: grass/trunk/lib/python/temporal/temporal_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_algebra.py	2016-01-04 23:26:26 UTC (rev 67484)
+++ grass/trunk/lib/python/temporal/temporal_algebra.py	2016-01-05 00:10:15 UTC (rev 67485)
@@ -767,7 +767,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 the 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
@@ -817,6 +817,7 @@
             count += 1
 
         grans = []
+        start_times = []
         ttypes = {}
         dbif, connected = init_dbif(self.dbif)
 
@@ -828,6 +829,7 @@
                 return False
 
             grans.append(stds.get_granularity())
+            start_times.append(stds.get_temporal_extent_as_tuple()[0])
             ttypes[stds.get_temporal_type()] = stds.get_temporal_type()
         
         # Only one temporal type is allowed
@@ -837,7 +839,7 @@
             
         # Compute the common granularity
         if "absolute" in ttypes.keys():
-            self.granularity = compute_common_absolute_time_granularity(grans)
+            self.granularity = compute_common_absolute_time_granularity(grans, start_times)
         else:
             self.granularity = compute_common_relative_time_granularity(grans)
             

Modified: grass/trunk/lib/python/temporal/temporal_granularity.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_granularity.py	2016-01-04 23:26:26 UTC (rev 67484)
+++ grass/trunk/lib/python/temporal/temporal_granularity.py	2016-01-05 00:10:15 UTC (rev 67485)
@@ -675,7 +675,10 @@
                 return "1 second"
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 60:
-            return "60 seconds"
+            if int(num)%60 == 0:
+                return "60 seconds"
+            else:
+                return "1 second"
 
     if granule in ["minutes",  "minute"]:
         # If the start minutes are different between the start dates
@@ -685,7 +688,10 @@
                 return "1 minute"
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 60:
-            return "60 minutes"
+            if int(num)%60 == 0:
+                return "60 minutes"
+            else:
+                return "1 minute"
 
     if granule in ["hours",  "hour"]:
         # If the start hours are different between the start dates
@@ -695,7 +701,10 @@
                 return "1 hour"
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 24:
-            return "24 hours"
+            if int(num)%24 == 0:
+                return "24 hours"
+            else:
+                return "1 hour"
 
     if granule in ["days",  "day"]:
         # If the start days are different between the start dates
@@ -705,7 +714,10 @@
                 return "1 day"
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 365:
-            return "365 days"
+            if int(num)%365 == 0:
+                return "365 days"
+            else:
+                return "1 day"
 
     if granule in ["months",  "month"]:
         # If the start months are different between the start dates
@@ -715,7 +727,10 @@
                 return "1 month"
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 12:
-            return "12 months"
+            if int(num)%12 == 0:
+                return "12 months"
+            else:
+                return "1 month"
 
     return common_granule
 

Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra_grs.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra_grs.py	2016-01-04 23:26:26 UTC (rev 67484)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra_grs.py	2016-01-05 00:10:15 UTC (rev 67485)
@@ -77,12 +77,12 @@
 
     def test_common_granularity_1(self):
         """Testing the common granularity function. """
-        ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+        ta = tgis.TemporalAlgebraParser(run=True, debug=True)
         expr = 'R = A : B'
         ret = ta.setup_common_granularity(expression=expr)
 
         self.assertEqual(ret, True)
-        self.assertEqual(ta.granularity, "1 months")
+        self.assertEqual(ta.granularity, "1 month")
 
         ta.count = 0
         ta.stdstype = "strds"



More information about the grass-commit mailing list