BrainVoyager v22.0

From User Interface Actions to Python Code

A unique feature of BrainVoyager is the possibility to convert actions in the graphical user interface (GUI) into corresponding Python code that is placed in the currently open notebook. A notebook can specify whether it wants to receive automatically generated code using the Log BV Action as Code toggle button at the right side of the BV Notebook toolbar (see screenshot below). Note that the setting is permanently stored per notebook allowing to prevent code adding for notebooks that are finished or if one wants to write code manually.

GUI-to-Code

The added code contains a series of commands that, when executed, will perform the same calculations that were launched with the help of the standard BV user interface, usually by opening dialogs, adjusting options and starting a desired process by pressing the OK or "GO button. The code corresponding to one such action will be added to the notebook as a new code cell that is inserted after the currently active cell (or as the first cell if the notebook is empty).

Create-VTC-dialog-to-code

The figure above shows an example of this process (for more details, see the Auto-Coding-GSG-Analysis.bvnb notebook in the Documents/BrainVoyager/Noebooks directory). In this example, the settings made in the Create VTC dialog (and Create VTC Options dialog) are converted into correspnding code that is added to the current notebook as a new code cell.

The GUI-to-code conversion process provides, thus, transparent documentation of the processing steps performed using the user interface; since code is inserted below the current cell, the respective notebook also documents the order in which analysis steps were performed. Since the auto-generated code cells can be executed at any time, the code cells added to the notebook supports reproducible data analysis also for users working with dialogs in the easy-to-use interface of BrainVoyager. Having both possibilities to generate code enables flexible mixing of GUI-based and direct programming usage of notebooks. Even for users preferring manual code writing, the automatically generated code may help to learn about the BrainVoyager programming interface and as a basis for custom programming.

In addition to the code performing specific operations such as data preprocessing or statistical analysis, the generated code often includes special commands to embed interactive visualizations - for details see the Embedded Viewers topic. An important feature of notebooks is that both self-written and auto-generated code can be further enriched by adding Markdown text, images and animations, e.g. to (furhter) show the results of performed processing steps. To quickly send screenshots of the current document state as well as additional dialogs or windows to a notebook, BrainVoyager provides special shortcuts that are described in the Image Cells topic. Cells can also be removed and reordered using the toolbar or Cell menu allowing to create polished sharable documents.

Limitations of Automatic Code Generation

In the first release (BrainVoyager 22.0), only basic BrainVoyager functions currently support automatic code generation. More functionality will be added in subsequent minor releases. The current version (22.0) supports opening documents from NIfTI or BrainVoyager files, generation of NIfTI or BrainVoyager files from DICOM data, FMR preprocessing, VMR preprocessing, FMR-VMR alignment, MNI transformation of anatomical and functional datasets as well as running GLM statistical analyses. The next release willl support more functionality including code generation for diffusion-weighted datasets and many mesh-related functions. Note also that the generated code does not include checks for return values, which should be added when adjusting generated code for more general processing pipelines as demonstrated, for example, in the Coding-GSG-Analysis.bvnb notebook.


Copyright © 2020 Rainer Goebel. All rights reserved.