Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lesson_14 [2019/08/30 14:08]
argemiro
lesson_14 [2020/02/20 17:43] (current)
argemiro
Line 1: Line 1:
-{{ :logo_guidebook1.jpg?400 |}} +{{ :logo_logo.png?400 |}}
-\\ +
-=====LESSON 14: Using "​For"​ to make successive calculations===== ​  +
-\\+
 \\ \\
 +=====  LESSON 14: Using "For Each Category"​ and "​Region Manager"​ to works with the concept of region ​ =====
 +
  
 ==== What will you learn? ==== ==== What will you learn? ====
 + 
 + 
  
 +  * How to use the concept of Regions
 +  * Functors: \\ - //[[:Region Manager]]//​\\ - //[[:For Each Category]]//​
 +
 +{{ :​tutorial:​region1.jpg|}}\\
 \\ \\
 +This subset of functors permits division of a map into several regional maps, which can be input for separate models or submodels, whose parameters are customized for each map’s region. Let’s adapt the model ''​Calc_forest_remaining_extent_per_state''​ (You can find this model in the folder: ''​\Guidebook_Dinamica_5\Models\using_concept_of_region''​) to use the concept of regions. First open the Region Tab in the library window.\\
 \\ \\
-The intent of this exercise is: 
 \\ \\
 \\ \\
-For thiswe will use:  +These functors can be combined to produce regional maps and submodelsas well as to merge the regional maps into a single map after a processing is performed. In this lesson you will learn how to retrieve the area of the remaining forest for each state; as a result each regional ​map will correspond to a state areaOpen the model the model ''​Calc_forest_remaining_extent_per_state''​Select the functors within the container ​//[[:Repeat]]// with the Hand tool and then drag them out of //[[:Repeat]]//.\\
-  * The protected areas map in the year 2000 i.e(Guidebook Dinamica_4/Database/Protected_areas/protected_areas_2000.tif) +
-  * The protected areas map in the year 2006 (Guidebook Dinamica_4/Database/Protected_areas/​protected_areas_2006.tif) +
-  * The Legal Amazon Biomass map (Guidebook Dinamica_4/​Database/biomass/biomass.tif)+
 \\ \\
 + ​{{:​tutorial:​inc._it._model_17.jpg|}}{{:​tutorial:​region2.jpg|}}
 +
 +
 +
 +<note tip>​**TIP**:​ Use Crtl + right button to keep continually selecting the functors, this will avoid selecting //​[[:​Repeat]]//​ as well. The functor //​[[:​Repeat]]//​ will shrink.
 +</​note>​
 +
 +Delete the container //​[[:​Repeat]]//​ and place the containers //[[:Region Manager]]// from the Region tab and //[[:For Each Category]]//​ from the Control tab. Place the latter within the first.{{ :​tutorial:​region3.jpg |}}\\
 \\ \\
-Initiallywe must open all the files that will be used. Click on the Input/output tab and from the library windowgrab two Load Categorical ​Map functors ​and place on the sketchDouble click each Load Categorical Map Functor ​and open the Protected areas map files for 2000 and 2006. Also grab and place one Load Map functor and open the Legal Amazon Biomass ​map.+//[[:Region Manager]]// manages the regionalization processwhile //[[:For Each Category]]//​ replaces ​the //​[[:​Repeat]]//​ making the model iterate for each category present in the categorical map used to define the regions, in this case the map of the Brazilian Amazon states. 
 + 
 +<​note>​While //​[[:​Repeat]]//​ iterates sequentially,​ //[[:For Each Category]]//​ iterates according to the map categories, which do not need to be sequential.<​/note> 
 + 
 +Now select all functors, except ​the input and output mapsand place them within //[[:For Each Category]]//​.  
 + 
 +<note tip>​**TIP**:​ it is easier to select everything to be placed within //[[:For Each Category]]//​ and then to take only //[[:Load Map]]// and //[[:Save Map]]// out of it.</​note> ​  
 + 
 +Now break the link between //[[:Load Categorical Map]]// and //​[[:​Calculate Map]]// (use the Remove Items tool and click on the arrow connecting both functors); next, connect the first to //[[:Region Manager]]// ​and to //[[:For Each Category]]//​ too. This map will control the regionalization process splitting the other maps into several regions according to its cell classes or categories through the functor //​[[:​Regionalize ​Map]]//. Drag this functor and place it within //[[:For Each Category]]//,​ break the link between Map ''​brazilian_amazon_lanscape.tif''​ (You can find this map in the folder: ''​\Guidebook_Dinamica_5\Database\using_concept_of_region''​) and //​[[:​Calculate Map]]// and finally connect the first to //​[[:​Regionalize Map]]//​. ​  
 + 
 +{{ :​tutorial:​region6.jpg |}}\\
 \\ \\
 +Note that there are two //[[:Number Map]]// functors disconnected within //​[[:​Calculate Map]]//. You do not need the Map #2 and Value #1 anymore, so delete them. Now connect //​[[:​Regionalize Map]]// to Map #1. Open the [[:​Save ​
 +Lookup Table]] functor and change the file name to ''​remaining_forest_extent_per_state''​. Make sure it will be saved into folder ''​\Guidebook_Dinamica_5\Models\using_concept_of_region''​\\
 \\ \\
