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 or xml) and your data directory. This will work as expected.

Workdir

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. 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 zip files.

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.

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 zip file, you have to use a Workdir container. Then, edit the Workdir and use the 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 zip archive.

Loops

A loop executes multiple steps simultaneously when all of the following conditions are met:

  • No connection is passed out of the loop.
  • No Mux functor is used directly inside the loop.
  • 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.

Create String

In the formatting parameters of Create String:

  • Padding specifies the total length of the final string, in number of characters, including characters such as “.” and “-”.
  • Precision specifies the total number of numeric digits, before any padding is added.

For example, the value -14.0392632603687, formatted as “<v1, 7, 4>” (7 characters of padding and 4 digits of precision), produces “0-14.04”. The leading “0” corresponds to the padding.

Calculate Python Expression

Packages can be installed from Calculate Python Expression in two ways:

  • Option (a): Using the dinamica.package(“package name”) function (one function call per package).
  • Option (b): Passing the list of packages to the “packages” port (one package name per line).

The difference between these two options is timing:

  • Option (a) runs during the execution of the Python script, so it can be called conditionally.
  • 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.

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”).

In addition, both forms allow installation parameters to be passed to the packages:

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.

Performance

  • Avoid the definition of maps using cell type “1 Bit Integer”. This cell type saves memory, but it also has a huge negative impact in performance.
  • Keep updated the Dinamica EGO installed in your system.