Skip to content

Commit

Permalink
temporal framework: Better error handling when enabling the temporal …
Browse files Browse the repository at this point in the history
…granularity algebra

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62704 15284696-431f-4ddb-bdfa-cd5b030d7da7
  • Loading branch information
huhabla committed Nov 11, 2014
1 parent 234ac52 commit 3fef961
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions lib/python/temporal/temporal_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def setup_common_granularity(self, expression, stdstype = 'strds', lexer = No
space time datasets in the expression to generate the map lists.
This function will analyze the expression to detect space time datasets
and computes are common granularity from all granularities.
and computes the common granularity from all granularities.
This granularity is then be used to generate the map lists. Hence, all
maps from all STDS will have equidistant temporal extents. The only meaningful
Expand All @@ -706,15 +706,18 @@ def setup_common_granularity(self, expression, stdstype = 'strds', lexer = No
parse the expression, default is TemporalAlgebraLexer
:return: True if successful, False otherwise
:TODO: Check for tmap and map functions in the expression to avoid
problems with map names that are handled as STDS
"""
l = lexer
# Split the expression to ignore the left part
expressions = expression.split("=")[1:]
expression = " ".join(expressions)


# Check if spatio-temporal operators are present in the expression
if "{" in expression or "}" in expression:
self.msgr.error(_("Spatio temporal operators are not supported in granularity algebra mode"))
return False

# detect all STDS
if l is None:
l = TemporalAlgebraLexer()
Expand Down Expand Up @@ -748,13 +751,15 @@ def setup_common_granularity(self, expression, stdstype = 'strds', lexer = No
stds = open_old_stds(name, stdstype, dbif)
# We need valid temporal topology
if stds.check_temporal_topology() is False:
self.msgr.error(_("All input space time datasets must have a valid temporal topology."))
return False

grans.append(stds.get_granularity())
ttypes[stds.get_temporal_type()] = stds.get_temporal_type()

# Only one temporal type is allowed
if len(ttypes) > 1:
self.msgr.error(_("All input space time datasets must have the same temporal type."))
return False

# Compute the common granularity
Expand All @@ -767,7 +772,8 @@ def setup_common_granularity(self, expression, stdstype = 'strds', lexer = No

return True

def parse(self, expression, stdstype = 'strds', maptype = 'rast', mapclass = RasterDataset, basename = None, overwrite=False):
def parse(self, expression, stdstype = 'strds', maptype = 'rast', mapclass = RasterDataset,
basename = None, overwrite=False):
self.lexer = TemporalAlgebraLexer()
self.lexer.build()
self.parser = yacc.yacc(module=self, debug=self.debug)
Expand Down Expand Up @@ -1264,7 +1270,8 @@ def assign_bool_value(self, map_i, tbrelations, topolist = ["EQUAL"]):
for boolean in relationmap.condition_value:
if isinstance(boolean, bool):
condition_value_list.append(boolean)
print(str(relationmap.get_temporal_extent_as_tuple()) + str(boolean))
if self.debug:
print(str(relationmap.get_temporal_extent_as_tuple()) + str(boolean))
if all(condition_value_list):
resultbool = True
else:
Expand Down Expand Up @@ -1306,9 +1313,11 @@ def compare_bool_value(self, map_i, tbrelations, compop, aggregate, topolist =
condition_value_list.append(')')
# Convert conditional list to concatenated string and evaluate booleans.
condition_value_str = ''.join(map(str, condition_value_list))
print(condition_value_str)
if self.debug:
print(condition_value_str)
resultbool = eval(condition_value_str)
print(resultbool)
if self.debug:
print(resultbool)
# Add boolean value to result list.
map_i.condition_value = [resultbool]

Expand Down Expand Up @@ -1524,10 +1533,12 @@ def set_granularity(self, maplistA, maplistB, toperator = 'l', topolist = ["EQUA
map_i.set_relative_time(int(start), int(end), relunit)
resultdict[map_i.get_id()] = map_i
else:
print('Topologic relation: ' + topo.upper() + ' not found.')
if self.debug:
print('Topologic relation: ' + topo.upper() + ' not found.')
resultdict[map_i.get_id()] = map_i
if unchanged == True:
print('Leave temporal extend of result map: ' + map_i.get_map_id() + ' unchanged.')
if self.debug:
print('Leave temporal extend of result map: ' + map_i.get_map_id() + ' unchanged.')

resultlist = resultdict.values()
# Sort list of maps chronological.
Expand Down Expand Up @@ -1861,7 +1872,8 @@ def recurse_compare(conditionlist):
# Add all maps that fulfill the conditions to result list.
if resultbool[0]:
resultlist.append(map_i)
print(map_i.get_map_id() + ' ' + str(map_i.condition_value))
if self.debug:
print(map_i.get_map_id() + ' ' + str(map_i.condition_value))
else:
inverselist.append(map_i)
if inverse:
Expand Down

0 comments on commit 3fef961

Please sign in to comment.