g.gui.gmodeler.html 19 KB

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