Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
calculate_python_expression [2026/08/18 02:22] hermann |
calculate_python_expression [2026/08/18 20:55] (current) hermann |
||
|---|---|---|---|
| Line 60: | Line 60: | ||
| <code> | <code> | ||
| - | result := CalculatePythonExpression ($"( | + | result := CalculatePythonExpression $"( |
| myTable = [["PatchId*", "Area"], [1, 12.4], [2, 8.7]] | myTable = [["PatchId*", "Area"], [1, 12.4], [2, 8.7]] | ||
| dinamica.outputs['patchCount'] = 42 | dinamica.outputs['patchCount'] = 42 | ||
| dinamica.outputs['filteredPatches'] = dinamica.prepareTable(myTable, 1) | dinamica.outputs['filteredPatches'] = dinamica.prepareTable(myTable, 1) | ||
| - | )") {{ }}; | + | )" {{ }}; |
| patchCount := ExtractStructNumber result "patchCount"; | patchCount := ExtractStructNumber result "patchCount"; | ||
| filteredPatches := ExtractStructTable result "filteredPatches"; | filteredPatches := ExtractStructTable result "filteredPatches"; | ||
| Line 73: | Line 73: | ||
| === Installing packages === | === Installing packages === | ||
| - | Packages can be installed in two ways: calling ''dinamica.package(...)'' from within the expression, or listing package names on the //packages// input port, one per line. The two differ in timing: ''dinamica.package(...)'' runs **during** the expression, so it can be called conditionally; the //packages// port always runs **before** the expression executes. Because ''dinamica.package(...)'' runs together with the script, it may fail if a package is already loaded in an incompatible version. | + | Packages can be installed in two ways: calling ''dinamica.package(...)'' from within the expression, or listing package names on the //packages// input port. The two differ in timing: ''dinamica.package(...)'' runs **during** the expression, so it can be called conditionally; the //packages// port always runs **before** the expression executes. |
| - | ''dinamica.package(packageName, installPath=None, loadPath=None)'' installs (if needed via pip) and imports the requested module. | + | **dinamica.package()** |
| + | |||
| + | ''dinamica.package(packageName, installPath=None, loadPath=None)'' installs (if needed via pip) and imports the requested module. Because it runs together with the script, it may fail if a package is already loaded in an incompatible version. | ||
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ | ||
| Line 109: | Line 111: | ||
| </code> | </code> | ||
| - | The //packages// port takes one package identifier per line, in any form accepted by ''pip''. It only installs — unlike ''dinamica.package()'', it does not also import the module, and it does not support specifying a separate install name and import name. Every listed package is installed before the expression runs, but the expression must still import each one itself, using its actual importable name (which may differ from the name given to ''pip''): | + | **The packages port** |
| + | |||
| + | The //packages// input port takes one package identifier per line, in any form accepted by ''pip''. Every listed package is installed before the expression runs. Unlike ''dinamica.package()'', the port only installs — it does not also import the module, and it does not support specifying a separate install name and import name. The expression must still import each package itself, using its actual importable name (which may differ from the name given to ''pip''). | ||
| The //packages// port: | The //packages// port: | ||
| Line 222: | Line 226: | ||
| <code> | <code> | ||
| - | result := CalculatePythonExpression ($"( | + | result := CalculatePythonExpression $"( |
| total = 0 | total = 0 | ||
| for row in dinamica.inputs['t1'][1:]: | for row in dinamica.inputs['t1'][1:]: | ||
| Line 228: | Line 232: | ||
| total += 1 | total += 1 | ||
| dinamica.outputs['patchCount'] = total | dinamica.outputs['patchCount'] = total | ||
| - | )") {{ | + | )" {{ |
| NumberTable landCoverAreas 1; | NumberTable landCoverAreas 1; | ||
| NumberValue minimumArea 1; | NumberValue minimumArea 1; | ||
| Line 240: | Line 244: | ||
| <code> | <code> | ||
| - | result := CalculatePythonExpression ($"( | + | result := CalculatePythonExpression $"( |
| dinamica.package('numpy') | dinamica.package('numpy') | ||
| Line 258: | Line 262: | ||
| dinamica.outputs['outlierPatches'] = dinamica.prepareTable(outlierTable, 1) | dinamica.outputs['outlierPatches'] = dinamica.prepareTable(outlierTable, 1) | ||
| - | )") {{ | + | )" {{ |
| NumberTable landCoverPatches 1; | NumberTable landCoverPatches 1; | ||
| }}; | }}; | ||
| Line 275: | Line 279: | ||
| CalculatePythonExpression | CalculatePythonExpression | ||
| - | |||