Widget 3D Head

Last modified by paulapopa on 2023/03/24 07:58

Source code: https://github.com/the-virtual-brain/tvb-widgets

This is part of a Pypi release: https://pypi.org/project/tvb-widgets/

tvb-widgets is also already installed in the official image released for EBRAINS lab, where you can test it directly.

Purpose

It is a Jupyter widget intended for visualization of the 3D Head data available for a patient:

  • surfaces of different types (cortex, face, skull, etc)
  • connectivity region centers
  • sensors locations (SEEG, MEG, EEG)

Inputs

It supports the above data in the form of their corresponding TVB datatypes:

  • Surface (CorticalSurface, FaceSurface, etc)
  • Connectivity
  • Sensors (SensorsInternal, SensorsMEG, SensorsEEG)

Installation

pip install tvb-widgets

API usage

We need to first import the widget API from tvbwidgets package, together with the TVB API and the display function:

import tvbwidgets.api as api

from tvb.simulator.lab import *

from IPython.core.display_functions import display 

Then, there are 2 options to work with the widget:

  1. Use a file browser to load the data and automatically display it
  2. Use directly the API to load the data and display it

For the first option, you have to run the following 2 lines of code in a notebook cell and then just use the UI controls:

widget = api.HeadBrowser()
display(widget)

For the second option, the API is described below:

In a new cell, we instantiate the HeadWidget and a FaceSurface datatype that we want to visualize. Using the add_datatype method we add the surface to our widget and display the widget:

widget = api.HeadWidget()

face = surfaces.FaceSurface().from_file()

face.configure()

widget.add_datatype(face)
display(widget)

Next, we can continue adding other datatypes to this widget, by calling add_datatype multiple times. A maximum of 10 datatypes are supported by this widget.

The Config object can be used to tweak the display options for each datatype.

In the code below, we add a Connectivity and SEEG Sensors:

conn = connectivity.Connectivity().from_file()

conn.configure()

widget.add_datatype(conn)

seeg = sensors.SensorsInternal().from_file()

seeg.configure()

widget.add_datatype(seeg, api.HeadWidgetConfig(name='SEEG'))

We can also provide a RegionMapping to be used as colormap for a surface: 

reg_map = region_mapping.RegionMapping.from_file()

config = api.HeadWidgetConfig(name='Cortex')

config.add_region_mapping_as_cmap(reg_map)

cortex = surfaces.CorticalSurface().from_file()

cortex.configure()

widget = api.HeadWidget()

widget.add_datatype(cortex, config)

display(widget)

Public

TVB Widgets