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_7 [2019/08/13 14:04]
argemiro ↷ Page name changed from lesson_9 to lesson_7
lesson_7 [2020/02/19 16:44]
argemiro
Line 1: Line 1:
-=====LESSON 7Calculating a lookup table using algebraic/​logical expression involving tables and values=====  ​+{{ :logo_logo.png?​400 |}}
 \\ \\
 \\ \\
-**Which Functors will you use in this lesson?**\\ \\ +====LESSON 7Creating a new column ​and retrieving a data column from tables====
-• FunctorsLoad Map and Save Map\\+
 \\ \\
- +  * To create ​new column in a given table we must open all the files that will be used to retrieve data from. Click on the Input/Output tab from the library window ​and grab three [[Load Lookup Table]] Functors and one [[Load Table]] placing them on the sketch. Open the [[Load Lookup Table]] functors and load the files ''​1999_production_value.csv'',​ ''​1999_harvested_area.csv''​ and ''​1999_production.csv''​ from the folder ''​Guidebook_Dinamica_5\Database\Tables\''​. Next, open [[Load Table]] and load ''​IBGE_crop_information_uptated.csv''​.
-we would like to demonstrate an example for calculate ​lookup ​table using algebraic/logical expression involving tables ​and values ​on Dinamica EGO+
 \\ \\
 \\ \\
-**The intention of this example is answer two questions:**\\+{{ :imagem43.png?​200 |}}
 \\ \\
-- In what year did the highest productivity for crop 3 occur? ​ 
 \\ \\
-- What was the value of this productivity?​+  * Now we can create a new column merge between ​the ''​1999_harvested_area.csv''​ and ''​1999_production.csv''​ files. On the Input/​Output tab, grab an [[Add Table Column]] and place it on the sketch. Connect the [[Load Lookup Table]] which contains the file ''​1999_harvested_area.csv''​ to [[Add Table Column]], selecting __Table__ as an input port. On the Functor Editor window, write a name for the created column (e.g. “production_value”). ​
 \\ \\
 \\ \\
-We will use: +<note important>​ 
-The Complete IBGE crop information Table (Dinamica EGO\Guidebook Dinamica_4\Models\Set_2\basics\IBGE_crop_information_complete.csv)+The position where the new column is inserted determines whether the new column is a key or data column. 
 +</​note>​
 \\ \\
 \\ \\
- +{{ :imagem44.png?500 |}}
-First, grab a “Load Table” and place it on the sketch. Double click the Load Table Functor and open the IBGE_crop_information_complete.csv file. +
-Now, we can switch the order of the year and crop columns. For this, grab a “Reorder Table Column” and place it on the sketch. Connect the Load Table to Reorder Table Column. In the Functor Editor window insert the index of the column to be moved (“1”) and the new column index.+
 \\ \\
 \\ \\
 +  * Connect the [[Load Lookup Table]] which contains the file ''​1999_production.csv''​ to [[Add Table Column]], the __Column Values__ port will be automatically assigned as an input port.
 \\ \\
 +  * Add another [[Add Table Column]] to the sketch, assign the output of the previous [[Add Table Column]] to the __Table__ input port of the recently added functor. Connect the [[Load Lookup Table]] with ''​1999_production_value.csv''​ to the new [[Add Table Column]]. In the Functor Editor window, choose a name for the created column (e.g. "​production"​). ​
 \\ \\
- +  * Add [[Set Table By Key]] to the sketch, assign ​the output of [[Add Table Column]] to the __Subtable__ input port of [[Set Table By Key]] and the [[Load Table]] with ''​IBGE_crop_information_uptated.csv''​ to the __Table__ port. In the Functor Editor ​window, enter ''​1999''​ as the key identifying the sub-table that will be updated or inserted. Additionally,​ toggle the __Ignore Column Names__ flag in the Functor Editor Window.
-Now, we can retrieve the harvested area per year corresponding to one of the crops. For this, first, grab “Get ​Table from key” and place it on the sketch. Connect ​the Reorder ​Table Column to Get Table from Key. In the functor editor ​window, enter the chain of keys (“3”) ​identifying the sub-table that will be retrieved. +
- \\+
 \\ \\
 +  * To save the result to a file, place a [[Save Table]] on the sketch, browse to ''​\Guidebook_Dinamica_5\Models\add_table_column_set_table_by_key''​ and write the file name (e.g. ''​IBGE_crop_information_complete''​). ​
 \\ \\
 +  * Click on the layout tool Execute Layout. Your final model should be similar to the one below: ​
 +\\ 
 \\ \\
-We can retrieve data column table corresponding to harvested area and data column table corresponding to productionFor this, grab two “Get Table Column” functors and place it on the sketch. Connect the Get Table from Key to these two Get Table Column Functors. For the first Get Table Column, in the tab Column Index or Name, insert the index of the column to be retrieved (“2” or “harvested area”). For the second Get Table Column, in the tab Column Index or Name, insert the index of the column to be retrieved (“3” or “production”). +{{ :imagem45.png?500 |}}
- \\+
 \\ \\
 \\ \\
 +  * Save and run the model. Select the [[Save Table]] functor and click on the eye button to open the resulting table.
 \\ \\
