Widget TimeSeries

Version 31.1 by rominabaila on 2023/05/15 10:50

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 the visualization of brain signals represented as time series.

Inputs

Time series can be given as inputs in two forms:

  • TVB TimeSeries datatype
  • Numpy arrays

This widget supports 2D, 3D, and 4D arrays. In all three cases, there is a fixed shape that the TimeSeries widget expects:

  • for 2D: (no_timepoints, no_channels)
  • for 3D: (no_timepoints, state_variable/mode, no_channels)
  • for 4D: (no_timepoints, state_variable, no_channels, mode)

* Note that the TVB TimeSeries datatype is always 4D and already has the expected shape. 

Requirements and installation

Before installing the tvb-widgets library containing the TimeSeries widget, the following python libraries and Jupyter extensions should be installed:

  • Libraries:
  • Extensions:

    jupyter labextension install @jupyter-widgets/jupyterlab-manager

    jupyter labextension install jupyter-matplotlib

Then, to install the tvb-widgets library, just type:

pip install tvb-widgets

API usage

First, the correct matplotlib backend must be set, which enables the interaction with the TimeSeries widget, by running the following command:

%matplotlib widget

 Then, the TimeSeriesWidget (from the tvb-widgets API) and the display function should be imported:

from tvbwidgets.api import TimeSeriesWidget
from IPython.core.display_functions import display

Assuming that the user has already created or imported a valid input, this is how the widget can be initialized and how an input can be assigned to it, using the add_datatype method (example below assumes that tsr  is a TVB TimeSeries datatype):

tsw = TimeSeriesWidget()
tsw.add_datatype(tsr)

Finally, to display and interact with the TimeSeries widget, the get_widget method is used inside the display function:

display(tsw)

Public

TVB Widgets