[GRASS-SVN] r59070 - grass/trunk/lib/python/temporal
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Feb 16 10:05:02 PST 2014
Author: huhabla
Date: 2014-02-16 10:05:02 -0800 (Sun, 16 Feb 2014)
New Revision: 59070
Modified:
grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py
grass/trunk/lib/python/temporal/unittests_temporal_raster_algebra.py
Log:
Included td(strds) into temporal raster algebra
Modified: grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py 2014-02-16 15:29:16 UTC (rev 59069)
+++ grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py 2014-02-16 18:05:02 UTC (rev 59070)
@@ -368,6 +368,12 @@
| expr MULT stds
| stds MULT expr
| expr MULT expr
+ | stds MOD t_td_var
+ | expr MOD t_td_var
+ | stds DIV t_td_var
+ | expr DIV t_td_var
+ | stds MULT t_td_var
+ | expr MULT t_td_var
"""
# Check input stds.
maplistA = self.check_stds(t[1])
@@ -398,8 +404,12 @@
# Generate an intermediate map
name = self.generate_map_name()
+ if "map_value" in dir(map_j) and len(map_j.map_value) > 0 and map_j.map_value[0].get_type() == "timediff":
+ mapbinput = map_j.map_value[0].get_type_value()[0]
+ else:
# Set first input for overlay module.
- mapbinput = map_j.get_id()
+ mapbinput = map_j.get_id()
+
# Create r.mapcalc expression string for the operation.
if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
cmdstring = "(%s %s %s)" %(map_new.cmd_list, t[2], mapbinput)
@@ -424,7 +434,6 @@
for map in resultlist:
print map.cmd_list
-
def p_arith1_operation_numeric1(self, t):
"""
expr : stds MOD number
@@ -501,6 +510,10 @@
| expr SUB stds
| stds SUB expr
| expr SUB expr
+ | stds ADD t_td_var
+ | expr ADD t_td_var
+ | expr SUB t_td_var
+ | stds SUB t_td_var
"""
# Check input stds.
@@ -532,8 +545,12 @@
# Generate an intermediate map
name = self.generate_map_name()
+ if "map_value" in dir(map_j) and len(map_j.map_value) > 0 and map_j.map_value[0].get_type() == "timediff":
+ mapbinput = map_j.map_value[0].get_type_value()[0]
+ else:
# Set first input for overlay module.
- mapbinput = map_j.get_id()
+ mapbinput = map_j.get_id()
+
# Create r.mapcalc expression string for the operation.
if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
cmdstring = "(%s %s %s)" %(map_new.cmd_list, t[2], mapbinput)
@@ -625,6 +642,8 @@
| expr T_ARITH1_OPERATOR stds
| stds T_ARITH1_OPERATOR expr
| expr T_ARITH1_OPERATOR expr
+ | stds T_ARITH1_OPERATOR t_td_var
+ | expr T_ARITH1_OPERATOR t_td_var
"""
# Check input stds.
maplistA = self.check_stds(t[1])
@@ -660,7 +679,13 @@
name = self.generate_map_name()
map_new.set_id(name + "@" + mapset)
# Set second input for overlay module.
- mapbinput = map_j.get_id()
+
+ if "map_value" in dir(map_j) and len(map_j.map_value) > 0 and map_j.map_value[0].get_type() == "timediff":
+ mapbinput = map_j.map_value[0].get_type_value()[0]
+ else:
+ # Set first input for overlay module.
+ mapbinput = map_j.get_id()
+
# Create r.mapcalc expression string for the operation.
if "cmd_list" in dir(map_new):
cmdstring = "(%s %s %s)" %(map_new.cmd_list, function, mapbinput)
@@ -697,6 +722,8 @@
| expr T_ARITH2_OPERATOR stds
| stds T_ARITH2_OPERATOR expr
| expr T_ARITH2_OPERATOR expr
+ | stds T_ARITH2_OPERATOR t_td_var
+ | expr T_ARITH2_OPERATOR t_td_var
"""
# Check input stds.
maplistA = self.check_stds(t[1])
@@ -731,7 +758,13 @@
name = self.generate_map_name()
map_new.set_id(name + "@" + self.mapset)
# Set second input for overlay module.
- mapbinput = map_j.get_id()
+
+ if "map_value" in dir(map_j) and len(map_j.map_value) > 0 and map_j.map_value[0].get_type() == "timediff":
+ mapbinput = map_j.map_value[0].get_type_value()[0]
+ else:
+ # Set first input for overlay module.
+ mapbinput = map_j.get_id()
+
# Create r.mapcalc expression string for the operation.
if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
cmdstring = "(%s %s %s)" %(map_new.cmd_list, function, mapbinput)
Modified: grass/trunk/lib/python/temporal/unittests_temporal_raster_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/unittests_temporal_raster_algebra.py 2014-02-16 15:29:16 UTC (rev 59069)
+++ grass/trunk/lib/python/temporal/unittests_temporal_raster_algebra.py 2014-02-16 18:05:02 UTC (rev 59070)
@@ -50,6 +50,65 @@
tgis.register_maps_in_space_time_dataset(type="rast", name="C", maps="c1",
start="2001-01-02", increment="2 day", interval=True)
+ def test_simple_arith_td_1(self):
+ """Simple arithmetic test with if condition"""
+ tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra.parse(expression='D = A + td(A)', basename="d", overwrite=True)
+
+ D = tgis.open_old_space_time_dataset("D", type="strds")
+ D.select()
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 5)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+
+ def test_simple_arith_td_2(self):
+ """Simple arithmetic test with if condition"""
+ tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra.parse(expression='D = A / td(A)', basename="d", overwrite=True)
+
+ D = tgis.open_old_space_time_dataset("D", type="strds")
+ D.select()
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_simple_arith_td_3(self):
+ """Simple arithmetic test with if condition"""
+ tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra.parse(expression='D = A {equal,+} td(A)', basename="d", overwrite=True)
+
+ D = tgis.open_old_space_time_dataset("D", type="strds")
+ D.select()
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 5)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+
+ def test_simple_arith_td_4(self):
+ """Simple arithmetic test with if condition"""
+ tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra.parse(expression='D = A {equal,/} td(A)', basename="d", overwrite=True)
+
+ D = tgis.open_old_space_time_dataset("D", type="strds")
+ D.select()
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+
def test_simple_arith_if_1(self):
"""Simple arithmetic test with if condition"""
tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
More information about the grass-commit
mailing list