-Now, grab two “Lookup Table” functors and place it on the sketch. Connect each one of these Get Table from key Functors to one Lookup Table to convert each one of these two tables to a lookup Tables. 
- \\ 
 \\ \\
 +{{ :​imagem46.png?​500 |}}
 \\ \\
 \\ \\
-Now, we will calculate the increase in harvested area between consecutive years. For this, grab Calculate Lookup Table and place it on the sketch. Click in the hook tool and insert a Number Table inside on the Calculate Lookup Table. Assign a number to   ​Number Value+ 
 +---- 
 + 
 +Using the table generated previously, we would like to demonstrate how to retrieve ​data column from it.
 \\ \\
 \\ \\
 +  * Grab a [[Load Table]], placing it on the sketch. Double click it and open the file generated in last step (e.g. ''​IBGE_crop_information_complete.csv''​).
 \\ \\
 \\ \\
-  +{{ :imagem47.png?500 |}}
-Now, Connect the functors Harvested Area and Harvested Quantify to Number Table +
- \\+
 \\ \\
 \\ \\
 +  * To retrieve a data column corresponding to the harvested area, we will use [[Get Table Column]]. Connect the [[Load Table]] to [[Get Table Column]]. In the input __Column Index or Name__ of the Functor Editor window, insert the index of the column to be retrieved (“3” or “harvested area”).
 \\ \\
-Double-click on Calculate value to add an expression to calculate the increase in harvested area between consecutive years. ​ 
-We used the expression: ​ 
-t2[line] / t1[line]. 
- \\ 
 \\ \\
 +{{ :​imagem48.png?​500 |}}
 \\ \\
 \\ \\
-Now, we extract attributes and summary statistics from a lookup table generated. For this, grab a “Extract Lookup ​Table Attributes” ​and place it on the sketch. Connect ​the Calculate Map and Extract Lookup ​Table Attributes. +  * Now, we can retrieve the harvested area per crop corresponding to the year of 2004 For this, grab a [[Get Table from Key]] and place it on the sketch. Connect ​[[Get Table Column]] to [[Get Table from Key]]. In the input __Keys__ of the Functor Editor window, insert the year you want to retrieve the harvested area per crop (in this example, “2004”).
- \\+
 \\ \\
 \\ \\
 +{{ :​imagem49.png?​500 |}}
 \\ \\
-Grab two “Get Lookup Table Value” Functors and place it on the sketch. Connect one Extract Lookup Table Attributes to each one of these Get Lookup Table Value Functors to retrieve a value at a specified key: 13 and 21, respectively (Specified in the Key box of the Functor editor window). The first takes the mode of the keys and the second takes the highest value. 
- \\ 
 \\ \\
 +  * Grab a [[Save Table]] and place it on the sketch. Connect [[Get Table From Key]] and [[Save Table]]. The final model should have the following structure: ​
 \\ \\
 \\ \\
-Now, to set values into a lookup table, grab a “Set Lookup Table Value” and place it on the sketch. Connect each Get Lookup Table Value on the Set Lookup Table Value (One is the mode key and other is the max value, i.e. most productive year and maximum productivity,​ respectively).+{{ :imagem50.png?500 |}}
 \\ \\
 \\ \\
-<note tip>**TIP:​**If ​the table is already filled init replaces ​the old values with new values.</​note>​+  ​To save the result to a fileedit [[Save Table]], browse to ''​\Guidebook_Dinamica_5\Models\add_table_column_set_table_by_key''​ and write the file name (e.g. IBGE_crop_information_update).
 \\ \\
 \\ \\
-{{ :imagem63.png?400 |}} +{{ :imagem51.png?500 |}}
-Finally, you need to save the result to a file. Grab a “Save Lookup Table”, place it on the sketch and connect the functor Set lookup table value. Open Save Map, browse to the preferred folder and write the name file (maximum_productive_year_and_productivity.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: ​ 
- \\ 
 \\ \\
-{{ :imagem64.png?1500 |}}+  * Save and run the modelTo see the resulting table, click on eye button of [[Save Table]]. This functor output is a table that looks like this:
 \\ \\
 \\ \\
-Now, click on eye button of “Save Lookup Table” to see the result. This functor output is table that looks like this: +{{ :imagem53.png?​300 |}}
- +
 \\ \\
 \\ \\
-{{ :​imagem65.png?​400 |}}+==== Congratulations,​ you have successfully completed this lesson! ====
 \\ \\
 +☞[[:​lesson_8 | Next Lesson]]
 \\ \\
-What does the result say about productivity along the analyzed period? **We can infer that 2011 was the most productive year with a productivity of 3.121386 tons/​ha.** +☞[[:​guidebook_start| Back to Guidebook Start]] ​