This is a simple demo showing for to interract with TVB in the command profile.
More examples can be found here: https://github.com/the-virtual-brain/tvb-framework/tree/master/tvb/interfaces/command/demos
from tvb.interfaces.command.lab import *
list_projects()
Create a new project to test with
import uuid
proj = new_project("sandbox" + str(uuid.uuid4()))
list_projects()
If you have the web UI open at the same time, you'll notice there's now a new project named "sandbox_project"
list_datatypes(proj.id)
Nothing! Let's import a connectivity
import os
import tvb_data
p = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity/connectivity_66.zip')
import_op = import_conn_zip(proj.id, p)
import_op = wait_to_finish(import_op)
import_op
list_operation_results(import_op.id)
conectivity_gid = get_operation_results(import_op.id)[0].gid
Now let's grab that connectivity from the database. IMPORTANT: Make sure to adjust the DT gid below to match the value in the id column above and run a simulation with it.
simulator_model = SimulatorAdapterModel()
# ConnectivityIndex gid from the column above
simulator_model.connectivity = conectivity_gid
simulator_model.simulation_length = 100
sim_op = fire_simulation(proj.id, simulator_model)
sim_op = wait_to_finish(sim_op)
sim_op
We should wait for the simulation to finish, and afterwards, TimeSeries should also be part of this project.
Refresh the Web GUI to see the status of your operation.
list_operation_results(sim_op.id)
time_series_region_index_id = get_operation_results(sim_op.id)[1].id
%matplotlib inline
import matplotlib.pyplot as plt
# Use TimeSeriesRegionIndex id
ts = load_dt(time_series_region_index_id)
for reg in range(66):
plt.plot(ts.data[:, 0, reg, 0])
plt.show()
You can re-evaluate this cell multiple times while it's running to see how the results gradually show up as the simulation finishes.