Posted by Rainer Goebel on 15 December 2020

BrainVoyager 22 - Part 1: BV Notebooks

An important aspect of BrainVoyager development in recent yeas is the support of reproducible data analysis. An important feature in this direction was the introduction of the Data Analysis Manager enabling easy specification of analysis pipelines for small or large studies with consistent parameter sets. BrainVoyager 22 goes a big step further by introducing BrainVoyager Notebooks, or BV Notebooks for short. Inspired by [Jupyter notebooks](https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/What is the Jupyter Notebook.html), BV notebooks provide sharable rich interactive documents containing code, explanatory text, images and animations in a sequence of cells. Furthermore, BV notebooks also contain interactive BrainVoyager Viewers that enable browsing through 3D volumes or inspecting brain surfaces with overlaid maps right inside notebooks. These "living documents" can be rerun step-by-step (or in one go) to reproduce processing steps. The following figure shows part of one of the example notebooks that are installed in the user's "Documents/BrainVoyager/Notebooks" folder:

Notebook-Snapshot2_nnbr

The figure above illustrates how these rich documents appear inside the BV Notebook main window in BrainVoyager (or in the standalone BV Notebook application). The figure also illustrates that a notebook is composed as a sequence of cells containing either code, rich text, and images (plus animations and interactive BV viewers). Python code cells can access the always available "brainvoyager" (or "bv") object to call into BrainVoyager's functionality. The code can, for example, be used to load standard BrainVoyager or NIfTI files from disk; it can also access documents currently open in BrainVoyager as shown in the code above (the "bv.adoc" line is a short version of "brainvoyager.active_document"). With access to a document object, its provided functions can be called. This object-oriented approach simplifies code writing. The (FMR) document above can, for example, create a design matrix from the attached protocol (line 3) and launch a single-run GLM calculation (line 5). Quick online help as well as the Python Developer Guide describes the available functionality of the BrainVoyager programming interface.

Converting GUI Actions Automatically into Python Code

BV Notebooks provide a new level of transparency for BrainVoyager users by documenting performed analysis steps as Python code. Besides entering code explicitly, BrainVoyager offers the exciting possibility to write code automatically when turning on the option to convert GUI actions into corresponding code. BV notebooks, thus, not only offer (script) programmers a means to write and document code but they also support non-programmers by converting essential GUI actions automatically into corresponding code. If, for example, the GO button in the FMR Preprocessing dialog is clicked, all selected preprocessing operations are converted into Python code, which is added to the current notebook. The auto-generated Python code contains BrainVoyager API (scripting) commands and, thus, serves as documentation of analysis steps that were executed in the user interface; furthermore, the auto-generated Python code can be rerun at a later time to reproduce derived data. The (auto-)written code can be easily enriched with rich text, images, animations and viewers.

Notebook-Snapshot3_sm

While the generated code is sufficient to document the performed preprocessing commands with their (non-default) parameters, a notebook can be enriched by additional explanatory text, graphics, animations and viewers. The figure below shows an added Markdown cell in editing mode providing a headline for the performed analysis.

Notebook-Snapshot4_sm

Besides Markdown text, images produced in the main user interface during (pre-)processing can be added to the notebook by a simple keyboard shortcut command (CTRL-G) after the respective window or dialog has been selected. The figure below shows the notebook after "sending" the motion parameter plot and adding a Markdown text cell with a sub-title:

Notebook-Snapshot5b_sm

A particularly interesting feature of BV notebooks is the possibility to embed BrainVoyager viewers in the output section of code cells. The "embed_viewer()" command can be manually added but it is also included in many scenarios when code is generated automatically, for example, when (NIfTI or standard BV) documents are opened or when GLM contrasts are displayed. The following figure is a screenshot of a section of a provided notebook with generated code when the 'Getting Started Guide' dataset was analysed using the user interface.

Notebook-Snapshot6_sm

Line 8 of the code that was sent to the notebook after overlaying a GLM has the "embed_viewer()" command. The output section of the code cell shows the embedded anatomical viewer that was also sent to the notebook automatically; note that the embedded viewer will also be created when running the code in the notebook at a later time. As default, an embedded viewer displays only a static image. Double-clicking the image converts it into a 3D viewer in-place, allowing to navigate with the mouse through the respective anatomical 3D volume with the overlaid map.

This short blog post on how notebooks are (auto-)created describes only the most basic possibilities. Several example notebooks and the BV Notebooks chapter in the User's Guide provide detailed information on how to get the most out of this exciting new feature of BrainVoyager.

