[GRASS-SVN] r67944 - in grass/trunk: lib/python/temporal temporal/t.rast.aggregate temporal/t.rast.aggregate/testsuite temporal/t.rast.aggregate.ds

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 24 14:23:50 PST 2016


Author: lucadelu
Date: 2016-02-24 14:23:50 -0800 (Wed, 24 Feb 2016)
New Revision: 67944

Modified:
   grass/trunk/lib/python/temporal/aggregation.py
   grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py
   grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py
   grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute.py
   grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute_parallel.py
Log:
t.rast.aggregate*: replace -s flag with suffix option

Modified: grass/trunk/lib/python/temporal/aggregation.py
===================================================================
--- grass/trunk/lib/python/temporal/aggregation.py	2016-02-24 22:02:53 UTC (rev 67943)
+++ grass/trunk/lib/python/temporal/aggregation.py	2016-02-24 22:23:50 UTC (rev 67944)
@@ -18,6 +18,9 @@
 """
 
 from space_time_datasets import *
+from datetime_math import create_suffix_from_datetime
+from datetime_math import create_time_suffix
+from datetime_math import create_numeric_suffic
 import grass.script as gscript
 from grass.exceptions import CalledModuleError
 
@@ -276,13 +279,16 @@
                            "start": str(granule.temporal_extent.get_start_time()),
                            "end": str(granule.temporal_extent.get_end_time())}))
 
-            if granule.is_time_absolute() is True and time_suffix is True:
+            if granule.is_time_absolute() is True and time_suffix == 'gran':
                 suffix = create_suffix_from_datetime(granule.temporal_extent.get_start_time(),
                                                      granularity)
+                output_name = "{ba}_{su}".format(ba=basename, su=suffix)
+            elif granule.is_time_absolute() is True and time_suffix == 'time':
+                suffix = create_time_suffix(granule)
+                output_name = "{ba}_{su}".format(ba=basename, su=suffix)
             else:
-                suffix = gscript.get_num_suffix(count + int(offset),
-                                                len(granularity_list) + int(offset))
-            output_name = "%s_%s" % (basename, suffix)
+                output_name = create_numeric_suffic(basename, count + int(offset),
+                                                    time_suffix)
 
             map_layer = RasterDataset("%s@%s" % (output_name,
                                                  get_current_mapset()))

Modified: grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py	2016-02-24 22:02:53 UTC (rev 67943)
+++ grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py	2016-02-24 22:23:50 UTC (rev 67944)
@@ -39,6 +39,15 @@
 #%end
 
 #%option
+#% key: suffix
+#% type: string
+#% description: Suffix to add at basename: set 'gran' for granularity, 'time' for the full time format, 'num' for numerical suffix with a specific number of digits (default %05)
+#% answer: gran
+#% required: no
+#% multiple: no
+#%end
+
+#%option
 #% key: granularity
 #% type: string
 #% description: Aggregation granularity, format absolute time "x years, x months, x weeks, x days, x hours, x minutes, x seconds" or an integer value for relative time
@@ -96,11 +105,6 @@
 #% description: Register Null maps
 #%end
 
-#%flag
-#% key: s
-#% description: Use start time - truncated according to granularity - as suffix (overrides offset option)
-#%end
-
 import grass.script as gcore
 import grass.temporal as tgis
 
@@ -120,7 +124,7 @@
     offset = options["offset"]
     nprocs = options["nprocs"]
     file_limit = options["file_limit"]
-    time_suffix = flags["s"]
+    time_suffix = options["suffix"]
 
     topo_list = sampling.split(",")
 

Modified: grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute.py	2016-02-24 22:02:53 UTC (rev 67943)
+++ grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute.py	2016-02-24 22:23:50 UTC (rev 67944)
@@ -82,7 +82,7 @@
         self.assertModule("t.rast.aggregate", input="A", output="B",
                           basename="b", granularity="1 months",
                           method="maximum", sampling=["contains"],
-                          file_limit=0, nprocs=3, flags="s")
+                          file_limit=0, nprocs=3)
 
         tinfo_string="""start_time=2001-01-01 00:00:00
                         end_time=2001-04-01 00:00:00
@@ -110,12 +110,20 @@
              "b_2001_03" + os.linesep
         self.assertEqual(maps, lister.outputs.stdout)
 
