temporal_raster_base_algebra.py 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649
  1. """!@package grass.temporal
  2. Temporal raster algebra
  3. (C) 2013 by the GRASS Development Team
  4. This program is free software under the GNU General Public
  5. License (>=v2). Read the file COPYING that comes with GRASS
  6. for details.
  7. @author Thomas Leppelt and Soeren Gebbert
  8. @code
  9. >>> p = TemporalRasterAlgebraLexer()
  10. >>> p.build()
  11. >>> p.debug = True
  12. >>> expression = 'R = A / B * 20 + C - 2.45'
  13. >>> p.test(expression)
  14. R = A / B * 20 + C - 2.45
  15. LexToken(NAME,'R',1,0)
  16. LexToken(EQUALS,'=',1,2)
  17. LexToken(NAME,'A',1,4)
  18. LexToken(DIV,'/',1,6)
  19. LexToken(NAME,'B',1,8)
  20. LexToken(MULT,'*',1,10)
  21. LexToken(INT,20,1,12)
  22. LexToken(ADD,'+',1,15)
  23. LexToken(NAME,'C',1,17)
  24. LexToken(SUB,'-',1,19)
  25. LexToken(FLOAT,2.45,1,21)
  26. >>> expression = 'R = A {equal,|/} B'
  27. >>> p.test(expression)
  28. R = A {equal,|/} B
  29. LexToken(NAME,'R',1,0)
  30. LexToken(EQUALS,'=',1,2)
  31. LexToken(NAME,'A',1,4)
  32. LexToken(T_ARITH1_OPERATOR,'{equal,|/}',1,6)
  33. LexToken(NAME,'B',1,17)
  34. >>> expression = 'R = A {equal,||} B'
  35. >>> p.test(expression)
  36. R = A {equal,||} B
  37. LexToken(NAME,'R',1,0)
  38. LexToken(EQUALS,'=',1,2)
  39. LexToken(NAME,'A',1,4)
  40. LexToken(T_COMP_OPERATOR,'{equal,||}',1,6)
  41. LexToken(NAME,'B',1,17)
  42. >>> expression = 'R = A {equal,&&} B'
  43. >>> p.test(expression)
  44. R = A {equal,&&} B
  45. LexToken(NAME,'R',1,0)
  46. LexToken(EQUALS,'=',1,2)
  47. LexToken(NAME,'A',1,4)
  48. LexToken(T_COMP_OPERATOR,'{equal,&&}',1,6)
  49. LexToken(NAME,'B',1,17)
  50. >>> expression = 'R = A {equal | during,+*} B'
  51. >>> p.test(expression)
  52. R = A {equal | during,+*} B
  53. LexToken(NAME,'R',1,0)
  54. LexToken(EQUALS,'=',1,2)
  55. LexToken(NAME,'A',1,4)
  56. LexToken(T_ARITH1_OPERATOR,'{equal | during,+*}',1,6)
  57. LexToken(NAME,'B',1,26)
  58. >>> expression = 'R = A {equal | during,+:} B'
  59. >>> p.test(expression)
  60. R = A {equal | during,+:} B
  61. LexToken(NAME,'R',1,0)
  62. LexToken(EQUALS,'=',1,2)
  63. LexToken(NAME,'A',1,4)
  64. LexToken(T_SELECT_OPERATOR,'{equal | during,+:}',1,6)
  65. LexToken(NAME,'B',1,26)
  66. >>> expression = 'R = abs(A) {equal,+:} exp(B) / sqrt(C) - log(D)'
  67. >>> p.test(expression)
  68. R = abs(A) {equal,+:} exp(B) / sqrt(C) - log(D)
  69. LexToken(NAME,'R',1,0)
  70. LexToken(EQUALS,'=',1,2)
  71. LexToken(ABS,'abs',1,4)
  72. LexToken(LPAREN,'(',1,7)
  73. LexToken(NAME,'A',1,8)
  74. LexToken(RPAREN,')',1,9)
  75. LexToken(T_SELECT_OPERATOR,'{equal,+:}',1,11)
  76. LexToken(EXP,'exp',1,22)
  77. LexToken(LPAREN,'(',1,25)
  78. LexToken(NAME,'B',1,26)
  79. LexToken(RPAREN,')',1,27)
  80. LexToken(DIV,'/',1,29)
  81. LexToken(SQRT,'sqrt',1,31)
  82. LexToken(LPAREN,'(',1,35)
  83. LexToken(NAME,'C',1,36)
  84. LexToken(RPAREN,')',1,37)
  85. LexToken(SUB,'-',1,39)
  86. LexToken(LOG,'log',1,41)
  87. LexToken(LPAREN,'(',1,44)
  88. LexToken(NAME,'D',1,45)
  89. LexToken(RPAREN,')',1,46)
  90. @endcode
  91. """
  92. import grass.pygrass.modules as pymod
  93. from temporal_raster_operator import *
  94. from temporal_algebra import *
  95. ##############################################################################
  96. class TemporalRasterAlgebraLexer(TemporalAlgebraLexer):
  97. """!Lexical analyzer for the GRASS GIS temporal algebra"""
  98. def __init__(self):
  99. TemporalAlgebraLexer.__init__(self)
  100. # Supported r.mapcalc functions.
  101. mapcalc_functions = {
  102. 'exp' : 'EXP',
  103. 'log' : 'LOG',
  104. 'sqrt' : 'SQRT',
  105. 'abs' : 'ABS',
  106. 'cos' : 'COS',
  107. 'acos' : 'ACOS',
  108. 'sin' : 'SIN',
  109. 'asin' : 'ASIN',
  110. 'tan' : 'TAN',
  111. 'double' : 'DOUBLE',
  112. 'float' : 'FLOATEXP',
  113. 'int' : 'INTEXP',
  114. 'isnull' : 'ISNULL',
  115. 'isntnull': 'ISNTNULL',
  116. 'null' : 'NULL',
  117. 'exist' : 'EXIST',
  118. }
  119. # This is the list of token names.
  120. raster_tokens = (
  121. 'MOD',
  122. 'DIV',
  123. 'MULT',
  124. 'ADD',
  125. 'SUB',
  126. 'T_ARITH1_OPERATOR',
  127. 'T_ARITH2_OPERATOR',
  128. 'L_SPAREN',
  129. 'R_SPAREN',
  130. )
  131. # Build the token list
  132. tokens = TemporalAlgebraLexer.tokens \
  133. + raster_tokens \
  134. + tuple(mapcalc_functions.values())
  135. # Regular expression rules for simple tokens
  136. t_MOD = r'[\%]'
  137. t_DIV = r'[\/]'
  138. t_MULT = r'[\*]'
  139. t_ADD = r'[\+]'
  140. t_SUB = r'[-]'
  141. t_T_ARITH1_OPERATOR = r'\{([a-zA-Z\| ]+[,])?([\|&+=]?[\%\*\/])\}'
  142. t_T_ARITH2_OPERATOR = r'\{([a-zA-Z\| ]+[,])?([\|&+=]?[+-])\}'
  143. t_L_SPAREN = r'\['
  144. t_R_SPAREN = r'\]'
  145. # Parse symbols
  146. def temporal_symbol(self, t):
  147. # Check for reserved words
  148. if t.value in TemporalRasterAlgebraLexer.time_functions.keys():
  149. t.type = TemporalRasterAlgebraLexer.time_functions.get(t.value)
  150. elif t.value in TemporalRasterAlgebraLexer.datetime_functions.keys():
  151. t.type = TemporalRasterAlgebraLexer.datetime_functions.get(t.value)
  152. elif t.value in TemporalRasterAlgebraLexer.conditional_functions.keys():
  153. t.type = TemporalRasterAlgebraLexer.conditional_functions.get(t.value)
  154. elif t.value in TemporalRasterAlgebraLexer.mapcalc_functions.keys():
  155. t.type = TemporalRasterAlgebraLexer.mapcalc_functions.get(t.value)
  156. else:
  157. t.type = 'NAME'
  158. return t
  159. ##############################################################################
  160. class TemporalRasterBaseAlgebraParser(TemporalAlgebraParser):
  161. """The temporal algebra class"""
  162. # Get the tokens from the lexer class
  163. tokens = TemporalRasterAlgebraLexer.tokens
  164. # Setting equal precedence level for select and hash operations.
  165. precedence = (
  166. ('left', 'T_SELECT_OPERATOR', 'T_SELECT', 'T_NOT_SELECT'), # 1
  167. ('left', 'ADD', 'SUB', 'T_ARITH2_OPERATOR'), #2
  168. ('left', 'AND', 'OR', 'T_COMP_OPERATOR', 'MOD', 'DIV', 'MULT',
  169. 'T_ARITH1_OPERATOR'))
  170. def __init__(self, pid=None, run = True, debug = False, spatial = False, \
  171. nprocs = 1, register_null = False):
  172. TemporalAlgebraParser.__init__(self, pid, run, debug, spatial)
  173. self.nprocs = nprocs
  174. self.empty_maps = {}
  175. self.register_null = register_null
  176. def check_null(self, t):
  177. try:
  178. int(t)
  179. return t
  180. except ValueError:
  181. return "null()"
  182. ######################### Temporal functions ##############################
  183. def eval_toperator(self, operator, comparison = False):
  184. """!This function evaluates a string containing temporal operations.
  185. @param operator String of temporal operations, e.g. {equal|during,=!:}.
  186. @return List of temporal relations (equal, during), the given function
  187. (!:) and the interval/instances (=).
  188. @code
  189. >>> init(True)
  190. >>> p = TemporalRasterBaseAlgebraParser()
  191. >>> operator = "{equal,:}"
  192. >>> p.eval_toperator(operator)
  193. (['EQUAL'], '=', ':')
  194. >>> operator = "{equal|during,:}"
  195. >>> p.eval_toperator(operator)
  196. (['EQUAL', 'DURING'], '=', ':')
  197. >>> operator = "{equal,!:}"
  198. >>> p.eval_toperator(operator)
  199. (['EQUAL'], '=', '!:')
  200. >>> operator = "{equal|during,!:}"
  201. >>> p.eval_toperator(operator)
  202. (['EQUAL', 'DURING'], '=', '!:')
  203. >>> operator = "{equal|during,=!:}"
  204. >>> p.eval_toperator(operator)
  205. (['EQUAL', 'DURING'], '=', '!:')
  206. >>> operator = "{equal|during|starts,#}"
  207. >>> p.eval_toperator(operator)
  208. (['EQUAL', 'DURING', 'STARTS'], '=', '#')
  209. >>> operator = "{!:}"
  210. >>> p.eval_toperator(operator)
  211. (['EQUAL'], '=', '!:')
  212. >>> operator = "{=:}"
  213. >>> p.eval_toperator(operator)
  214. (['EQUAL'], '=', ':')
  215. >>> operator = "{#}"
  216. >>> p.eval_toperator(operator)
  217. (['EQUAL'], '=', '#')
  218. >>> operator = "{equal|during}"
  219. >>> p.eval_toperator(operator)
  220. (['EQUAL', 'DURING'], None, None)
  221. >>> operator = "{equal}"
  222. >>> p.eval_toperator(operator)
  223. (['EQUAL'], None, None)
  224. >>> operator = "{equal,||}"
  225. >>> p.eval_toperator(operator, True)
  226. (['EQUAL'], '=', '||')
  227. >>> operator = "{equal|during,&&}"
  228. >>> p.eval_toperator(operator, True)
  229. (['EQUAL', 'DURING'], '=', '&&')
  230. @endcode
  231. """
  232. p = TemporalRasterOperatorParser()
  233. p.parse(operator, comparison)
  234. p.relations = [rel.upper() for rel in p.relations]
  235. return(p.relations, p.temporal, p.function)
  236. ###########################################################################
  237. def p_statement_assign(self, t):
  238. # The expression should always return a list of maps.
  239. """
  240. statement : stds EQUALS expr
  241. """
  242. if self.run:
  243. # Create the process queue for parallel mapcalc processing
  244. process_queue = pymod.ParallelModuleQueue(int(self.nprocs))
  245. if isinstance(t[3], list):
  246. num = len(t[3])
  247. count = 0
  248. returncode = 0
  249. register_list = []
  250. for i in range(num):
  251. # Check if resultmap names exist in GRASS database.
  252. rastername = self.basename + "_" + str(i) + "@" + self.mapset
  253. rastermap = RasterDataset(rastername)
  254. if rastermap.map_exists() and self.overwrite == False:
  255. self.msgr.fatal("Error raster maps with basename %s exist. Use --o flag to overwrite existing file" \
  256. %(rastername))
  257. map_test_list = []
  258. for map_i in t[3]:
  259. newident = self.basename + "_" + str(count)
  260. if "cmd_list" in dir(map_i):
  261. print(newident + ' = ' + map_i.cmd_list)
  262. # Build r.mapcalc module and execute expression.
  263. # Change map name to given basename.
  264. # Create deepcopy of r.mapcalc module.
  265. map_test = map_i.get_new_instance(newident + "@" + self.mapset)
  266. map_test.set_temporal_extent(map_i.get_temporal_extent())
  267. map_test.set_spatial_extent(map_i.get_spatial_extent())
  268. map_test_list.append(map_test)
  269. m = copy.deepcopy(self.m_mapcalc)
  270. m_expression = newident + "=" + map_i.cmd_list
  271. m.inputs["expression"].value = m_expression
  272. m.flags["overwrite"].value = self.overwrite
  273. process_queue.put(m)
  274. else:
  275. map_i.set_id(newident + "@" + self.mapset)
  276. map_test_list.append(map_i)
  277. count += 1
  278. process_queue.wait()
  279. for map_i in map_test_list:
  280. if not map_test.map_exists():
  281. self.msgr.error(_("Error computing map <%s>"%(map_i.get_id()) ))
  282. else:
  283. register_list.append(map_i)
  284. # Open connection to temporal database.
  285. dbif, connect = init_dbif(self.dbif)
  286. # Create result space time dataset.
  287. resultstds = open_new_space_time_dataset(t[1], self.stdstype, \
  288. 'absolute', t[1], t[1], \
  289. 'mean', self.dbif, \
  290. overwrite = self.overwrite)
  291. for map_i in register_list:
  292. # Get meta data from grass database.
  293. map_i.load()
  294. # Do not register empty maps if not required
  295. # In case of a null map continue, do not register null maps
  296. if map_i.metadata.get_min() is None and \
  297. map_i.metadata.get_max() is None:
  298. if not self.register_null:
  299. self.empty_maps[map_i.get_name()] = map_i.get_name()
  300. continue
  301. if map_i.is_in_db(dbif) and self.overwrite:
  302. # Update map in temporal database.
  303. map_i.update_all(dbif)
  304. elif map_i.is_in_db(dbif) and self.overwrite == False:
  305. # Raise error if map exists and no overwrite flag is given.
  306. self.msgr.fatal("Error vector map %s exist in temporal database. Use overwrite flag. : \n%s" \
  307. %(map_i.get_map_id(), cmd.popen.stderr))
  308. else:
  309. # Insert map into temporal database.
  310. map_i.insert(dbif)
  311. # Register map in result space time dataset.
  312. success = resultstds.register_map(map_i, dbif)
  313. resultstds.update_from_registered_maps(dbif)
  314. dbif.close()
  315. t[0] = register_list
  316. self.remove_empty_maps()
  317. def p_arith1_operation(self, t):
  318. """
  319. expr : stds MOD stds
  320. | expr MOD stds
  321. | stds MOD expr
  322. | expr MOD expr
  323. | stds DIV stds
  324. | expr DIV stds
  325. | stds DIV expr
  326. | expr DIV expr
  327. | stds MULT stds
  328. | expr MULT stds
  329. | stds MULT expr
  330. | expr MULT expr
  331. """
  332. # Check input stds.
  333. maplistA = self.check_stds(t[1])
  334. maplistB = self.check_stds(t[3])
  335. topolist = self.get_temporal_topo_list(maplistA, maplistB)
  336. if self.run:
  337. resultlist = []
  338. for map_i in topolist:
  339. # Generate an intermediate map for the result map list.
  340. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  341. # Set first input for overlay module.
  342. mapainput = map_i.get_id()
  343. # Loop over temporal related maps and create overlay modules.
  344. tbrelations = map_i.get_temporal_relations()
  345. count = 0
  346. for map_j in (tbrelations['EQUAL']):
  347. # Create overlayed map extent.
  348. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  349. temp_op = '=')
  350. # Stop the loop if no temporal or spatial relationship exist.
  351. if returncode == 0:
  352. break
  353. if count == 0:
  354. # Set map name.
  355. name = map_new.get_id()
  356. else:
  357. # Generate an intermediate map
  358. name = self.generate_map_name()
  359. # Set first input for overlay module.
  360. mapbinput = map_j.get_id()
  361. # Create r.mapcalc expression string for the operation.
  362. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  363. cmdstring = "(%s %s %s)" %(map_new.cmd_list, t[2], mapbinput)
  364. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  365. cmdstring = "(%s %s %s)" %(mapainput, t[2], map_j.cmd_list)
  366. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  367. cmdstring = "(%s %s %s)" %(map_new.cmd_list, t[2], map_j.cmd_list)
  368. else:
  369. cmdstring = "(%s %s %s)" %(mapainput, t[2], mapbinput)
  370. # Conditional append of module command.
  371. map_new.cmd_list = cmdstring
  372. # Set new map name to temporary map name.
  373. mapainput = name
  374. count += 1
  375. # Append map to result map list.
  376. if returncode == 1:
  377. resultlist.append(map_new)
  378. t[0] = resultlist
  379. if self.debug:
  380. for map in resultlist:
  381. print map.cmd_list
  382. def p_arith1_operation_numeric1(self, t):
  383. """
  384. expr : stds MOD number
  385. | expr MOD number
  386. | stds DIV number
  387. | expr DIV number
  388. | stds MULT number
  389. | expr MULT number
  390. """
  391. # Check input stds.
  392. maplist = self.check_stds(t[1])
  393. if self.run:
  394. resultlist = []
  395. for map_i in maplist:
  396. mapinput = map_i.get_id()
  397. # Create r.mapcalc expression string for the operation.
  398. if "cmd_list" in dir(map_i):
  399. cmdstring = "(%s %s %s)" %(map_i.cmd_list, t[2], t[3])
  400. else:
  401. cmdstring = "(%s %s %s)" %(mapinput, t[2], t[3])
  402. # Conditional append of module command.
  403. map_i.cmd_list = cmdstring
  404. # Append map to result map list.
  405. resultlist.append(map_i)
  406. t[0] = resultlist
  407. if self.debug:
  408. for map in resultlist:
  409. print map.cmd_list
  410. def p_arith1_operation_numeric2(self, t):
  411. """
  412. expr : number MOD stds
  413. | number MOD expr
  414. | number DIV stds
  415. | number DIV expr
  416. | number MULT stds
  417. | number MULT expr
  418. """
  419. # Check input stds.
  420. maplist = self.check_stds(t[3])
  421. if self.run:
  422. resultlist = []
  423. for map_i in maplist:
  424. mapinput = map_i.get_id()
  425. # Create r.mapcalc expression string for the operation.
  426. if "cmd_list" in dir(map_i):
  427. cmdstring = "(%s %s %s)" %(t[1], t[2], map_i.cmd_list)
  428. else:
  429. cmdstring = "(%s %s %s)" %(t[1], t[2], mapinput)
  430. # Conditional append of module command.
  431. map_i.cmd_list = cmdstring
  432. # Append map to result map list.
  433. resultlist.append(map_i)
  434. t[0] = resultlist
  435. if self.debug:
  436. for map in resultlist:
  437. print map.cmd_list
  438. def p_arith2_operation(self, t):
  439. """
  440. expr : stds ADD stds
  441. | expr ADD stds
  442. | stds ADD expr
  443. | expr ADD expr
  444. | stds SUB stds
  445. | expr SUB stds
  446. | stds SUB expr
  447. | expr SUB expr
  448. """
  449. # Check input stds.
  450. maplistA = self.check_stds(t[1])
  451. maplistB = self.check_stds(t[3])
  452. topolist = self.get_temporal_topo_list(maplistA, maplistB)
  453. if self.run:
  454. resultlist = []
  455. for map_i in topolist:
  456. # Generate an intermediate map for the result map list.
  457. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  458. # Set first input for overlay module.
  459. mapainput = map_i.get_id()
  460. # Loop over temporal related maps and create overlay modules.
  461. tbrelations = map_i.get_temporal_relations()
  462. count = 0
  463. for map_j in (tbrelations['EQUAL']):
  464. # Create overlayed map extent.
  465. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  466. temp_op = '=')
  467. # Stop the loop if no temporal or spatial relationship exist.
  468. if returncode == 0:
  469. break
  470. if count == 0:
  471. # Set map name.
  472. name = map_new.get_id()
  473. else:
  474. # Generate an intermediate map
  475. name = self.generate_map_name()
  476. # Set first input for overlay module.
  477. mapbinput = map_j.get_id()
  478. # Create r.mapcalc expression string for the operation.
  479. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  480. cmdstring = "(%s %s %s)" %(map_new.cmd_list, t[2], mapbinput)
  481. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  482. cmdstring = "(%s %s %s)" %(mapainput, t[2], map_j.cmd_list)
  483. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  484. cmdstring = "(%s %s %s)" %(map_new.cmd_list, t[2], map_j.cmd_list)
  485. else:
  486. cmdstring = "(%s %s %s)" %(mapainput, t[2], mapbinput)
  487. # Conditional append of module command.
  488. map_new.cmd_list = cmdstring
  489. # Set new map name to temporary map name.
  490. mapainput = name
  491. count += 1
  492. # Append map to result map list.
  493. if returncode == 1:
  494. resultlist.append(map_new)
  495. t[0] = resultlist
  496. if self.debug:
  497. for map in resultlist:
  498. print map.cmd_list
  499. def p_arith2_operation_numeric1(self, t):
  500. """
  501. expr : stds ADD number
  502. | expr ADD number
  503. | stds SUB number
  504. | expr SUB number
  505. """
  506. # Check input stds.
  507. maplist = self.check_stds(t[1])
  508. if self.run:
  509. resultlist = []
  510. for map_i in maplist:
  511. mapinput = map_i.get_id()
  512. # Create r.mapcalc expression string for the operation.
  513. if "cmd_list" in dir(map_i):
  514. cmdstring = "(%s %s %s)" %(map_i.cmd_list, t[2], t[3])
  515. else:
  516. cmdstring = "(%s %s %s)" %(mapinput, t[2], t[3])
  517. # Conditional append of module command.
  518. map_i.cmd_list = cmdstring
  519. # Append map to result map list.
  520. resultlist.append(map_i)
  521. t[0] = resultlist
  522. if self.debug:
  523. for map in resultlist:
  524. print map.cmd_list
  525. def p_arith2_operation_numeric2(self, t):
  526. """
  527. expr : number ADD stds
  528. | number ADD expr
  529. | number SUB stds
  530. | number SUB expr
  531. """
  532. # Check input stds.
  533. maplist = self.check_stds(t[3])
  534. if self.run:
  535. resultlist = []
  536. for map_i in maplist:
  537. mapinput = map_i.get_id()
  538. # Create r.mapcalc expression string for the operation.
  539. if "cmd_list" in dir(map_i):
  540. cmdstring = "(%s %s %s)" %(t[1], t[2], map_i.cmd_list)
  541. else:
  542. cmdstring = "(%s %s %s)" %(t[1], t[2], mapinput)
  543. # Conditional append of module command.
  544. map_i.cmd_list = cmdstring
  545. # Append map to result map list.
  546. resultlist.append(map_i)
  547. t[0] = resultlist
  548. if self.debug:
  549. for map in resultlist:
  550. print map.cmd_list
  551. def p_arith1_operation_relation(self, t):
  552. """
  553. expr : stds T_ARITH1_OPERATOR stds
  554. | expr T_ARITH1_OPERATOR stds
  555. | stds T_ARITH1_OPERATOR expr
  556. | expr T_ARITH1_OPERATOR expr
  557. """
  558. # Check input stds.
  559. maplistA = self.check_stds(t[1])
  560. maplistB = self.check_stds(t[3])
  561. relations, temporal, function= self.eval_toperator(t[2])
  562. topolist = self.get_temporal_topo_list(maplistA, maplistB, topolist = relations)
  563. if self.run:
  564. resultlist = []
  565. for map_i in topolist:
  566. # Generate an intermediate map for the result map list.
  567. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  568. # Set first input for overlay module.
  569. mapainput = map_i.get_id()
  570. # Loop over temporal related maps and create overlay modules.
  571. tbrelations = map_i.get_temporal_relations()
  572. count = 0
  573. for topo in relations:
  574. if topo in tbrelations.keys():
  575. for map_j in (tbrelations[topo]):
  576. # Create overlayed map extent.
  577. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  578. temp_op = temporal)
  579. print(returncode)
  580. # Stop the loop if no temporal or spatial relationship exist.
  581. if returncode == 0:
  582. break
  583. if count == 0:
  584. # Set map name.
  585. name = map_new.get_id()
  586. else:
  587. # Generate an intermediate map
  588. name = self.generate_map_name()
  589. map_new.set_id(name + "@" + mapset)
  590. # Set second input for overlay module.
  591. mapbinput = map_j.get_id()
  592. # Create r.mapcalc expression string for the operation.
  593. if "cmd_list" in dir(map_new):
  594. cmdstring = "(%s %s %s)" %(map_new.cmd_list, function, mapbinput)
  595. print('with cmd in a: ' + map_j.get_id())
  596. elif "cmd_list" in dir(map_j):
  597. cmdstring = "(%s %s %s)" %(mapainput, function, map_j.cmd_list)
  598. print('with cmd in b')
  599. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  600. cmdstring = "(%s %s %s)" %(map_new.cmd_list, function, map_j.cmd_list)
  601. print('with cmd in b')
  602. else:
  603. cmdstring = "(%s %s %s)" %(mapainput, function, mapbinput)
  604. print(cmdstring)
  605. # Conditional append of module command.
  606. map_new.cmd_list = cmdstring
  607. # Set new map name to temporary map name.
  608. mapainput = name
  609. count += 1
  610. if returncode == 0:
  611. break
  612. # Append map to result map list.
  613. if returncode == 1:
  614. resultlist.append(map_new)
  615. t[0] = resultlist
  616. if self.debug:
  617. for map in resultlist:
  618. print map.cmd_list
  619. def p_arith2_operation_relation(self, t):
  620. """
  621. expr : stds T_ARITH2_OPERATOR stds
  622. | expr T_ARITH2_OPERATOR stds
  623. | stds T_ARITH2_OPERATOR expr
  624. | expr T_ARITH2_OPERATOR expr
  625. """
  626. # Check input stds.
  627. maplistA = self.check_stds(t[1])
  628. maplistB = self.check_stds(t[3])
  629. relations, temporal, function= self.eval_toperator(t[2])
  630. topolist = self.get_temporal_topo_list(maplistA, maplistB, topolist = relations)
  631. if self.run:
  632. resultlist = []
  633. for map_i in topolist:
  634. # Generate an intermediate map for the result map list.
  635. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  636. # Set first input for overlay module.
  637. mapainput = map_i.get_id()
  638. # Loop over temporal related maps and create overlay modules.
  639. tbrelations = map_i.get_temporal_relations()
  640. count = 0
  641. for topo in relations:
  642. if topo in tbrelations.keys():
  643. for map_j in (tbrelations[topo]):
  644. # Create overlayed map extent.
  645. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  646. temp_op = temporal)
  647. # Stop the loop if no temporal or spatial relationship exist.
  648. if returncode == 0:
  649. break
  650. if count == 0:
  651. # Set map name.
  652. name = map_new.get_id()
  653. else:
  654. # Generate an intermediate map
  655. name = self.generate_map_name()
  656. map_new.set_id(name + "@" + self.mapset)
  657. # Set second input for overlay module.
  658. mapbinput = map_j.get_id()
  659. # Create r.mapcalc expression string for the operation.
  660. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  661. cmdstring = "(%s %s %s)" %(map_new.cmd_list, function, mapbinput)
  662. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  663. cmdstring = "(%s %s %s)" %(mapainput, function, map_j.cmd_list)
  664. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  665. cmdstring = "(%s %s %s)" %(map_new.cmd_list, function, map_j.cmd_list)
  666. else:
  667. cmdstring = "(%s %s %s)" %(mapainput, function, mapbinput)
  668. # Conditional append of module command.
  669. map_new.cmd_list = cmdstring
  670. # Set new map name to temporary map name.
  671. mapainput = name
  672. count += 1
  673. if returncode == 0:
  674. break
  675. # Append map to result map list.
  676. if returncode == 1:
  677. resultlist.append(map_new)
  678. t[0] = resultlist
  679. if self.debug:
  680. for map in resultlist:
  681. print map.cmd_list
  682. def p_mapcalc_function(self, t):
  683. # Supported mapcalc functions.
  684. """
  685. mapcalc_arith : ABS
  686. | LOG
  687. | SQRT
  688. | EXP
  689. | COS
  690. | ACOS
  691. | SIN
  692. | ASIN
  693. | TAN
  694. | DOUBLE
  695. | FLOATEXP
  696. | INTEXP
  697. """
  698. t[0] = t[1]
  699. if self.debug:
  700. for map in resultlist:
  701. print map.cmd_list
  702. def p_mapcalc_operation(self, t):
  703. # Examples:
  704. # sin(A)
  705. # log(B)
  706. """
  707. expr : mapcalc_arith LPAREN stds RPAREN
  708. | mapcalc_arith LPAREN expr RPAREN
  709. """
  710. # Check input stds.
  711. maplist = self.check_stds(t[3])
  712. if self.run:
  713. resultlist = []
  714. for map_i in maplist:
  715. # Create r.mapcalc expression string for the operation.
  716. if "cmd_list" in dir(map_i):
  717. cmdstring = "%s(%s)" %(t[1].lower(), map_i.cmd_list)
  718. else:
  719. cmdstring = "%s(%s)" %(t[1].lower(), map_i.get_id())
  720. # Set new command list for map.
  721. map_i.cmd_list = cmdstring
  722. # Append map with updated command list to result list.
  723. resultlist.append(map_i)
  724. t[0] = resultlist
  725. if self.debug:
  726. for map in resultlist:
  727. print map.cmd_list
  728. def p_s_var_expr(self, t):
  729. # Examples:
  730. # isnull(A)
  731. """
  732. s_var_expr : ISNULL LPAREN stds RPAREN
  733. | ISNULL LPAREN expr RPAREN
  734. """
  735. # Check input stds.
  736. maplist = self.check_stds(t[3])
  737. if self.run:
  738. resultlist = []
  739. for map_i in maplist:
  740. # Create r.mapcalc expression string for the operation.
  741. if "cmd_list" in dir(map_i):
  742. cmdstring = "%s(%s)" %(t[1].lower(), map_i.cmd_list)
  743. else:
  744. cmdstring = "%s(%s)" %(t[1].lower(), map_i.get_id())
  745. # Set new command list for map.
  746. map_i.cmd_list = cmdstring
  747. # Append map with updated command list to result list.
  748. resultlist.append(map_i)
  749. t[0] = resultlist
  750. if self.debug:
  751. for map in resultlist:
  752. print map.cmd_list
  753. def p_s_var_expr_1(self, t):
  754. # Examples:
  755. # isntnull(A)
  756. """
  757. s_var_expr : ISNTNULL LPAREN stds RPAREN
  758. | ISNTNULL LPAREN expr RPAREN
  759. """
  760. # Check input stds.
  761. maplist = self.check_stds(t[3])
  762. if self.run:
  763. resultlist = []
  764. for map_i in maplist:
  765. # Create r.mapcalc expression string for the operation.
  766. if "cmd_list" in dir(map_i):
  767. cmdstring = "!isnull(%s)" %(map_i.cmd_list)
  768. else:
  769. cmdstring = "!isnull(%s)" %(map_i.get_id())
  770. # Set new command list for map.
  771. map_i.cmd_list = cmdstring
  772. # Append map with updated command list to result list.
  773. resultlist.append(map_i)
  774. t[0] = resultlist
  775. if self.debug:
  776. for map in resultlist:
  777. print map.cmd_list
  778. def p_s_var_expr2(self, t):
  779. # Examples:
  780. # A <= 2
  781. """
  782. s_var_expr : stds comp_op number
  783. | expr comp_op number
  784. """
  785. # Check input stds.
  786. maplist = self.check_stds(t[1])
  787. if self.run:
  788. resultlist = []
  789. for map_i in maplist:
  790. # Create r.mapcalc expression string for the operation.
  791. if "cmd_list" in dir(map_i):
  792. cmdstring = "%s %s %s" %(map_i.cmd_list, t[2], t[3])
  793. else:
  794. cmdstring = "%s %s %s" %(map_i.get_id(), t[2], t[3])
  795. # Set new command list for map.
  796. map_i.cmd_list = cmdstring
  797. # Append map with updated command list to result list.
  798. resultlist.append(map_i)
  799. t[0] = resultlist
  800. if self.debug:
  801. for map in resultlist:
  802. print map.cmd_list
  803. def p_s_var_expr3(self, t):
  804. # Examples:
  805. # A <= 2 || B == 10
  806. # A < 3 && A > 1
  807. """
  808. s_var_expr : s_var_expr AND AND s_var_expr
  809. | s_var_expr OR OR s_var_expr
  810. """
  811. # Check input stds.
  812. maplistA = self.check_stds(t[1])
  813. maplistB = self.check_stds(t[4])
  814. topolist = self.get_temporal_topo_list(maplistA, maplistB)
  815. if self.run:
  816. resultlist = []
  817. for map_i in topolist:
  818. # Loop over temporal related maps and create overlay modules.
  819. tbrelations = map_i.get_temporal_relations()
  820. count = 0
  821. for map_j in (tbrelations['EQUAL']):
  822. # Generate an intermediate map for the result map list.
  823. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  824. # Set first input for overlay module.
  825. mapainput = map_i.get_id()
  826. # Create overlayed map extent.
  827. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  828. temp_op = '=')
  829. # Stop the loop if no temporal or spatial relationship exist.
  830. if returncode == 0:
  831. break
  832. if count == 0:
  833. # Set map name.
  834. name = map_new.get_id()
  835. else:
  836. # Generate an intermediate map
  837. name = self.generate_map_name()
  838. # Set first input for overlay module.
  839. mapbinput = map_j.get_id()
  840. # Create r.mapcalc expression string for the operation.
  841. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  842. cmdstring = "%s %s %s" %(map_new.cmd_list, t[2] + t[3], mapbinput)
  843. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  844. cmdstring = "%s %s %s" %(mapainput, t[2] + t[3], map_j.cmd_list)
  845. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  846. cmdstring = "%s %s %s" %(map_new.cmd_list, t[2] + t[3], map_j.cmd_list)
  847. else:
  848. cmdstring = "%s %s %s" %(mapainput, t[2] + t[3], mapbinput)
  849. # Conditional append of module command.
  850. map_new.cmd_list = cmdstring
  851. # Set new map name to temporary map name.
  852. #mapainput = name
  853. count += 1
  854. # Append map to result map list.
  855. if returncode == 1:
  856. resultlist.append(map_new)
  857. t[0] = resultlist
  858. if self.debug:
  859. for map in resultlist:
  860. print map.cmd_list
  861. def p_s_var_expr4(self, t):
  862. # Examples:
  863. # exist(B)
  864. """
  865. s_var_expr : EXIST LPAREN stds RPAREN
  866. | EXIST LPAREN expr RPAREN
  867. """
  868. # Check input stds.
  869. maplist = self.check_stds(t[3])
  870. if self.run:
  871. resultlist = []
  872. for map_i in maplist:
  873. # Create r.mapcalc expression string for the operation.
  874. if "cmd_list" in dir(map_i):
  875. cmdstring = "%s" %(map_i.cmd_list)
  876. else:
  877. cmdstring = "%s" %(map_i.get_id())
  878. # Set new command list for map.
  879. map_i.cmd_list = cmdstring
  880. # Append map with updated command list to result list.
  881. resultlist.append(map_i)
  882. t[0] = resultlist
  883. if self.debug:
  884. for map in resultlist:
  885. print map.cmd_list
  886. def p_s_expr_condition_if(self, t):
  887. # Examples:
  888. # if(s_var_expr, B)
  889. # if(A == 1, B)
  890. """
  891. expr : IF LPAREN s_var_expr COMMA stds RPAREN
  892. | IF LPAREN s_var_expr COMMA expr RPAREN
  893. """
  894. ifmaplist = self.check_stds(t[3])
  895. thenmaplist = self.check_stds(t[5])
  896. topolist = self.get_temporal_topo_list(ifmaplist, thenmaplist)
  897. resultlist = []
  898. for map_i in topolist:
  899. #print(map_i.get_id())
  900. # Loop over temporal related maps and create overlay modules.
  901. tbrelations = map_i.get_temporal_relations()
  902. count = 0
  903. for map_j in (tbrelations['EQUAL']):
  904. # Generate an intermediate map for the result map list.
  905. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  906. # Set first input for overlay module.
  907. mapainput = map_i.get_id()
  908. # Create overlayed map extent.
  909. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  910. temp_op = '=')
  911. # Stop the loop if no temporal or spatial relationship exist.
  912. if returncode == 0:
  913. break
  914. if count == 0:
  915. # Set map name.
  916. name = map_new.get_id()
  917. else:
  918. # Generate an intermediate map
  919. name = self.generate_map_name()
  920. # Set first input for overlay module.
  921. mapbinput = map_j.get_id()
  922. # Create r.mapcalc expression string for the operation.
  923. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  924. cmdstring = "if(%s,%s)" %(map_new.cmd_list, mapbinput)
  925. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  926. cmdstring = "if(%s,%s)" %(mapainput, map_j.cmd_list)
  927. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  928. cmdstring = "if(%s,%s)" %(map_new.cmd_list, map_j.cmd_list)
  929. else:
  930. cmdstring = "if(%s,%s)" %(mapainput, mapbinput)
  931. # Conditional append of module command.
  932. map_new.cmd_list = cmdstring
  933. # Set new map name to temporary map name.
  934. #mapainput = name
  935. count += 1
  936. # Append map to result map list.
  937. if returncode == 1:
  938. resultlist.append(map_new)
  939. t[0] = resultlist
  940. if self.debug:
  941. for map in resultlist:
  942. print map.cmd_list
  943. def p_s_numeric_condition_if(self, t):
  944. # Examples:
  945. # if(s_var_expr, 1)
  946. # if(A == 5, 10)
  947. """
  948. expr : IF LPAREN s_var_expr COMMA number RPAREN
  949. | IF LPAREN s_var_expr COMMA NULL LPAREN RPAREN RPAREN
  950. """
  951. ifmaplist = self.check_stds(t[3])
  952. resultlist = []
  953. # Select input for r.mapcalc expression based on length of PLY object.
  954. if len(t) == 7:
  955. numinput = t[5]
  956. elif len(t) == 9:
  957. numinput = self.check_null(t[5])
  958. # Iterate over condition map list.
  959. for map_i in ifmaplist:
  960. mapinput = map_i.get_id()
  961. # Create r.mapcalc expression string for the operation.
  962. if "cmd_list" in dir(map_i):
  963. cmdstring = "if(%s,%s)" %(map_i.cmd_list, numinput)
  964. else:
  965. cmdstring = "if(%s,%s)" %(mapinput, numinput)
  966. # Conditional append of module command.
  967. map_i.cmd_list = cmdstring
  968. # Append map to result map list.
  969. resultlist.append(map_i)
  970. t[0] = resultlist
  971. if self.debug:
  972. for map in resultlist:
  973. print map.cmd_list
  974. def p_s_expr_condition_if_relation(self, t):
  975. # Examples:
  976. # if({equal||during}, s_var_expr, A)
  977. """
  978. expr : IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA stds RPAREN
  979. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA expr RPAREN
  980. """
  981. relations, temporal, function= self.eval_toperator(t[3])
  982. ifmaplist = self.check_stds(t[5])
  983. thenmaplist = self.check_stds(t[7])
  984. topolist = self.get_temporal_topo_list(ifmaplist, thenmaplist,
  985. topolist = relations)
  986. resultlist = []
  987. for map_i in topolist:
  988. #print(map_i.get_id())
  989. # Loop over temporal related maps.
  990. tbrelations = map_i.get_temporal_relations()
  991. count = 0
  992. for topo in relations:
  993. if topo in tbrelations.keys():
  994. for map_j in (tbrelations[topo]):
  995. # Generate an intermediate map for the result map list.
  996. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  997. # Set first input for overlay module.
  998. mapainput = map_i.get_id()
  999. # Create overlayed map extent.
  1000. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  1001. temp_op = '=')
  1002. # Stop the loop if no temporal or spatial relationship exist.
  1003. if returncode == 0:
  1004. break
  1005. if count == 0:
  1006. # Set map name.
  1007. name = map_new.get_id()
  1008. else:
  1009. # Generate an intermediate map
  1010. name = self.generate_map_name()
  1011. # Set first input for overlay module.
  1012. mapbinput = map_j.get_id()
  1013. #print(mapbinput)
  1014. #mapbinput = mapbinput.split('@')[0]
  1015. # Create r.mapcalc expression string for the operation.
  1016. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  1017. cmdstring = "if(%s,%s)" %(map_new.cmd_list, mapbinput)
  1018. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  1019. cmdstring = "if(%s,%s)" %(mapainput, map_j.cmd_list)
  1020. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  1021. cmdstring = "if(%s,%s)" %(map_new.cmd_list, map_j.cmd_list)
  1022. else:
  1023. cmdstring = "if(%s,%s)" %(mapainput, mapbinput)
  1024. # Conditional append of module command.
  1025. map_new.cmd_list = cmdstring
  1026. # Set new map name to temporary map name.
  1027. #mapainput = name
  1028. count += 1
  1029. # Append map to result map list.
  1030. if returncode == 1:
  1031. resultlist.append(map_new)
  1032. t[0] = resultlist
  1033. if self.debug:
  1034. for map in resultlist:
  1035. print map.cmd_list
  1036. def p_s_expr_condition_elif(self, t):
  1037. # Examples:
  1038. # if(s_var_expr, A, B)
  1039. """
  1040. expr : IF LPAREN s_var_expr COMMA stds COMMA stds RPAREN
  1041. | IF LPAREN s_var_expr COMMA stds COMMA expr RPAREN
  1042. | IF LPAREN s_var_expr COMMA expr COMMA stds RPAREN
  1043. | IF LPAREN s_var_expr COMMA expr COMMA expr RPAREN
  1044. """
  1045. ifmaplist = self.check_stds(t[3])
  1046. thenmaplist = self.check_stds(t[5])
  1047. elsemaplist = self.check_stds(t[7])
  1048. resultlist = []
  1049. thendict = {}
  1050. elsedict = {}
  1051. # Get topologies for the appropriate conclusion term.
  1052. thentopolist = self.get_temporal_topo_list(ifmaplist, thenmaplist)
  1053. # Fill dictionaries with related maps for both conclusion terms.
  1054. for map_i in thentopolist:
  1055. thenrelations = map_i.get_temporal_relations()
  1056. relationmaps = thenrelations['EQUAL']
  1057. thendict[map_i.get_id()] = relationmaps
  1058. # Get topologies for the alternative conclusion term.
  1059. elsetopolist = self.get_temporal_topo_list(ifmaplist, elsemaplist)
  1060. for map_i in elsetopolist:
  1061. elserelations = map_i.get_temporal_relations()
  1062. relationmaps = elserelations['EQUAL']
  1063. elsedict[map_i.get_id()] = relationmaps
  1064. # Loop through conditional map list.
  1065. for map_i in ifmaplist:
  1066. if map_i.get_id() in thendict.keys():
  1067. thenlist = thendict[map_i.get_id()]
  1068. else:
  1069. thenlist = []
  1070. if map_i.get_id() in elsedict.keys():
  1071. elselist = elsedict[map_i.get_id()]
  1072. else:
  1073. elselist = []
  1074. # Set iteration amount to maximal or minimum number of related
  1075. # conclusion maps, depending on null map creation flag.
  1076. if self.null:
  1077. iternum = max(len(thenlist), len(elselist))
  1078. else:
  1079. iternum = min(len(thenlist), len(elselist))
  1080. # Calculate difference in conclusion lengths.
  1081. iterthen = iternum - len(thenlist)
  1082. iterelse = iternum - len(elselist)
  1083. # Extend null maps to the list to get conclusions with same length.
  1084. if iterthen != 0:
  1085. for i in range(iterthen):
  1086. thenlist.extend(['null()'])
  1087. if iterelse != 0:
  1088. for i in range(iterelse):
  1089. elselist.extend(['null()'])
  1090. # Combine the conclusions in a paired list.
  1091. conclusionlist = zip(thenlist, elselist)
  1092. for i in range(iternum):
  1093. conclusionmaps = conclusionlist[i]
  1094. # Generate an intermediate map for the result map list.
  1095. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  1096. # Set first input for overlay module.
  1097. mapifinput = map_i.get_id()
  1098. # Get conclusion maps.
  1099. map_then = conclusionmaps[0]
  1100. map_else = conclusionmaps[1]
  1101. # Check if conclusions are map objects.
  1102. if map_then != 'null()':
  1103. # Create overlayed map extent.
  1104. returncode = self.overlay_map_extent(map_new, map_then, 'and', \
  1105. temp_op = '=')
  1106. maptheninput = map_then.get_id()
  1107. # Continue the loop if no temporal or spatial relationship exist.
  1108. if returncode == 0:
  1109. continue
  1110. else:
  1111. maptheninput = 'null()'
  1112. # Check if conclusions are map objects.
  1113. if map_else != 'null()':
  1114. # Create overlayed map extent.
  1115. returncode = self.overlay_map_extent(map_new, map_else, 'and', \
  1116. temp_op = '=')
  1117. mapelseinput = map_else.get_id()
  1118. # Continue the loop if no temporal or spatial relationship exist.
  1119. if returncode == 0:
  1120. continue
  1121. else:
  1122. mapelseinput = 'null()'
  1123. #if map_then != 'null()' and map_else != 'null()':
  1124. # Create r.mapcalc expression string for the operation.
  1125. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_then) \
  1126. and "cmd_list" not in dir(map_else):
  1127. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, maptheninput,
  1128. mapelseinput)
  1129. elif "cmd_list" in dir(map_new) and "cmd_list" in dir(map_then) \
  1130. and "cmd_list" not in dir(map_else):
  1131. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, map_then.cmd_list,
  1132. mapelseinput)
  1133. elif "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_then) \
  1134. and "cmd_list" in dir(map_else):
  1135. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, maptheninput,
  1136. map_else.cmd_list)
  1137. elif "cmd_list" in dir(map_new) and "cmd_list" in dir(map_then) \
  1138. and "cmd_list" in dir(map_else):
  1139. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, map_then.cmd_list,
  1140. map_else.cmd_list)
  1141. elif "cmd_list" not in dir(map_new) and "cmd_list" in dir(map_then) \
  1142. and "cmd_list" not in dir(map_else):
  1143. cmdstring = "if(%s, %s, %s)" %(mapifinput, map_then.cmd_list,
  1144. mapelseinput)
  1145. elif "cmd_list" not in dir(map_new) and "cmd_list" not in dir(map_then) \
  1146. and "cmd_list" in dir(map_else):
  1147. cmdstring = "if(%s, %s, %s)" %(mapifinput, maptheninput,
  1148. map_else.cmd_list)
  1149. elif "cmd_list" not in dir(map_new) and "cmd_list" in dir(map_then) \
  1150. and "cmd_list" in dir(map_else):
  1151. cmdstring = "if(%s, %s, %s)" %(mapifinput, map_then.cmd_list,
  1152. map_else.cmd_list)
  1153. else:
  1154. cmdstring = "if(%s, %s, %s)" %(mapifinput, maptheninput,
  1155. mapelseinput)
  1156. # Conditional append of module command.
  1157. map_new.cmd_list = cmdstring
  1158. # Append map to result map list.
  1159. if returncode == 1:
  1160. resultlist.append(map_new)
  1161. t[0] = resultlist
  1162. if self.debug:
  1163. for map in resultlist:
  1164. print map.cmd_list
  1165. def p_s_numeric_condition_elif(self, t):
  1166. # Examples:
  1167. # if(s_var_expr, 1, 2)
  1168. # if(A == 5, 10, 0)
  1169. """
  1170. expr : IF LPAREN s_var_expr COMMA number COMMA number RPAREN
  1171. | IF LPAREN s_var_expr COMMA NULL LPAREN RPAREN COMMA number RPAREN
  1172. | IF LPAREN s_var_expr COMMA number COMMA NULL LPAREN RPAREN RPAREN
  1173. | IF LPAREN s_var_expr COMMA NULL LPAREN RPAREN COMMA NULL LPAREN RPAREN RPAREN
  1174. """
  1175. ifmaplist = self.check_stds(t[3])
  1176. resultlist = []
  1177. # Select input for r.mapcalc expression based on length of PLY object.
  1178. if len(t) == 9:
  1179. numthen = t[5]
  1180. numelse = t[7]
  1181. elif len(t) == 11 and t[6] == '(':
  1182. numthen = t[5] + t[6] + t[7]
  1183. numelse = t[9]
  1184. elif len(t) == 11 and t[6] == ',':
  1185. numthen = t[5]
  1186. numelse = t[7] + t[8] + t[9]
  1187. elif len(t) == 13:
  1188. numthen = t[5] + t[6] + t[7]
  1189. numelse = t[9] + t[10] + t[11]
  1190. # Iterate over condition map list.
  1191. for map_i in ifmaplist:
  1192. mapinput = map_i.get_id()
  1193. # Create r.mapcalc expression string for the operation.
  1194. if "cmd_list" in dir(map_i):
  1195. cmdstring = "if(%s, %s, %s)" %(map_i.cmd_list, numthen, numelse)
  1196. else:
  1197. cmdstring = "if(%s, %s, %s)" %(mapinput, numthen, numelse)
  1198. # Conditional append of module command.
  1199. map_i.cmd_list = cmdstring
  1200. # Append map to result map list.
  1201. resultlist.append(map_i)
  1202. t[0] = resultlist
  1203. if self.debug:
  1204. for map in resultlist:
  1205. print map.cmd_list
  1206. def p_s_numeric_expr_condition_elif(self, t):
  1207. # Examples:
  1208. # if(s_var_expr, 1, A)
  1209. # if(A == 5 && C > 5, A, null())
  1210. """
  1211. expr : IF LPAREN s_var_expr COMMA number COMMA stds RPAREN
  1212. | IF LPAREN s_var_expr COMMA NULL LPAREN RPAREN COMMA stds RPAREN
  1213. | IF LPAREN s_var_expr COMMA number COMMA expr RPAREN
  1214. | IF LPAREN s_var_expr COMMA NULL LPAREN RPAREN COMMA expr RPAREN
  1215. | IF LPAREN s_var_expr COMMA stds COMMA number RPAREN
  1216. | IF LPAREN s_var_expr COMMA stds COMMA NULL LPAREN RPAREN RPAREN
  1217. | IF LPAREN s_var_expr COMMA expr COMMA number RPAREN
  1218. | IF LPAREN s_var_expr COMMA expr COMMA NULL LPAREN RPAREN RPAREN
  1219. """
  1220. ifmaplist = self.check_stds(t[3])
  1221. resultlist = []
  1222. thenmaplist = []
  1223. numthen = ''
  1224. elsemaplist = []
  1225. numelse = ''
  1226. # Select input for r.mapcalc expression based on length of PLY object.
  1227. if len(t) == 9:
  1228. try:
  1229. thenmaplist = self.check_stds(t[5])
  1230. except:
  1231. numthen = self.check_null(t[5])
  1232. try:
  1233. elsemaplist = self.check_stds(t[7])
  1234. except:
  1235. numelse = self.check_null(t[7])
  1236. elif len(t) == 11:
  1237. try:
  1238. thenmaplist = self.check_stds(t[5])
  1239. except:
  1240. numthen = self.check_null(t[5])
  1241. try:
  1242. elsemaplist = self.check_stds(t[9])
  1243. except:
  1244. numelse = self.check_null(t[7])
  1245. if thenmaplist != []:
  1246. topolist = self.get_temporal_topo_list(ifmaplist, thenmaplist)
  1247. elif elsemaplist != []:
  1248. topolist = self.get_temporal_topo_list(ifmaplist, elsemaplist)
  1249. if numthen != '':
  1250. numinput = numthen
  1251. elif numelse != '':
  1252. numinput = numelse
  1253. # Iterate over condition map lists with temporal relations.
  1254. for map_i in topolist:
  1255. # Loop over temporal related maps and create overlay modules.
  1256. tbrelations = map_i.get_temporal_relations()
  1257. count = 0
  1258. for map_j in (tbrelations['EQUAL']):
  1259. # Generate an intermediate map for the result map list.
  1260. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  1261. # Set first input for overlay module.
  1262. mapainput = map_i.get_id()
  1263. # Create overlayed map extent.
  1264. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  1265. temp_op = '=')
  1266. # Stop the loop if no temporal or spatial relationship exist.
  1267. if returncode == 0:
  1268. break
  1269. if count == 0:
  1270. # Set map name.
  1271. name = map_new.get_id()
  1272. else:
  1273. # Generate an intermediate map
  1274. name = self.generate_map_name()
  1275. # Set first input for overlay module.
  1276. mapbinput = map_j.get_id()
  1277. # Create r.mapcalc expression string for the operation.
  1278. if thenmaplist != []:
  1279. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  1280. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, mapbinput, \
  1281. numinput)
  1282. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  1283. cmdstring = "if(%s,%s,%s)" %(mapainput, map_j.cmd_list, \
  1284. numinput)
  1285. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  1286. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, map_j.cmd_list, \
  1287. numinput)
  1288. else:
  1289. cmdstring = "if(%s,%s,%s)" %(mapainput, mapbinput, numinput)
  1290. if elsemaplist != []:
  1291. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  1292. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, numinput, \
  1293. mapbinput)
  1294. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  1295. cmdstring = "if(%s,%s,%s)" %(mapainput, numinput, \
  1296. map_j.cmd_list)
  1297. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  1298. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, numinput, \
  1299. map_j.cmd_list)
  1300. else:
  1301. cmdstring = "if(%s,%s,%s)" %(mapainput, numinput, mapbinput)
  1302. # Conditional append of module command.
  1303. map_new.cmd_list = cmdstring
  1304. # Set new map name to temporary map name.
  1305. #mapainput = name
  1306. count += 1
  1307. # Append map to result map list.
  1308. if returncode == 1:
  1309. resultlist.append(map_new)
  1310. t[0] = resultlist
  1311. if self.debug:
  1312. for map in resultlist:
  1313. print map.cmd_list
  1314. def p_s_numeric_expr_condition_elif_relation(self, t):
  1315. # Examples:
  1316. # if({during},s_var_expr, 1, A)
  1317. # if({during}, A == 5, A, null())
  1318. """
  1319. expr : IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA number COMMA stds RPAREN
  1320. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA NULL LPAREN RPAREN COMMA stds RPAREN
  1321. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA number COMMA expr RPAREN
  1322. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA NULL LPAREN RPAREN COMMA expr RPAREN
  1323. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA stds COMMA number RPAREN
  1324. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA stds COMMA NULL LPAREN RPAREN RPAREN
  1325. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA expr COMMA number RPAREN
  1326. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA expr COMMA NULL LPAREN RPAREN RPAREN
  1327. """
  1328. relations, temporal, function= self.eval_toperator(t[3])
  1329. ifmaplist = self.check_stds(t[5])
  1330. resultlist = []
  1331. thenmaplist = []
  1332. numthen = ''
  1333. elsemaplist = []
  1334. numelse = ''
  1335. # Select input for r.mapcalc expression based on length of PLY object.
  1336. if len(t) == 11:
  1337. try:
  1338. thenmaplist = self.check_stds(t[7])
  1339. except:
  1340. numthen = self.check_null(t[7])
  1341. try:
  1342. elsemaplist = self.check_stds(t[9])
  1343. except:
  1344. numelse = self.check_null(t[9])
  1345. elif len(t) == 13:
  1346. try:
  1347. thenmaplist = self.check_stds(t[7])
  1348. except:
  1349. numthen = self.check_null(t[7])
  1350. try:
  1351. elsemaplist = self.check_stds(t[11])
  1352. except:
  1353. numelse = self.check_null(t[9])
  1354. if thenmaplist != []:
  1355. topolist = self.get_temporal_topo_list(ifmaplist, thenmaplist, \
  1356. topolist = relations)
  1357. elif elsemaplist != []:
  1358. topolist = self.get_temporal_topo_list(ifmaplist, elsemaplist, \
  1359. topolist = relations)
  1360. if numthen != '':
  1361. numinput = numthen
  1362. elif numelse != '':
  1363. numinput = numelse
  1364. # Iterate over condition map lists with temporal relations.
  1365. for map_i in topolist:
  1366. # Loop over temporal related maps and create overlay modules.
  1367. tbrelations = map_i.get_temporal_relations()
  1368. count = 0
  1369. for topo in relations:
  1370. if topo in tbrelations.keys():
  1371. for map_j in (tbrelations[topo]):
  1372. # Generate an intermediate map for the result map list.
  1373. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  1374. # Set first input for overlay module.
  1375. mapainput = map_i.get_id()
  1376. # Create overlayed map extent.
  1377. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  1378. temp_op = '=')
  1379. # Stop the loop if no temporal or spatial relationship exist.
  1380. if returncode == 0:
  1381. break
  1382. if count == 0:
  1383. # Set map name.
  1384. name = map_new.get_id()
  1385. else:
  1386. # Generate an intermediate map
  1387. name = self.generate_map_name()
  1388. # Set first input for overlay module.
  1389. mapbinput = map_j.get_id()
  1390. # Create r.mapcalc expression string for the operation.
  1391. if thenmaplist != []:
  1392. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  1393. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, mapbinput, \
  1394. numinput)
  1395. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  1396. cmdstring = "if(%s,%s,%s)" %(mapainput, map_j.cmd_list, \
  1397. numinput)
  1398. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  1399. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, map_j.cmd_list, \
  1400. numinput)
  1401. else:
  1402. cmdstring = "if(%s,%s,%s)" %(mapainput, mapbinput, numinput)
  1403. if elsemaplist != []:
  1404. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  1405. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, numinput, \
  1406. mapbinput)
  1407. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  1408. cmdstring = "if(%s,%s,%s)" %(mapainput, numinput, \
  1409. map_j.cmd_list)
  1410. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  1411. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, numinput, \
  1412. map_j.cmd_list)
  1413. else:
  1414. cmdstring = "if(%s,%s,%s)" %(mapainput, numinput, mapbinput)
  1415. # Conditional append of module command.
  1416. map_new.cmd_list = cmdstring
  1417. # Set new map name to temporary map name.
  1418. #mapainput = name
  1419. count += 1
  1420. # Append map to result map list.
  1421. if returncode == 1:
  1422. resultlist.append(map_new)
  1423. t[0] = resultlist
  1424. if self.debug:
  1425. for map in resultlist:
  1426. print map.cmd_list
  1427. def p_s_expr_condition_elif_relation(self, t):
  1428. # Examples:
  1429. # if({equal||during}, s_var_expr, A, B)
  1430. """
  1431. expr : IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA stds COMMA stds RPAREN
  1432. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA stds COMMA expr RPAREN
  1433. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA expr COMMA stds RPAREN
  1434. | IF LPAREN T_REL_OPERATOR COMMA s_var_expr COMMA expr COMMA expr RPAREN
  1435. """
  1436. relations, temporal, function= self.eval_toperator(t[3])
  1437. ifmaplist = self.check_stds(t[5])
  1438. thenmaplist = self.check_stds(t[7])
  1439. elsemaplist = self.check_stds(t[9])
  1440. resultlist = []
  1441. thendict = {}
  1442. elsedict = {}
  1443. # Get topologies for the appropriate conclusion term.
  1444. thentopolist = self.get_temporal_topo_list(ifmaplist, thenmaplist, \
  1445. topolist = relations)
  1446. # Fill dictionaries with related maps for both conclusion terms.
  1447. for map_i in thentopolist:
  1448. thenrelations = map_i.get_temporal_relations()
  1449. relationmaps = []
  1450. for topo in relations:
  1451. if topo in thenrelations.keys():
  1452. relationmaps = relationmaps + thenrelations[topo]
  1453. thendict[map_i.get_id()] = relationmaps
  1454. # Get topologies for the alternative conclusion term.
  1455. elsetopolist = self.get_temporal_topo_list(ifmaplist, elsemaplist, \
  1456. topolist = relations)
  1457. for map_i in elsetopolist:
  1458. elserelations = map_i.get_temporal_relations()
  1459. relationmaps = []
  1460. for topo in relations:
  1461. if topo in elserelations.keys():
  1462. relationmaps = relationmaps + elserelations[topo]
  1463. elsedict[map_i.get_id()] = relationmaps
  1464. # Loop trough conditional map list.
  1465. for map_i in ifmaplist:
  1466. if map_i.get_id() in thendict.keys():
  1467. thenlist = thendict[map_i.get_id()]
  1468. else:
  1469. thenlist = []
  1470. if map_i.get_id() in elsedict.keys():
  1471. elselist = elsedict[map_i.get_id()]
  1472. else:
  1473. elselist = []
  1474. # Set iteration amount to maximal or minimum number of related
  1475. # conclusion maps, depending on null map creation flag.
  1476. if self.null:
  1477. iternum = max(len(thenlist), len(elselist))
  1478. else:
  1479. iternum = min(len(thenlist), len(elselist))
  1480. # Calculate difference in conclusion lengths.
  1481. iterthen = iternum - len(thenlist)
  1482. iterelse = iternum - len(elselist)
  1483. # Extend null maps to the list to get conclusions with same length.
  1484. if iterthen != 0:
  1485. for i in range(iterthen):
  1486. thenlist.extend(['null()'])
  1487. if iterelse != 0:
  1488. for i in range(iterelse):
  1489. elselist.extend(['null()'])
  1490. # Combine the conclusions in a paired list.
  1491. conclusionlist = zip(thenlist, elselist)
  1492. for i in range(iternum):
  1493. conclusionmaps = conclusionlist[i]
  1494. # Generate an intermediate map for the result map list.
  1495. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  1496. # Set first input for overlay module.
  1497. mapifinput = map_i.get_id()
  1498. # Get conclusion maps.
  1499. map_then = conclusionmaps[0]
  1500. map_else = conclusionmaps[1]
  1501. # Check if conclusions are map objects.
  1502. if map_then != 'null()':
  1503. # Create overlayed map extent.
  1504. returncode = self.overlay_map_extent(map_new, map_then, 'and', \
  1505. temp_op = '=')
  1506. maptheninput = map_then.get_id()
  1507. # Continue the loop if no temporal or spatial relationship exist.
  1508. if returncode == 0:
  1509. continue
  1510. else:
  1511. maptheninput = 'null()'
  1512. # Check if conclusions are map objects.
  1513. if map_else != 'null()':
  1514. # Create overlayed map extent.
  1515. returncode = self.overlay_map_extent(map_new, map_else, 'and', \
  1516. temp_op = '=')
  1517. mapelseinput = map_else.get_id()
  1518. # Continue the loop if no temporal or spatial relationship exist.
  1519. if returncode == 0:
  1520. continue
  1521. else:
  1522. mapelseinput = 'null()'
  1523. #if map_then != 'null()' and map_else != 'null()':
  1524. # Create r.mapcalc expression string for the operation.
  1525. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_then) \
  1526. and "cmd_list" not in dir(map_else):
  1527. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, maptheninput,
  1528. mapelseinput)
  1529. elif "cmd_list" in dir(map_new) and "cmd_list" in dir(map_then) \
  1530. and "cmd_list" not in dir(map_else):
  1531. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, map_then.cmd_list,
  1532. mapelseinput)
  1533. elif "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_then) \
  1534. and "cmd_list" in dir(map_else):
  1535. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, maptheninput,
  1536. map_else.cmd_list)
  1537. elif "cmd_list" in dir(map_new) and "cmd_list" in dir(map_then) \
  1538. and "cmd_list" in dir(map_else):
  1539. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, map_then.cmd_list,
  1540. map_else.cmd_list)
  1541. elif "cmd_list" not in dir(map_new) and "cmd_list" in dir(map_then) \
  1542. and "cmd_list" not in dir(map_else):
  1543. cmdstring = "if(%s, %s, %s)" %(mapifinput, map_then.cmd_list,
  1544. mapelseinput)
  1545. elif "cmd_list" not in dir(map_new) and "cmd_list" not in dir(map_then) \
  1546. and "cmd_list" in dir(map_else):
  1547. cmdstring = "if(%s, %s, %s)" %(mapifinput, maptheninput,
  1548. map_else.cmd_list)
  1549. elif "cmd_list" not in dir(map_new) and "cmd_list" in dir(map_then) \
  1550. and "cmd_list" in dir(map_else):
  1551. cmdstring = "if(%s, %s, %s)" %(mapifinput, map_then.cmd_list,
  1552. map_else.cmd_list)
  1553. else:
  1554. cmdstring = "if(%s, %s, %s)" %(mapifinput, maptheninput,
  1555. mapelseinput)
  1556. # Conditional append of module command.
  1557. map_new.cmd_list = cmdstring
  1558. # Append map to result map list.
  1559. if returncode == 1:
  1560. resultlist.append(map_new)
  1561. t[0] = resultlist
  1562. if self.debug:
  1563. for map in resultlist:
  1564. print map.cmd_list
  1565. def p_ts_var_expr1(self, t):
  1566. # Combination of spatial and temporal conditional expressions.
  1567. # Examples:
  1568. # A <= 2 || start_date <= 2013-01-01
  1569. # end_date > 2013-01-15 && A > 10
  1570. # IMPORTANT: Only the intersection of map lists in conditionals are
  1571. # exported.
  1572. """
  1573. ts_var_expr : s_var_expr AND AND t_var_expr
  1574. | t_var_expr AND AND s_var_expr
  1575. | t_var_expr OR OR s_var_expr
  1576. | s_var_expr OR OR t_var_expr
  1577. | ts_var_expr AND AND s_var_expr
  1578. | ts_var_expr AND AND t_var_expr
  1579. | ts_var_expr OR OR s_var_expr
  1580. | ts_var_expr OR OR t_var_expr
  1581. | s_var_expr AND AND ts_var_expr
  1582. | t_var_expr AND AND ts_var_expr
  1583. | s_var_expr OR OR ts_var_expr
  1584. | t_var_expr OR OR ts_var_expr
  1585. """
  1586. # Check whether inputs are map lists or global temporal variables and
  1587. # store each in separate lists.
  1588. ts_var_dict = {"temporal" : [], "spatial" : []}
  1589. temporal_list = []
  1590. spatial_list = []
  1591. operator = t[2] + t[3]
  1592. temporalop = GlobalTemporalVar()
  1593. temporalop.relationop = operator
  1594. temporalop.topology.append("EQUAL")
  1595. if isinstance(t[1], dict) and "spatial" in t[1]:
  1596. temporal_list = temporal_list + t[1]["temporal"]
  1597. spatial_list.append(t[1]["spatial"])
  1598. elif isinstance(t[1], list):
  1599. if all([isinstance(i, ta.GlobalTemporalVar) for i in t[1]]):
  1600. temporal_list = temporal_list + t[1]
  1601. else:
  1602. tsexprA = self.check_stds(t[1])
  1603. spatial_list.append(tsexprA)
  1604. elif isinstance(t[1], ta.GlobalTemporalVar):
  1605. temporal_list.append(t[1])
  1606. if temporal_list != [] and \
  1607. isinstance(t[4], ta.GlobalTemporalVar):
  1608. temporal_list.append(temporalop)
  1609. if temporal_list != [] and \
  1610. isinstance(t[4], list) and \
  1611. all([isinstance(i, ta.GlobalTemporalVar) for i in t[4]]):
  1612. temporal_list.append(temporalop)
  1613. if isinstance(t[4], dict) and "spatial" in t[4]:
  1614. temporal_list = temporal_list + t[4]["temporal"]
  1615. spatial_list.append(t[4]["spatial"])
  1616. elif isinstance(t[4], list):
  1617. if all([isinstance(i, ta.GlobalTemporalVar) for i in t[4]]):
  1618. temporal_list = temporal_list + t[4]
  1619. else:
  1620. tsexprB = self.check_stds(t[4])
  1621. spatial_list.append(tsexprB)
  1622. elif isinstance(t[4], ta.GlobalTemporalVar):
  1623. temporal_list.append(t[4])
  1624. ts_var_dict["temporal"] = temporal_list
  1625. # Condition for two map lists in spatio temporal expression.
  1626. if len(spatial_list) == 2:
  1627. # Build topology for both map lists in spatio temporal expression.
  1628. topolist = self.get_temporal_topo_list(spatial_list[0], spatial_list[1])
  1629. resultlist = []
  1630. for map_i in topolist:
  1631. # Loop over temporal related maps and create overlay modules.
  1632. tbrelations = map_i.get_temporal_relations()
  1633. count = 0
  1634. for map_j in (tbrelations['EQUAL']):
  1635. # Generate an intermediate map for the result map list.
  1636. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  1637. # Set first input for overlay module.
  1638. mapainput = map_i.get_id()
  1639. # Create overlayed map extent.
  1640. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  1641. temp_op = '=')
  1642. # Stop the loop if no temporal or spatial relationship exist.
  1643. if returncode == 0:
  1644. break
  1645. if count == 0:
  1646. # Set map name.
  1647. name = map_new.get_id()
  1648. else:
  1649. # Generate an intermediate map
  1650. name = self.generate_map_name()
  1651. # Set first input for overlay module.
  1652. mapbinput = map_j.get_id()
  1653. # Create r.mapcalc expression string for the operation.
  1654. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  1655. cmdstring = "%s %s %s" %(map_new.cmd_list, operator, mapbinput)
  1656. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  1657. cmdstring = "%s %s %s" %(mapainput, operator, map_j.cmd_list)
  1658. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  1659. cmdstring = "%s %s %s" %(map_new.cmd_list, operator, map_j.cmd_list)
  1660. else:
  1661. cmdstring = "%s %s %s" %(mapainput, operator, mapbinput)
  1662. # Conditional append of module command.
  1663. map_new.cmd_list = cmdstring
  1664. # Set new map name to temporary map name.
  1665. #mapainput = name
  1666. count += 1
  1667. # Append map to result map list.
  1668. if returncode == 1:
  1669. resultlist.append(map_new)
  1670. # Return dictionary with spatial map list of temporal
  1671. # intersected maps and temporal expression in list form.
  1672. ts_var_dict["spatial"] = resultlist
  1673. # Condition for only one map list in spatio temporal expression.
  1674. elif len(spatial_list) == 1:
  1675. ts_var_dict["spatial"] = spatial_list[0]
  1676. t[0] = ts_var_dict
  1677. def p_ts_expr_condition_if(self, t):
  1678. # Examples:
  1679. # if(ts_var_expr, A)
  1680. # if(start_year == 2013 || B != 5, A)
  1681. """
  1682. expr : IF LPAREN ts_var_expr COMMA stds RPAREN
  1683. | IF LPAREN ts_var_expr COMMA expr RPAREN
  1684. """
  1685. ts_var_dict = t[3]
  1686. spatialcond = ts_var_dict["spatial"]
  1687. # Extract spatial map list from condition.
  1688. ifmaplist = self.check_stds(spatialcond)
  1689. thenmaplist = self.check_stds(t[5])
  1690. topolist = self.get_temporal_topo_list(ifmaplist, thenmaplist)
  1691. resultlist = []
  1692. resultspatial = []
  1693. for map_i in topolist:
  1694. #print(map_i.get_id())
  1695. # Loop over temporal related maps and create overlay modules.
  1696. tbrelations = map_i.get_temporal_relations()
  1697. count = 0
  1698. for map_j in (tbrelations['EQUAL']):
  1699. # Generate an intermediate map for the result map list.
  1700. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  1701. # Set first input for overlay module.
  1702. mapainput = map_i.get_id()
  1703. # Create overlayed map extent.
  1704. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  1705. temp_op = '=')
  1706. # Stop the loop if no temporal or spatial relationship exist.
  1707. if returncode == 0:
  1708. break
  1709. if count == 0:
  1710. # Set map name.
  1711. name = map_new.get_id()
  1712. else:
  1713. # Generate an intermediate map
  1714. name = self.generate_map_name()
  1715. # Set first input for overlay module.
  1716. mapbinput = map_j.get_id()
  1717. # Create r.mapcalc expression string for the operation.
  1718. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  1719. cmdstring = "if(%s,%s)" %(map_new.cmd_list, mapbinput)
  1720. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  1721. cmdstring = "if(%s,%s)" %(mapainput, map_j.cmd_list)
  1722. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  1723. cmdstring = "if(%s,%s)" %(map_new.cmd_list, map_j.cmd_list)
  1724. else:
  1725. cmdstring = "if(%s,%s)" %(mapainput, mapbinput)
  1726. # Conditional append of module command.
  1727. map_new.cmd_list = cmdstring
  1728. # Set new map name to temporary map name.
  1729. #mapainput = name
  1730. count += 1
  1731. # Append map to result map list.
  1732. if returncode == 1:
  1733. resultspatial.append(map_new)
  1734. # Evaluate temporal statements in spatio temporal condition.
  1735. #if len(ts_var_dict["temporal"]) == 1:
  1736. #temporalcond = ts_var_dict["temporal"][0]
  1737. #else:
  1738. temporalcond = ts_var_dict["temporal"]
  1739. resultspatial = self.check_stds(resultspatial)
  1740. thencond = self.build_condition_list(temporalcond, resultspatial)
  1741. thenresult = self.eval_condition_list(thencond)
  1742. # Clear the map list.
  1743. resultlist = self.check_stds(thenresult, clear = True)
  1744. t[0] = resultlist
  1745. if self.debug:
  1746. for map in resultlist:
  1747. print map.cmd_list
  1748. def p_ts_expr_condition_if_relation(self, t):
  1749. # Examples:
  1750. # if({equal||during}, ts_var_expr, A)
  1751. # if({starts||during}, B > 2 || end_month() == 4, A)
  1752. """
  1753. expr : IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA stds RPAREN
  1754. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA expr RPAREN
  1755. """
  1756. relations, temporal, function= self.eval_toperator(t[3])
  1757. ts_var_dict = t[5]
  1758. spatialcond = ts_var_dict["spatial"]
  1759. # Extract spatial map list from condition.
  1760. ifmaplist = self.check_stds(spatialcond)
  1761. thenmaplist = self.check_stds(t[7])
  1762. topolist = self.get_temporal_topo_list(ifmaplist, thenmaplist,
  1763. topolist = relations)
  1764. resultspatial = []
  1765. for map_i in topolist:
  1766. #print(map_i.get_id())
  1767. # Loop over temporal related maps and create overlay modules.
  1768. tbrelations = map_i.get_temporal_relations()
  1769. count = 0
  1770. for topo in relations:
  1771. if topo in tbrelations.keys():
  1772. for map_j in (tbrelations[topo]):
  1773. # Generate an intermediate map for the result map list.
  1774. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  1775. # Set first input for overlay module.
  1776. mapainput = map_i.get_id()
  1777. # Create overlayed map extent.
  1778. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  1779. temp_op = '=')
  1780. # Stop the loop if no temporal or spatial relationship exist.
  1781. if returncode == 0:
  1782. break
  1783. if count == 0:
  1784. # Set map name.
  1785. name = map_new.get_id()
  1786. else:
  1787. # Generate an intermediate map
  1788. name = self.generate_map_name()
  1789. # Set first input for overlay module.
  1790. mapbinput = map_j.get_id()
  1791. # Create r.mapcalc expression string for the operation.
  1792. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  1793. cmdstring = "if(%s,%s)" %(map_new.cmd_list, mapbinput)
  1794. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  1795. cmdstring = "if(%s,%s)" %(mapainput, map_j.cmd_list)
  1796. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  1797. cmdstring = "if(%s,%s)" %(map_new.cmd_list, map_j.cmd_list)
  1798. else:
  1799. cmdstring = "if(%s,%s)" %(mapainput, mapbinput)
  1800. # Conditional append of module command.
  1801. map_new.cmd_list = cmdstring
  1802. # Set new map name to temporary map name.
  1803. #mapainput = name
  1804. count += 1
  1805. # Append map to result map list.
  1806. if returncode == 1:
  1807. resultspatial.append(map_new)
  1808. # Evaluate temporal statements in spatio temporal condition.
  1809. #if len(ts_var_dict["temporal"]) == 1:
  1810. #temporalcond = ts_var_dict["temporal"][0]
  1811. #else:
  1812. temporalcond = ts_var_dict["temporal"]
  1813. resultspatial = self.check_stds(resultspatial)
  1814. thencond = self.build_condition_list(temporalcond, resultspatial, relations)
  1815. thenresult = self.eval_condition_list(thencond)
  1816. # Clear the map list.
  1817. resultlist = self.check_stds(thenresult, clear = True)
  1818. t[0] = resultlist
  1819. if self.debug:
  1820. for map in resultlist:
  1821. print map.cmd_list
  1822. def p_ts_numeric_condition_if(self, t):
  1823. # Examples:
  1824. # if(ts_var_expr, 1)
  1825. # if(A == 5 && start_day() > 5, 10)
  1826. """
  1827. expr : IF LPAREN ts_var_expr COMMA number RPAREN
  1828. | IF LPAREN ts_var_expr COMMA NULL LPAREN RPAREN RPAREN
  1829. """
  1830. ts_var_dict = t[3]
  1831. spatialcond = ts_var_dict["spatial"]
  1832. ifmaplist = self.check_stds(spatialcond)
  1833. resultspatial = []
  1834. # Select input for r.mapcalc expression based on length of PLY object.
  1835. if len(t) == 7:
  1836. numinput = t[5]
  1837. elif len(t) == 9:
  1838. numinput = t[5] + t[6] + t[7]
  1839. # Iterate over condition map list.
  1840. for map_i in ifmaplist:
  1841. mapinput = map_i.get_id()
  1842. # Create r.mapcalc expression string for the operation.
  1843. if "cmd_list" in dir(map_i):
  1844. cmdstring = "if(%s,%s)" %(map_i.cmd_list, numinput)
  1845. else:
  1846. cmdstring = "if(%s,%s)" %(mapinput, numinput)
  1847. # Conditional append of module command.
  1848. map_i.cmd_list = cmdstring
  1849. # Append map to result map list.
  1850. resultspatial.append(map_i)
  1851. temporalcond = ts_var_dict["temporal"]
  1852. resultspatial = self.check_stds(resultspatial)
  1853. thencond = self.build_condition_list(temporalcond, resultspatial)
  1854. thenresult = self.eval_condition_list(thencond)
  1855. # Clear the map list.
  1856. resultlist = self.check_stds(thenresult, clear = True)
  1857. t[0] = resultlist
  1858. if self.debug:
  1859. for map in resultlist:
  1860. print map.cmd_list
  1861. def p_ts_expr_condition_elif(self, t):
  1862. # Examples:
  1863. # if(s_var_expr, A, B)
  1864. # if(start_day() < 20 && B > 2, A, B)
  1865. """
  1866. expr : IF LPAREN ts_var_expr COMMA stds COMMA stds RPAREN
  1867. | IF LPAREN ts_var_expr COMMA stds COMMA expr RPAREN
  1868. | IF LPAREN ts_var_expr COMMA expr COMMA stds RPAREN
  1869. | IF LPAREN ts_var_expr COMMA expr COMMA expr RPAREN
  1870. """
  1871. ts_var_dict = t[3]
  1872. spatialcond = ts_var_dict["spatial"]
  1873. ifmaplist = self.check_stds(spatialcond)
  1874. thenmaplist = self.check_stds(t[5])
  1875. elsemaplist = self.check_stds(t[7])
  1876. resultspatial = []
  1877. thendict = {}
  1878. elsedict = {}
  1879. # Get topologies for the appropriate conclusion term.
  1880. thentopolist = self.get_temporal_topo_list(ifmaplist, thenmaplist)
  1881. # Fill dictionaries with related maps for both conclusion terms.
  1882. for map_i in thentopolist:
  1883. thenrelations = map_i.get_temporal_relations()
  1884. relationmaps = thenrelations['EQUAL']
  1885. thendict[map_i.get_id()] = relationmaps
  1886. # Get topologies for the alternative conclusion term.
  1887. elsetopolist = self.get_temporal_topo_list(ifmaplist, elsemaplist)
  1888. for map_i in elsetopolist:
  1889. elserelations = map_i.get_temporal_relations()
  1890. relationmaps = elserelations['EQUAL']
  1891. elsedict[map_i.get_id()] = relationmaps
  1892. # Loop through conditional map list.
  1893. for map_i in ifmaplist:
  1894. if map_i.get_id() in thendict.keys():
  1895. thenlist = thendict[map_i.get_id()]
  1896. else:
  1897. thenlist = []
  1898. if map_i.get_id() in elsedict.keys():
  1899. elselist = elsedict[map_i.get_id()]
  1900. else:
  1901. elselist = []
  1902. # Set iteration amount to maximal or minimum number of related
  1903. # conclusion maps, depending on null map creation flag.
  1904. if self.null:
  1905. iternum = max(len(thenlist), len(elselist))
  1906. else:
  1907. iternum = min(len(thenlist), len(elselist))
  1908. # Calculate difference in conclusion lengths.
  1909. iterthen = iternum - len(thenlist)
  1910. iterelse = iternum - len(elselist)
  1911. # Extend null maps to the list to get conclusions with same length.
  1912. if iterthen != 0:
  1913. for i in range(iterthen):
  1914. thenlist.extend(['null()'])
  1915. if iterelse != 0:
  1916. for i in range(iterelse):
  1917. elselist.extend(['null()'])
  1918. # Combine the conclusions in a paired list.
  1919. conclusionlist = zip(thenlist, elselist)
  1920. for i in range(iternum):
  1921. conclusionmaps = conclusionlist[i]
  1922. # Generate an intermediate map for the result map list.
  1923. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  1924. # Set first input for overlay module.
  1925. mapifinput = map_i.get_id()
  1926. # Get conclusion maps.
  1927. map_then = conclusionmaps[0]
  1928. map_else = conclusionmaps[1]
  1929. # Check if conclusions are map objects.
  1930. if map_then != 'null()':
  1931. # Create overlayed map extent.
  1932. returncode = self.overlay_map_extent(map_new, map_then, 'and', \
  1933. temp_op = '=')
  1934. maptheninput = map_then.get_id()
  1935. # Continue the loop if no temporal or spatial relationship exist.
  1936. if returncode == 0:
  1937. continue
  1938. else:
  1939. maptheninput = 'null()'
  1940. # Check if conclusions are map objects.
  1941. if map_else != 'null()':
  1942. # Create overlayed map extent.
  1943. returncode = self.overlay_map_extent(map_new, map_else, 'and', \
  1944. temp_op = '=')
  1945. mapelseinput = map_else.get_id()
  1946. # Continue the loop if no temporal or spatial relationship exist.
  1947. if returncode == 0:
  1948. continue
  1949. else:
  1950. mapelseinput = 'null()'
  1951. #if map_then != 'null()' and map_else != 'null()':
  1952. # Create r.mapcalc expression string for the operation.
  1953. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_then) \
  1954. and "cmd_list" not in dir(map_else):
  1955. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, maptheninput,
  1956. mapelseinput)
  1957. elif "cmd_list" in dir(map_new) and "cmd_list" in dir(map_then) \
  1958. and "cmd_list" not in dir(map_else):
  1959. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, map_then.cmd_list,
  1960. mapelseinput)
  1961. elif "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_then) \
  1962. and "cmd_list" in dir(map_else):
  1963. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, maptheninput,
  1964. map_else.cmd_list)
  1965. elif "cmd_list" in dir(map_new) and "cmd_list" in dir(map_then) \
  1966. and "cmd_list" in dir(map_else):
  1967. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, map_then.cmd_list,
  1968. map_else.cmd_list)
  1969. elif "cmd_list" not in dir(map_new) and "cmd_list" in dir(map_then) \
  1970. and "cmd_list" not in dir(map_else):
  1971. cmdstring = "if(%s, %s, %s)" %(mapifinput, map_then.cmd_list,
  1972. mapelseinput)
  1973. elif "cmd_list" not in dir(map_new) and "cmd_list" not in dir(map_then) \
  1974. and "cmd_list" in dir(map_else):
  1975. cmdstring = "if(%s, %s, %s)" %(mapifinput, maptheninput,
  1976. map_else.cmd_list)
  1977. elif "cmd_list" not in dir(map_new) and "cmd_list" in dir(map_then) \
  1978. and "cmd_list" in dir(map_else):
  1979. cmdstring = "if(%s, %s, %s)" %(mapifinput, map_then.cmd_list,
  1980. map_else.cmd_list)
  1981. else:
  1982. cmdstring = "if(%s, %s, %s)" %(mapifinput, maptheninput,
  1983. mapelseinput)
  1984. # Conditional append of module command.
  1985. map_new.cmd_list = cmdstring
  1986. # Append map to result map list.
  1987. if returncode == 1:
  1988. resultspatial.append(map_new)
  1989. temporalcond = ts_var_dict["temporal"]
  1990. resultspatial = self.check_stds(resultspatial)
  1991. thencond = self.build_condition_list(temporalcond, resultspatial)
  1992. thenresult = self.eval_condition_list(thencond)
  1993. #elseresult = self.eval_condition_list(thencond, inverse = True)
  1994. # Combine and sort else and then statement to result map list.
  1995. #combilist = thenresult + elseresult
  1996. #resultlist = sorted(combilist, key = AbstractDatasetComparisonKeyStartTime)
  1997. # Clear the map list.
  1998. #resultlist = self.check_stds(resultlist, clear = True)
  1999. resultlist = self.check_stds(thenresult, clear = True)
  2000. t[0] = resultlist
  2001. if self.debug:
  2002. for map in resultlist:
  2003. print map.cmd_list
  2004. def p_ts_expr_condition_elif_relation(self, t):
  2005. # Examples:
  2006. # if({equal||during}, s_var_expr, A, B)
  2007. # if({contains}, start_day() == 3 || C != 2, A, B)
  2008. """
  2009. expr : IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA stds COMMA stds RPAREN
  2010. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA stds COMMA expr RPAREN
  2011. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA expr COMMA stds RPAREN
  2012. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA expr COMMA expr RPAREN
  2013. """
  2014. relations, temporal, function= self.eval_toperator(t[3])
  2015. ts_var_dict = t[5]
  2016. spatialcond = ts_var_dict["spatial"]
  2017. # Extract spatial map list from condition.
  2018. ifmaplist = self.check_stds(spatialcond)
  2019. thenmaplist = self.check_stds(t[7])
  2020. elsemaplist = self.check_stds(t[9])
  2021. resultspatial = []
  2022. thendict = {}
  2023. elsedict = {}
  2024. # Get topologies for the appropriate conclusion term.
  2025. thentopolist = self.get_temporal_topo_list(ifmaplist, thenmaplist, \
  2026. topolist = relations)
  2027. # Fill dictionaries with related maps for both conclusion terms.
  2028. for map_i in thentopolist:
  2029. thenrelations = map_i.get_temporal_relations()
  2030. relationmaps = []
  2031. for topo in relations:
  2032. if topo in thenrelations.keys():
  2033. relationmaps = relationmaps + thenrelations[topo]
  2034. thendict[map_i.get_id()] = relationmaps
  2035. # Get topologies for the alternative conclusion term.
  2036. elsetopolist = self.get_temporal_topo_list(ifmaplist, elsemaplist, \
  2037. topolist = relations)
  2038. for map_i in elsetopolist:
  2039. elserelations = map_i.get_temporal_relations()
  2040. relationmaps = []
  2041. for topo in relations:
  2042. if topo in elserelations.keys():
  2043. relationmaps = relationmaps + elserelations[topo]
  2044. elsedict[map_i.get_id()] = relationmaps
  2045. # Loop trough conditional map list.
  2046. for map_i in ifmaplist:
  2047. if map_i.get_id() in thendict.keys():
  2048. thenlist = thendict[map_i.get_id()]
  2049. else:
  2050. thenlist = []
  2051. if map_i.get_id() in elsedict.keys():
  2052. elselist = elsedict[map_i.get_id()]
  2053. else:
  2054. elselist = []
  2055. # Set iteration amount to maximal or minimum number of related
  2056. # conclusion maps, depending on null map creation flag.
  2057. if self.null:
  2058. iternum = max(len(thenlist), len(elselist))
  2059. else:
  2060. iternum = min(len(thenlist), len(elselist))
  2061. # Calculate difference in conclusion lengths.
  2062. iterthen = iternum - len(thenlist)
  2063. iterelse = iternum - len(elselist)
  2064. # Extend null maps to the list to get conclusions with same length.
  2065. if iterthen != 0:
  2066. for i in range(iterthen):
  2067. thenlist.extend(['null()'])
  2068. if iterelse != 0:
  2069. for i in range(iterelse):
  2070. elselist.extend(['null()'])
  2071. # Combine the conclusions in a paired list.
  2072. conclusionlist = zip(thenlist, elselist)
  2073. for i in range(iternum):
  2074. conclusionmaps = conclusionlist[i]
  2075. # Generate an intermediate map for the result map list.
  2076. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  2077. # Set first input for overlay module.
  2078. mapifinput = map_i.get_id()
  2079. # Get conclusion maps.
  2080. map_then = conclusionmaps[0]
  2081. map_else = conclusionmaps[1]
  2082. # Check if conclusions are map objects.
  2083. if map_then != 'null()':
  2084. # Create overlayed map extent.
  2085. returncode = self.overlay_map_extent(map_new, map_then, 'and', \
  2086. temp_op = '=')
  2087. maptheninput = map_then.get_id()
  2088. # Continue the loop if no temporal or spatial relationship exist.
  2089. if returncode == 0:
  2090. continue
  2091. else:
  2092. maptheninput = 'null()'
  2093. # Check if conclusions are map objects.
  2094. if map_else != 'null()':
  2095. # Create overlayed map extent.
  2096. returncode = self.overlay_map_extent(map_new, map_else, 'and', \
  2097. temp_op = '=')
  2098. mapelseinput = map_else.get_id()
  2099. # Continue the loop if no temporal or spatial relationship exist.
  2100. if returncode == 0:
  2101. continue
  2102. else:
  2103. mapelseinput = 'null()'
  2104. #if map_then != 'null()' and map_else != 'null()':
  2105. # Create r.mapcalc expression string for the operation.
  2106. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_then) \
  2107. and "cmd_list" not in dir(map_else):
  2108. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, maptheninput,
  2109. mapelseinput)
  2110. elif "cmd_list" in dir(map_new) and "cmd_list" in dir(map_then) \
  2111. and "cmd_list" not in dir(map_else):
  2112. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, map_then.cmd_list,
  2113. mapelseinput)
  2114. elif "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_then) \
  2115. and "cmd_list" in dir(map_else):
  2116. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, maptheninput,
  2117. map_else.cmd_list)
  2118. elif "cmd_list" in dir(map_new) and "cmd_list" in dir(map_then) \
  2119. and "cmd_list" in dir(map_else):
  2120. cmdstring = "if(%s, %s, %s)" %(map_new.cmd_list, map_then.cmd_list,
  2121. map_else.cmd_list)
  2122. elif "cmd_list" not in dir(map_new) and "cmd_list" in dir(map_then) \
  2123. and "cmd_list" not in dir(map_else):
  2124. cmdstring = "if(%s, %s, %s)" %(mapifinput, map_then.cmd_list,
  2125. mapelseinput)
  2126. elif "cmd_list" not in dir(map_new) and "cmd_list" not in dir(map_then) \
  2127. and "cmd_list" in dir(map_else):
  2128. cmdstring = "if(%s, %s, %s)" %(mapifinput, maptheninput,
  2129. map_else.cmd_list)
  2130. elif "cmd_list" not in dir(map_new) and "cmd_list" in dir(map_then) \
  2131. and "cmd_list" in dir(map_else):
  2132. cmdstring = "if(%s, %s, %s)" %(mapifinput, map_then.cmd_list,
  2133. map_else.cmd_list)
  2134. else:
  2135. cmdstring = "if(%s, %s, %s)" %(mapifinput, maptheninput,
  2136. mapelseinput)
  2137. # Conditional append of module command.
  2138. map_new.cmd_list = cmdstring
  2139. # Append map to result map list.
  2140. if returncode == 1:
  2141. resultspatial.append(map_new)
  2142. temporalcond = ts_var_dict["temporal"]
  2143. resultspatial = self.check_stds(resultspatial)
  2144. thencond = self.build_condition_list(temporalcond, resultspatial, relations)
  2145. thenresult = self.eval_condition_list(thencond)
  2146. #elseresult = self.eval_condition_list(thencond, inverse = True)
  2147. # Combine and sort else and then statement to result map list.
  2148. #combilist = thenresult + elseresult
  2149. #resultlist = sorted(combilist, key = AbstractDatasetComparisonKeyStartTime)
  2150. # Clear the map list.
  2151. resultlist = self.check_stds(thenresult, clear = True)
  2152. t[0] = resultlist
  2153. if self.debug:
  2154. for map in resultlist:
  2155. print map.cmd_list
  2156. def p_ts_numeric_condition_elif(self, t):
  2157. # Examples:
  2158. # if(ts_var_expr, 1, 2)
  2159. # if(A == 1 || end_year == 2013, 10, null())
  2160. """
  2161. expr : IF LPAREN ts_var_expr COMMA number COMMA number RPAREN
  2162. | IF LPAREN ts_var_expr COMMA NULL LPAREN RPAREN COMMA number RPAREN
  2163. | IF LPAREN ts_var_expr COMMA number COMMA NULL LPAREN RPAREN RPAREN
  2164. | IF LPAREN ts_var_expr COMMA NULL LPAREN RPAREN COMMA NULL LPAREN RPAREN RPAREN
  2165. """
  2166. ts_var_dict = t[3]
  2167. spatialcond = ts_var_dict["spatial"]
  2168. # Extract spatial map list from condition.
  2169. ifmaplist = self.check_stds(spatialcond)
  2170. resultspatial = []
  2171. # Select input for r.mapcalc expression based on length of PLY object.
  2172. if len(t) == 9:
  2173. numthen = t[5]
  2174. numelse = t[7]
  2175. elif len(t) == 11:
  2176. numthen = self.check_null(t[5])
  2177. numelse = self.check_null(t[7])
  2178. elif len(t) == 13:
  2179. numthen = self.check_null(t[5])
  2180. numelse = self.check_null(t[9])
  2181. # Iterate over condition map list.
  2182. for map_i in ifmaplist:
  2183. mapinput = map_i.get_id()
  2184. # Create r.mapcalc expression string for the operation.
  2185. if "cmd_list" in dir(map_i):
  2186. cmdstring = "if(%s, %s, %s)" %(map_i.cmd_list, numthen, numelse)
  2187. else:
  2188. cmdstring = "if(%s, %s, %s)" %(mapinput, numthen, numelse)
  2189. # Conditional append of module command.
  2190. map_i.cmd_list = cmdstring
  2191. # Append map to result map list.
  2192. resultspatial.append(map_i)
  2193. temporalcond = ts_var_dict["temporal"]
  2194. resultspatial = self.check_stds(resultspatial)
  2195. thencond = self.build_condition_list(temporalcond, resultspatial)
  2196. thenresult = self.eval_condition_list(thencond)
  2197. #elseresult = self.eval_condition_list(thencond, inverse = True)
  2198. # Combine and sort else and then statement to result map list.
  2199. #combilist = thenresult + elseresult
  2200. #resultlist = sorted(combilist, key = AbstractDatasetComparisonKeyStartTime)
  2201. # Clear the map list.
  2202. #resultlist = self.check_stds(resultlist, clear = True)
  2203. resultlist = self.check_stds(thenresult, clear = True)
  2204. t[0] = resultlist
  2205. def p_ts_numeric_expr_condition_elif(self, t):
  2206. # Examples:
  2207. # if(ts_var_expr, 1, A)
  2208. # if(A == 5 && start_day() > 5, A, null())
  2209. """
  2210. expr : IF LPAREN ts_var_expr COMMA number COMMA stds RPAREN
  2211. | IF LPAREN ts_var_expr COMMA NULL LPAREN RPAREN COMMA stds RPAREN
  2212. | IF LPAREN ts_var_expr COMMA number COMMA expr RPAREN
  2213. | IF LPAREN ts_var_expr COMMA NULL LPAREN RPAREN COMMA expr RPAREN
  2214. | IF LPAREN ts_var_expr COMMA stds COMMA number RPAREN
  2215. | IF LPAREN ts_var_expr COMMA stds COMMA NULL LPAREN RPAREN RPAREN
  2216. | IF LPAREN ts_var_expr COMMA expr COMMA number RPAREN
  2217. | IF LPAREN ts_var_expr COMMA expr COMMA NULL LPAREN RPAREN RPAREN
  2218. """
  2219. ts_var_dict = t[3]
  2220. spatialcond = ts_var_dict["spatial"]
  2221. ifmaplist = self.check_stds(spatialcond)
  2222. resultspatial = []
  2223. thenmaplist = []
  2224. numthen = ''
  2225. elsemaplist = []
  2226. numelse = ''
  2227. # Select input for r.mapcalc expression based on length of PLY object.
  2228. if len(t) == 9:
  2229. try:
  2230. thenmaplist = self.check_stds(t[5])
  2231. except:
  2232. numthen = t[5]
  2233. try:
  2234. elsemaplist = self.check_stds(t[7])
  2235. except:
  2236. numelse = t[7]
  2237. elif len(t) == 11:
  2238. try:
  2239. thenmaplist = self.check_stds(t[5])
  2240. except:
  2241. numthen = t[5] + t[6] + t[7]
  2242. try:
  2243. elsemaplist = self.check_stds(t[9])
  2244. except:
  2245. numelse = t[7] + t[8] + t[9]
  2246. if thenmaplist != []:
  2247. topolist = self.get_temporal_topo_list(ifmaplist, thenmaplist)
  2248. elif elsemaplist != []:
  2249. topolist = self.get_temporal_topo_list(ifmaplist, elsemaplist)
  2250. if numthen != '':
  2251. numinput = numthen
  2252. elif numelse != '':
  2253. numinput = numelse
  2254. # Iterate over condition map lists with temporal relations.
  2255. for map_i in topolist:
  2256. # Loop over temporal related maps and create overlay modules.
  2257. tbrelations = map_i.get_temporal_relations()
  2258. count = 0
  2259. for map_j in (tbrelations['EQUAL']):
  2260. # Generate an intermediate map for the result map list.
  2261. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  2262. # Set first input for overlay module.
  2263. mapainput = map_i.get_id()
  2264. # Create overlayed map extent.
  2265. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  2266. temp_op = '=')
  2267. # Stop the loop if no temporal or spatial relationship exist.
  2268. if returncode == 0:
  2269. break
  2270. if count == 0:
  2271. # Set map name.
  2272. name = map_new.get_id()
  2273. else:
  2274. # Generate an intermediate map
  2275. name = self.generate_map_name()
  2276. # Set first input for overlay module.
  2277. mapbinput = map_j.get_id()
  2278. # Create r.mapcalc expression string for the operation.
  2279. if thenmaplist != []:
  2280. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  2281. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, mapbinput, \
  2282. numinput)
  2283. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  2284. cmdstring = "if(%s,%s,%s)" %(mapainput, map_j.cmd_list, \
  2285. numinput)
  2286. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  2287. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, map_j.cmd_list, \
  2288. numinput)
  2289. else:
  2290. cmdstring = "if(%s,%s,%s)" %(mapainput, mapbinput, numinput)
  2291. if elsemaplist != []:
  2292. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  2293. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, numinput, \
  2294. mapbinput)
  2295. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  2296. cmdstring = "if(%s,%s,%s)" %(mapainput, numinput, \
  2297. map_j.cmd_list)
  2298. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  2299. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, numinput, \
  2300. map_j.cmd_list)
  2301. else:
  2302. cmdstring = "if(%s,%s,%s)" %(mapainput, numinput, mapbinput)
  2303. # Conditional append of module command.
  2304. map_new.cmd_list = cmdstring
  2305. # Set new map name to temporary map name.
  2306. #mapainput = name
  2307. count += 1
  2308. # Append map to result map list.
  2309. if returncode == 1:
  2310. resultspatial.append(map_new)
  2311. temporalcond = ts_var_dict["temporal"]
  2312. resultspatial = self.check_stds(resultspatial)
  2313. thencond = self.build_condition_list(temporalcond, resultspatial)
  2314. thenresult = self.eval_condition_list(thencond)
  2315. # Clear the map list.
  2316. resultlist = self.check_stds(thenresult, clear = True)
  2317. t[0] = resultlist
  2318. if self.debug:
  2319. for map in resultlist:
  2320. print map.cmd_list
  2321. def p_ts_numeric_expr_condition_elif_relation(self, t):
  2322. # Examples:
  2323. # if({during},ts_var_expr, 1, A)
  2324. # if({during}, A == 5 && start_day() > 5, A, null())
  2325. """
  2326. expr : IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA number COMMA stds RPAREN
  2327. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA NULL LPAREN RPAREN COMMA stds RPAREN
  2328. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA number COMMA expr RPAREN
  2329. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA NULL LPAREN RPAREN COMMA expr RPAREN
  2330. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA stds COMMA number RPAREN
  2331. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA stds COMMA NULL LPAREN RPAREN RPAREN
  2332. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA expr COMMA number RPAREN
  2333. | IF LPAREN T_REL_OPERATOR COMMA ts_var_expr COMMA expr COMMA NULL LPAREN RPAREN RPAREN
  2334. """
  2335. relations, temporal, function= self.eval_toperator(t[3])
  2336. ts_var_dict = t[5]
  2337. spatialcond = ts_var_dict["spatial"]
  2338. ifmaplist = self.check_stds(spatialcond)
  2339. resultspatial = []
  2340. thenmaplist = []
  2341. numthen = ''
  2342. elsemaplist = []
  2343. numelse = ''
  2344. # Select input for r.mapcalc expression based on length of PLY object.
  2345. if len(t) == 11:
  2346. try:
  2347. thenmaplist = self.check_stds(t[7])
  2348. except:
  2349. numthen = t[7]
  2350. try:
  2351. elsemaplist = self.check_stds(t[9])
  2352. except:
  2353. numelse = t[9]
  2354. elif len(t) == 13:
  2355. try:
  2356. thenmaplist = self.check_stds(t[7])
  2357. except:
  2358. numthen = t[9] + t[10] + t[11]
  2359. try:
  2360. elsemaplist = self.check_stds(t[11])
  2361. except:
  2362. numelse = t[9] + t[10] + t[11]
  2363. if thenmaplist != []:
  2364. topolist = self.get_temporal_topo_list(ifmaplist, thenmaplist, \
  2365. topolist = relations)
  2366. elif elsemaplist != []:
  2367. topolist = self.get_temporal_topo_list(ifmaplist, elsemaplist, \
  2368. topolist = relations)
  2369. if numthen != '':
  2370. numinput = numthen
  2371. elif numelse != '':
  2372. numinput = numelse
  2373. # Iterate over condition map lists with temporal relations.
  2374. for map_i in topolist:
  2375. # Loop over temporal related maps and create overlay modules.
  2376. tbrelations = map_i.get_temporal_relations()
  2377. count = 0
  2378. for topo in relations:
  2379. if topo in tbrelations.keys():
  2380. for map_j in (tbrelations[topo]):
  2381. # Generate an intermediate map for the result map list.
  2382. map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', copy = True)
  2383. # Set first input for overlay module.
  2384. mapainput = map_i.get_id()
  2385. # Create overlayed map extent.
  2386. returncode = self.overlay_map_extent(map_new, map_j, 'and', \
  2387. temp_op = '=')
  2388. # Stop the loop if no temporal or spatial relationship exist.
  2389. if returncode == 0:
  2390. break
  2391. if count == 0:
  2392. # Set map name.
  2393. name = map_new.get_id()
  2394. else:
  2395. # Generate an intermediate map
  2396. name = self.generate_map_name()
  2397. # Set first input for overlay module.
  2398. mapbinput = map_j.get_id()
  2399. # Create r.mapcalc expression string for the operation.
  2400. if thenmaplist != []:
  2401. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  2402. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, mapbinput, \
  2403. numinput)
  2404. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  2405. cmdstring = "if(%s,%s,%s)" %(mapainput, map_j.cmd_list, \
  2406. numinput)
  2407. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  2408. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, map_j.cmd_list, \
  2409. numinput)
  2410. else:
  2411. cmdstring = "if(%s,%s,%s)" %(mapainput, mapbinput, numinput)
  2412. if elsemaplist != []:
  2413. if "cmd_list" in dir(map_new) and "cmd_list" not in dir(map_j):
  2414. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, numinput, \
  2415. mapbinput)
  2416. elif "cmd_list" in dir(map_j) and "cmd_list" not in dir(map_new):
  2417. cmdstring = "if(%s,%s,%s)" %(mapainput, numinput, \
  2418. map_j.cmd_list)
  2419. elif "cmd_list" in dir(map_j) and "cmd_list" in dir(map_new):
  2420. cmdstring = "if(%s,%s,%s)" %(map_new.cmd_list, numinput, \
  2421. map_j.cmd_list)
  2422. else:
  2423. cmdstring = "if(%s,%s,%s)" %(mapainput, numinput, mapbinput)
  2424. # Conditional append of module command.
  2425. map_new.cmd_list = cmdstring
  2426. # Set new map name to temporary map name.
  2427. #mapainput = name
  2428. count += 1
  2429. # Append map to result map list.
  2430. if returncode == 1:
  2431. resultspatial.append(map_new)
  2432. temporalcond = ts_var_dict["temporal"]
  2433. resultspatial = self.check_stds(resultspatial)
  2434. thencond = self.build_condition_list(temporalcond, resultspatial)
  2435. thenresult = self.eval_condition_list(thencond)
  2436. # Clear the map list.
  2437. resultlist = self.check_stds(thenresult, clear = True)
  2438. t[0] = resultlist
  2439. if self.debug:
  2440. for map in resultlist:
  2441. print map.cmd_list
  2442. ###############################################################################
  2443. if __name__ == "__main__":
  2444. import doctest
  2445. doctest.testmod()