< class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Commodo aute sunt voluptate voluptate esse et occaecat eiusmod nostrud. Esse enim occaecat deserunt aliqua duis qui. Dolore exercitation proident labore tempor consectetur mollit proident quis dolore irure. Eu laborum non id est occaecat amet veniam quis esse. Aliqua non laboris ut cupidatat laboris voluptate aliqua veniam enim.
< class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Magna ullamco duis sit labore quis velit cillum velit eu eiusmod mollit. Laborum consectetur ut dolore consequat irure exercitation cillum culpa ipsum eiusmod anim. Officia culpa qui id qui ad qui elit. Adipisicing consequat excepteur minim elit ipsum ullamco dolore. Officia dolor aliqua irure officia officia cillum in minim.
< class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Veniam tempor consectetur consequat veniam dolore. Tempor velit cupidatat officia ullamco aliquip Lorem aute non velit. Sit nulla ex id laborum veniam sit. Duis et ex sit sunt incididunt aliquip ea anim. Ullamco duis duis incididunt et incididunt tempor. Aute dolore non consectetur voluptate aliquip. < class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Aute commodo elit amet esse quis aliquip. Aute qui sunt consequat laborum sit mollit. Pariatur aliqua excepteur commodo amet sit aliqua aute culpa nostrud. Quis minim ut ea aliquip elit ut occaecat irure amet. Laboris qui proident mollit cupidatat magna voluptate consequat pariatur.
< class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Culpa aute magna duis id reprehenderit deserunt cillum excepteur. Est occaecat ipsum voluptate aute proident labore. Culpa culpa id eu voluptate ut deserunt minim reprehenderit esse laboris minim. In do fugiat proident cillum officia exercitation cillum irure nulla laborum ea. Cupidatat sunt ea enim ex ad eiusmod irure ipsum excepteur cupidatat. < class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Fugiat fugiat ut eiusmod esse nulla. Non nostrud nulla eu irure ea nisi. Ex consequat amet cupidatat dolor magna aliquip do enim. Ipsum in laboris ut fugiat ut do minim. Anim cupidatat et anim ullamco Lorem sit sint minim exercitation.
< class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Adipisicing mollit ullamco nulla irure ipsum culpa et ea laborum. Consectetur amet aute aliqua laborum occaecat sunt ullamco tempor amet sint. Consectetur amet ex anim amet exercitation sunt occaecat do incididunt magna. Velit non in anim nisi dolore excepteur. < class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Fugiat occaecat minim dolor exercitation reprehenderit officia sint adipisicing et. Laborum non tempor magna esse exercitation id nostrud nisi ex reprehenderit. Tempor pariatur velit cillum enim minim. Laboris voluptate sint labore aliqua veniam mollit aliqua quis nostrud Lorem enim. Pariatur qui labore dolore cupidatat minim excepteur.
< class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Lorem id aute sint amet et qui duis occaecat sunt ea tempor. Reprehenderit consectetur quis irure cillum aliquip ex reprehenderit veniam ullamco. Dolore cillum velit magna consequat magna magna tempor ad proident occaecat velit. Ex magna ex aute aute ea. < class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Ad nulla officia reprehenderit consequat dolore pariatur anim dolore esse ea. Qui do veniam amet proident ut. Exercitation enim labore nostrud anim laboris id veniam laborum fugiat officia. Eu quis incididunt sit et adipisicing. Nisi tempor exercitation consequat officia proident nisi consequat Lorem consequat incididunt.
< class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Quis in ex minim culpa nisi reprehenderit ad. Ut labore sunt mollit fugiat quis quis reprehenderit Lorem reprehenderit ut. Esse deserunt fugiat incididunt nisi mollit nisi proident qui pariatur aliquip. Non nostrud eu dolor do eiusmod amet. Elit qui occaecat minim do eu. Eiusmod non ex cupidatat excepteur ipsum. < class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Proident qui deserunt do culpa duis culpa laboris sunt. Consectetur minim nostrud dolor veniam excepteur duis culpa ut commodo. Pariatur id magna ipsum non non proident reprehenderit esse commodo fugiat. Labore reprehenderit ex nostrud laborum mollit pariatur. Cillum enim sunt laborum Lorem aliqua ex. Nostrud cillum est deserunt ullamco veniam minim.
< class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Enim non do ipsum consequat aute ad. Mollit amet velit amet nostrud non aliquip dolor. Veniam pariatur culpa laboris amet et mollit in ad pariatur consequat commodo. Consequat reprehenderit ex consectetur eiusmod aliqua quis minim ea. Ut sint aliqua ipsum do magna labore laborum veniam in quis aute. < class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Deserunt sint deserunt ad sunt id consequat laborum adipisicing. Pariatur amet quis occaecat anim laboris non ut. Reprehenderit dolore commodo ullamco irure velit proident ipsum ex. Amet ad consectetur eiusmod mollit adipisicing. Excepteur qui ex ullamco aliquip sunt fugiat voluptate tempor ex. Anim ullamco eiusmod nulla id nulla eiusmod ex qui esse velit.
< class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Exercitation laboris irure esse incididunt occaecat sint ex proident do minim. Labore Lorem sit pariatur elit et eiusmod minim anim veniam. Ad mollit id tempor culpa magna id elit tempor est. Et proident cupidatat qui amet ea nisi pariatur ea officia. < class="[&_a]:text-brand-500 [&_a]: [&_a]: [&_a:hover]:text-brand-500 [&_a:hover]: [&_a:hover]: [&_a:visited]:text-brand-500 [&_a:visited]: [&_a:visited]: block transform decoration-brand-500/ border-brand-500/" id=""> Nulla exercitation est consectetur culpa tempor incididunt laborum ipsum. Veniam aute officia laborum tempor exercitation ipsum eiusmod eu. Adipisicing velit id Lorem est adipisicing enim exercitation. Lorem laborum officia fugiat irure nulla nisi esse dolore. Amet officia reprehenderit ullamco nostrud do exercitation qui.