BrainVoyager Python Developer Guide 0.9


Since Python in combination with libraries such as NumPy leads to fast executable code, Python is not only a good language to write application scripts but can be used also for scientific computation, i.e. to implement new analysis tools. In BrainVoyager, Python is thus viewed as a great alternative to writing plugins in C++/JavaScript since Python is easier to learn and use and because code is interpreted avoiding the C++ compilation "overhead" (including handling different IDEs on different operating systems for cross-platform plugins). The provided BrainVoyager API used for scripting allows to focus on the code that is relevant for implementing new functionality instead of re-writing code e.g. to load data sets. Furthermore, the access to the Qt library allows to quickly build graphcial user interfaces allowing to present new tools to BrainVoyager users in interactive dialogs. Besides importing scientific libraries such as NumPy and SciPy, it is also possible to use established plotting tools such as the "standard" Python MatPlotLib library. The snapshot below shows a simple script ("") that is available in the "Documents/BVExtensions/PythonPlugins" folder that shows how a minimal environment for scientific computing can be created, including import of NumPy and SciPy as well as using MatPlotLib for plotting simple functions. The upper part shows the BrainVoyager Python IDE and the generated MatPlotLib output after clicking the Run button, while the lower part shows the BrainVoyager Python console that can be used interactively to inspect variables and to call defined functions as usual. The embedded Python console also shows debugging information when trying to run scripts with syntax errors (interactive debugging is planned for a future release).

While the scripting interface allows to call BrainVoyager functions, it does not provide efficient access to data structures. In order to provide fast access to internal BrainVoyager data arrays, a special bva module has been developed that allows to access memory blocks directly as NumPy arrays.

Copyright © 2020 Rainer Goebel. All rights reserved.