+    def test_aggregation_1month_time(self):
+        """Aggregation one month time suffix"""
+        self.assertModule("t.rast.aggregate", input="A", output="B",
+                          basename="b", granularity="1 months",
+                          method="maximum", sampling=["contains"],
+                          file_limit=0, nprocs=3, suffix='time')
+        self.assertRasterExists('b_2001_01_01T00_00_00')
+
     def test_aggregation_2months(self):
         """Aggregation two month"""
         self.assertModule("t.rast.aggregate", input="A", output="B",
                           basename="b", granularity="2 months",
                           method="minimum", sampling=["contains"],
-                          nprocs=4, offset=10)
+                          nprocs=4, offset=10, suffix='num%02')
 
         tinfo_string="""start_time=2001-01-01 00:00:00
                         end_time=2001-05-01 00:00:00
@@ -147,7 +155,8 @@
         self.assertModule("t.rast.aggregate", input="A", output="B",
                           basename="b", granularity="3 months",
                           method="sum", sampling=["contains"],
-                          file_limit=0, nprocs=9, offset=100)
+                          file_limit=0, nprocs=9, offset=100,
+                          suffix='num%03')
 
         tinfo_string="""start_time=2001-01-01 00:00:00
                         end_time=2001-04-01 00:00:00

Modified: grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute_parallel.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute_parallel.py	2016-02-24 22:02:53 UTC (rev 67943)
+++ grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute_parallel.py	2016-02-24 22:23:50 UTC (rev 67944)
@@ -57,7 +57,7 @@
         self.assertModule("t.rast.aggregate", input="A", output="B",
                           basename="b", granularity="12 hours",
                           method="sum", sampling=["contains"],
-                          nprocs=9, flags="s", file_limit=2)
+                          nprocs=9, file_limit=2)
 
         tinfo_string="""start_time=2001-01-01 00:00:00
                         end_time=2001-04-01 00:00:00
@@ -82,7 +82,7 @@
         self.assertModule("t.rast.aggregate", input="A", output="B",
                           basename="b", granularity="1 day",
                           method="sum", sampling=["contains"],
-                          nprocs=4, flags="s")
+                          nprocs=4)
         end = datetime.now()
 
         delta = end - start
@@ -107,7 +107,7 @@
         self.assertModule("t.rast.aggregate", input="A", output="B",
                           basename="b", granularity="1 day",
                           method="sum", sampling=["contains"],
-                          nprocs=3, flags="s")
+                          nprocs=3)
         end = datetime.now()
 
         delta = end - start
@@ -125,7 +125,7 @@
                         max_min=21.0
                         max_max=3225.0"""
 
-        info = SimpleModule("t.info", flags="g", input="B")
+        info = SimpleModule("t.info", input="B", flags="g")
         #info.run()
         #print info.outputs.stdout
         self.assertModuleKeyValue(module=info, reference=tinfo_string,
@@ -137,7 +137,7 @@
         self.assertModule("t.rast.aggregate", input="A", output="B",
                           basename="b", granularity="1 day",
                           method="sum", sampling=["contains"],
-                          nprocs=2, flags="s")
+                          nprocs=2)
         end = datetime.now()
 
         delta = end - start

Modified: grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py	2016-02-24 22:02:53 UTC (rev 67943)
+++ grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py	2016-02-24 22:23:50 UTC (rev 67944)
@@ -48,6 +48,15 @@
 #%end
 
 #%option
+#% key: suffix
+#% type: string
+#% description: Suffix to add at basename: set 'gran' for granularity, 'time' for the full time format, 'num' for numerical suffix with a specific number of digits (default %05)
+#% answer: gran
+#% required: no
+#% multiple: no
+#%end
+
+#%option
 #% key: method
 #% type: string
 #% description: Aggregate operation to be performed on the raster maps
@@ -88,11 +97,6 @@
 #% description: Register Null maps
 #%end
 
-#%flag
-#% key: s
-#% description: Use start time - truncated according to granularity - as suffix (overrides offset option)
-#%end
-
 import grass.script as gcore
 import grass.temporal as tgis
 
@@ -112,7 +116,7 @@
     sampling = options["sampling"]
     offset = options["offset"]
     nprocs = options["nprocs"]
-    time_suffix = flags["s"]
+    time_suffix = options["suffix"]
     type = options["type"]
     
     topo_list = sampling.split(",")



More information about the grass-commit mailing list