-{{ :14a.png?​200 ​|}}+{{ :tutorial:​region7.jpg |}}\\
 \\ \\
 \\ \\
-Grab and place on the sketch one Calculate Map ContainerClick in the hook tool to insert three Number Map functorAssign a numbers to each Number ValueConnect the Load Map and Load Categorical Map to Number Map functors+At a last step, you will need to modify ​the //[[:Calculate Map]]//Open it with Edit FunctorWrite: **if i1 = 2 then 1 else null**Remember that "​2"​ represents forest.\\
 \\ \\
 +{{ :​tutorial:​region5.jpg |}}\\
 \\ \\
-{{ :14b.png?400 |}}+Finally save the model as a new file ''​calc_forest_remaining_extent_per_state_using_subregions''​ into folder ''​\Guidebook_Dinamica_5\Database\using_concept_of_region''​ and run it.\\ 
 \\ \\
 +Can you explain how this model works?\\
 \\ \\
-Now, write the following equation inside ​to Calculate Map to calculate biomass in expanded protected areas (2000-2006) using the Number Map functors:  ​+Observe that you did not need to segregate the information per state in //[[:Calculate Map]]// because //​[[:​Regionalize Map]]// already did it. 
 +  
 +<​note>​The region approach is a helpful way to break the map into several subsets either to customize a submodel, for example to run with different parameters per country, state or county, or to optimize the memory usage as the model does not need to handle all the map cells for a specific calculation or processing, but only the cells selected from a region per time</​note>​
 \\ \\
-if not isNull(i2) and isNull(i3) then 
-    i1 
-else  
-    null 
 \\ \\
-{{ :​14c.png?​400 |}}+===Congratulations,​ you have successfully completed this lesson!===
 \\ \\
 +☞[[lesson_15|Next Lesson]]
 \\ \\
