Useful Tips for Creating Models

The following are useful tips for creating models.

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.

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.

Submodel Group Names in the Functor Library

A submodel's group name can contain subgroups. To define a name within a subgroup, separate 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

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 (a) 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:

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.