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 turn this off to prevent code adding for notebooks that are finished or if one wants to write code manually.
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).
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), essential basic BrainVoyager functionality supported automatic code generation, including 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. BrainVoyager 22.2 added code generation for basic mesh-related functions (see
Auto-Coding-GSG-Analysis.bvnb notebook). Note also that the atuo-generated code does not include checks for return values of functions, which should be added when adjusting generated code for more general processing pipelines as demonstrated, for example, in the manually written code of the
Copyright © 2021 Rainer Goebel. All rights reserved.