This is an old revision of the document!


PHP's gd library is missing or unable to create PNG images



LESSON 11: Creating local Submodels and using a Submodel in a Model


Local submodels can be created by simply selecting the parts of a model that will be converted to a submodel and clicking on the tab Edit โ†’ Create Submodel. The selection will be replaced by the new submodel and the visual representation of the new submodel will be available to be edited as a new tab on the script editor. At any time, the user can make changes to the local submodel and apply those changes clicking on Apply changes / Update Submodel Properties on the model toolbar.

It is also possible to select parts of a local submodel and create another local submodel using that selection. The new local submodel will be a dependency of the previous one, but the submodel creation process is basically the same. If the selection is empty, an empty local submodel will be created. The process for updating an empty submodel is the same process used to update any local submodel.

Initially, we will learn how to create a submodel and next we will learn how to use it in a Model. We will start with the model 5_calculate_lookup_table located in Guidebook_Dinamica_5/Models/Set_2/basics/5_calculate_lookup_table. Using this model we will answer the following question:

What is the productivity for each crop across the considered time window?

  • Select the functors of the model that should be included in the submodel as shown by the image below.





  • With this selection active, Click on Edit tab and next on Create a Submodel to encompass all the selected functors into a local submodel:





  • In the Submodel Editor window, insert a submodel name (e.g. Calc Most Productive year), specify the input and output ports of this submodel and click ok, creating the submodel.





  • Previously, the submodel only calculated productivity for crop 3. Now, we must give the user the option to choose the crop to be calculated. For this, we must create an entry (creating an input for the submodel). For this, place a functor Integer value (where the user can choose the crop - 1, 2 or 3) and connect to get table from key functor:






  • We can use this submodel in an independent model. To do so, select the submodel tab on the sketch, open submodel options and select Publish Submodel:



  • Now, Create a new model script, grab a Load Table Functor and place it on the sketch. Double click the Load Table Functor and open the IBGE_crop_information_complete.csv file located in Guidebook_Dinamica_5/Models/Set_2/basics/2_add_table_column_set_table_by_key/IBGE_crop_information_complete.csv.


  • Grab a Reorder Table Column and place it on the sketch to switch the order of the year and crop key columns. 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 (0).





  • Now, let's insert our previously created Submodel. First, click on the Submodels tab and from the library window grab a Calc Most Productive year Submodel and place it on the sketch. We want to calculate the most productive year for each crop; thus, we will use this Submodel 3 times, i.e. for the crops 1, 2 and 3 inserting the number that corresponds to each crop on the Integer value functor. To save the results to a file, grab three Save Table functors, place them on the sketch and connect to each Submodel (for the three crops). Open Save Table Functors, browse to the Guidebook_Dinamica_5/Models/Set_2/basics/6_submodel and write the file names (e.g. most_productive_year_for_crop_1.csv, most_productive_year_for_crop_2.csv and most_productive_year_for_crop_3.csv).



  • The final model will look like the one in the imagem below. Save and run the model.




  • Now, click on eye button of Save Table to see the result. These functors outputs are tables that looks like this:





What does this result say about the productivity for each crop within the analyzed period?


We can infer that 2009 was the most productive year for Crop 1 along the analyzed period, with a productivity of 80.25549 tons/ha. For the Crop 2, 2015 was the most productive year, with a productivity of 3.535804 tons/ha and 2011 was the most productive year for Crop 3, with a productivity of 3.121386 tons/ha.

Congratulations, you have successfully completed this lesson!