-
Notifications
You must be signed in to change notification settings - Fork 73
SCIRun Python API 0.2
The API contains global functions for network editing, file management, module state modification, and data object extraction and insertion.
-
scirun_add_module("ModuleName")
- Adds a new instance of a module to the network. Returns the module ID as a string.
-
scirun_remove_module("ModuleID")
- Removes the module specified by the ID string.
-
scirun_execute_all()
- Executes the entire current network.
-
scirun_module_ids()
- Returns a list of all module ID strings in the current network.
-
scirun_connect_modules("ModuleIDFrom", fromIndex, "ModuleIDTo", toIndex)
- Connects ports between two modules by index. From is the output, To is the input.
-
scirun_disconnect_modules("ModuleIDFrom", fromIndex, "ModuleIDTo", toIndex)
- Used to disconnect two modules, with the same syntax as connecting.
-
scirun_save_network("Filename.srn5")
- Saves the current network file.
-
scirun_load_network("Filename.srn5")
- Loads the specified network file.
-
scirun_import_network("Filename.srn")
- Imports the specified v4 network file.
-
scirun_quit()
- Enables quitting SCIRun after the next network execution is complete.
-
scirun_force_quit()
- Quits SCIRun immediately.
-
scirun_get_module_state("ModuleID", "StateVariableName")
- Returns the value of a the specified module state variable.
-
scirun_set_module_state("ModuleID", "StateVariableName", value)
- Sets the specified module state variable's value.
-
scirun_dump_module_state("ModuleID")
- Returns a dictionary with the entire state of the specified module.
-
scirun_get_module_transient_state("ModuleID", "StateVariableName")
- Returns the value of a the specified module transient state variable.
-
scirun_set_module_transient_state("ModuleID", "StateVariableName", value)
- Sets the specified module transient state variable's value. Used to pass data values (strings, matrices, fields [coming soon]) back to modules.
-
scirun_get_module_input_type("ModuleID", portIndex)
- Returns the type of the input data object on the specified port.
-
scirun_get_module_input_object("ModuleID", "PortName")
- Returns a special
PyDatatype
wrapper object containing a copy of the data on the specified input port, by name.
- Returns a special
-
scirun_get_module_input_value("ModuleID", "PortName")
- Returns a Python object containing a copy of the data on the specified input port.
-
scirun_get_module_input_object_by_index("ModuleID", portIndex)
- Returns a special
PyDatatype
wrapper object containing a copy of the data on the specified input port, by port index.
- Returns a special
-
scirun_get_module_input_value_by_index("ModuleID", portIndex)
- Returns a Python object containing a copy of the data on the specified input port, by index.
- This module lets you set input/output variable names in the module UI. Once this is done (or by using the defaults), one can use assignment syntax to read input data and send output data.
- Examples
-
pythonOutput = "hello"
will send a string to the output port associated withpythonOutput
-
field = inputField1
will extract a field object from the input port associated withinputField1
-
outputString1 = "string concat " + inputString1
Input/Output can be combined on the same line.
-
- Examples
- If there is an installation of the packages with other python builds on the machine, the system path can be used to use those packages.
There are many ways to install packages in python. pip is an easy way that is usually included with python.
if pip is not installed for the scirun installation of python, follow these directions: https://pip.pypa.io/en/stable/installing/. Be sure to use the python in "scirun_root"/bin/Externals/Install/Python_external/bin/
*make sure that pip is installed *in the terminal:
cd "scirun_root"/bin/Externals/Install/Python_external/bin/
./python3 -m pip install numpy
in the terminal:
cd "matlab_root"/extern/engines/python
"scirun_root"/bin/Externals/Install/Python_external/bin/python3.4 setup.py build --build-base="builddir" install --prefix="installdir"
Full instructions are located at http://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
In SCIRun 5, Matlab code and functions can be run using the matlab engine for python in the python console or python interface. To do so, make sure that the matlab engine is installed (previous section). Full documentation found at http://www.mathworks.com/help/matlab/matlab-engine-for-python.html