Widget TimeSeries
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.
Backends
Starting with tvb-widgets 1.5.0, the TS widget comes in 2 forms, corresponding to the 2 different libraries (we called them backends) used for plotting: matplotlib and plotly. The matplotlib backend, build on top of the mne library, offers more advanced scientifical features, while the plotly backend has a more appealing look and moves faster when talking about the basic interactions.
Below you can see the TS widget with each backend option (first one using the matplotlib backend, the second one using the plotly backend).
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:
- mne >= 1.0
- matplotlib
- plotly == 5.14.0
- ipywidgets == 7.7.2
- ipympl >= 0.8.5
Extensions:
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install jupyter-matplotlib
jupyter labextension install jupyterlab-plotly
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)