%matplotlib widget
import os
import numpy
import matplotlib.pyplot as plt
from tvb.simulator.lab import *
The scripting interface has two interactive tools for looking at the TimeSeries generated in simulations. This tutorial shows an example of their use, using a demo dataset for region time-series.
These are mainly of use for longer simulations, of at least a few seconds.
As a simple set of example data, we will use a linear stochastic model with the default connectivity:
connectivity=connectivity.Connectivity.from_file()
connectivity.speed=numpy.array([1.0])
sim = simulator.Simulator(
connectivity=connectivity,
coupling=coupling.Linear(a=numpy.array([2e-4])),
integrator=integrators.EulerStochastic(dt=10.0),
model=models.Linear(gamma=numpy.array([-1e-2])),
monitors=(monitors.Raw(),),
simulation_length=60e3
).configure()
(time, data), = sim.run()
plt.figure()
plt.plot(time/1e3, data[:, 0, :, 0], 'k', alpha=0.1);
plt.xlabel('Time (s)')
Because we just stored our simulation as a simple array, we need to turn it into one of TVB's TimeSeries datatypes, which is what the two plotting tools operate on, in this case we'll use TimeSeriesRegion.
tsr = time_series.TimeSeriesRegion(
data=data,
connectivity=sim.connectivity,
sample_period=sim.monitors[0].period / 1e3,
sample_period_unit='s')
tsr.configure()
tsr
Our typical approach throughout these tutorials has been to to simply plot our time-series using PyLab's plot() function. This is fine as a quick way to look at the small amounts of data we'd been producing, but is insufficient for longer, more meaningful, time-series, such as we get when trying to runs simulations aimed at generating time-series comparable to experimental data.
TimeSeriesInteractive is a tool for looking at these longer time-series. It's still relatively simple, but it adds a number of useful features. The time-series are plotted in the main central panel with a constant vertical offset, the label for each channel or region displayed down the left hand side. Along the bottom are three basic controls: on the left there is a slider that allows the length of the window to be changed (in physical units); in the middle a set of buttons exist to step forward and backward through the time-series at different speeds (at the top of the window there is an indicator showing where you are in the time-series); and on the right the vertical spacing, or offset between time series can be set, this has the effect of scaling the time-series' amplitudes.
#Create and launch the interactive visualiser
import tvb.simulator.plot.timeseries_interactive as ts_int
tsi = ts_int.TimeSeriesInteractive(time_series=tsr)
tsi.configure()
tsi.show()