t.rast.mapcalc.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <h2>DESCRIPTION</h2>
  2. The purpose of <em>t.rast.mapcalc</em> is to perform spatio-temporal <em>mapcalc</em> expressions
  3. on maps of temporally sampled space time raster datasets (STRDS). Spatial and temporal
  4. operators and internal variables are available in the expression string. The description of the spatial
  5. operators, functions and internal variables is available in the <a href="r.mapcalc.html">r.mapcalc</a> manual page.
  6. The temporal functions are described in detail below.
  7. <p>
  8. This module expects several parameter. All space time raster datasets that are referenced in
  9. the <em>mapcalc expression</em> must be listed in the <em>input</em> option. The <em>first</em> space time raster
  10. dataset that is listed as input will be used to temporally sample all other
  11. space time raster datasets. The temporal sampling method can be chosen using
  12. the <em>method</em> option. The order of the STRDS's in the mapcalc expression can be different
  13. to the order of the STRDS's in the input option. The resulting space time raster dataset
  14. must be specified in the <em>output</em> option together with the <em>base</em> name
  15. of generated raster maps that are registered in the resulting STRDS. Empty maps
  16. resulting from map-calculation are not registered by default. This behavior can be changed
  17. with the <em>-n</em> flag. The flag <em>-s</em> can be used to assure that only spatial related
  18. maps in the STRDS's are processed. Spatial related means that temporally related maps overlap
  19. in their spatial extent.
  20. <p>
  21. The module <em>t.rast.mapcalc</em> supports parallel processing. The option
  22. <em>nprocs</em> specifies the number of processes that can be started in parallel.
  23. <p>
  24. A mapcalc expression must be provided to process the temporal
  25. sampled maps. Temporal internal variables are available in addition to
  26. the <em>r.mapcalc</em> spatial operators and functions:
  27. <p>
  28. Supported internal variables for relative and absolute time:
  29. <ul>
  30. <li> <em>td()</em> - This internal variable
  31. represents the size of the current sample time interval
  32. in days and fraction of days for absolute time,
  33. and in relative units in case of relative time. </li>
  34. <li> <em>start_time()</em> - This internal variable represent
  35. the time difference between the start time of the sample space time
  36. raster dataset and the start time of the current sample interval or instance. The time
  37. is measured in days and fraction of days for absolute time,
  38. and in relative units in case of relative time. </li>
  39. <li> <em>end_time()</em> - This internal variable represent
  40. the time difference between the start time of the sample space time
  41. raster dataset and the end time of the current sample interval. The time
  42. is measured in days and fraction of days for absolute time,
  43. and in relative units in case of relative time.
  44. The end_time() will be represented by null() in case of a time instance.</li>
  45. </ul>
  46. <p>
  47. Supported internal variables for absolute time of the current sample interval or instance:
  48. <ul>
  49. <li> <em>start_doy()</em> - Day of year (doy) from the start time [1 - 366] </li>
  50. <li> <em>start_dow()</em> - Day of week (dow) from the start time [1 - 7],
  51. the start of the week is monday == 1 </li>
  52. <li> <em>start_year()</em> - The year of the start time [0 - 9999] </li>
  53. <li> <em>start_month()</em> - The month of the start time [1 - 12] </li>
  54. <li> <em>start_week()</em> - Week of year of the start time [1 - 54] </li>
  55. <li> <em>start_day()</em> - Day of month from the start time [1 - 31] </li>
  56. <li> <em>start_hour()</em> - The hour of the start time [0 - 23] </li>
  57. <li> <em>start_minute()</em> - The minute of the start time [0 - 59] </li>
  58. <li> <em>start_second()</em> - The second of the start time [0 - 59] </li>
  59. <li> <em>end_doy()</em> - Day of year (doy) from the end time [1 - 366] </li>
  60. <li> <em>end_dow()</em> - Day of week (dow) from the end time [1 - 7],
  61. the start of the week is monday == 1 </li>
  62. <li> <em>end_year()</em> - The year of the end time [0 - 9999] </li>
  63. <li> <em>end_month()</em> - The month of the end time [1 - 12] </li>
  64. <li> <em>end_woy()</em> - Week of year (woy) of the end time [1 - 54] </li>
  65. <li> <em>end_day()</em> - Day of month from the start time [1 - 31] </li>
  66. <li> <em>end_hour()</em> - The hour of the end time [0 - 23] </li>
  67. <li> <em>end_minute()</em> - The minute of the end time [0 - 59] </li>
  68. <li> <em>end_second()</em> - The second of the end time [0 - 59] </li>
  69. </ul>
  70. The <em>end_*</em> functions are represented by the null() internal variables
  71. in case of time instances.
  72. <h2>NOTE</h2>
  73. We will discuss the internal work of <em>t.rast.mapcalc</em> with an example.
  74. Imagine we have two STRDS as input, each with monthly granularity. The first one
  75. <em>A</em> has 6 raster maps (a3 ... a8) with a temporal range from March to August. The second
  76. STRDS <em>B</em> has 12 raster maps (b1 ... b12) ranging from January to December.
  77. The value of the raster maps is the number of the month from their interval start time.
  78. Dataset <em>A</em> will be used to sample dataset <em>B</em> to create a dataset <em>C</em>.
  79. We want to add all maps with equal time stamps if the month of the start time is May or June,
  80. otherwise we multiply the maps. The command will look as follows:
  81. <p>
  82. <div class="code"><pre>
  83. t.rast.mapcalc input=A,B output=C base=c method=equal \
  84. expr="if(start_month() == 5 || start_month() == 6, (A + B), (A * B))"
  85. </pre></div>
  86. <p>
  87. The resulting raster maps in dataset C can be listed with <em>t.rast.list</em>:
  88. <p>
  89. <div class="code"><pre>
  90. name start_time min max
  91. c_1 2001-03-01 00:00:00 9.0 9.0
  92. c_2 2001-04-01 00:00:00 16.0 16.0
  93. c_3 2001-05-01 00:00:00 10.0 10.0
  94. c_4 2001-06-01 00:00:00 12.0 12.0
  95. c_5 2001-07-01 00:00:00 49.0 49.0
  96. c_6 2001-08-01 00:00:00 64.0 64.0
  97. </pre></div>
  98. <p>
  99. Internally the spatio-temporal expression will be analyzed for each time interval
  100. of the sample dataset A, the temporal functions will be replaced by numerical values,
  101. the names of the space time raster datasets will be replaced by the corresponding raster maps.
  102. The final expression will be passed to <em>r.mapcalc</em>, resulting in 6 runs:
  103. <p>
  104. <div class="code"><pre>
  105. r.mapcalc expr="c_1 = if(3 == 5 || 3 == 6, (a3 + b3), (a3 * b3))"
  106. r.mapcalc expr="c_2 = if(4 == 5 || 4 == 6, (a4 + b4), (a4 * b4))"
  107. r.mapcalc expr="c_3 = if(5 == 5 || 5 == 6, (a5 + b5), (a5 * b5))"
  108. r.mapcalc expr="c_4 = if(6 == 5 || 6 == 6, (a6 + b6), (a6 * b6))"
  109. r.mapcalc expr="c_5 = if(7 == 5 || 7 == 6, (a7 + b7), (a7 * b7))"
  110. r.mapcalc expr="c_6 = if(8 == 5 || 8 == 6, (a8 + b8), (a8 * b8))"
  111. </pre></div>
  112. <p>
  113. <h2>EXAMPLE</h2>
  114. Here the full script to reproduce the example:
  115. <p>
  116. <div class="code"><pre>
  117. g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
  118. # Lets create the raster maps
  119. r.mapcalc expr="a3 = 3"
  120. r.mapcalc expr="a4 = 4"
  121. r.mapcalc expr="a5 = 5"
  122. r.mapcalc expr="a6 = 6"
  123. r.mapcalc expr="a7 = 7"
  124. r.mapcalc expr="a8 = 8"
  125. r.mapcalc expr="b1 = 1"
  126. r.mapcalc expr="b2 = 2"
  127. r.mapcalc expr="b3 = 3"
  128. r.mapcalc expr="b4 = 4"
  129. r.mapcalc expr="b5 = 5"
  130. r.mapcalc expr="b6 = 6"
  131. r.mapcalc expr="b7 = 7"
  132. r.mapcalc expr="b8 = 8"
  133. r.mapcalc expr="b9 = 8"
  134. r.mapcalc expr="b10 = 10"
  135. r.mapcalc expr="b11 = 11"
  136. r.mapcalc expr="b12 = 12"
  137. t.create type=strds temporaltype=absolute \
  138. output=A title="Dataset A" descr="Dataset A"
  139. t.create type=strds temporaltype=absolute \
  140. output=B title="Dataset B" descr="Dataset B"
  141. t.register -i type=rast input=A maps=a3,a4,a5,a6,a7,a8 \
  142. start="2001-03-01" increment="1 months"
  143. t.register -i type=rast input=B maps=b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12 \
  144. start="2001-01-01" increment="1 months"
  145. t.rast.mapcalc input=A,B output=C base=c method=equal \
  146. expr="if(start_month() == 5 || start_month() == 6, (A + B), (A * B))"
  147. t.info type=strds input=C
  148. t.rast.list -h input=C columns=name,start_time,min,max
  149. </pre></div>
  150. <h2>SEE ALSO</h2>
  151. <em>
  152. <a href="r.mapcalc.html">r.mapcalc</a>,
  153. <a href="t.register.html">t.register</a>,
  154. <a href="t.rast.list.html">t.rast.list</a>,
  155. <a href="t.info.html">t.info</a>
  156. </em>
  157. <h2>AUTHOR</h2>
  158. S&ouml;ren Gebbert
  159. <p><i>Last changed: $Date$</i>