[GRASS-SVN] r67945 - in grass/trunk/temporal/t.rast.gapfill: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 25 01:12:47 PST 2016
Author: lucadelu
Date: 2016-02-25 01:12:47 -0800 (Thu, 25 Feb 2016)
New Revision: 67945
Modified:
grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py
grass/trunk/temporal/t.rast.gapfill/testsuite/test_gapfill.py
Log:
t.rast.gapfill: added suffix option
Modified: grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py
===================================================================
--- grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py 2016-02-24 22:23:50 UTC (rev 67944)
+++ grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py 2016-02-25 09:12:47 UTC (rev 67945)
@@ -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: nprocs
#% type: integer
#% description: Number of interpolation processes to run in parallel
@@ -71,6 +80,7 @@
base = options["basename"]
where = options["where"]
nprocs = options["nprocs"]
+ tsuffix = options["suffix"]
mapset = grass.gisenv()["MAPSET"]
@@ -102,7 +112,11 @@
for _map in maps:
if _map.get_id() is None:
count += 1
- _id = "%s_%d@%s" % (base, num + count, mapset)
+ if sp.get_temporal_type() == 'absolute' and tsuffix in ['gran', 'time']:
+ _id = "{ba}@{ma}".format(ba=base, ma=mapset)
+ else:
+ map_name = tgis.create_numeric_suffic(base, num + count, tsuffix)
+ _id = "{name}@{ma}".format(name=map_name, ma=mapset)
_map.set_id(_id)
gap_list.append(_map)
@@ -152,7 +166,20 @@
for intp_list in map_matrix:
new_map = intp_list[0]
count += 1
- new_id = "%s_%i@%s"%(_map.get_name(), count, tgis.get_current_mapset())
+ if sp.get_temporal_type() == 'absolute' and tsuffix == 'gran':
+ suffix = tgis.create_suffix_from_datetime(new_map.temporal_extent.get_start_time(),
+ sp.get_granularity())
+ new_id = "{ba}_{su}@{ma}".format(ba=new_map.get_name(),
+ su=suffix, ma=mapset)
+ elif sp.get_temporal_type() == 'absolute' and tsuffix == 'time':
+ suffix = tgis.create_time_suffix(new_map)
+ new_id = "{ba}_{su}@{ma}".format(ba=new_map.get_name(),
+ su=suffix, ma=mapset)
+ else:
+ map_name = tgis.create_numeric_suffic(new_map.get_name(),
+ count, tsuffix)
+ new_id = "{name}@{ma}".format(name=map_name, ma=mapset)
+
new_map.set_id(new_id)
overwrite_flags[new_id] = False
Modified: grass/trunk/temporal/t.rast.gapfill/testsuite/test_gapfill.py
===================================================================
--- grass/trunk/temporal/t.rast.gapfill/testsuite/test_gapfill.py 2016-02-24 22:23:50 UTC (rev 67944)
+++ grass/trunk/temporal/t.rast.gapfill/testsuite/test_gapfill.py 2016-02-25 09:12:47 UTC (rev 67945)
@@ -51,8 +51,8 @@
inputs="A")
def test_simple_2procs(self):
- self.assertModule("t.rast.gapfill", input="A",
- basename="test", nprocs=2, verbose=True)
+ self.assertModule("t.rast.gapfill", input="A", suffix="num%01",
+ basename="test", nprocs=2, verbose=True)
#self.assertModule("t.info", type="strds", flags="g", input="A")
@@ -90,7 +90,7 @@
def test_simple_where(self):
self.assertModule("t.rast.gapfill", input="A", where="start_time >= '2001-03-01'",
- basename="test", nprocs=1, verbose=True)
+ basename="test", nprocs=1, verbose=True, suffix="num%01")
#self.assertModule("t.info", type="strds", flags="g", input="A")
@@ -125,7 +125,7 @@
def test_simple_where_2(self):
self.assertModule("t.rast.gapfill", input="A", where="start_time <= '2001-05-01'",
- basename="test", nprocs=1, verbose=True)
+ basename="test", nprocs=1, verbose=True, suffix="num%01")
#self.assertModule("t.info", type="strds", flags="g", input="A")
@@ -155,7 +155,7 @@
def test_simple_empty(self):
self.assertModule("t.rast.gapfill", input="A", where="start_time >= '2001-10-01'",
- basename="test", nprocs=1, verbose=True)
+ basename="test", nprocs=1, verbose=True, suffix="num%01")
#self.assertModule("t.info", type="strds", flags="g", input="A")
@@ -181,6 +181,82 @@
self.assertModule(rast_list)
self.assertLooksLike(text, rast_list.outputs.stdout)
+ def test_simple_gran(self):
+ self.assertModule("t.rast.gapfill", input="A",
+ basename="test", nprocs=2, verbose=True)
+
+ #self.assertModule("t.info", type="strds", flags="g", input="A")
+
+ tinfo_string="""start_time=2001-01-01 00:00:00
+ end_time=2002-01-01 00:00:00
+ granularity=1 month
+ map_time=interval
+ number_of_maps=12
+ min_min=100.0
+ min_max=1200.0
+ max_min=100.0
+ max_max=1200.0"""
+
+ info = SimpleModule("t.info", flags="g", type="strds", input="A")
+ self.assertModuleKeyValue(module=info, reference=tinfo_string, precision=2, sep="=")
+
+ text="""name|start_time|end_time|min|max
+a_1|2001-01-01 00:00:00|2001-02-01 00:00:00|100.0|100.0
+test_2001_02|2001-02-01 00:00:00|2001-03-01 00:00:00|200.0|200.0
+test_2001_03|2001-03-01 00:00:00|2001-04-01 00:00:00|300.0|300.0
+a_2|2001-04-01 00:00:00|2001-05-01 00:00:00|400.0|400.0
+test_2001_05|2001-05-01 00:00:00|2001-06-01 00:00:00|500.0|500.0
+test_2001_06|2001-06-01 00:00:00|2001-07-01 00:00:00|600.0|600.0
+test_2001_07|2001-07-01 00:00:00|2001-08-01 00:00:00|700.0|700.0
+test_2001_08|2001-08-01 00:00:00|2001-09-01 00:00:00|800.0|800.0
+test_2001_09|2001-09-01 00:00:00|2001-10-01 00:00:00|900.0|900.0
+test_2001_10|2001-10-01 00:00:00|2001-11-01 00:00:00|1000.0|1000.0
+test_2001_11|2001-11-01 00:00:00|2001-12-01 00:00:00|1100.0|1100.0
+a_3|2001-12-01 00:00:00|2002-01-01 00:00:00|1200.0|1200.0
+
+"""
+ rast_list = SimpleModule("t.rast.list", columns=("name","start_time","end_time","min,max"), input="A")
+ self.assertModule(rast_list)
+ self.assertLooksLike(text, rast_list.outputs.stdout)
+
+ def test_simple_gran(self):
+ self.assertModule("t.rast.gapfill", input="A", suffix="time",
+ basename="test", nprocs=2, verbose=True)
+
+ #self.assertModule("t.info", type="strds", flags="g", input="A")
+
+ tinfo_string="""start_time=2001-01-01 00:00:00
+ end_time=2002-01-01 00:00:00
+ granularity=1 month
+ map_time=interval
+ number_of_maps=12
+ min_min=100.0
+ min_max=1200.0
+ max_min=100.0
+ max_max=1200.0"""
+
+ info = SimpleModule("t.info", flags="g", type="strds", input="A")
+ self.assertModuleKeyValue(module=info, reference=tinfo_string, precision=2, sep="=")
+
+ text="""name|start_time|end_time|min|max
+a_1|2001-01-01 00:00:00|2001-02-01 00:00:00|100.0|100.0
+test_2001_02_01T00_00_00|2001-02-01 00:00:00|2001-03-01 00:00:00|200.0|200.0
+test_2001_03_01T00_00_00|2001-03-01 00:00:00|2001-04-01 00:00:00|300.0|300.0
+a_2|2001-04-01 00:00:00|2001-05-01 00:00:00|400.0|400.0
+test_2001_05_01T00_00_00|2001-05-01 00:00:00|2001-06-01 00:00:00|500.0|500.0
+test_2001_06_01T00_00_00|2001-06-01 00:00:00|2001-07-01 00:00:00|600.0|600.0
+test_2001_07_01T00_00_00|2001-07-01 00:00:00|2001-08-01 00:00:00|700.0|700.0
+test_2001_08_01T00_00_00|2001-08-01 00:00:00|2001-09-01 00:00:00|800.0|800.0
+test_2001_09_01T00_00_00|2001-09-01 00:00:00|2001-10-01 00:00:00|900.0|900.0
+test_2001_10_01T00_00_00|2001-10-01 00:00:00|2001-11-01 00:00:00|1000.0|1000.0
+test_2001_11_01T00_00_00|2001-11-01 00:00:00|2001-12-01 00:00:00|1100.0|1100.0
+a_3|2001-12-01 00:00:00|2002-01-01 00:00:00|1200.0|1200.0
+
+"""
+ rast_list = SimpleModule("t.rast.list", columns=("name","start_time","end_time","min,max"), input="A")
+ self.assertModule(rast_list)
+ self.assertLooksLike(text, rast_list.outputs.stdout)
+
if __name__ == '__main__':
from grass.gunittest.main import test
test()
More information about the grass-commit
mailing list