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
model_tips [2026/06/12 14:24]
admin
model_tips [2026/07/26 14:18] (current)
hermann
Line 2: Line 2:
  
 The following are useful tips for creating models. The following are useful tips for creating models.
 +
 +===== File Paths =====
 +
 +The Dinamica EGO interface shows absolute filepaths for easier reading, but they are relative indeed. So, to easily change the location of a model, keep the same path between the script file ([[ego_script|ego]] or [[xml_script|xml]]) and your data directory. This will work as expected.
  
 ===== Workdir ===== ===== Workdir =====
Line 7: Line 11:
 The following functors can be placed, directly or indirectly, inside a **Workdir**:​ Load Map, Load Categorical Map, Load Table, Load Lookup Table, Load Weights, Save Map, Save Categorical Map, Save Table, Save Lookup Table, and Save Weights. The following functors can be placed, directly or indirectly, inside a **Workdir**:​ Load Map, Load Categorical Map, Load Table, Load Lookup Table, Load Weights, Save Map, Save Categorical Map, Save Table, Save Lookup Table, and Save Weights.
  
-When placed inside a Workdir, the file name used by the functor becomes relative to the folder defined by the Workdir. This simplifies switching the input data folder for multiple functors in the same model.+When placed inside a Workdir, the file name used by the functor becomes relative to the folder defined by the Workdir. This simplifies switching the input data folder for multiple functors in the same model. You can use several [[Workdir]] in the same model. 
 + 
 +See the example located in the folder ''​Examples\run_lucc_northern_mato_grosso\run_roads_with_comments_and_workdirs''​ of the Dinamica examples. 
 + 
 +===== Loading Files from Zip Files ===== 
 + 
 +Maps, tables, lookup tables and Weights of Evidence files can be loaded from [[wp>​Zip_(file_format)|zip]] files. 
 + 
 +[[wp>​Zip_(file_format)|Zip]] files are useful to pack all files used by a model in a single archive. However, zipping all files does not increase the amount of data that Dinamica EGO can handle simultaneously. Behind the curtains, Dinamica unzips the files into a temporary folder and loads them from there. 
 + 
 +[[wp>​Zip_(file_format)|Zip]] files are also limited to 4 GBytes in Dinamica. If you use a file outside the zip archive, these files can be much bigger than that. 
 + 
 +To read a file located in a [[wp>​Zip_(file_format)|zip]] file, you have to use a [[Workdir]] container. Then, edit the [[Workdir]] and use the [[wp>​Zip_(file_format)|zip]] file name in the "​folder"​ input port. Place a file loader ([[Load Map]], [[Load Weights]] etc) inside the [[Workdir]] container. The file name mentioned in the file loader must match the name used by the file contained in the [[wp>​Zip_(file_format)|zip]] archive.
  
 ===== Loops ===== ===== Loops =====
Line 17: Line 33:
   * No member of the loop is expected as an output port of a submodel.   * No member of the loop is expected as an output port of a submodel.
  
-Sometimes, however, it is convenient to force a loop that //could// run its steps simultaneously to run them sequentially instead. A simple way to do this is to place a ''​MuxValue 0 0''​ functor inside the loop. +Sometimes, however, it is convenient to force a loop that //could// run its steps simultaneously to run them sequentially instead. A simple way to do this is to place a ''​MuxValue 0 0''​ functor inside the loop. See [[basic_data_flow|Basic Data Flow]] for why these conditions hold — a loop'​s ​iterations are only independentand therefore only parallelizablewhen nothing connects one to the next.
- +
-===== Submodel Group Names in the Functor Library ===== +
- +
-A submodel'​s ​group name can contain subgroups. To define a name within a subgroupseparate the subgroup names in the group name using a colon (''":"''​). For example, the name ''"​Elevation Graph:​Tools:​Debug"''​ defines a //Debug// subgroup inside a //Tools// subgroup, which in turn is inside an //Elevation Graph// group.+
  
 ===== Create String ===== ===== Create String =====
Line 34: Line 46:
 ===== Calculate Python Expression ===== ===== Calculate Python Expression =====
  
-Packages can be installed from **Calculate Python Expression** in two ways:+Packages can be installed ​either by calling ''​dinamica.package(...)'' ​from within the expression (runs during execution, so it can be called conditionally) or by listing them on the //​packages//​ input port (installed before the script runs). See [[calculate_python_expression#​utilities|Calculate Python Expression ​— Utilities]] for the full ''​dinamica.package()''​ syntax and examples.
  
-  * Option (a) Using the ''​dinamica.package("​package name"​)''​ function (one function call per package). +===== Calculate R Expression =====
-  * Option (a) Passing the list of packages to the **"​packages"​** port (one package name per line).+
  
-The difference between these two options is timing:+Packages can be installed from **Calculate R Expression** using the ''​dinamicaPackage("​package name"​)''​ function (one function call per package). ''​dinamicaPackage("​package"​)''​ also acts as an ''​import''​ clausewhen the package name is the same as the name of the module to be loaded via ''​import'',​ the package is installed and the module of the same name is loaded. See [[calculate_r_expression#​installing_packages|Calculate R Expression — Installing Packages]] for more detail.
  
-  * Option (a) runs **during** the execution of the Python script, so it can be called conditionally. +===== Wizards =====
-  * Option (b) always runs **before** the script is executed.+
  
-Because option (a) runs together with the script, it may fail if a package is already loaded but in a version incompatible with the package about to be installed.+Functors that are part of submodel cannot export input and/or output ports to wizards.
  
-Option (a), ''​dinamica.package("​package"​)'',​ also acts as an ''​import''​ clause: when the package name is the same as the name of the module to be loaded via ''​import'',​ the package is installed and the module of the same name is loaded. If the package name and its internal module name differ, you can use the syntax ''​dinamica.package("​module name", "​package name"​)'',​ for example ''​dinamica.package("​samgeo",​ "​segment-geospatial"​)''​.+===== Performance =====
  
-In additionboth forms allow installation parameters to be passed to the packages:+  * Avoid the definition of maps using [[cell type type|cell type]] "1 Bit Integer"​. This cell type saves memorybut it also has a huge negative impact in performance. 
 +  * Keep updated ​the Dinamica EGO installed in your system.
  
-  * Option (a): ''​dinamica.package("​torchvision",​ "​torchvision==0.19.1 --index-url https://​download.pytorch.org/​whl/​cu121"​)''​ 
-  * Option (b): pass the string ''​torchvision==0.19.1 --index-url https://​download.pytorch.org/​whl/​cu121''​ to the **"​packages"​** port. 
  
-These parameters are those accepted by Python'​s ''​pip''​. 
- 
-===== Calculate R Expression ===== 
- 
-Packages can be installed from **Calculate R Expression** using the ''​dinamicaPackage("​package name"​)''​ function (one function call per package). ''​dinamicaPackage("​package"​)''​ also acts as an ''​import''​ clause: when the package name is the same as the name of the module to be loaded via ''​import'',​ the package is installed and the module of the same name is loaded. 
- 
-===== Wizards ===== 
- 
-Functors that are part of a submodel cannot export input and/or output ports to wizards.