[GRASS-SVN] r69314 - in grass/trunk/lib/python/temporal: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 30 23:56:41 PDT 2016
Author: huhabla
Date: 2016-08-30 23:56:41 -0700 (Tue, 30 Aug 2016)
New Revision: 69314
Modified:
grass/trunk/lib/python/temporal/temporal_algebra.py
grass/trunk/lib/python/temporal/temporal_operator.py
grass/trunk/lib/python/temporal/temporal_raster3d_algebra.py
grass/trunk/lib/python/temporal/temporal_raster_algebra.py
grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py
grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra_mixed_stds.py
grass/trunk/lib/python/temporal/testsuite/unittests_temporal_conditionals.py
grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra.py
grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra_grs.py
Log:
temporal framework: Implementation of a dry-run concept, some code cleanup
Modified: grass/trunk/lib/python/temporal/temporal_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_algebra.py 2016-08-31 06:55:24 UTC (rev 69313)
+++ grass/trunk/lib/python/temporal/temporal_algebra.py 2016-08-31 06:56:41 UTC (rev 69314)
@@ -738,13 +738,13 @@
)
def __init__(self, pid=None, run=True, debug=False, spatial=False,
- null=False, register_null=False, dry_run=False, nprocs=1):
+ register_null=False, dry_run=False, nprocs=1):
self.run = run
self.dry_run = dry_run # Compute the processes and output but Do not start the processes
self.process_chain_dict = {} # This dictionary stores all processes, as well as the maps to register and remove
- self.process_chain_dict["processes"] = [] # process decsription
+ self.process_chain_dict["processes"] = [] # The mapcalc and v.patch module calls
self.process_chain_dict["register"] = [] # Maps that must be registered/updated or inserted in a new STDS
- self.process_chain_dict["remove"] = [] # Maps that must be removed
+ self.process_chain_dict["remove"] = [] # The g.remove module calls
self.process_chain_dict["STDS"] = {} # The STDS that must be created
self.debug = debug
@@ -753,7 +753,6 @@
self.names = {}
# Count map names
self.spatial = spatial
- self.null = null
self.mapset = get_current_mapset()
self.temporaltype = None
self.msgr = get_tgis_message_interface()
@@ -787,7 +786,6 @@
parse the expression, default is TemporalAlgebraLexer
:return: True if successful, False otherwise
-
"""
l = lexer
# Split the expression to ignore the left part
@@ -866,7 +864,7 @@
:param mapclass:
:param basename:
:param overwrite:
- :return: The process chain dictionary
+ :return: The process chain dictionary is dry-run was enabled, None otherwise
"""
self.lexer = TemporalAlgebraLexer()
self.lexer.build()
@@ -881,7 +879,8 @@
self.expression = expression
self.parser.parse(expression)
- return self.process_chain_dict
+ if self.dry_run is True:
+ return self.process_chain_dict
def generate_map_name(self):
"""Generate an unique map name and register it in the objects map list
@@ -1101,8 +1100,11 @@
m.inputs["name"].value = stringlist
m.flags["f"].value = True
# print(m.get_bash())
- m.run()
+ self.process_chain_dict["remove"].append(m.get_dict())
+ if self.dry_run is False:
+ m.run()
+
def check_stds(self, input, clear=False, stds_type=None, check_type=True):
""" Check if input space time dataset exist in database and return its map list.
@@ -1623,8 +1625,8 @@
a8 at B - start: 8 end: 10
"""
- topologylist = ["EQUAL", "FOLLOWS", "PRECEDES", "OVERLAPS", "OVERLAPPED", \
- "DURING", "STARTS", "FINISHES", "CONTAINS", "STARTED", \
+ topologylist = ["EQUAL", "FOLLOWS", "PRECEDES", "OVERLAPS", "OVERLAPPED",
+ "DURING", "STARTS", "FINISHES", "CONTAINS", "STARTED",
"FINISHED"]
for topo in topolist:
@@ -1977,7 +1979,6 @@
for ele in conditionlist:
if ele == '||':
ele_index = conditionlist.index(ele)
- topolist = conditionlist.pop(ele_index -1)
right = conditionlist.pop(ele_index)
left = conditionlist.pop(ele_index - 2)
if any([left, right]):
@@ -1988,7 +1989,6 @@
recurse_compare(conditionlist)
if ele == '&&':
ele_index = conditionlist.index(ele)
- topolist = conditionlist.pop(ele_index -1)
right = conditionlist.pop(ele_index)
left = conditionlist.pop(ele_index - 2)
if all([left, right]):
@@ -1997,6 +1997,7 @@
result = False
conditionlist[ele_index - 2] = result
recurse_compare(conditionlist)
+
resultlist = conditionlist
return(resultlist)
@@ -2283,9 +2284,9 @@
# R = merge(A, B)
"""
expr : MERGE LPAREN stds COMMA stds RPAREN
- | MERGE LPAREN expr COMMA stds RPAREN
- | MERGE LPAREN stds COMMA expr RPAREN
- | MERGE LPAREN expr COMMA expr RPAREN
+ | MERGE LPAREN expr COMMA stds RPAREN
+ | MERGE LPAREN stds COMMA expr RPAREN
+ | MERGE LPAREN expr COMMA expr RPAREN
"""
if self.run:
# Check input map.
@@ -2308,7 +2309,7 @@
typeB = maplistB[0].metadata.get_datatype()
if typeA != typeB:
- grass.fatal(_("Space time datasets to merge must have the same temporal type"))
+ raise FatalError(_("Space time datasets to merge must have the same temporal type"))
resultlist = maplistA + maplistB
@@ -2323,34 +2324,40 @@
def p_t_hash(self,t):
"""
t_hash_var : stds HASH stds
- | expr HASH stds
- | stds HASH expr
- | expr HASH expr
+ | expr HASH stds
+ | stds HASH expr
+ | expr HASH expr
"""
if self.run:
maplistA = self.check_stds(t[1])
maplistB = self.check_stds(t[3])
resultlist = self.get_temporal_topo_list(maplistA, maplistB,
- count_map = True)
+ count_map = True)
t[0] = resultlist
def p_t_hash2(self,t):
"""
t_hash_var : stds T_HASH_OPERATOR stds
- | stds T_HASH_OPERATOR expr
- | expr T_HASH_OPERATOR stds
- | expr T_HASH_OPERATOR expr
+ | stds T_HASH_OPERATOR expr
+ | expr T_HASH_OPERATOR stds
+ | expr T_HASH_OPERATOR expr
"""
if self.run:
maplistA = self.check_stds(t[1])
maplistB = self.check_stds(t[3])
- topolist = self.eval_toperator(t[2], optype = 'hash')[0]
+ topolist = self.eval_toperator(t[2], optype='hash')[0]
resultlist = self.get_temporal_topo_list(maplistA, maplistB, topolist,
count_map = True)
t[0] = resultlist
+ def p_t_hash_paren(self, t):
+ """
+ t_hash_var : LPAREN t_hash_var RPAREN
+ """
+ t[0] = t[2]
+
def p_t_td_var(self, t):
"""
t_td_var : TD LPAREN stds RPAREN
@@ -2361,11 +2368,11 @@
for map_i in maplist:
if map_i.is_time_absolute:
start, end = map_i.get_absolute_time()
- if end != None:
+ if end is not None:
td = time_delta_to_relative_time(end - start)
else:
- start, end, unit = current.get_relative_time()
- if end != None:
+ start, end, unit = map_i.get_relative_time()
+ if end is not None:
td = end - start
if "map_value" in dir(map_i):
gvar = GlobalTemporalVar()
@@ -2424,8 +2431,8 @@
# A # B == 2
# td(A) < 31
"""
- t_var_expr : t_td_var comp_op number
- | t_hash_var comp_op number
+ t_var_expr : t_td_var comp_op number
+ | t_hash_var comp_op number
"""
if self.run:
maplist = self.check_stds(t[1])
@@ -2456,7 +2463,7 @@
# start_day(B) < start_month(A)
"""
t_var_expr : t_var LPAREN stds RPAREN comp_op number
- | t_var LPAREN expr RPAREN comp_op number
+ | t_var LPAREN expr RPAREN comp_op number
"""
# TODO: Implement comparison operator for map lists.
#| t_var LPAREN stds RPAREN comp_op t_var LPAREN stds RPAREN
@@ -2529,11 +2536,12 @@
function = t[2] + t[3]
aggregate = t[2]
# Build conditional values based on topological relationships.
- complist = self.get_temporal_topo_list(tvarexprA, tvarexprB, topolist = relations,
- compare_bool = True, compop = function[0], aggregate = aggregate)
+ complist = self.get_temporal_topo_list(tvarexprA, tvarexprB, topolist=relations,
+ compare_bool=True, compop=function[0],
+ aggregate=aggregate)
# Set temporal extent based on topological relationships.
resultlist = self.set_temporal_extent_list(complist, topolist = relations,
- temporal = temporal)
+ temporal=temporal)
t[0] = resultlist
@@ -2548,13 +2556,13 @@
tvarexprA = t[1]
tvarexprB = t[3]
# Evaluate temporal comparison operator.
- relations, temporal, function, aggregate = self.eval_toperator(t[2], optype = 'boolean')
+ relations, temporal, function, aggregate = self.eval_toperator(t[2], optype='boolean')
# Build conditional values based on topological relationships.
- complist = self.get_temporal_topo_list(tvarexprA, tvarexprB, topolist = relations,
- compare_bool = True, compop = function[0], aggregate = aggregate)
+ complist = self.get_temporal_topo_list(tvarexprA, tvarexprB, topolist=relations,
+ compare_bool=True, compop=function[0], aggregate=aggregate)
# Set temporal extent based on topological relationships.
- resultlist = self.set_temporal_extent_list(complist, topolist = relations,
- temporal = temporal)
+ resultlist = self.set_temporal_extent_list(complist, topolist=relations,
+ temporal=temporal)
t[0] = resultlist
@@ -2583,7 +2591,7 @@
# Return map list.
t[0] = selectlist
else:
- t[0] = t[1] , "*"
+ t[0] = t[1] + "*"
if self.debug:
print(str(t[1]), "* = ", t[1], t[2], t[3])
@@ -2605,7 +2613,7 @@
maplistB = self.check_stds(t[3])
# Perform negative selection.
selectlist = self.perform_temporal_selection(maplistA, maplistB,
- inverse = True)
+ inverse=True)
# Return map list.
t[0] = selectlist
else:
@@ -2614,17 +2622,16 @@
if self.debug:
print(t[1] + "* = ", t[1], t[2], t[3])
-
def p_expr_t_select_operator(self, t):
# Temporal equal selection
# The temporal topology relation equals is implicit
# Examples:
# A {!:} B # Select the part of A that is temporally unequal to B
# A {:} B # Select the part of A that is temporally equal B
- # A {equals, !:} B # Select the part of A that is temporally unequal to B
- # A {during, !:} B # Select the part of A that is temporally not during B
- # A {overlaps, :} B # Select the part of A that temporally overlaps B
- # A {overlaps|equals, :} B # Select the part of A that temporally overlaps or equals B
+ # A {!:, equals} B # Select the part of A that is temporally unequal to B
+ # A {!:, during} B # Select the part of A that is temporally not during B
+ # A {:, overlaps} B # Select the part of A that temporally overlaps B
+ # A {:, overlaps|equals} B # Select the part of A that temporally overlaps or equals B
"""
expr : stds T_SELECT_OPERATOR stds
| expr T_SELECT_OPERATOR stds
@@ -2633,8 +2640,8 @@
"""
if self.run:
# Check input stds.
- maplistA = self.check_stds(t[1])
- maplistB = self.check_stds(t[3])
+ maplistA = self.check_stds(t[1])
+ maplistB = self.check_stds(t[3])
# Evaluate temporal operator.
operators = self.eval_toperator(t[2], optype='select')
# Check for negative selection.
@@ -2647,7 +2654,7 @@
topolist=operators[0],
inverse=negation)
selectlist = self.set_granularity(selectlist, maplistB, operators[1],
- operators[0])
+ operators[0])
# Return map list.
t[0] = selectlist
else:
Modified: grass/trunk/lib/python/temporal/temporal_operator.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_operator.py 2016-08-31 06:55:24 UTC (rev 69313)
+++ grass/trunk/lib/python/temporal/temporal_operator.py 2016-08-31 06:56:41 UTC (rev 69314)
@@ -159,27 +159,27 @@
tokens = tokens + tuple(relations.values())
# Regular expression rules for simple tokens
- t_T_SELECT = r':'
- t_T_NOT_SELECT = r'!:'
- t_COMMA = r','
- t_LEFTREF = '^[l|left]'
- t_RIGHTREF ='^[r|right]'
- t_UNION = '^[u|union]'
- t_DISJOINT = '^[d|disjoint]'
- t_INTERSECT = '^[i|intersect]'
- t_HASH = r'\#'
- t_OR = r'[\|]'
- t_AND = r'[&]'
- t_DISOR = r'\+'
- t_XOR = r'\^'
- t_NOT = r'\~'
- t_MOD = r'[\%]'
- t_DIV = r'[\/]'
- t_MULT = r'[\*]'
- t_ADD = r'[\+]'
- t_SUB = r'[-]'
- t_CLPAREN = r'\{'
- t_CRPAREN = r'\}'
+ t_T_SELECT = r':'
+ t_T_NOT_SELECT = r'!:'
+ t_COMMA = r','
+ t_LEFTREF = '^[l|left]'
+ t_RIGHTREF ='^[r|right]'
+ t_UNION = '^[u|union]'
+ t_DISJOINT = '^[d|disjoint]'
+ t_INTERSECT = '^[i|intersect]'
+ t_HASH = r'\#'
+ t_OR = r'[\|]'
+ t_AND = r'[&]'
+ t_DISOR = r'\+'
+ t_XOR = r'\^'
+ t_NOT = r'\~'
+ t_MOD = r'[\%]'
+ t_DIV = r'[\/]'
+ t_MULT = r'[\*]'
+ t_ADD = r'[\+]'
+ t_SUB = r'[-]'
+ t_CLPAREN = r'\{'
+ t_CRPAREN = r'\}'
# These are the things that should be ignored.
t_ignore = ' \t'
@@ -221,7 +221,7 @@
# Handle errors.
def t_error(self, t):
raise SyntaxError("syntax error on line %d near '%s'" %
- (t.lineno, t.value))
+ (t.lineno, t.value))
# Build the lexer
def build(self,**kwargs):
@@ -246,17 +246,27 @@
self.lexer = TemporalOperatorLexer()
self.lexer.build()
self.parser = yacc.yacc(module=self)
- self.relations = None
- self.temporal = None
- self.function = None
- self.aggregate = None
+ self.relations = None # Temporal relations equals, contain, during, ...
+ self.temporal = None # Temporal operation like intersect, left, right, ...
+ self.function = None # Actual operation
+ self.aggregate = None # Aggregation function
- def parse(self, expression, optype = 'relation'):
+ def parse(self, expression, optype='relation'):
+ """Parse the expression and fill the object variables
+
+ :param expression:
+ :param optype: The parameter optype can be of type:
+ - select { :, during, r}
+ - boolean {&&, contains, |}
+ - raster { *, equal, |}
+ - vector { |, starts, &}
+ - hash { #, during, l}
+ - relation {during}
+ :return:
+ """
self.optype = optype
self.parser.parse(expression)
- # The parameter optype can be of type: select {:, during, r}, boolean{&&, contains, |},
- # raster{*, equal, |}, vector {|, starts, &},
- # hash{#, during, l} or relation {during}.
+ #
# Error rule for syntax errors.
def p_error(self, t):
@@ -266,7 +276,6 @@
tokens = TemporalOperatorLexer.tokens
def p_relation_operator(self, t):
- # The expression should always return a list of maps.
"""
operator : CLPAREN relation CRPAREN
| CLPAREN relationlist CRPAREN
@@ -286,12 +295,11 @@
t[0] = t[2]
def p_relation_bool_operator(self, t):
- # The expression should always return a list of maps.
"""
- operator : CLPAREN OR OR COMMA relation CRPAREN
- | CLPAREN AND AND COMMA relation CRPAREN
- | CLPAREN OR OR COMMA relationlist CRPAREN
- | CLPAREN AND AND COMMA relationlist CRPAREN
+ operator : CLPAREN OR OR COMMA relation CRPAREN
+ | CLPAREN AND AND COMMA relation CRPAREN
+ | CLPAREN OR OR COMMA relationlist CRPAREN
+ | CLPAREN AND AND COMMA relationlist CRPAREN
"""
if not self.optype == 'boolean':
raise SyntaxError("invalid syntax")
@@ -308,16 +316,15 @@
t[0] = t[2]
def p_relation_bool_combi_operator(self, t):
- # The expression should always return a list of maps.
"""
- operator : CLPAREN OR OR COMMA relation COMMA OR CRPAREN
- | CLPAREN OR OR COMMA relation COMMA AND CRPAREN
- | CLPAREN AND AND COMMA relation COMMA OR CRPAREN
- | CLPAREN AND AND COMMA relation COMMA AND CRPAREN
- | CLPAREN OR OR COMMA relationlist COMMA OR CRPAREN
- | CLPAREN OR OR COMMA relationlist COMMA AND CRPAREN
- | CLPAREN AND AND COMMA relationlist COMMA OR CRPAREN
- | CLPAREN AND AND COMMA relationlist COMMA AND CRPAREN
+ operator : CLPAREN OR OR COMMA relation COMMA OR CRPAREN
+ | CLPAREN OR OR COMMA relation COMMA AND CRPAREN
+ | CLPAREN AND AND COMMA relation COMMA OR CRPAREN
+ | CLPAREN AND AND COMMA relation COMMA AND CRPAREN
+ | CLPAREN OR OR COMMA relationlist COMMA OR CRPAREN
+ | CLPAREN OR OR COMMA relationlist COMMA AND CRPAREN
+ | CLPAREN AND AND COMMA relationlist COMMA OR CRPAREN
+ | CLPAREN AND AND COMMA relationlist COMMA AND CRPAREN
"""
if not self.optype == 'boolean':
raise SyntaxError("invalid syntax")
@@ -334,12 +341,11 @@
t[0] = t[2]
def p_relation_bool_combi_operator2(self, t):
- # The expression should always return a list of maps.
"""
- operator : CLPAREN OR OR COMMA relation COMMA temporal CRPAREN
- | CLPAREN AND AND COMMA relation COMMA temporal CRPAREN
- | CLPAREN OR OR COMMA relationlist COMMA temporal CRPAREN
- | CLPAREN AND AND COMMA relationlist COMMA temporal CRPAREN
+ operator : CLPAREN OR OR COMMA relation COMMA temporal CRPAREN
+ | CLPAREN AND AND COMMA relation COMMA temporal CRPAREN
+ | CLPAREN OR OR COMMA relationlist COMMA temporal CRPAREN
+ | CLPAREN AND AND COMMA relationlist COMMA temporal CRPAREN
"""
if not self.optype == 'boolean':
raise SyntaxError("invalid syntax")
@@ -356,16 +362,15 @@
t[0] = t[2]
def p_relation_bool_combi_operator3(self, t):
- # The expression should always return a list of maps.
"""
- operator : CLPAREN OR OR COMMA relation COMMA OR COMMA temporal CRPAREN
- | CLPAREN OR OR COMMA relation COMMA AND COMMA temporal CRPAREN
- | CLPAREN AND AND COMMA relation COMMA OR COMMA temporal CRPAREN
- | CLPAREN AND AND COMMA relation COMMA AND COMMA temporal CRPAREN
- | CLPAREN OR OR COMMA relationlist COMMA OR COMMA temporal CRPAREN
- | CLPAREN OR OR COMMA relationlist COMMA AND COMMA temporal CRPAREN
- | CLPAREN AND AND COMMA relationlist COMMA OR COMMA temporal CRPAREN
- | CLPAREN AND AND COMMA relationlist COMMA AND COMMA temporal CRPAREN
+ operator : CLPAREN OR OR COMMA relation COMMA OR COMMA temporal CRPAREN
+ | CLPAREN OR OR COMMA relation COMMA AND COMMA temporal CRPAREN
+ | CLPAREN AND AND COMMA relation COMMA OR COMMA temporal CRPAREN
+ | CLPAREN AND AND COMMA relation COMMA AND COMMA temporal CRPAREN
+ | CLPAREN OR OR COMMA relationlist COMMA OR COMMA temporal CRPAREN
+ | CLPAREN OR OR COMMA relationlist COMMA AND COMMA temporal CRPAREN
+ | CLPAREN AND AND COMMA relationlist COMMA OR COMMA temporal CRPAREN
+ | CLPAREN AND AND COMMA relationlist COMMA AND COMMA temporal CRPAREN
"""
if not self.optype == 'boolean':
raise SyntaxError("invalid syntax")
@@ -382,13 +387,12 @@
t[0] = t[2]
def p_select_relation_operator(self, t):
- # The expression should always return a list of maps.
"""
operator : CLPAREN select CRPAREN
- | CLPAREN select COMMA relation CRPAREN
- | CLPAREN select COMMA relationlist CRPAREN
- | CLPAREN select COMMA relation COMMA temporal CRPAREN
- | CLPAREN select COMMA relationlist COMMA temporal CRPAREN
+ | CLPAREN select COMMA relation CRPAREN
+ | CLPAREN select COMMA relationlist CRPAREN
+ | CLPAREN select COMMA relation COMMA temporal CRPAREN
+ | CLPAREN select COMMA relationlist COMMA temporal CRPAREN
"""
if not self.optype == 'select':
raise SyntaxError("invalid syntax")
@@ -398,10 +402,6 @@
self.relations = ['equal']
self.temporal = "l"
self.function = t[2]
- elif len(t) == 5:
- self.relations = ['equal']
- self.temporal = t[3]
- self.function = t[2]
elif len(t) == 6:
if isinstance(t[4], list):
self.relations = t[4]
@@ -419,13 +419,12 @@
t[0] = t[2]
def p_hash_relation_operator(self, t):
- # The expression should always return a list of maps.
"""
operator : CLPAREN HASH CRPAREN
- | CLPAREN HASH COMMA relation CRPAREN
- | CLPAREN HASH COMMA relationlist CRPAREN
- | CLPAREN HASH COMMA relation COMMA temporal CRPAREN
- | CLPAREN HASH COMMA relationlist COMMA temporal CRPAREN
+ | CLPAREN HASH COMMA relation CRPAREN
+ | CLPAREN HASH COMMA relationlist CRPAREN
+ | CLPAREN HASH COMMA relation COMMA temporal CRPAREN
+ | CLPAREN HASH COMMA relationlist COMMA temporal CRPAREN
"""
if not self.optype == 'hash':
raise SyntaxError("invalid syntax")
@@ -435,10 +434,6 @@
self.relations = ['equal']
self.temporal = "l"
self.function = t[2]
- elif len(t) == 5:
- self.relations = ['equal']
- self.temporal = t[3]
- self.function = t[2]
elif len(t) == 6:
if isinstance(t[4], list):
self.relations = t[4]
@@ -459,10 +454,10 @@
# The expression should always return a list of maps.
"""
operator : CLPAREN arithmetic CRPAREN
- | CLPAREN arithmetic COMMA relation CRPAREN
- | CLPAREN arithmetic COMMA relationlist CRPAREN
- | CLPAREN arithmetic COMMA relation COMMA temporal CRPAREN
- | CLPAREN arithmetic COMMA relationlist COMMA temporal CRPAREN
+ | CLPAREN arithmetic COMMA relation CRPAREN
+ | CLPAREN arithmetic COMMA relationlist CRPAREN
+ | CLPAREN arithmetic COMMA relation COMMA temporal CRPAREN
+ | CLPAREN arithmetic COMMA relationlist COMMA temporal CRPAREN
"""
if not self.optype == 'raster':
raise SyntaxError("invalid syntax")
@@ -472,10 +467,6 @@
self.relations = ['equal']
self.temporal = "l"
self.function = t[2]
- elif len(t) == 5:
- self.relations = ['equal']
- self.temporal = t[3]
- self.function = t[2]
elif len(t) == 6:
if isinstance(t[4], list):
self.relations = t[4]
@@ -496,10 +487,10 @@
# The expression should always return a list of maps.
"""
operator : CLPAREN overlay CRPAREN
- | CLPAREN overlay COMMA relation CRPAREN
- | CLPAREN overlay COMMA relationlist CRPAREN
- | CLPAREN overlay COMMA relation COMMA temporal CRPAREN
- | CLPAREN overlay COMMA relationlist COMMA temporal CRPAREN
+ | CLPAREN overlay COMMA relation CRPAREN
+ | CLPAREN overlay COMMA relationlist CRPAREN
+ | CLPAREN overlay COMMA relation COMMA temporal CRPAREN
+ | CLPAREN overlay COMMA relationlist COMMA temporal CRPAREN
"""
if not self.optype == 'overlay':
raise SyntaxError("invalid syntax")
@@ -509,10 +500,6 @@
self.relations = ['equal']
self.temporal = "l"
self.function = t[2]
- elif len(t) == 5:
- self.relations = ['equal']
- self.temporal = t[3]
- self.function = t[2]
elif len(t) == 6:
if isinstance(t[4], list):
self.relations = t[4]
@@ -572,10 +559,10 @@
# The list of relations.
"""
temporal : LEFTREF
- | RIGHTREF
- | UNION
- | DISJOINT
- | INTERSECT
+ | RIGHTREF
+ | UNION
+ | DISJOINT
+ | INTERSECT
"""
t[0] = t[1]
@@ -602,10 +589,10 @@
# The list of relations.
"""
overlay : AND
- | OR
- | XOR
- | DISOR
- | NOT
+ | OR
+ | XOR
+ | DISOR
+ | NOT
"""
t[0] = t[1]
###############################################################################
Modified: grass/trunk/lib/python/temporal/temporal_raster3d_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_raster3d_algebra.py 2016-08-31 06:55:24 UTC (rev 69313)
+++ grass/trunk/lib/python/temporal/temporal_raster3d_algebra.py 2016-08-31 06:56:41 UTC (rev 69314)
@@ -17,9 +17,13 @@
class TemporalRaster3DAlgebraParser(TemporalRasterBaseAlgebraParser):
"""The temporal raster algebra class"""
- def __init__(self, pid=None, run=False, debug=True, spatial = False, nprocs = 1, register_null = False):
- TemporalRasterBaseAlgebraParser.__init__(self, pid, run, debug, spatial, nprocs, register_null)
+ def __init__(self, pid=None, run=False, debug=True, spatial=False,
+ register_null=False, dry_run=False, nprocs=1):
+ TemporalRasterBaseAlgebraParser.__init__(self, pid=pid, run=run, debug=debug,
+ spatial=spatial, register_null=register_null,
+ dry_run=dry_run, nprocs=nprocs)
+
self.m_mapcalc = pymod.Module('r3.mapcalc')
self.m_mremove = pymod.Module('g.remove')
Modified: grass/trunk/lib/python/temporal/temporal_raster_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_raster_algebra.py 2016-08-31 06:55:24 UTC (rev 69313)
+++ grass/trunk/lib/python/temporal/temporal_raster_algebra.py 2016-08-31 06:56:41 UTC (rev 69314)
@@ -59,9 +59,13 @@
class TemporalRasterAlgebraParser(TemporalRasterBaseAlgebraParser):
"""The temporal raster algebra class"""
- def __init__(self, pid=None, run=False, debug=True, spatial = False, nprocs = 1, register_null = False):
- TemporalRasterBaseAlgebraParser.__init__(self, pid, run, debug, spatial, nprocs, register_null)
+ def __init__(self, pid=None, run=False, debug=True, spatial=False,
+ register_null=False, dry_run=False, nprocs=1):
+ TemporalRasterBaseAlgebraParser.__init__(self, pid=pid, run=run, debug=debug,
+ spatial=spatial, register_null=register_null,
+ dry_run=dry_run, nprocs=nprocs)
+
self.m_mapcalc = pymod.Module('r.mapcalc')
self.m_mremove = pymod.Module('g.remove')
@@ -91,6 +95,9 @@
self.expression = expression
self.parser.parse(expression)
+ if self.dry_run is True:
+ return self.process_chain_dict
+
######################### Temporal functions ##############################
def p_statement_assign(self, t):
@@ -101,6 +108,7 @@
TemporalRasterBaseAlgebraParser.p_statement_assign(self, t)
def p_ts_neighbour_operation(self, t):
+ # Spatial and temporal neighbour operations via indexing
# Examples:
# A[1,0]
# B[-2]
Modified: grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py 2016-08-31 06:55:24 UTC (rev 69313)
+++ grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py 2016-08-31 06:56:41 UTC (rev 69314)
@@ -138,12 +138,15 @@
('left', 'AND', 'OR', 'T_COMP_OPERATOR', 'MOD', 'DIV', 'MULT',
'T_ARITH1_OPERATOR'))
- def __init__(self, pid=None, run = True, debug = False, spatial = False, \
- nprocs = 1, register_null = False):
- TemporalAlgebraParser.__init__(self, pid, run, debug, spatial)
- self.nprocs = nprocs
- self.register_null = register_null
+ def __init__(self, pid=None, run=True,
+ debug=False, spatial=False,
+ register_null=False,
+ dry_run=False, nprocs=1):
+ TemporalAlgebraParser.__init__(self, pid=pid, run=run, debug=debug,
+ spatial=spatial, register_null=register_null,
+ dry_run=dry_run, nprocs=nprocs)
+
def check_null(self, t):
try:
int(t)
@@ -152,10 +155,10 @@
return "null()"
######################### Temporal functions ##############################
- def get_temporal_topo_list(self, maplistA, maplistB = None, topolist = ["EQUAL"],
- assign_val = False, count_map = False, compare_bool = False,
- compare_cmd = False, compop = None, aggregate = None,
- new = False, convert = False, operator_cmd = False):
+ def get_temporal_topo_list(self, maplistA, maplistB=None, topolist=["EQUAL"],
+ assign_val=False, count_map=False, compare_bool=False,
+ compare_cmd=False, compop=None, aggregate=None,
+ new=False, convert=False, operator_cmd=False):
"""Build temporal topology for two space time data sets, copy map objects
for given relation into map list.
@@ -182,8 +185,8 @@
:return: List of maps from maplistA that fulfil the topological relationships
to maplistB specified in topolist.
"""
- topologylist = ["EQUAL", "FOLLOWS", "PRECEDES", "OVERLAPS", "OVERLAPPED", \
- "DURING", "STARTS", "FINISHES", "CONTAINS", "STARTED", \
+ topologylist = ["EQUAL", "FOLLOWS", "PRECEDES", "OVERLAPS", "OVERLAPPED",
+ "DURING", "STARTS", "FINISHES", "CONTAINS", "STARTED",
"FINISHED"]
complementdict = {"EQUAL": "EQUAL", "FOLLOWS" : "PRECEDES",
"PRECEDES" : "FOLLOWS", "OVERLAPS" : "OVERLAPPED",
@@ -284,7 +287,7 @@
leftsub = sub_cmdstring(map_i)
rightsub = sub_cmdstring(relmap)
if operator == None:
- self.msgr.fatal("Error: Can't build command string for map %s, operator is missing" \
+ self.msgr.fatal("Error: Can't build command string for map %s, operator is missing"
%(map_i.get_map_id()))
cmdstring = "(%s %s %s)" %(leftsub, operator, rightsub)
return(cmdstring)
@@ -360,17 +363,17 @@
for relationmap in relationmaplist:
# Create r.mapcalc expression string for the operation.
cmdstring = self.build_command_string(leftcmd,
- relationmap,
- operator = operator,
- cmd_type = "operator")
+ relationmap,
+ operator=operator,
+ cmd_type="operator")
leftcmd = cmdstring
# Add command list to result map.
map_i.cmd_list = cmdstring
return(cmdstring)
- def set_temporal_extent_list(self, maplist, topolist = ["EQUAL"], temporal = 'l' ,
- cmd_bool = False, cmd_type = None, operator = None):
+ def set_temporal_extent_list(self, maplist, topolist=["EQUAL"], temporal='l' ,
+ cmd_bool=False, cmd_type=None, operator=None):
""" Change temporal extent of map list based on temporal relations to
other map list and given temporal operator.
@@ -393,8 +396,8 @@
# Loop over temporal related maps and create overlay modules.
tbrelations = map_i.get_temporal_relations()
# Generate an intermediate map for the result map list.
- map_new = self.generate_new_map(base_map=map_i, bool_op = 'and',
- copy = True, rename = True)
+ map_new = self.generate_new_map(base_map=map_i, bool_op='and',
+ copy=True, rename=True)
# Combine temporal and spatial extents of intermediate map with related maps.
for topo in topolist:
@@ -402,11 +405,11 @@
for map_j in (tbrelations[topo]):
if temporal == 'r':
# Generate an intermediate map for the result map list.
- map_new = self.generate_new_map(base_map=map_i, bool_op = 'and',
- copy = True, rename = True)
+ map_new = self.generate_new_map(base_map=map_i, bool_op='and',
+ copy=True, rename=True)
# Create overlayed map extent.
- returncode = self.overlay_map_extent(map_new, map_j, 'and', \
- temp_op = temporal)
+ returncode = self.overlay_map_extent(map_new, map_j, 'and',
+ temp_op = temporal)
# Stop the loop if no temporal or spatial relationship exist.
if returncode == 0:
@@ -418,9 +421,9 @@
if cmd_bool:
# Create r.mapcalc expression string for the operation.
cmdstring = self.build_command_string(map_i,
- map_j,
- operator = operator,
- cmd_type = cmd_type)
+ map_j,
+ operator=operator,
+ cmd_type=cmd_type)
# Conditional append of module command.
map_new.cmd_list = cmdstring
# Write map object to result dictionary.
@@ -436,10 +439,10 @@
return(resultlist)
- def build_condition_cmd_list(self, iflist, thenlist, elselist = None,
- condition_topolist = ["EQUAL"],
- conclusion_topolist = ["EQUAL"],
- temporal = 'l', null = False):
+ def build_condition_cmd_list(self, iflist, thenlist, elselist=None,
+ condition_topolist=["EQUAL"],
+ conclusion_topolist=["EQUAL"],
+ temporal='l', null=False):
"""This function build the r.mapcalc command strings for spatial conditionals.
For Example: 'if(a1 == 1, b1, c2)'
@@ -464,10 +467,10 @@
# Build conclusion command map list.
conclusiontopolist = self.get_temporal_topo_list(thenlist, elselist, conclusion_topolist)
conclusionlist = self.set_temporal_extent_list(conclusiontopolist,
- topolist = conclusion_topolist,
- temporal = temporal ,
- cmd_bool = True,
- cmd_type = "conclusion")
+ topolist = conclusion_topolist,
+ temporal = temporal ,
+ cmd_bool = True,
+ cmd_type = "conclusion")
# Check if any conclusion is a numeric statements.
elif any([isinstance(thenlist, str), isinstance(elselist, str)]):
conclusionlist = []
@@ -477,9 +480,9 @@
numinput = elselist
for map_i in listinput:
# Create r.mapcalc expression string for the operation.
- cmdstring = self.build_command_string( map_i,
- numinput,
- cmd_type = 'conclusion')
+ cmdstring = self.build_command_string(map_i,
+ numinput,
+ cmd_type = 'conclusion')
# Conditional append of module command.
map_i.cmd_list = cmdstring
# Append map to result map list.
@@ -491,8 +494,8 @@
for map_i in listinput:
# Create r.mapcalc expression string for the operation.
cmdstring = self.build_command_string(numinput,
- map_i,
- cmd_type = 'conclusion')
+ map_i,
+ cmd_type = 'conclusion')
# Conditional append of module command.
map_i.cmd_list = cmdstring
# Append map to result map list.
@@ -509,8 +512,8 @@
for map_i in iflist:
# Create r.mapcalc expression string for the operation.
cmdstring = self.build_command_string(map_i,
- conclusionlist,
- cmd_type = 'condition')
+ conclusionlist,
+ cmd_type = 'condition')
# Conditional append of module command.
map_i.cmd_list = cmdstring
# Append map to result map list.
@@ -519,12 +522,12 @@
elif isinstance(conclusionlist, list):
# Build result command map list between conditions and conclusions.
conditiontopolist = self.get_temporal_topo_list(iflist, conclusionlist,
- topolist = condition_topolist)
+ topolist=condition_topolist)
resultlist = self.set_temporal_extent_list(conditiontopolist,
- topolist = condition_topolist,
- temporal = 'r' ,
- cmd_bool = True,
- cmd_type = "condition")
+ topolist=condition_topolist,
+ temporal='r',
+ cmd_bool=True,
+ cmd_type="condition")
return(resultlist)
###########################################################################
@@ -543,7 +546,6 @@
if isinstance(t[3], list):
num = len(t[3])
count = 0
- returncode = 0
register_list = []
for i in range(num):
# Check if resultmap names exist in GRASS database.
@@ -572,12 +574,14 @@
m_expression = newident + "=" + map_i.cmd_list
m.inputs["expression"].value = str(m_expression)
m.flags["overwrite"].value = self.overwrite
+ #print(m.get_bash())
+ self.process_chain_dict["processes"].append(m.get_dict())
if self.dry_run is False:
process_queue.put(m)
elif map_i.map_exists():
- # Copy map if it exists
+ # Copy map if it exists b = a
map_test = map_i.get_new_instance(newident + "@" + self.mapset)
map_test.set_temporal_extent(map_i.get_temporal_extent())
map_test.set_spatial_extent(map_i.get_spatial_extent())
@@ -588,12 +592,16 @@
m.inputs["expression"].value = str(m_expression)
m.flags["overwrite"].value = self.overwrite
+ #print(m.get_bash())
+
+ self.process_chain_dict["processes"].append(m.get_dict())
+
if self.dry_run is False:
process_queue.put(m)
else:
self.msgr.error(_("Error computing map <%s>"%map_i.get_id()))
- count += 1
+ count += 1
if self.dry_run is False:
process_queue.wait()
@@ -603,29 +611,35 @@
# Open connection to temporal database.
dbif, connect = init_dbif(self.dbif)
+
# Create result space time dataset.
-
if self.dry_run is False:
resultstds = open_new_stds(t[1], self.stdstype,
'absolute', t[1], t[1],
'mean', self.dbif,
overwrite = self.overwrite)
for map_i in register_list:
- # Get meta data from grass database.
- map_i.load()
- # Do not register empty maps if not required
- # In case of a null map continue, do not register null maps
- if map_i.metadata.get_min() is None and \
- map_i.metadata.get_max() is None:
- if not self.register_null:
- self.removable_maps[map_i.get_name()] = map_i
- continue
+ # Put the map into the process dictionary
+ start, end = map_i.get_temporal_extent_as_tuple()
+ self.process_chain_dict["register"].append((map_i.get_name(), str(start), str(end)))
+
+ if self.dry_run is False:
+ # Get meta data from grass database.
+ map_i.load()
+ # Do not register empty maps if not required
+ # In case of a null map continue, do not register null maps
+ if map_i.metadata.get_min() is None and \
+ map_i.metadata.get_max() is None:
+ if not self.register_null:
+ self.removable_maps[map_i.get_name()] = map_i
+ continue
+
if map_i.is_in_db(dbif) and self.overwrite:
# Update map in temporal database.
if self.dry_run is False:
map_i.update_all(dbif)
- elif map_i.is_in_db(dbif) and self.overwrite == False:
+ elif map_i.is_in_db(dbif) and self.overwrite is False:
# Raise error if map exists and no overwrite flag is given.
self.msgr.fatal("Error raster map %s exist in temporal database. "
"Use overwrite flag."%map_i.get_map_id())
@@ -639,6 +653,10 @@
if self.dry_run is False:
resultstds.update_from_registered_maps(dbif)
+ self.process_chain_dict["STDS"]["name"] = t[1]
+ self.process_chain_dict["STDS"]["stdstype"] = self.stdstype
+ self.process_chain_dict["STDS"]["temporal_type"] = 'absolute'
+
dbif.close()
t[0] = register_list
# Remove intermediate maps
@@ -713,14 +731,14 @@
resultlist = []
for map_i in topolist:
# Generate an intermediate map for the result map list.
- map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
+ map_new = self.generate_new_map(base_map=map_i, bool_op='and', copy=True)
# Loop over temporal related maps and create overlay modules.
tbrelations = map_i.get_temporal_relations()
count = 0
for map_j in (tbrelations['EQUAL']):
# Create overlayed map extent.
returncode = self.overlay_map_extent(map_new, map_j, 'and', \
- temp_op = 'l')
+ temp_op='l')
# Stop the loop if no temporal or spatial relationship exist.
if returncode == 0:
break
@@ -733,8 +751,8 @@
# Create r.mapcalc expression string for the operation.
cmdstring = self.build_command_string(map_i, map_j,
- operator = t[2],
- cmd_type = "operator")
+ operator=t[2],
+ cmd_type="operator")
# Conditional append of module command.
map_new.cmd_list = cmdstring
count += 1
@@ -751,23 +769,23 @@
def p_arith1_operation_numeric1(self, t):
"""
expr : stds MOD number
- | expr MOD number
- | stds DIV number
- | expr DIV number
- | stds MULT number
- | expr MULT number
- | stds MOD numberstr
- | expr MOD numberstr
- | stds DIV numberstr
- | expr DIV numberstr
- | stds MULT numberstr
- | expr MULT numberstr
- | stds MOD mapexpr
- | expr MOD mapexpr
- | stds DIV mapexpr
- | expr DIV mapexpr
- | stds MULT mapexpr
- | expr MULT mapexpr
+ | expr MOD number
+ | stds DIV number
+ | expr DIV number
+ | stds MULT number
+ | expr MULT number
+ | stds MOD numberstr
+ | expr MOD numberstr
+ | stds DIV numberstr
+ | expr DIV numberstr
+ | stds MULT numberstr
+ | expr MULT numberstr
+ | stds MOD mapexpr
+ | expr MOD mapexpr
+ | stds DIV mapexpr
+ | expr DIV mapexpr
+ | stds MULT mapexpr
+ | expr MULT mapexpr
"""
# Check input stds.
maplist = self.check_stds(t[1])
@@ -796,23 +814,23 @@
def p_arith1_operation_numeric2(self, t):
"""
expr : number MOD stds
- | number MOD expr
- | number DIV stds
- | number DIV expr
- | number MULT stds
- | number MULT expr
- | numberstr MOD stds
- | numberstr MOD expr
- | numberstr DIV stds
- | numberstr DIV expr
- | numberstr MULT stds
- | numberstr MULT expr
- | mapexpr MOD stds
- | mapexpr MOD expr
- | mapexpr DIV stds
- | mapexpr DIV expr
- | mapexpr MULT stds
- | mapexpr MULT expr
+ | number MOD expr
+ | number DIV stds
+ | number DIV expr
+ | number MULT stds
+ | number MULT expr
+ | numberstr MOD stds
+ | numberstr MOD expr
+ | numberstr DIV stds
+ | numberstr DIV expr
+ | numberstr MULT stds
+ | numberstr MULT expr
+ | mapexpr MOD stds
+ | mapexpr MOD expr
+ | mapexpr DIV stds
+ | mapexpr DIV expr
+ | mapexpr MULT stds
+ | mapexpr MULT expr
"""
# Check input stds.
maplist = self.check_stds(t[3])
@@ -863,15 +881,15 @@
resultlist = []
for map_i in topolist:
# Generate an intermediate map for the result map list.
- map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
+ map_new = self.generate_new_map(base_map=map_i, bool_op='and', copy=True)
# Loop over temporal related maps and create overlay modules.
tbrelations = map_i.get_temporal_relations()
count = 0
for map_j in (tbrelations['EQUAL']):
# Create overlayed map extent.
- returncode = self.overlay_map_extent(map_new, map_j, 'and', \
- temp_op = 'l')
+ returncode = self.overlay_map_extent(map_new, map_j, 'and',
+ temp_op='l')
# Stop the loop if no temporal or spatial relationship exist.
if returncode == 0:
break
@@ -884,8 +902,8 @@
# Create r.mapcalc expression string for the operation.
cmdstring = self.build_command_string(map_i, map_j,
- operator = t[2],
- cmd_type = "operator")
+ operator=t[2],
+ cmd_type="operator")
# Conditional append of module command.
map_new.cmd_list = cmdstring
count += 1
@@ -903,17 +921,17 @@
def p_arith2_operation_numeric1(self, t):
"""
expr : stds ADD number
- | expr ADD number
- | stds SUB number
- | expr SUB number
- | stds ADD numberstr
- | expr ADD numberstr
- | stds SUB numberstr
- | expr SUB numberstr
- | stds ADD mapexpr
- | expr ADD mapexpr
- | stds SUB mapexpr
- | expr SUB mapexpr
+ | expr ADD number
+ | stds SUB number
+ | expr SUB number
+ | stds ADD numberstr
+ | expr ADD numberstr
+ | stds SUB numberstr
+ | expr SUB numberstr
+ | stds ADD mapexpr
+ | expr ADD mapexpr
+ | stds SUB mapexpr
+ | expr SUB mapexpr
"""
# Check input stds.
maplist = self.check_stds(t[1])
@@ -941,17 +959,17 @@
def p_arith2_operation_numeric2(self, t):
"""
expr : number ADD stds
- | number ADD expr
- | number SUB stds
- | number SUB expr
- | numberstr ADD stds
- | numberstr ADD expr
- | numberstr SUB stds
- | numberstr SUB expr
- | mapexpr ADD stds
- | mapexpr ADD expr
- | mapexpr SUB stds
- | mapexpr SUB expr
+ | number ADD expr
+ | number SUB stds
+ | number SUB expr
+ | numberstr ADD stds
+ | numberstr ADD expr
+ | numberstr SUB stds
+ | numberstr SUB expr
+ | mapexpr ADD stds
+ | mapexpr ADD expr
+ | mapexpr SUB stds
+ | mapexpr SUB expr
"""
# Check input stds.
maplist = self.check_stds(t[3])
@@ -989,13 +1007,13 @@
# Check input stds.
maplistA = self.check_stds(t[1])
maplistB = self.check_stds(t[3])
- relations, temporal, function, aggregate = self.eval_toperator(t[2], optype = 'raster')
+ relations, temporal, function, aggregate = self.eval_toperator(t[2], optype='raster')
# Build conditional values based on topological relationships.
- complist = self.get_temporal_topo_list(maplistA, maplistB, topolist = relations,
- operator_cmd = True, compop = function)
+ complist = self.get_temporal_topo_list(maplistA, maplistB, topolist=relations,
+ operator_cmd=True, compop=function)
# Set temporal extent based on topological relationships.
- resultlist = self.set_temporal_extent_list(complist, topolist = relations,
- temporal = temporal)
+ resultlist = self.set_temporal_extent_list(complist, topolist=relations,
+ temporal=temporal)
t[0] = resultlist
@@ -1018,11 +1036,11 @@
maplistB = self.check_stds(t[3])
relations, temporal, function, aggregate = self.eval_toperator(t[2], optype = 'raster')
# Build conditional values based on topological relationships.
- complist = self.get_temporal_topo_list(maplistA, maplistB, topolist = relations,
- operator_cmd = True, compop = function)
+ complist = self.get_temporal_topo_list(maplistA, maplistB, topolist=relations,
+ operator_cmd=True, compop=function)
# Set temporal extent based on topological relationships.
- resultlist = self.set_temporal_extent_list(complist, topolist = relations,
- temporal = temporal)
+ resultlist = self.set_temporal_extent_list(complist, topolist=relations,
+ temporal=temporal)
t[0] = resultlist
@@ -1033,10 +1051,10 @@
def p_arith_operation_numeric_string(self, t):
"""
numberstr : number ADD number
- | number SUB number
- | number DIV number
- | number MULT number
- | number MOD number
+ | number SUB number
+ | number DIV number
+ | number MULT number
+ | number MOD number
"""
numstring = "(%s %s %s)" %(t[1], t[2], t[3])
@@ -1064,8 +1082,7 @@
t[0] = t[1]
if self.debug:
- for map in resultlist:
- print(map.cmd_list)
+ print(t[1])
def p_mapcalc_operation1(self, t):
@@ -1248,8 +1265,9 @@
function = t[2] + t[3]
aggregate = t[2]
# Build conditional values based on topological relationships.
- complist = self.get_temporal_topo_list(s_var_exprA, s_var_exprB, topolist = relations,
- compare_cmd = True, compop = function, aggregate = aggregate)
+ complist = self.get_temporal_topo_list(s_var_exprA, s_var_exprB, topolist=relations,
+ compare_cmd=True, compop=function,
+ aggregate=aggregate)
# Set temporal extent based on topological relationships.
resultlist = self.set_temporal_extent_list(complist, topolist = relations,
temporal = temporal)
@@ -1272,13 +1290,14 @@
s_var_exprA = self.check_stds(t[1])
s_var_exprB = self.check_stds(t[3])
# Evaluate temporal comparison operator.
- relations, temporal, function, aggregate = self.eval_toperator(t[2], optype = 'boolean')
+ relations, temporal, function, aggregate = self.eval_toperator(t[2], optype='boolean')
# Build conditional values based on topological relationships.
- complist = self.get_temporal_topo_list(s_var_exprA, s_var_exprB, topolist = relations,
- compare_cmd = True, compop = function, aggregate = aggregate)
+ complist = self.get_temporal_topo_list(s_var_exprA, s_var_exprB, topolist=relations,
+ compare_cmd=True, compop=function,
+ aggregate=aggregate)
# Set temporal extent based on topological relationships.
- resultlist = self.set_temporal_extent_list(complist, topolist = relations,
- temporal = temporal)
+ resultlist = self.set_temporal_extent_list(complist, topolist=relations,
+ temporal=temporal)
t[0] = resultlist
@@ -1299,10 +1318,10 @@
ifmaplist = self.check_stds(t[3])
thenmaplist = self.check_stds(t[5])
resultlist = self.build_condition_cmd_list(ifmaplist, thenmaplist,
- elselist = None,
- condition_topolist = ["EQUAL"],
- conclusion_topolist = ["EQUAL"],
- temporal = 'r', null = False)
+ elselist=None,
+ condition_topolist=["EQUAL"],
+ conclusion_topolist=["EQUAL"],
+ temporal='r', null=False)
t[0] = resultlist
if self.debug:
@@ -1355,10 +1374,10 @@
ifmaplist = self.check_stds(t[5])
thenmaplist = self.check_stds(t[7])
resultlist = self.build_condition_cmd_list(ifmaplist, thenmaplist,
- elselist = None,
- condition_topolist = relations,
- conclusion_topolist = ["EQUAL"],
- temporal = 'r', null = False)
+ elselist=None,
+ condition_topolist=relations,
+ conclusion_topolist=["EQUAL"],
+ temporal='r', null=False)
t[0] = resultlist
if self.debug:
@@ -1384,10 +1403,10 @@
elsemaplist = self.check_stds(t[7])
# Create conditional command map list.
resultlist = self.build_condition_cmd_list(ifmaplist, thenmaplist,
- elselist = elsemaplist,
- condition_topolist = ["EQUAL"],
- conclusion_topolist = ["EQUAL"],
- temporal = 'r', null = False)
+ elselist=elsemaplist,
+ condition_topolist=["EQUAL"],
+ conclusion_topolist=["EQUAL"],
+ temporal='r', null=False)
t[0] = resultlist
@@ -1429,9 +1448,9 @@
print(numthen + " " +numelse )
# Create conditional command map list.
resultlist = self.build_condition_cmd_list(ifmaplist, numthen, numelse,
- condition_topolist = ["EQUAL"],
- conclusion_topolist = ["EQUAL"],
- temporal = 'r', null = False)
+ condition_topolist=["EQUAL"],
+ conclusion_topolist=["EQUAL"],
+ temporal='r', null=False)
t[0] = resultlist
@@ -1480,9 +1499,9 @@
# Create conditional command map list.
resultlist = self.build_condition_cmd_list(ifmaplist, theninput, elseinput,
- condition_topolist = ["EQUAL"],
- conclusion_topolist = ["EQUAL"],
- temporal = 'r', null = False)
+ condition_topolist=["EQUAL"],
+ conclusion_topolist=["EQUAL"],
+ temporal='r', null=False)
t[0] = resultlist
@@ -1532,9 +1551,9 @@
# Create conditional command map list.
resultlist = self.build_condition_cmd_list(ifmaplist, theninput, elseinput,
- condition_topolist = relations,
- conclusion_topolist = ["EQUAL"],
- temporal = 'r', null = False)
+ condition_topolist=relations,
+ conclusion_topolist=["EQUAL"],
+ temporal='r', null=False)
t[0] = resultlist
@@ -1563,9 +1582,9 @@
# Create conditional command map list.
resultlist = self.build_condition_cmd_list(ifmaplist, thenmaplist, elsemaplist,
- condition_topolist = relations,
- conclusion_topolist = ["EQUAL"],
- temporal = 'r', null = False)
+ condition_topolist=relations,
+ conclusion_topolist=["EQUAL"],
+ temporal='r', null=False)
t[0] = resultlist
@@ -1604,12 +1623,12 @@
aggregate = t[2]
# Build conditional values based on topological relationships.
complist = self.get_temporal_topo_list(s_var_exprA, s_var_exprB,
- topolist = relations, compare_cmd = True,
- compop = function, aggregate = aggregate,
- convert = True)
+ topolist=relations, compare_cmd=True,
+ compop=function, aggregate=aggregate,
+ convert=True)
# Set temporal extent based on topological relationships.
- resultlist = self.set_temporal_extent_list(complist, topolist = relations,
- temporal = temporal)
+ resultlist = self.set_temporal_extent_list(complist, topolist=relations,
+ temporal=temporal)
t[0] = resultlist
Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra_mixed_stds.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra_mixed_stds.py 2016-08-31 06:55:24 UTC (rev 69313)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra_mixed_stds.py 2016-08-31 06:56:41 UTC (rev 69314)
@@ -31,26 +31,24 @@
cls.runModule("r3.mapcalc", overwrite=True, quiet=True, expression="a4 = 4")
tgis.open_new_stds(name="A", type="str3ds", temporaltype="absolute",
- title="A", descr="A", semantic="field", overwrite=True)
+ title="A", descr="A", semantic="field", overwrite=True)
tgis.register_maps_in_space_time_dataset(type="raster3d", name="A", maps="a1,a2,a3,a4",
start="2001-01-01", increment="1 day", interval=True)
-
cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="b1 = 5")
cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="b2 = 6")
tgis.open_new_stds(name="B", type="strds", temporaltype="absolute",
- title="B", descr="B", semantic="field", overwrite=True)
+ title="B", descr="B", semantic="field", overwrite=True)
tgis.register_maps_in_space_time_dataset(type="raster", name="B", maps="b1,b2",
start="2001-01-01", increment="2 day", interval=True)
-
cls.runModule("v.random", overwrite=True, quiet=True, npoints=20, seed=3, output='c1')
tgis.open_new_stds(name="C", type="stvds", temporaltype="absolute",
- title="B", descr="C", semantic="field", overwrite=True)
+ title="B", descr="C", semantic="field", overwrite=True)
tgis.register_maps_in_space_time_dataset(type="vector", name="C", maps="c1",
start="2001-01-02", increment="2 day", interval=True)
@@ -59,15 +57,16 @@
def tearDownClass(cls):
"""Remove the temporary region
"""
- cls.runModule("t.remove", flags="rf", type="str3ds", inputs="A", quiet=True)
+ cls.runModule("t.remove", flags="rf", type="str3ds", inputs="A", quiet=True)
cls.runModule("t.remove", flags="rf", type="strds", inputs="B", quiet=True)
cls.runModule("t.remove", flags="rf", type="stvds", inputs="C", quiet=True)
cls.del_temp_region()
def test_temporal_select_operators1(self):
"""Testing the temporal select operator. Including temporal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression="R = A {:,during} stvds(C)", stdstype = 'str3ds', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression="R = A {:,during} stvds(C)",
+ stdstype='str3ds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="str3ds")
D.select()
@@ -80,10 +79,21 @@
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True, dry_run=True)
+ pc = ta.parse(expression="R = A {:,during} stvds(C)",
+ stdstype='str3ds', basename="r", overwrite=True)
+
+ print(pc)
+
+ self.assertEqual(len(pc["register"]), 2)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "str3ds")
+
def test_temporal_select_operators2(self):
"""Testing the temporal select operator. Including temporal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression="R = A {:,equal|during} stvds(C)", stdstype = 'str3ds', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression="R = A {:,equal|during} stvds(C)",
+ stdstype='str3ds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="str3ds")
D.select()
@@ -96,11 +106,23 @@
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True,
+ dry_run=True)
+ pc = ta.parse(expression="R = A {:,equal|during} stvds(C)",
+ stdstype='str3ds', basename="r", overwrite=True)
+
+ print(pc)
+
+ self.assertEqual(len(pc["register"]), 2)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "str3ds")
+
def test_temporal_select_operators3(self):
"""Testing the temporal select operator. Including temporal relations
and negation operation. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression="R = A {!:,during} stvds(C)", stdstype = 'str3ds', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression="R = A {!:,during} stvds(C)",
+ stdstype='str3ds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="str3ds")
D.select()
@@ -116,13 +138,12 @@
def test_temporal_select_operators4(self):
"""Testing the temporal select operator. Including temporal relations and
temporal operators. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="V = C {:,contains} str3ds(A)",
- stdstype = 'stvds', basename="r", overwrite=True)
+ stdstype='stvds', basename="r", overwrite=True)
D = tgis.open_old_stds("V", type="stvds")
D.select()
- maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 1)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 2))
@@ -133,13 +154,12 @@
def test_temporal_select_operators5(self):
"""Testing the temporal select operator. Including temporal relations and
temporal operators. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A {:,during} strds(B)",
- stdstype = 'str3ds', basename="r", overwrite=True)
+ stdstype='str3ds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="str3ds")
D.select()
- maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 4)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
@@ -149,14 +169,12 @@
def test_temporal_hash_operator1(self):
"""Testing the hash operator function in conditional statement. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = if(A {#,during} stvds(C) == 1, A)",
- stdstype = 'str3ds',
- basename="r", overwrite=True)
+ stdstype='str3ds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="str3ds")
D.select()
- maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
self.assertEqual(D.metadata.get_min_min(), 2)
self.assertEqual(D.metadata.get_max_max(), 3)
@@ -168,39 +186,49 @@
def test_temporal_hash_operator2(self):
"""Testing the hash operator function in conditional statement. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = if({during}, stvds(C) {#,contains} A == 2, A)",
- stdstype = 'str3ds', basename="r", overwrite=True)
+ stdstype='str3ds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="str3ds")
D.select()
- maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
self.assertEqual(D.metadata.get_min_min(), 2)
self.assertEqual(D.metadata.get_max_max(), 3)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 2))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
- self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
- def test_different_stds_handling(self):
+ def test_different_stds_handling1(self):
"""Testing the handling of different stds types as output. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = if({during}, stvds(C) {#,contains} str3ds(A) == 2, str3ds(A))",
- stdstype = 'strds', basename="r", overwrite=True)
+ stdstype='strds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="str3ds")
D.select()
- maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
self.assertEqual(D.metadata.get_min_min(), 2)
self.assertEqual(D.metadata.get_max_max(), 3)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 2))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
- self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
+ def test_different_stds_handling2(self):
+ """Testing the handling of different stds types as output. """
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True,
+ dry_run=True)
+ pc = ta.parse(expression="R = if({during}, (stvds(C) {#,contains} str3ds(A)) == 2, str3ds(A))",
+ stdstype='strds', basename="r", overwrite=True)
+
+ self.assertEqual(len(pc["register"]), 2)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+
if __name__ == '__main__':
test()
Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_conditionals.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_conditionals.py 2016-08-31 06:55:24 UTC (rev 69313)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_conditionals.py 2016-08-31 06:56:41 UTC (rev 69314)
@@ -77,7 +77,7 @@
def test_temporal_condition_1(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression='R = if(start_date(A) >= "2001-01-03", A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -93,7 +93,7 @@
def test_temporal_condition_2(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression='R = if(td(A) == 1, A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -109,7 +109,7 @@
def test_temporal_condition_3(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression='R = if(td(A) == 1 || start_date(A) >= "2001-01-03", A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -125,7 +125,7 @@
def test_temporal_condition_4(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression='R = if(start_date(A) >= "2001-01-03", A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -141,7 +141,7 @@
def test_temporal_condition_5(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression='R = if(start_day(A) <= 2, A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -157,8 +157,9 @@
def test_temporal_condition_6(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if(td(A) == 1 {||,during} start_date(C) < "2001-01-02", A)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if(td(A) == 1 {||,during} start_date(C) < "2001-01-02", A)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -173,8 +174,9 @@
def test_temporal_condition_7(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if({over},start_date(C) == "2001-01-02" {&&,contains} td(A) == 1, B)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if({over},start_date(C) == "2001-01-02" {&&,contains} td(A) == 1, B)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -189,8 +191,9 @@
def test_temporal_condition_8(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {||,over,|} td(E) == 2, B)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {||,over,|} td(E) == 2, B)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -205,8 +208,9 @@
def test_temporal_condition_9(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {&&,over,&} td(E) == 2, B)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {&&,over,&} td(E) == 2, B)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -221,8 +225,9 @@
def test_temporal_condition_10(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {||,over,|,r} td(E) == 2, E)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {||,over,|,r} td(E) == 2, E)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -237,8 +242,9 @@
def test_temporal_condition_11(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {&&,over,r} td(E) == 2, E)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {&&,over,r} td(E) == 2, E)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -253,8 +259,9 @@
def test_temporal_condition_12(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {&&,over,|,r} td(E) == 2, E)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if(start_date(B) <= "2001-01-01" {&&,over,|,r} td(E) == 2, E)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -269,8 +276,9 @@
def test_temporal_conditional_13(self):
"""Testing the hash operator function in conditional statement. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if({equal|during},td(B) == 2 {&&,contains} td(A) == 1, A)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if({equal|during},td(B) == 2 {&&,contains} td(A) == 1, A)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -286,8 +294,9 @@
def test_temporal_condition_else_1(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if(start_date(A) <= "2001-01-03", A, D)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if(start_date(A) <= "2001-01-03", A, D)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -302,8 +311,9 @@
def test_temporal_condition_else_2(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if(td(D) == 1 && start_date(A) >= "2001-01-04", A, D)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if(td(D) == 1 && start_date(A) >= "2001-01-04", A, D)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -318,13 +328,14 @@
def test_temporal_condition_else_3(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if({during},td(B) == 2 {&&,contains} start_date(D) >= "2001-01-04", A, D)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if({during},td(B) == 2 {&&,contains} start_date(D) >= "2001-01-04", A, D)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 8)
+ self.assertEqual(D.metadata.get_min_min(), 8)
self.assertEqual(D.metadata.get_max_max(), 9)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
@@ -334,8 +345,9 @@
def test_temporal_condition_else_4(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
- ta.parse(expression='R = if({equal|over},start_date(B) <= "2001-01-01" {&&,over,|,r} td(E) == 2, E, B)', basename="r", overwrite=True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
+ ta.parse(expression='R = if({equal|over},start_date(B) <= "2001-01-01" {&&,over,|,r} td(E) == 2, E, B)',
+ basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra.py 2016-08-31 06:55:24 UTC (rev 69313)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra.py 2016-08-31 06:56:41 UTC (rev 69314)
@@ -70,7 +70,7 @@
def test_temporal_extent1(self):
"""Testing the temporal extent operators. """
- ta = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A {:,during,r} C", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -84,12 +84,22 @@
self.assertEqual(end, datetime.datetime(2001, 1, 4))
self.assertEqual( D.check_temporal_topology(), False)
self.assertEqual(D.get_granularity(), u'2 days')
+
+ ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True, dry_run=True)
+ pc = ta.parse(expression="R = A {:,during,r} C", basename="r", overwrite=True)
+ self.assertEqual(len(pc["register"]), 2)
+ self.assertEqual(len(pc["processes"]), 2)
+ self.assertEqual(pc["processes"][0]["name"], "r.mapcalc")
+ self.assertEqual(pc["processes"][1]["name"], "r.mapcalc")
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
def test_temporal_conditional_time_dimension_bug(self):
- """Testing the conditional time dimension bug, that uses the time
- dimension of the conditional statement instead the time dimension
+ """Testing the conditional time dimension bug, that uses the time
+ dimension of the conditional statement instead the time dimension
of the then/else statement."""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = if({contains}, B == 5, A - 1, A + 1)", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -105,7 +115,7 @@
def test_simple_arith_hash_1(self):
"""Simple arithmetic test including the hash operator"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = A + (A {#, equal,l} A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -120,7 +130,7 @@
def test_simple_arith_td_1(self):
"""Simple arithmetic test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = A + td(A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -134,7 +144,7 @@
def test_simple_arith_td_2(self):
"""Simple arithmetic test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = A / td(A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -148,7 +158,7 @@
def test_simple_arith_td_3(self):
"""Simple arithmetic test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = A {+,equal} td(A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -163,7 +173,7 @@
def test_simple_arith_td_4(self):
"""Simple arithmetic test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = A {/, equal} td(A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -178,7 +188,7 @@
def test_simple_arith_if_1(self):
"""Simple arithmetic test with if condition"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = if({equal}, start_date(A) >= "2001-01-02", A + A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -192,7 +202,7 @@
def test_simple_arith_if_2(self):
"""Simple arithmetic test with if condition"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = if({equal}, A#A == 1, A - A)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -206,7 +216,7 @@
def test_complex_arith_if_1(self):
"""Complex arithmetic test with if condition"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = if(start_date(A) < "2001-01-03" && A#A == 1, A{+, starts,l}C, A{+, finishes,l}C)', \
basename="r", overwrite=True)
@@ -221,7 +231,7 @@
def test_simple_arith_1(self):
"""Simple arithmetic test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {*, equal} A {+, equal} A", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -235,7 +245,7 @@
def test_simple_arith_2(self):
"""Simple arithmetic test that creates an empty strds"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {*, during} A {+, during} A", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -243,7 +253,7 @@
def test_simple_arith_3(self):
"""Simple arithmetic test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A / A + A*A/A", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -254,10 +264,10 @@
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
-
+
def test_temporal_intersection_1(self):
"""Simple temporal intersection test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {+,equal,i} B", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
@@ -265,7 +275,7 @@
def test_temporal_intersection_2(self):
"""Simple temporal intersection test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {+,during,i} B", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -279,7 +289,7 @@
def test_temporal_intersection_3(self):
"""Simple temporal intersection test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {+,starts,i} B", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -293,7 +303,7 @@
def test_temporal_intersection_4(self):
"""Simple temporal intersection test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {+,finishes,intersect} B", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -307,7 +317,7 @@
def test_temporal_intersection_5(self):
"""Simple temporal intersection test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {+,starts|finishes,i} B", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -321,7 +331,7 @@
def test_temporal_intersection_6(self):
"""Simple temporal intersection test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = B {+,overlaps,u} C", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -335,7 +345,7 @@
def test_temporal_intersection_7(self):
"""Simple temporal intersection test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = B {+,overlapped,u} C", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -349,7 +359,7 @@
def test_temporal_intersection_8(self):
"""Simple temporal intersection test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = A {+,during,l} buff_t(C, "1 day") ',
basename="r", overwrite=True)
@@ -364,7 +374,7 @@
def test_temporal_neighbors_1(self):
"""Simple temporal neighborhood computation test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = A[-1] + A[1]',
basename="r", overwrite=True)
@@ -379,7 +389,7 @@
def test_temporal_neighbors_2(self):
"""Simple temporal neighborhood computation test"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = A[0,0,-1] + A[0,0,1]',
basename="r", overwrite=True)
@@ -394,15 +404,15 @@
def test_tmap_function1(self):
"""Testing the tmap function. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = tmap(singletmap)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 1)
- self.assertEqual(D.metadata.get_min_min(), 99)
- self.assertEqual(D.metadata.get_max_max(), 99)
+ self.assertEqual(D.metadata.get_min_min(), 99)
+ self.assertEqual(D.metadata.get_max_max(), 99)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
@@ -411,15 +421,15 @@
def test_tmap_function2(self):
"""Testing the tmap function. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = tmap(singletmap) + 1', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 1)
- self.assertEqual(D.metadata.get_min_min(), 100)
- self.assertEqual(D.metadata.get_max_max(), 100)
+ self.assertEqual(D.metadata.get_min_min(), 100)
+ self.assertEqual(D.metadata.get_max_max(), 100)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
@@ -428,15 +438,15 @@
def test_map_function1(self):
"""Testing the map function. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = map(singlemap) + A', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 4)
- self.assertEqual(D.metadata.get_min_min(), 101)
- self.assertEqual(D.metadata.get_max_max(), 104)
+ self.assertEqual(D.metadata.get_min_min(), 101)
+ self.assertEqual(D.metadata.get_max_max(), 104)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -445,15 +455,15 @@
def test_map_function2(self):
"""Testing the map function. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression='R = A * map(singlemap)', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 4)
- self.assertEqual(D.metadata.get_min_min(), 100)
- self.assertEqual(D.metadata.get_max_max(), 400)
+ self.assertEqual(D.metadata.get_min_min(), 100)
+ self.assertEqual(D.metadata.get_max_max(), 400)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -462,14 +472,14 @@
def test_temporal_select(self):
"""Testing the temporal select operator. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A : A", basename="r", overwrite=True)
D = tgis.open_old_stds("R", 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)
+ 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))
@@ -478,14 +488,14 @@
def test_temporal_select(self):
"""Testing the temporal select operator. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A : D", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 3)
- self.assertEqual(D.metadata.get_max_max(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 3)
+ self.assertEqual(D.metadata.get_max_max(), 4)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -494,14 +504,14 @@
def test_temporal_select_operators1(self):
"""Testing the temporal select operator. Including temporal relations. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A : D", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 3)
- self.assertEqual(D.metadata.get_max_max(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 3)
+ self.assertEqual(D.metadata.get_max_max(), 4)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -510,14 +520,14 @@
def test_temporal_select_operators2(self):
"""Testing the temporal select operator. Including temporal relations. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {!:,during} C", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 1)
- self.assertEqual(D.metadata.get_max_max(), 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))
@@ -525,16 +535,16 @@
self.assertEqual(D.get_granularity(), u'1 day')
def test_temporal_select_operators3(self):
- """Testing the temporal select operator. Including temporal relations and
+ """Testing the temporal select operator. Including temporal relations and
different temporal operators (lr|+&)"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {:,during,d} B", basename="r", overwrite=True)
D = tgis.open_old_stds("R", 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)
+ 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))
@@ -542,9 +552,9 @@
self.assertEqual(D.get_granularity(), u'2 days')
def test_temporal_select_operators4(self):
- """Testing the temporal select operator. Including temporal relations and
+ """Testing the temporal select operator. Including temporal relations and
different temporal operators (lr|+&)"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A {:,equal|during,r} C", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -565,14 +575,14 @@
def test_temporal_hash_operator1(self):
"""Testing the temporal hash operator in the raster algebra. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = if(A # D == 1, A)", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 3)
- self.assertEqual(D.metadata.get_max_max(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 3)
+ self.assertEqual(D.metadata.get_max_max(), 4)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -581,14 +591,14 @@
def test_temporal_hash_operator2(self):
"""Testing the temporal hash operator in the raster algebra. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = A # D", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 1)
- self.assertEqual(D.metadata.get_max_max(), 1)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 1)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -597,14 +607,14 @@
def test_temporal_hash_operator3(self):
"""Testing the temporal hash operator in the raster algebra. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = C {#,contains} A", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 1)
- self.assertEqual(D.metadata.get_min_min(), 2)
- self.assertEqual(D.metadata.get_max_max(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 2)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 2))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
@@ -613,30 +623,30 @@
def test_temporal_hash_operator4(self):
"""Testing the temporal hash operator in the raster algebra. """
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = if({contains},A # D == 1, C {#,contains} A)", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 1)
- self.assertEqual(D.metadata.get_min_min(), 2)
- self.assertEqual(D.metadata.get_max_max(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 2)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 2))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'2 days')
-
+
def test_raster_arithmetic_relation_1(self):
"""Arithmetic test with temporal intersection"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = B {+,contains,l} A ", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 8)
- self.assertEqual(D.metadata.get_max_max(), 13)
+ self.assertEqual(D.metadata.get_min_min(), 8)
+ self.assertEqual(D.metadata.get_max_max(), 13)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -645,14 +655,14 @@
def test_raster_arithmetic_relation_2(self):
"""Arithmetic test with temporal intersection"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = B {*,contains,l} A ", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 10)
- self.assertEqual(D.metadata.get_max_max(), 72)
+ self.assertEqual(D.metadata.get_min_min(), 10)
+ self.assertEqual(D.metadata.get_max_max(), 72)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -661,45 +671,45 @@
def test_raster_arithmetic_relation_3(self):
"""Arithmetic test with temporal intersection"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = B {+,contains,l} A ", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 8)
- self.assertEqual(D.metadata.get_max_max(), 13)
+ self.assertEqual(D.metadata.get_min_min(), 8)
+ self.assertEqual(D.metadata.get_max_max(), 13)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'2 days')
-
+
def test_raster_arithmetic_relation_4(self):
"""Arithmetic test with temporal intersection"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = B {+,contains,r} A ", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(),4)
- self.assertEqual(D.metadata.get_min_min(), 8)
- self.assertEqual(D.metadata.get_max_max(), 13)
+ self.assertEqual(D.metadata.get_min_min(), 8)
+ self.assertEqual(D.metadata.get_max_max(), 13)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
-
+
def test_raster_arithmetic_relation_5(self):
"""Complex arithmetic test with temporal intersection"""
- tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
tra.parse(expression="R = tmap(singletmap) {+,equal| precedes| follows,l} A + map(singlemap)", basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(),1)
- self.assertEqual(D.metadata.get_min_min(), 208)
+ self.assertEqual(D.metadata.get_min_min(), 208)
self.assertEqual(D.metadata.get_max_max(), 208)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra_grs.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra_grs.py 2016-08-31 06:55:24 UTC (rev 69313)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra_grs.py 2016-08-31 06:56:41 UTC (rev 69314)
@@ -37,6 +37,7 @@
cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="d2 = 11")
cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="d3 = 12")
cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="singletmap = 99")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="nullmap = null()")
tgis.open_new_stds(name="A", type="strds", temporaltype="absolute",
title="A", descr="A", semantic="field", overwrite=True)
@@ -61,6 +62,8 @@
start="2001-05-01", increment="5 days", interval=True)
tgis.register_maps_in_space_time_dataset(type="raster", name=None, maps="singletmap",
start="2001-03-01", end="2001-04-01")
+ tgis.register_maps_in_space_time_dataset(type="raster", name=None, maps="nullmap",
+ start="2001-01-01", end="2001-07-01")
def tearDown(self):
return
@@ -95,13 +98,87 @@
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 month')
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True, dry_run=True)
+ tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
+ pc = tra.parse(expression=expr, basename="r", overwrite=True)
+
+ self.assertEqual(len(pc["register"]), 6)
+ self.assertEqual(len(pc["processes"]), 6)
+ self.assertEqual(pc["processes"][0]["name"], "r.mapcalc")
+ self.assertEqual(pc["processes"][5]["name"], "r.mapcalc")
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
def test_2(self):
"""Simple arithmetik test"""
tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ expr = "R = A + B + C"
+ ret = tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
+ self.assertEqual(ret, True)
+
+ tra.parse(expression=expr, basename="r", overwrite=True)
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 6)
+ self.assertEqual(D.metadata.get_min_min(), 17) # 1 + 7 + 9
+ self.assertEqual(D.metadata.get_max_max(), 23) # 6 + 8 + 9
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 7, 1))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 month')
+
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True, dry_run=True)
+ tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
+ pc = tra.parse(expression=expr, basename="r", overwrite=True)
+
+ self.assertEqual(len(pc["register"]), 6)
+ self.assertEqual(len(pc["processes"]), 6)
+ self.assertEqual(pc["processes"][0]["name"], "r.mapcalc")
+ self.assertEqual(pc["processes"][5]["name"], "r.mapcalc")
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+ def test_3(self):
+ """Simple arithmetik test with null map"""
+ tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ expr = "R = A + B + C + tmap(nullmap)"
+ ret = tra.setup_common_granularity(expression=expr,
+ lexer=tgis.TemporalRasterAlgebraLexer())
+ self.assertEqual(ret, True)
+
+ tra.parse(expression=expr, basename="r", overwrite=True)
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 0)
+ self.assertEqual(D.metadata.get_min_min(), None)
+ self.assertEqual(D.metadata.get_max_max(), None)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, None)
+ self.assertEqual(end, None)
+ self.assertEqual( D.check_temporal_topology(), False)
+ self.assertEqual(D.get_granularity(), None)
+
+ tra = tgis.TemporalRasterAlgebraParser(run=True, debug=True, dry_run=True)
+ tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
+ pc = tra.parse(expression=expr, basename="r", overwrite=True)
+
+ print(pc)
+
+ self.assertEqual(len(pc["register"]), 0)
+ self.assertEqual(len(pc["processes"]), 0)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+ def test_4(self):
+ """Simple arithmetik test"""
+ tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
expr = "R = if(D == 11, A - 1, A + 1)"
ret = tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
self.assertEqual(ret, True)
-
+
tra.parse(expression=expr, basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -149,7 +226,7 @@
expr = 'R = A + td(A:D)'
ret = tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
self.assertEqual(ret, True)
-
+
tra.parse(expression=expr, basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -169,7 +246,7 @@
expr = 'R = if(start_date(A) >= "2001-02-01", A + A)'
ret = tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
self.assertEqual(ret, True)
-
+
tra.parse(expression=expr, basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -187,7 +264,7 @@
expr = 'R = if(A#A == 1, A - A)'
ret = tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
self.assertEqual(ret, True)
-
+
tra.parse(expression=expr, basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -205,7 +282,7 @@
expr = 'R = if(start_date(A) < "2001-03-01" && A#A == 1, A+C, A-C)'
ret = tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
self.assertEqual(ret, True)
-
+
tra.parse(expression=expr, basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -223,7 +300,7 @@
expr ='R = (A[0,0,-1] : D) + (A[0,0,1] : D)'
ret = tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
self.assertEqual(ret, True)
-
+
tra.parse(expression=expr, basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -234,14 +311,14 @@
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 2))
self.assertEqual(end, datetime.datetime(2001, 5, 6))
-
+
def test_map(self):
"""Test STDS + single map without timestamp"""
tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
expr = "R = A + map(singletmap)"
ret = tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
self.assertEqual(ret, True)
-
+
tra.parse(expression=expr, basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -252,20 +329,20 @@
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 7, 1))
-
+
def test_tmap_map(self):
"""Test STDS + single map with and without timestamp"""
tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
expr = "R = tmap(singletmap) + A + map(singletmap)"
ret = tra.setup_common_granularity(expression=expr, lexer = tgis.TemporalRasterAlgebraLexer())
self.assertEqual(ret, True)
-
+
tra.parse(expression=expr, basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
self.assertEqual(D.metadata.get_number_of_maps(),1)
- self.assertEqual(D.metadata.get_min_min(), 201)
+ self.assertEqual(D.metadata.get_min_min(), 201)
self.assertEqual(D.metadata.get_max_max(), 201)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 3, 1))
More information about the grass-commit
mailing list