g.gui.gmodeler.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <!-- meta page description: wxGUI Graphical Modeler -->
  2. <!-- meta page index: topic_gui|GUI -->
  3. <h2>DESCRIPTION</h2>
  4. <p>
  5. The <b>Graphical Modeler</b> is
  6. a <em><a href="wxGUI.html">wxGUI</a></em> component which allows the user to
  7. create, edit, and manage complex models using easy-to-use
  8. interface. When performing analytical operations in GRASS, the
  9. operations are not isolated, but part of a chain of operations. Using
  10. Graphical Modeler, that chain of processes (ie. GRASS modules)
  11. can be wrapped into one process (ie. model). So it's easier to execute
  12. the model later with slightly different inputs or parameters.
  13. <br>
  14. Models represent a programming technique used in GRASS GIS to
  15. concatenate models together to accomplish a task. It is advantageous
  16. when user see boxes and ovals that are connected by lines and
  17. represent some tasks rather than seeing lines of coded text. Graphical
  18. Modeler can be used as custom tool that automates a process. Created
  19. model can simplify or shorten a task can be run many times and it can
  20. also be shared with others. Important note is that models cannot
  21. perform specified tasks that one cannot perform manually with GRASS
  22. GIS. It is recommended to first do process manually, note the steps
  23. (eg. using Copy button in module dialogs) and later duplicate them in
  24. model.
  25. <p>
  26. The Graphical Modeler allows you to:
  27. <ul>
  28. <li>define data items (raster, vector, 3D raster maps)</li>
  29. <li>define actions (GRASS commands)</li>
  30. <li>define relations between data and action items</li>
  31. <li>define loops (eg. map series) and conditions (if-else statements)</li>
  32. <li>define model variables</li>
  33. <li>parameterize GRASS commands</li>
  34. <li>define intermediate data</li>
  35. <li>validate and run model</li>
  36. <li>store model properties to the file (<i>GRASS Model File|*.gxm</i>)</li>
  37. <li>export model to Python script</li>
  38. <li>export model to image file</li>
  39. </ul>
  40. <h3>Main dialog</h3>
  41. Graphical Modeler can be launched from the Layer Manager menu
  42. <tt>File -&gt; Graphical modeler</tt> or from the main
  43. toolbar <img src="icons/modeler-main.png" alt="icon">. It's also
  44. available as stand-alone module <em>g.gui.gmodeler</em>.
  45. <p>
  46. The main Graphical Modeler menu contains options which enable the user
  47. to fully control the model. Directly under the main menu one can find
  48. toolbar with buttons (see figure below). There are options like
  49. (<font size="2" color="red">1</font>) Create new model,
  50. (<font size="2" color="red">2</font>) Load model from file,
  51. (<font size="2" color="red">3</font>) Save current model to file,
  52. (<font size="2" color="red">4</font>) Export model to image,
  53. (<font size="2" color="red">5</font>) Export model to Python script,
  54. (<font size="2" color="red">6</font>) Add command (GRASS modul) to
  55. model, (<font size="2" color="red">7</font>) Add data to model,
  56. (<font size="2" color="red">8</font>) Manually define relation between
  57. data and commands, (<font size="2" color="red">9</font>) Add
  58. loop/series to model, (<font size="2" color="red">10</font>) Add
  59. comment to model, (<font size="2" color="red">11</font>) Redraw model
  60. canvas, (<font size="2" color="red">12</font>) Validate model,
  61. (<font size="2" color="red">13</font>) Run model, (<font size="2"
  62. color="red">14</font>) Manage model variables, (<font size="2"
  63. color="red">15</font>) Model settings, (<font size="2"
  64. color="red">16</font>) Show manual and last of them is button
  65. (<font size="2" color="red">17</font>) Quit Graphical Modeler.
  66. <p>
  67. <center>
  68. <img src="g_gui_gmodeler_toolbar.png">
  69. <br>
  70. <i>Figure: Components of Graphical Modeler menu toolbar.</i>
  71. </center>
  72. <p>
  73. There is also lower menu bar in Graphical modeler dialog where one can
  74. manage model items, see commands, add or manage model variables,
  75. define default values and descriptions. Python editor dialog window
  76. allows seeing performation written in Python code. The rightmost tab of
  77. the bottom menu is automatically triggered when the model is activated and
  78. shows all the steps of running GRASS modeler modules. In case of errors
  79. in the calculation process, it is written at that place.
  80. <center>
  81. <a href="g_gui_gmodeler_lower_toolbar.png"><img src="g_gui_gmodeler_lower_toolbar.png" width="700"></a>
  82. <br>
  83. <i>Figure: Lower Graphical Modeler menu toolbar.
  84. </i>
  85. </center>
  86. <h3>Components of models</h3>
  87. The workflow is usually established from four types of diagrams. Input and derived
  88. model data are usually represented with oval diagram.
  89. This type of model elements stores path to
  90. specific data on the user's disk. It is possible to insert vector data, raster data,
  91. database tables, etc. The type of data is clear distinguishable in the model by
  92. its color. Different model elements are shown in the figures below.
  93. <ul>
  94. <li> (<font size="2" color="red">A</font>) raster data: <img src="g_gui_gmodeler_raster.png" alt="raster" style="margin: 0px 0px -5px 0px">
  95. <li> (<font size="2" color="red">B</font>) relation: <img src="g_gui_gmodeler_relation.png" alt="relation" style="margin: 10px 0px 0px 0px">
  96. <li> (<font size="2" color="red">C</font>) GRASS module: <img src="g_gui_gmodeler_modul.png" alt="module" style="margin: 0px 0px -5px 0px">
  97. <li> (<font size="2" color="red">D</font>) loop: <img src="g_gui_gmodeler_loop.png" alt="loop" style="margin: 15px 0px -5px 0px">
  98. <li> (<font size="2" color="red">E</font>) database table: <img src="g_gui_gmodeler_db.png" alt="db" style="margin: 10px 0px -5px 0px">
  99. <li> (<font size="2" color="red">F</font>) 3D raster data: <img src="g_gui_gmodeler_raster3d.png" alt="raster3D" style="margin: 10px 0px -5px 0px">
  100. <li> (<font size="2" color="red">G</font>) vector data: <img src="g_gui_gmodeler_vector.png" alt="vector" style="margin: 10px 0px -5px 0px">
  101. <li> (<font size="2" color="red">H</font>) disabled GRASS module: <img src="g_gui_gmodeler_modulex.png" alt="module" style="margin: 10px 0px -5px 0px">
  102. <li> (<font size="2" color="red">I</font>) comment: <img src="g_gui_gmodeler_comment.png" alt="comment" style="margin: 10px 0px -5px 0px">
  103. </ul>
  104. <center>
  105. <a href="g_gui_gmodeler_model_classification.png">
  106. <img src="g_gui_gmodeler_model_classification.png" width="500"></a>
  107. <br>
  108. <i>Figure: A model to perform unsupervised classification using MLC
  109. (<a href="i.maxlik.html">i.maxlik</a>) and SMAP (<a href="i.smap.html">i.smap</a>).
  110. </i>
  111. </center>
  112. <p>
  113. Another example:
  114. <center>
  115. <a href="g_gui_gmodeler_model_usle.png">
  116. <img src="g_gui_gmodeler_model_usle.png" width="600"></a>
  117. <br>
  118. <i>Figure: A model to perform estimation of average annual soil loss
  119. caused by sheet and rill erosion using The Universal Soil Loss
  120. Equation.</i>
  121. </center>
  122. <p>
  123. Example as part of landslide prediction process:
  124. <center>
  125. <a href="g_gui_gmodeler_model_landslides.png">
  126. <img src="g_gui_gmodeler_model_landslides.png" width="600"></a>
  127. <br>
  128. <i>Figure: A model to perform creation of parametric maps used by geologists
  129. to predict landlides in area of interest.</i>
  130. </center>
  131. <h2>EXAMPLE</h2>
  132. In this example the <tt>zipcodes_wake</tt> vector data and the
  133. <tt>elev_state_500m</tt> raster data from the North Carolina
  134. sample dataset (original <a href="http://grass.osgeo.org/sampledata/north_carolina/nc_rast_geotiff.zip">raster</a> and
  135. <a href="http://grass.osgeo.org/sampledata/north_carolina/nc_shape.zip">vector</a>
  136. data) are used to calculate average elevation for every
  137. zone. The important part of the process is Graphical Modeler, namely its
  138. possibilities of process automation.
  139. <p>
  140. In command console the procedure would be as follows:
  141. <div class="code"><pre>
  142. # input data import
  143. r.import input=elev_state_500m.tif output=elevation
  144. v.import input=zipcodes_wake.shp output=zipcodes_wake
  145. # computation region settings
  146. g.region vector=zipcodes_wake
  147. # raster statistics (average values), upload to vector map table calculation
  148. v.rast.stats -c map=zipcodes_wake raster=elevation column_prefix=rst method=average
  149. # univariate statistics on selected table column for zipcode map calculation
  150. v.db.univar map=zipcodes_wake column=rst_average
  151. # conversation from vector to raster layer (due to result presentation)
  152. v.to.rast input=zipcodes_wake output=zipcodes_avg use=attr attribute_column=rst_average
  153. # display settings
  154. r.colors -e map=zipcodes_avg color=bgyr
  155. d.mon start=wx0 bgcolor=white
  156. d.barscale style=arrow_ends color=black bgcolor=white fontsize=10
  157. d.rast map=zipcodes_avg bgcolor=white
  158. d.vect map=zipcodes_wake type=boundary color=black
  159. d.northarrow style=1a at=85.0,15.0 color=black fill_color=black width=0 fontsize=10
  160. d.legend raster=zipcodes_avg lines=50 thin=5 labelnum=5 color=black fontsize=10
  161. </pre></div>
  162. To start performing above steps as an automatic process with Graphical Modeler
  163. press the <img src="icons/modeler-main.png" alt="icon"> icon or
  164. type <em>g.gui.gmodeler</em>. The simplest way of inserting elements
  165. is by adding complete GRASS command to Command field in GRASS command
  166. dialog (see figure below). With full text search one can faster
  167. module hunting. Then label and command can be added. In case that only
  168. module name is inserted, after <i>Enter</i> button pressing, module
  169. dialog window is displayed and it is possible to set all of usual
  170. module options (parameters and flags).
  171. <p>
  172. <center>
  173. <a href="g_gui_gmodeler_dlg_module.png"><img src="g_gui_gmodeler_dlg_module.png"
  174. width="400"></a>
  175. <br>
  176. <i>Figure: Dialog for adding GRASS commands to model.</i>
  177. </center>
  178. <p>
  179. All used modules can be parameterized in the model. That causes launching the
  180. dialog with input options for model after the model is run. In this example
  181. input layers (<tt>zipcodes_wake</tt> vector data and <tt>elev_state_500m</tt>
  182. raster data) are parameterized. Parameterized elements have a little thicker
  183. boarder in the model scheme with diagrams.
  184. <center>
  185. <a href="g_gui_gmodeler_parameter.png">
  186. <img src="g_gui_gmodeler_parameter.png" width="500"></a>
  187. <br>
  188. <i>Figure: Model parameter settings.</i>
  189. </center>
  190. <p>
  191. The final model, the list of all model items, and the Python code window with
  192. <i>Save</i> and <i>Run</i> option are in the figures below.
  193. <center>
  194. <a href="g_gui_gmodeler_model_avg.png">
  195. <img src="g_gui_gmodeler_model_avg.png" width="600"></a>
  196. <br>
  197. <i>Figure: A model to perform average statistics for zipcode zones.</i>
  198. </center>
  199. <br>
  200. <center>
  201. <a href="g_gui_gmodeler_items.png">
  202. <img src="g_gui_gmodeler_items.png" width="600"></a>
  203. <p>
  204. <a href="g_gui_gmodeler_python.png">
  205. <img src="g_gui_gmodeler_python.png" width="600"></a>
  206. <br>
  207. <i>Figure: Items with Python editor window.</i>
  208. </center>
  209. <p>
  210. The resultant model for Graphical Modeler is available
  211. <a href="g_gui_gmodeler_zipcodes_avg_elevation.gxm">here</a>.
  212. <p>
  213. After model is run with <img src="icons/execute.png" alt="run"> button
  214. and inputs are set, results can be displayed as follows:
  215. <center>
  216. <a href="g_gui_gmodeler_avg_run.png"><img src="g_gui_gmodeler_avg_run.png" width="500"></a>
  217. <a href="g_gui_gmodeler_avg_map.png"><img src="g_gui_gmodeler_avg_map.png" width="300"></a>
  218. <br>
  219. <i>Figure: Average elevation for zipcodes using North Carolina sample dataset as
  220. automatic calculation performed by Graphical Modeler.</i>
  221. </center>
  222. <p>
  223. When one wants to run model again with the same data or the same names, it is
  224. necessary to use <tt>--overwrite</tt> option. It will cause maps with identical
  225. names to be overwritten. Instead of setting it for every
  226. module separately it is handy to change Model Property settings globally.
  227. This dialog includes also metadata settings, where model name, model description
  228. and autor(s) of model can be set.
  229. <center>
  230. <a href="g_gui_gmodeler_model_properties.png">
  231. <img src="g_gui_gmodeler_model_properties.png" width="350"></a>
  232. <br>
  233. <i>Figure: Model properties.</i>
  234. </center>
  235. <p>
  236. Another useful trick is the possibility to set variables. Their content can be used
  237. as a substitute for other items. Value of variables can be values such as
  238. raster or vector data, integer, float, string value or they may constitute some
  239. region, mapset, file or direction data type.
  240. Then it is not
  241. necessary to set any parameters for input data. Dialog with viariable settings
  242. is automatically displayed after model is run. So, instead of Model parameters
  243. (e.g. <tt>r.import</tt> a <tt>v.import</tt>, see
  244. <em><a href="g_gui_gmodeler_avg_run.png">Run model dialog</a></em> above)
  245. there are <tt>Variables</tt>.
  246. <center>
  247. <a href="g_gui_gmodeler_variables_run.png">
  248. <img src="g_gui_gmodeler_variables_run.png" width="500"></a>
  249. <br>
  250. <i>Figure: Model with variable inputs.</i>
  251. </center>
  252. <p>
  253. The key point is usage of <tt>%</tt> before the substituting variable and
  254. settings in Variables dialog. For example, when there is a model variable
  255. <tt>raster</tt> that references a file path and that value is required to be
  256. used as one of inputs to a particular model, it should be specified in Variable
  257. dialog with competent name (<tt>raster</tt>), data type, default value and
  258. description. Then it should be set in module dialog as input called
  259. <tt>%raster</tt>.
  260. <center>
  261. <a href="g_gui_gmodeler_variables.png">
  262. <img src="g_gui_gmodeler_variables.png" width="600"></a>
  263. <br>
  264. <i>Figure: Example of raster file variable settings.</i>
  265. </center>
  266. <br>
  267. <center>
  268. <a href="g_gui_gmodeler_variables_raster.png">
  269. <img src="g_gui_gmodeler_variables_raster.png" width="600"></a>
  270. <br>
  271. <i>Figure: Example of raster file variable usage.</i>
  272. </center>
  273. <p>
  274. Finally, the model settings can be stored to the file as a GRASS GIS Model
  275. File <tt>*.gxm</tt> what represents very handy advantage. It can be shared as reusable
  276. workflow that be run by different users with different data.
  277. <p>
  278. For example, this model can later be used to calculate (let's say)
  279. average precipe value for every administrative region in Slovakia
  280. using <tt>precip</tt> raster data from
  281. <a href="https://grass.osgeo.org/uploads/grass/sampledata/slovakia3d_grass7.tar.gz">
  282. Slovakia precipitation dataset</a> and administration boudaries of Slovakia from
  283. <a href="https://www.geoportal.sk/sk/zbgis_smd/na-stiahnutie/">Slovak Geoportal</a>
  284. (only with a few clicks).
  285. <p>
  286. There can be some data in a model that did not exist before the process and
  287. that it is not worth it to maintain after the process executes. They can
  288. be described as being <tt>Intermediate</tt> by single clicking using the right
  289. mouse button, see figure below. All such data should be deleted following
  290. model completion. The boundary of intermediate component is dotted line.
  291. <center>
  292. <a href="g_gui_gmodeler_intermediate_data.png">
  293. <img src="g_gui_gmodeler_intermediate_data.png" width="400"></a>
  294. <br>
  295. <i>Figure: Usage and definition of intermediate data in model.</i>
  296. </center>
  297. <p>
  298. Using Python editor in wxGUI Graphical Modeler one can add python code and then
  299. run it with <tt>Run</tt> button or just save it as python script <tt>*.py</tt>.
  300. Result is shown below.
  301. <center>
  302. <a href="g_gui_gmodeler_python_code.png">
  303. <img src="g_gui_gmodeler_python_code.png" width="350"></a>
  304. <a href="g_gui_gmodeler_python_code_result.png">
  305. <img src="g_gui_gmodeler_python_code_result.png" width="350"></a>
  306. <br>
  307. <i>Figure: Python editor in wxGUI Graphical Modeler.</i>
  308. </center>
  309. <p>
  310. In the example below the <a href="http://e4ftl01.cr.usgs.gov/MOLT/MOD13Q1.006/">MODIS MOD13Q1</a>
  311. (NDVI) satellite data products are used in a loop. The original data are
  312. stored as coded integer values that need to be multiplied by the
  313. value <tt>0.0001</tt> to represent real <i>ndvi values</i>. Moreover, GRASS GIS
  314. provides a predefined color table called <tt>ndvi</tt> to represent <i>ndvi data</i>.
  315. In this case it is not necessary to work with every image separately.
  316. <br>
  317. The Graphical Modeler is an appropriate tool to
  318. process data in an effective way using loop and variables (<tt>%map</tt> for a
  319. particular MODIS image in mapset and <tt>%ndvi</tt> for original data name suffix).
  320. After the loop component is added to model, it is necessary to define series of maps
  321. with required settings of map type, mapset, etc.
  322. <center>
  323. <a href="g_gui_gmodeler_loop_dlg.png">
  324. <img src="g_gui_gmodeler_loop_dlg.png" width="300"></a>
  325. <br>
  326. <i>Figure: MODIS data representation in GRASS GIS after Graphical Modeler usage.</i>
  327. </center>
  328. <p>
  329. When the model is supplemented by all of modules, these modules should be
  330. ticked in the boxes of loop dialog. The final model and its results are shown below.
  331. <center>
  332. <a href="g_gui_gmodeler_loop_final.png">
  333. <img src="g_gui_gmodeler_loop_final.png" width="400"></a>
  334. <br>
  335. <i>Figure: Model with loop.</i>
  336. </center>
  337. <p>
  338. <center>
  339. <a href="g_gui_gmodeler_modis_1o.png">
  340. <img src="g_gui_gmodeler_modis_1o.png" width="300"></a>
  341. <a href="g_gui_gmodeler_modis_1.png">
  342. <img src="g_gui_gmodeler_modis_1.png" width="300"></a>
  343. <a href="g_gui_gmodeler_modis_2o.png">
  344. <img src="g_gui_gmodeler_modis_2o.png" width="300"></a><br>
  345. <a href="g_gui_gmodeler_modis_2.png">
  346. <img src="g_gui_gmodeler_modis_2.png" width="300"></a>
  347. <a href="g_gui_gmodeler_modis_3o.png">
  348. <img src="g_gui_gmodeler_modis_3o.png" width="300"></a>
  349. <a href="g_gui_gmodeler_modis_3.png">
  350. <img src="g_gui_gmodeler_modis_3.png" width="300"></a>
  351. <br>
  352. <i>Figure: MODIS data representation in GRASS GIS after Graphical Modeler usage.</i>
  353. </center>
  354. <p>
  355. The steps to enter in the command console would be as follows:
  356. <div class="code"><pre>
  357. # rename original image with preselected suffix
  358. g.rename raster = %map,%map.%ndvi
  359. # convert integer values
  360. r.mapcalc expression = %map = %map.%ndvi * 0.0001
  361. # set color table appropriate for nvdi data
  362. r.colors = map = %map color = ndvi
  363. </pre></div>
  364. <h2>SEE ALSO</h2>
  365. <em>
  366. <a href="wxGUI.html">wxGUI</a><br>
  367. <a href="wxGUI.components.html">wxGUI components</a>
  368. </em>
  369. <p>
  370. See also selected user models available from this
  371. <a href="http://svn.osgeo.org/grass/grass-addons/grass7/models">SVN repository</a>.
  372. <p>
  373. See also
  374. the <a href="http://grasswiki.osgeo.org/wiki/WxGUI_Graphical_Modeler">wiki</a> page
  375. (especially various <a href="http://grasswiki.osgeo.org/wiki/WxGUI_Graphical_Modeler#Video_tutorials">video
  376. tutorials</a>).
  377. <h2>AUTHORS</h2>
  378. Martin Landa, OSGeoREL, Czech Technical University in Prague, Czech Republic<br>
  379. Various manual improvements by Ludmila Furkevicova, Slovak University of Technology in Bratislava, Slovak Republic
  380. <p>
  381. <i>$Date$</i>