Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Submit feedback
    • Contribute to GitLab
  • Sign in
OpenWalnut Core
OpenWalnut Core
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 44
    • Issues 44
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • OpenWalnut
  • OpenWalnut CoreOpenWalnut Core
  • Wiki
  • OpenWalnutPython

OpenWalnutPython

Last edited by Alexander Wiebel Jul 13, 2017
Page history

Using python scripts to control module pipelines

This new feature allows to control module graphs via python scripts. You can:

  • create, destroy, and connect modules
  • change and retrieve the values of properties
  • trigger triggers
  • wait for new input on connectors
  • wait for properties to get changed

This allows to build fully automatic batch processing pipelines.

How to load external modules from module toolboxes?

If you want to use modules from an external toolbox you must tell OpenWalnut how to load those modules. The OpenWalnut scripting interface is there a bit different from the Qt GUI. However there are two possibilities to tell the OW script interpreter where to search for additional modules.

  • Using an existing config.qt4gui file. If you have such a an file in your OW config directory you may place a symlink/copy symlink to it with the name config.script. config.script. Then the script interpreter will load the same module toolboxes as the Qt GUI. On Linux and MacOS, you could do:
cd ~/.OpenWalnut
ln -s qt4gui.config config.script
On Windows, just copy the `config.qt4gui` file and rename it to `config.script`
  • If you don't have such a config file, you might either create one by running and configuring the Qt GUI and then proceed as suggested above with a symlink/copy, or you can also create a plain text file named: config.script with the following line:
    additionalModulePaths=/home/you/path/to/your/toolbox/lib, /another/path/, /etc/pp

When the script interpreter fires up with debug log messages you should see something like this:

[Walnut] Reading config file from: "/home/you/.OpenWalnut/config.script"

How to write a python script for OpenWalnut?

import sys,time

data   = rootContainer.createDataModule( sys.argv[1] )
gauss  = rootContainer.create( "Gauss Filtering" )
writer = rootContainer.create( "Write NIfTI" )

writer.getInputConnector( "in" ).connect( gauss.getOutputConnector( "out" ) )
writer.getProperties().getProperty( "Filename" ).setFilename( sys.argv[2] )
gauss.getInputConnector( "in" ).connect( data.getOutputConnector( "out" ) )

writer.getInputConnector( "in" ).waitForInput()
time.sleep( 0.1 )
writer.getProperties().getProperty( "Do save" ).click()
time.sleep( 5 )
quit()

There are some good practices when working with the script interpreter:

  1. Wire the whole graph but ommit the data sources (e.g. data modules) in the beginning
  2. When all is wired (but the data sources) and all parameters are set, then you may wire the rest (data sources) and wait for specific events
  3. Keep in mind that writing to disk needs some time, so do a small sleep
  4. Each module might have connector names that differ from in and out, so run a Qt GUI version next to it to identify easily the connector names
  5. See source:resources/scripting/template.py for a rich featured example script

How to run a python script for OpenWalnut?

You might call the script interpreter directly from you build directory via: bin/openwalnut-script. Then you append the option -f and the path of the python script you want to execute. For example:

/home/you/repos/OW/build/bin/openwalnut-script -f ../resources/scripting/template.py ./inDir ./outDir
Clone repository
  • DeveloperTools
  • DiffusionIndices
  • Documentation
  • Downloads
  • EditorConfiguration
  • FAQ
  • FiberSimilarityMetrics
  • FirstSteps
  • Getting_OpenWalnut
  • Glossary
  • HowtoDocumentCode
  • IllustrativeConnectivityVisualization
  • InstallMSYS2
  • InstallMinGW
  • InstallVisualStudio
View All Pages