-Click on the Input/​output from the library window, grab and place on the sketch the Save map functor and connect the functor Calculate Map and Save Table. Open Save Map, browse to the Guidebook Dinamica_4/​Models/​Set_3/​basics/​3_calculate map4/ and  write the name file (Suggestion:​ expanded protected areas biomass.tif). +[[:guidebook_startBack to Guidebook ​Start]]
-Grab and place on the sketch the Extract map attributes functor and Connect the functor Calculate Map to Extract map attributes. +
-\\ +
-\\ +
-{{ :​14d.png?​400 |}} +
-\\ +
-\\ +
-Now, grab and place on the sketch one Calculate value functor to . Click in the hook tool to create three hook functors inside the Calculate Map: one Number table and two Number value functors. Click on the Number value functor and number table with the Functor Editor tool and enter “1”, “2” and “3”, respectively. This is a number identifier for each element and will be represented within the equation box as v1 (value 1), v2 (value 2) and t1(table 1) respectively.  +
-\\ +
-Grab and place on the sketch two Real value functors to insert a double precision real constant: A CO2 conversion factor (3.666) and a Carbon Content (0.47). Connect the Extract map attributes Map to Number Table and the two Real Value functors to Number Value Functor inside the Calculate Value. +
-\\ +
-\\ +
-{{ :​14e.png?​400 |}} +
-\\ +
-\\ +
-Now, write the following equation inside to Calculate Map to calculate CO2 content in expanded protected areas (2000-2006):​ \\ +
-t1["​cellSum"​] * t1["​cellArea"​] * v1 * v2 +
-\\ +
-\\ +
-{{ :14f.png?​400 ​|}} +
-\\ +
-\\ +
-<note tip>TIP: You can copy an equation from a text editor (using Ctrl+C) and paste it in the equation box (using Ctrl+V).</​note>​ +
-\\ +
-\\ +
-Grab and place on the sketch one Set Lookup Table Value Functor ​to insert the calculate values into a lookup table. It is important to pay attention to add correctly the key to the line in which the value will be inserted. +
-\\ +
-\\ +
-{{ :​14g.png?​400 |}} +
-\\ +
-\\ +
-Click on the Input/​output from the library window, grab and place on the sketch the Save Lookup Table functor. Connect the Set Lookup Table Value to Save Lookup Table. Open Save Table, browse to the C:/​Users/​at-lf/​Documents/​GuideBook Dinamica/Guidebook ​Dinamica_4/​Models/​Set_3/​basics/​3_calculate map4/ and  write the name file (expanded protected areas co2.csv). \\ +
-Mark the eye button at the top of “Save Table” to viewer the results hereafter. Save and run the model! +
-\\ +
-Click on the layout tool Left to Right and your final model will look like the one below:  +
-\\ +
-\\ +
-{{ :​14h.png?​400 |}} +
-\\ +
-\\ +
-Now, click on eye button of “Save Lookup Table” to see the result. This functor output is table that looks like this: +
-\\ +
-\\ +
-{{ :​14i.png?​400 |}} +
-\\ +
-\\ +
-**Now, the input map is produced for each iteration, calculating Map produces a map containing the remaining forest for each category.** +
-\\ +
-\\ +
-Grab the container Repeat from the Control tab and place it on the sketch. Drag the previously model into it. It will automatically resize to envelop Calculate Map.  +
-\\ +
-\\ +
-Then add the functor Step into Repeat. Open Calculate Map by clicking on its top left icon and connect Step to Value port of Number Value. The Step functor self-associates to the enveloping container and passes to Calculate Map the current step. Thus for each iteration Calculate Map produces a map containing the current Amazon Protected areas for each time step.  +
-\\ +
-\\ +
-{{ :​14j.png?​400 |}} +
-\\ +
-\\ +
-Now you need to fill in a table in order to store the area calculated for each category. The functor Set Table Cell Value updates a table placing a value to a position defined by a key. To fill in the entire table, you need to develop a loop that enables this functor to browse through the table. To close this loop, you will need a functor that is key to the development of dynamic models.  +
-\\ +
-\\ +
-Here we introduce the concept of Mux functor. A Mux functor can be a map, a categorical map, a lookup table, a table or a value. Look at the Control tab to find Mux Table and drag it into Repeat. Also drag Set Table Cell Value from the Table tab. +
-\\ +
-\\ +
-{{ :​14k.png?​400 |}} +
-\\ +
-\\ +
-Now, click on the Mux Table with the Edit Functor Ports. Every Mux functor has two input ports. In the first iteration, it reads the input from the Initial port; thereafter it receives the data from the model step through the port Feedback. This process allows data to be updated by the model, thus becoming dynamic. Hence this functor is key to the incorporation of feedback into a dynamic model.  +
-\\ +
-\\ +
-{{ :​14l.png?​400 |}} +
-\\ +
-\\ +
-Also open Set Table Cell Value with the Edit Functor Ports. This functor receives a table that will be updated with a value placed in a position defined by a key. So you need to connect table output from the functor Mux Lookup table to the input port of Set Table Cell Value. +
-\\ +
-\\ +
-{{ :​14m.png?​400 |}} +
-\\ +
-\\ +
-Again, let’s connect the output from Set Table Cell Value to Mux Table. When a connection has two or more options, the Edit Functor Ports window opens automatically. You have to choose the port Feedback.  +
-\\ +
-\\ +
-{{ :​14n.png?​500 |}} +
-\\ +
-\\ +
-Now click on the port Initial with the right mouse button. You will open a table editor. In this case you just need to enter “0“ and “0” as Key and Value for the first table record, and then save these inputs using the ”+” button. \\ +
-Still, you need to connect the output from Calculate Value to the input port of Set Lookup Table Value.  +
-\\ +
-\\ +
-{{ :​14o.png?​500 |}} +
-\\ +
-\\ +
-The Edit Functor Ports window pops up because there are two options. Connect the arrow to the port Value; the key comes from the current model step via the connection of Step to Set Lookup Table Value. \\ +
-Observe that the feedback connection is between Mux Lookup Table and Set Calculate Value. As a last step, you need to save the lookup table into a file. Drag the functor Save Lookup Table from the Input/​Output tab. Connect Set Lookup Table Value to it and edit the name for the CSV file.  +
-\\ +
-\\ +
-{{ :​14p.png?​500 |}} +
-\\ +
-\\ +
-<note tip>TIP: Although Suffix Digits is “2” by default, the file name won’t have a suffix because it will be saved after Repeat is done.</​note>​ +
-\\ +
-\\ +
-As a last step, you need to save the lookup table into a file. Drag the functor Save Lookup Table from the Input/​Output tab. Connect Set Lookup Table Value to it and edit the name for the CSV file.  +
- +
-Mark the eye button at the top of “Save Table” to viewer the results hereafter. \\ \\ +
-**Save and run the model!** ​ \\ \\ +
-Click on the layout tool Left to Right and your final model will look like the one below:  +
-\\ +
-\\ +
-{{ :​14q.png?​500 |}} +
-\\ +
-\\ +
-Now, click on eye button of “Save Lookup Table” to see the result. This functor output is table that looks like this: +
-\\ +
-\\ +
-{{ :​14r.png?​400 |}} +
-\\ +
-\\ +
-**What is your model doing?** Your model calculates the biomass of the expanded Legal Amazon Protected Areas every year. Thus, it was not necessary to construct a model for each time transition. +
- +
- +
- +