t.select.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <h2>DESCRIPTION</h2>
  2. <em>t.select</em> performs selection of maps that are registered in
  3. space time datasets using temporal algebra.
  4. <h3>PROGRAM USE</h3>
  5. The module expects an <b>expression</b> as input parameter in the following form:
  6. <p>
  7. <tt>"result = expression"</tt>
  8. <p>
  9. The statement structure is similar to r.mapcalc, see <a href="r.mapcalc.html">r.mapcalc</a>.
  10. Where <b>result</b> represents the name of a space time dataset
  11. (STDS)that will contain the result of the calculation that is given as
  12. <b>expression</b> on the right side of the equality sign.
  13. These expression can be any valid or nested combination of temporal
  14. operations and functions that are provided by the temporal algebra.
  15. <br>
  16. The temporal algebra works with space time datasets of any type
  17. (STRDS, STR3DS and STVDS). The algebra provides methods for map
  18. selection from STDS based on their temporal relations. It is also
  19. possible to temporally shift maps, to create temporal buffer and to
  20. snap time instances to create a valid temporal topology. Furthermore
  21. expressions can be nested and evaluated in conditional statements (if,
  22. else statements). Within if-statements the algebra provides temporal
  23. variables like start time, end time, day of year, time differences or
  24. number of maps per time interval to build up conditions. These
  25. operations can be assigned to space time datasets or to the results of
  26. operations between space time datasets.
  27. <p>
  28. The type of the input space time datasets must be defined with the input
  29. parameter <b>type</b>. Possible options are STRDS, STVDS or STR3DS.
  30. The default is set to space time raster datasets (STRDS).
  31. <p>
  32. As default, topological relationships between space time datasets will be
  33. evaluated only temporal. Use the <b>s</b> flag to activate the
  34. additionally spatial topology evaluation.
  35. <p>
  36. The expression option must be passed as <b>quoted</b>
  37. expression, for example: <br>
  38. <div class="code"><pre>
  39. t.select expression="C = A : B"
  40. </pre></div>
  41. Where <b>C</b> is the new space time raster dataset that will contain maps
  42. from <b>A</b> that are selected by equal temporal relationships
  43. to the existing dataset <b>B</b> in this case.
  44. <h2>TEMPORAL ALGEBRA</h2>
  45. The temporal algebra provides a wide range of temporal operators and
  46. functions that will be presented in the following section.
  47. <h3>TEMPORAL RELATIONS</h3>
  48. Several temporal topology relations between registered maps of space
  49. time datasets are supported: <br>
  50. <div class="code"><pre>
  51. equals A ------
  52. B ------
  53. during A ----
  54. B ------
  55. contains A ------
  56. B ----
  57. starts A ----
  58. B ------
  59. started A ------
  60. B ----
  61. finishs A ----
  62. B ------
  63. finished A ------
  64. B ----
  65. precedes A ----
  66. B ----
  67. follows A ----
  68. B ----
  69. overlapped A ------
  70. B ------
  71. overlaps A ------
  72. B ------
  73. over booth overlaps and overlapped
  74. </pre></div>
  75. The relations must be read as: A is related to B, like - A equals B - A is
  76. during B - A contains B <p>
  77. Topological relations must be specified in {} parentheses. <br>
  78. <h3>TEMPORAL OPERATORS</h3>
  79. The temporal algebra defines temporal operators that can be combined with other
  80. operators to perform spatio-temporal operations.
  81. The temporal operators process the time instances and intervals of two temporal
  82. related maps and calculate the result temporal extent by five different possibilities.
  83. <div class="code"><pre>
  84. LEFT REFERENCE l Use the time stamp of the left space time dataset
  85. INTERSECTION i Intersection
  86. DISJOINT UNION d Disjoint union
  87. UNION u Union
  88. RIGHT REFERENCE r Use the time stamp of the right space time dataset
  89. </pre></div>
  90. <h3>TEMPORAL SELECTION</h3>
  91. The temporal selection simply selects parts of a space time dataset without
  92. processing raster or vector data.
  93. The algebra provides a selection operator <b>:</b> that selects parts
  94. of a space time dataset that are temporally equal to parts of a second one
  95. by default. The following expression
  96. <div class="code"><pre>
  97. C = A : B
  98. </pre></div>
  99. means: Select all parts of space time dataset A that are equal to B and store
  100. it in space time dataset C. The parts are time stamped maps. <p>
  101. In addition the inverse selection operator <b>!:</b> is defined as the
  102. complement of the selection operator, hence the following expression
  103. <div class="code"><pre>
  104. C = A !: B
  105. </pre></div>
  106. means: select all parts of space time time dataset A that are not equal to B
  107. and store it in space time dataset (STDS) C. <p>
  108. To select parts of a STDS by different topological relations to other STDS,
  109. the temporal topology selection operator can be used. The operator consists of
  110. the temporal selection operator, the topological relations, that must be separated
  111. by the logical OR operator <b>|</b> and the temporal extent operator.
  112. All three parts are separated by comma and surrounded by curly braces:
  113. <div class="code"><pre>
  114. {"temporal selection operator", "topological relations", "temporal operator"}
  115. </pre></div>
  116. Examples:
  117. <div class="code"><pre>
  118. C = A {:, equals} B
  119. C = A {!:, equals} B
  120. </pre></div>
  121. We can now define arbitrary topological relations using the OR operator "|"
  122. to connect them:
  123. <div class="code"><pre>
  124. C = A {:,equals|during|overlaps} B
  125. </pre></div>
  126. Select all parts of A that are equal to B, during B or overlaps B. <br>
  127. In addition we can define the temporal extent of the result STDS by adding the
  128. temporal operator.
  129. <div class="code"><pre>
  130. C = A {:, during,r} B
  131. </pre></div>
  132. Select all parts of A that are during B and use the temporal extents from B for
  133. C. <br>
  134. <br>
  135. The selection operator is implicitly contained in the temporal topology
  136. selection operator, so that the following statements are exactly the same:
  137. <div class="code"><pre>
  138. C = A : B
  139. C = A {:} B
  140. C = A {:,equal} B
  141. C = A {:,equal,l} B
  142. </pre></div>
  143. Same for the complementary selection:
  144. <div class="code"><pre>
  145. C = A !: B
  146. C = A {!:} B
  147. C = A {!:,equal} B
  148. C = A {!:,equal,l} B
  149. </pre></div>
  150. <h3>CONDITIONAL STATEMENTS</h3>
  151. Selection operations can be evaluated within conditional statements.
  152. <br>
  153. <div class="code"><pre>
  154. Note A and B can either be space time datasets or expressions. The temporal
  155. relationship between the conditions and the conclusions can be defined at the
  156. beginning of the if statement. The relationship between then and else conclusion
  157. must be always equal.
  158. if statement decision option temporal relations
  159. if(if, then, else)
  160. if(conditions, A) A if conditions are True; temporal topological relation between if and then is equal.
  161. if(conditions, A, B) A if conditions are True, B otherwise; temporal topological relation between if, then and else is equal.
  162. if(topologies, conditions, A) A if conditions are True; temporal topological relation between if and then is explicit specified by topologies.
  163. if(topologies, conditions, A, B) A if conditions are True, B otherwise; temporal topological relation between if, then and else is explicit specified by topologies.
  164. </pre></div>
  165. The conditions are comparison expressions that are used to evaluate
  166. space time datasets. Specific values of temporal variables are
  167. compared by logical operators and evaluated for each map of the STDS.<br>
  168. <b>Important:</b> The conditions are evaluated from left to right.
  169. <h4>Logical operators</h4>
  170. <div class="code"><pre>
  171. Symbol description
  172. == equal
  173. != not equal
  174. > greater than
  175. >= greater than or equal
  176. < less than
  177. <= less than or equal
  178. && and
  179. || or
  180. </pre></div>
  181. <h4>Temporal functions</h4>
  182. The following temporal function are evaluated only for the STDS that must
  183. be given in parenthesis.
  184. <div class="code"><pre>
  185. td(A) Returns a list of time intervals of STDS A
  186. start_time(A) Start time as HH::MM:SS
  187. start_date(A) Start date as yyyy-mm-DD
  188. start_datetime(A) Start datetime as yyyy-mm-DD HH:MM:SS
  189. end_time(A) End time as HH:MM:SS
  190. end_date(A) End date as yyyy-mm-DD
  191. end_datetime(A) End datetime as yyyy-mm-DD HH:MM
  192. start_doy(A) Day of year (doy) from the start time [1 - 366]
  193. start_dow(A) Day of week (dow) from the start time [1 - 7], the start of the week is Monday == 1
  194. start_year(A) The year of the start time [0 - 9999]
  195. start_month(A) The month of the start time [1 - 12]
  196. start_week(A) Week of year of the start time [1 - 54]
  197. start_day(A) Day of month from the start time [1 - 31]
  198. start_hour(A) The hour of the start time [0 - 23]
  199. start_minute(A) The minute of the start time [0 - 59]
  200. start_second(A) The second of the start time [0 - 59]
  201. end_doy(A) Day of year (doy) from the end time [1 - 366]
  202. end_dow(A) Day of week (dow) from the end time [1 - 7], the start of the week is Monday == 1
  203. end_year(A) The year of the end time [0 - 9999]
  204. end_month(A) The month of the end time [1 - 12]
  205. end_week(A) Week of year of the end time [1 - 54]
  206. end_day(A) Day of month from the start time [1 - 31]
  207. end_hour(A) The hour of the end time [0 - 23]
  208. end_minute(A) The minute of the end time [0 - 59]
  209. end_second(A) The second of the end time [0 - 59]
  210. </pre></div>
  211. <h4>Comparison operator</h4>
  212. The conditions are comparison expressions that are used to evaluate
  213. space time datasets. Specific values of temporal variables are
  214. compared by logical operators and evaluated for each map of the STDS and
  215. the related maps.
  216. For complex relations the comparison operator can be used to combine conditions:
  217. <br>
  218. The structure is similar to the select operator with the extension of an aggregation operator:
  219. {"comparison operator", "topological relations", aggregation operator, "temporal operator"}
  220. <br>
  221. This aggregation operator (| or &) define the behaviour if a map is related the more
  222. than one map, e.g for the topological relations 'contains'.
  223. Should all (&) conditions for the related maps be true or is it sufficient to
  224. have any (|) condition that is true. The resulting boolean value is then compared
  225. to the first condition by the comparison operator (|| or &&).
  226. As default the aggregation operator is related to the comparison operator: <br>
  227. Comparison operator -> aggregation operator:
  228. <div class="code"><pre>
  229. || -> | and && -> &
  230. </pre></div>
  231. Examples:
  232. <div class="code"><pre>
  233. Condition 1 {||, equal, r} Condition 2
  234. Condition 1 {&&, equal|during, l} Condition 2
  235. Condition 1 {&&, equal|contains, |, l} Condition 2
  236. Condition 1 {&&, equal|during, l} Condition 2 && Condition 3
  237. Condition 1 {&&, equal|during, l} Condition 2 {&&,contains, |, r} Condition 3
  238. </pre></div>
  239. <h4>Hash operator</h4>
  240. Additionally the number of maps in intervals can be computed and used in
  241. conditional statements with the hash (#) operator. <br>
  242. <div class="code"><pre>
  243. A{#, contains}B
  244. </pre></div>
  245. This expression computes the number of maps from space
  246. time dataset B which are during the time intervals of maps from
  247. space time dataset A.<br>
  248. A list of integers (scalars) corresponding to the maps of A
  249. that contain maps from B will be returned. <p>
  250. <div class="code"><pre>
  251. C = if({equal}, A {#, contains} B > 2, A {:, contains} B)
  252. </pre></div>
  253. This expression selects all maps from A that temporally contains at least 2
  254. maps from B and stores them in space time dataset C. The leading equal statement
  255. in the if condition specifies the temporal relation between the if and then part
  256. of the if expression. This is very important, so we do not need to specify a
  257. global time reference (a space time dataset) for temporal processing.
  258. <p>
  259. Furthermore the temporal algebra allows temporal buffering, shifting
  260. and snapping with the functions buff_t(), tshift() and tsnap()
  261. respectively.
  262. <div class="code"><pre>
  263. buff_t(A, size) Buffer STDS A with granule ("1 month" or 5)
  264. tshift(A, size) Shift STDS A with granule ("1 month" or 5)
  265. tsnap(A) Snap time instances and intervals of STDS A
  266. </pre></div>
  267. <br>
  268. <h4>Single map with temporal extent</h4>
  269. The temporal algebra can also handle single maps with time stamps in the
  270. map function.
  271. <div class="code"><pre>
  272. tmap()
  273. </pre></div>
  274. For example:
  275. <div class="code"><pre>
  276. C = A {:,during} tmap(event)
  277. </pre></div>
  278. This statement select all maps from space time data set A that are during
  279. the temporal extent of single map 'event'
  280. <br>
  281. <h2>Examples</h2>
  282. Select all maps from space time dataset A which have equal time stamps
  283. with space time dataset B and C and are earlier that Jan. 1. 2005 and
  284. store them in space time dataset D.
  285. <div class="code"><pre>
  286. D = if(start_date(A) < "2005-01-01", A : B : C)
  287. </pre></div>
  288. Select all maps from space time dataset A which contains more than three
  289. maps of space time dataset B, else select maps from C with time
  290. stamps that are not equal to A and store them in space time dataset D.
  291. <div class="code"><pre>
  292. D = if(A {#, contains} B > 3, A {:, contains} B, C)
  293. </pre></div>
  294. Select all maps from space time dataset B which are during the temporal
  295. buffered space time dataset A with a map interval of three days, else
  296. select maps from C and store them in space time dataset D.
  297. <div class="code"><pre>
  298. D = if(contains, td(buff_t(A, "1 days")) == 3, B, C)
  299. </pre></div>
  300. <h2>SEE ALSO</h2>
  301. <em>
  302. <a href="r.mapcalc.html">r.mapcalc</a>
  303. </em>
  304. <h2>REFERENCES</h2>
  305. <a href="http://www.dabeaz.com/ply/">PLY(Python-Lex-Yacc)</a>
  306. <h2>AUTHORS</h2>
  307. Thomas Leppelt, S&ouml;ren Gebbert, Th&uuml;nen Institute of Climate-Smart Agriculture
  308. <p><i>Last changed: $Date$</i>