Selaa lähdekoodia

temporal framework: Improved common granularity computation and related fixes

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67485 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 9 vuotta sitten
vanhempi
commit
45427a82b4

+ 4 - 2
lib/python/temporal/temporal_algebra.py

@@ -767,7 +767,7 @@ class TemporalAlgebraParser(object):
              space time datasets in the expression to generate the map lists.
              space time datasets in the expression to generate the map lists.
              
              
              This function will analyze the expression to detect space time datasets
              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
              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
              maps from all STDS will have equidistant temporal extents. The only meaningful
@@ -817,6 +817,7 @@ class TemporalAlgebraParser(object):
             count += 1
             count += 1
 
 
         grans = []
         grans = []
+        start_times = []
         ttypes = {}
         ttypes = {}
         dbif, connected = init_dbif(self.dbif)
         dbif, connected = init_dbif(self.dbif)
 
 
@@ -828,6 +829,7 @@ class TemporalAlgebraParser(object):
                 return False
                 return False
 
 
             grans.append(stds.get_granularity())
             grans.append(stds.get_granularity())
+            start_times.append(stds.get_temporal_extent_as_tuple()[0])
             ttypes[stds.get_temporal_type()] = stds.get_temporal_type()
             ttypes[stds.get_temporal_type()] = stds.get_temporal_type()
         
         
         # Only one temporal type is allowed
         # Only one temporal type is allowed
@@ -837,7 +839,7 @@ class TemporalAlgebraParser(object):
             
             
         # Compute the common granularity
         # Compute the common granularity
         if "absolute" in ttypes.keys():
         if "absolute" in ttypes.keys():
-            self.granularity = compute_common_absolute_time_granularity(grans)
+            self.granularity = compute_common_absolute_time_granularity(grans, start_times)
         else:
         else:
             self.granularity = compute_common_relative_time_granularity(grans)
             self.granularity = compute_common_relative_time_granularity(grans)
             
             

+ 20 - 5
lib/python/temporal/temporal_granularity.py

@@ -675,7 +675,10 @@ def compute_common_absolute_time_granularity(gran_list,
                 return "1 second"
                 return "1 second"
         # Make sure the granule does not exceed the hierarchy limit
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 60:
         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 granule in ["minutes",  "minute"]:
         # If the start minutes are different between the start dates
         # If the start minutes are different between the start dates
@@ -685,7 +688,10 @@ def compute_common_absolute_time_granularity(gran_list,
                 return "1 minute"
                 return "1 minute"
         # Make sure the granule does not exceed the hierarchy limit
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 60:
         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 granule in ["hours",  "hour"]:
         # If the start hours are different between the start dates
         # If the start hours are different between the start dates
@@ -695,7 +701,10 @@ def compute_common_absolute_time_granularity(gran_list,
                 return "1 hour"
                 return "1 hour"
         # Make sure the granule does not exceed the hierarchy limit
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 24:
         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 granule in ["days",  "day"]:
         # If the start days are different between the start dates
         # If the start days are different between the start dates
@@ -705,7 +714,10 @@ def compute_common_absolute_time_granularity(gran_list,
                 return "1 day"
                 return "1 day"
         # Make sure the granule does not exceed the hierarchy limit
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 365:
         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 granule in ["months",  "month"]:
         # If the start months are different between the start dates
         # If the start months are different between the start dates
@@ -715,7 +727,10 @@ def compute_common_absolute_time_granularity(gran_list,
                 return "1 month"
                 return "1 month"
         # Make sure the granule does not exceed the hierarchy limit
         # Make sure the granule does not exceed the hierarchy limit
         if int(num) > 12:
         if int(num) > 12:
-            return "12 months"
+            if int(num)%12 == 0:
+                return "12 months"
+            else:
+                return "1 month"
 
 
     return common_granule
     return common_granule
 
 

+ 2 - 2
lib/python/temporal/testsuite/unittests_temporal_algebra_grs.py

@@ -77,12 +77,12 @@ class TestTemporalAlgebraGranularity(TestCase):
 
 
     def test_common_granularity_1(self):
     def test_common_granularity_1(self):
         """Testing the common granularity function. """
         """Testing the common granularity function. """
-        ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+        ta = tgis.TemporalAlgebraParser(run=True, debug=True)
         expr = 'R = A : B'
         expr = 'R = A : B'
         ret = ta.setup_common_granularity(expression=expr)
         ret = ta.setup_common_granularity(expression=expr)
 
 
         self.assertEqual(ret, True)
         self.assertEqual(ret, True)
-        self.assertEqual(ta.granularity, "1 months")
+        self.assertEqual(ta.granularity, "1 month")
 
 
         ta.count = 0
         ta.count = 0
         ta.stdstype = "strds"
         ta.stdstype = "strds"