The Virtual Brain Project

Table Of Contents

Previous topic

core Package

Next topic

code_versions Package

This Page

adapters Package


Root classes for adding custom functionality to the code.

class tvb.core.adapters.abcadapter.ABCAdapter[source]

Bases: builtins.object

Root Abstract class for all TVB Adapters.

KEYWORD_OPTION = 'option_'
KEYWORD_PARAMS = '_parameters_'
KEY_ALL = 'allValue'
KEY_ATTRIBUTES = 'attributes'
KEY_CONDITION = 'conditions'
KEY_DATATYPE = 'datatype'
KEY_DEFAULT = 'default'
KEY_DESCRIPTION = 'description'
KEY_DISABLED = 'disabled'
KEY_DTYPE = 'elementType'
KEY_FILTERABLE = 'filterable'
KEY_ID = 'id'
KEY_LABEL = 'label'
KEY_NAME = 'name'
KEY_OPTIONS = 'options'
KEY_REQUIRED = 'required'
KEY_TYPE = 'type'
KEY_UI_HIDE = 'ui_hidden'
KEY_VALUE = 'value'
STATIC_ACCEPTED_TYPES = ('str', 'float', 'int', 'upload', 'bool', 'dict', 'array', 'select', 'selectMultiple', 'dynamic', 'list')
TYPE_MULTIPLE = 'selectMultiple'
TYPE_SELECT = 'select'

Adds additional info on the operation to be displayed in the UI. Usually a warning message.

static build_adapter(stored_adapter)[source]

Having a module and a class name, create an instance of ABCAdapter.

static build_adapter_from_class(adapter_class)[source]

Having a subclass of ABCAdapter, prepare an instance for launching an operation with it.

static can_be_active()[source]

To be overridden where needed (e.g. Matlab dependent adapters). :return: By default True, and False when the current Adapter can not be executed in the current env for various reasons (e.g. no Matlab or Octave installed)


To be implemented in each Adapter that requires any specific configurations before the actual launch.

convert_ui_inputs(kwargs, validation_required=True)[source]

Convert HTTP POST parameters into Python parameters.


Method should approximate based on input arguments, the time it will take for the operation to finish (in seconds).

classmethod get_group_description()[source]
classmethod get_group_name()[source]

Describes inputs and outputs of the launch method.


Describes inputs and outputs of the launch method.


Abstract method to be implemented in each adapter. Should return the required memory for launching the adapter in kilo-Bytes.


Abstract method to be implemented in each adapter. Should return the required memory for launching the adapter.

classmethod get_ui_description()[source]
classmethod get_ui_name()[source]
classmethod get_ui_subsection()[source]

To be implemented in each Adapter. Will contain the logic of the Adapter. Any returned DataType will be stored in DB, by the Framework.

static load_entity_by_gid(data_gid)[source]

Load a generic DataType, specified by GID.

prepare_ui_inputs(kwargs, validation_required=True)[source]

Prepare the inputs received from a HTTP Post in a form that will be used by the Python adapter.

Returns:a list with the inputs from the parameters list that are instances of DataType, and a dictionary with all parameters which are different than the declared defauts
stored_adapter = None
class tvb.core.adapters.abcadapter.ABCAdapterForm(prefix='', project_id=None, draw_ranges=True)[source]

Bases: tvb.core.neotraits.forms.Form

static get_filters()[source]
static get_input_name()[source]
static get_required_datatype()[source]

This is used to fill in defaults for GET requests. Makes sense for analyzers, because for each form, we have an algorithm to relate to.

class tvb.core.adapters.abcadapter.ABCAsynchronous[source]

Bases: tvb.core.adapters.abcadapter.ABCAdapter

Abstract class, for marking adapters that are prone to be executed on Cluster.

Parameters:size – size in bytes
Returns:size in kB
class tvb.core.adapters.abcadapter.ABCSynchronous[source]

Bases: tvb.core.adapters.abcadapter.ABCAdapter

Abstract class, for marking adapters that are prone to be NOT executed on Cluster.


Annotation that configures NumPy not to throw an exception in case of floating points errors are computed. It should be used on Adapter methods where computation of NaN/ Inf/etc. is allowed.


Annotation that guides NumPy behavior in case of floating point errors. The NumPy default is to just print a warning to sys.stdout, this annotation will raise our custom exception. This annotation will enforce that an exception is thrown in case a floating point error is produced.

e.g. If NaN is take as input and not produced inside the context covered by this annotation,
nothing happens from this method p.o.v.
e.g. If inside a method annotated with this method we have something like numpy.log(-1),
then LaunchException is thrown.


class tvb.core.adapters.abcdisplayer.ABCDisplayer[source]

Bases: tvb.core.adapters.abcadapter.ABCSynchronous

Abstract class, for marking Adapters used for UI display only.

KEY_CONTENT = 'mainContent'
KEY_CONTENT_MODULE = 'keyContentModule'
KEY_IS_ADAPTER = 'isAdapter'
PARAM_FIGURE_SIZE = 'figure_size'
build_display_result(template, parameters, pages=None)[source]

Helper method for building the result of the ABCDisplayer. :param template : path towards the HTML template to display. It can be absolute path, or relative :param parameters : dictionary with parameters for “template” :param pages : dictionary of pages to be used with <xi:include>

build_h5_url(entity_gid, method_name, parameter=None)[source]
build_url(method_name, entity_gid, parameter=None)[source]
static dump_with_precision(xs, precision=3)[source]

Dump a list of numbers into a string, each at the specified precision.


Should be implemented by all visualizers that can be used by portlets.

static get_one_dimensional_list(list_of_elements, expected_size, error_msg)[source]

Used for obtaining a list of ‘expected_size’ number of elements from the list ‘list_of_elements’. If the list ‘list_of_elements’ doesn’t have sufficient elements then an exception will be thrown.

list_of_elements - a list of one or two dimensions expected_size - the number of elements that should have the returned list error_msg - the message that will be used for the thrown exception.


Visualizers should no occupy any additional disk space.

static paths2url(datatype_gid, attribute_name, flatten=False, parameter=None)[source]

Prepare a File System Path for passing into an URL.

class tvb.core.adapters.abcdisplayer.URLGenerator[source]

Bases: builtins.object

DATATYPE_ATTRIBUTE = 'read_datatype_attribute'
FLOW = 'flow'
H5_FILE = 'read_from_h5_file'
INVOKE_ADAPTER = 'invoke_adapter'
static build_base_h5_url(entity_gid)[source]
static build_h5_url(entity_gid, method_name, flatten=False, datatype_kwargs=None, parameter=None)[source]
static build_url(entity_gid, method_name, adapter_id, parameter=None)[source]
static paths2url(datatype_gid, attribute_name, flatten=False, parameter=None)[source]

Prepare a File System Path for passing into an URL.


class tvb.core.adapters.abcremover.ABCRemover(handled_datatype)[source]

Bases: builtins.object


Perform basic operation, should overwrite in specific implementations.


class tvb.core.adapters.abcuploader.ABCUploader[source]

Bases: tvb.core.adapters.abcadapter.ABCSynchronous

Base class of the uploaders

LOGGER = <Logger tvb.core.adapters.abcuploader (INFO)>

As it is an upload algorithm and we do not have information about data, we can not approximate this.


Return the required memory to run this algorithm. As it is an upload algorithm and we do not have information about data, we can not approximate this.

static read_list_data(full_path, dimensions=None, dtype=<class 'numpy.float64'>, skiprows=0, usecols=None)[source]

Read numpy.array from a text file or a npy/npz file.

static read_matlab_data(path, matlab_data_name=None)[source]

Read array from matlab file.

class tvb.core.adapters.abcuploader.ABCUploaderForm(prefix='', project_id=None)[source]

Bases: tvb.core.adapters.abcadapter.ABCAdapterForm

static get_filters()[source]
static get_input_name()[source]
static get_required_datatype()[source]


This is a framework helper module. Some framework datatypes have functions that will be called via http by the TVB GUI. These functions will receive some arguments as strings and return json serializable structures usually dicts. This module contains functions to parse those strings and construct those responses.


Parse a slicing expression >>> parse_slice(”::1, :”) (slice(None, None, 1), slice(None, None, None)) >>> parse_slice(“2”) 2 >>> parse_slice(“[2]”) 2

tvb.core.adapters.arguments_serialisation.postprocess_voxel_ts(ts, slices, background_value=None, background_min=None, background_max=None, label=None)[source]

Read TimeLine from TS and prepare the result for TSVolumeViewer.

  • ts – TS instance, with read_data_slice method
  • slices – slices for reading from H5

A complex dictionary with information about current voxel.

tvb.core.adapters.arguments_serialisation.preprocess_space_parameters(x, y, z, max_x, max_y, max_z)[source]

Covert ajax call parameters into numbers and validate them.

  • x – coordinate
  • y – coordinate
  • z – coordinate that will be reversed
  • max_x – maximum x accepted value
  • max_y – maximum y accepted value
  • max_z – maximum z accepted value

(x, y, z) as integers, Z reversed

tvb.core.adapters.arguments_serialisation.preprocess_time_parameters(t1, t2, time_length)[source]

Covert ajax call parameters into numbers and validate them.

  • t1 – start time
  • t2 – end time
  • time_length – maximum time length in current TS

(t1, t2, t2-t1) as numbers

>>> slice_str(slice(1, None, 2))
>>> slice_str((slice(None, None, 2), slice(None), 4))
'::2, :, 4'
Does not handle ... yet



exception tvb.core.adapters.exceptions.IntrospectionException(message, parent_exception=None)[source]

Bases: tvb.basic.exceptions.TVBException

Exception class for problems when introspection failed.

exception tvb.core.adapters.exceptions.InvalidParameterException(message, parent_exception=None)[source]

Bases: tvb.core.adapters.exceptions.LaunchException

Exception class for parameter validation issue.

exception tvb.core.adapters.exceptions.LaunchException(message, parent_exception=None)[source]

Bases: tvb.basic.exceptions.TVBException

Exception class for problem with launching an operation.

exception tvb.core.adapters.exceptions.NoMemoryAvailableException(message, parent_exception=None)[source]

Bases: tvb.basic.exceptions.TVBException

Exception class raised when an adapter requires more memory that is available on machine.

exception tvb.core.adapters.exceptions.ParseException(message, parent_exception=None)[source]

Bases: tvb.basic.exceptions.TVBException

Exception class for problem with parsing files an operation.

exception tvb.core.adapters.exceptions.XmlParserException(message, parent_exception=None)[source]

Bases: tvb.core.adapters.exceptions.IntrospectionException

Exception class for problems when parsing xml files.


Preparation validation and manipulation of adapter input trees .. moduleauthor:: Mihai Andrei <>

class tvb.core.adapters.input_tree.InputTreeManager[source]

Bases: builtins.object

append_required_defaults(kwargs, algorithm_inputs)[source]

Add if necessary any parameters marked as required that have a default value in the algorithm interface but were not submitted from the UI. For example in operations launched from context-menu or from data structure.

convert_ui_inputs(flat_input_interface, kwargs, metadata_out, validation_required=True)[source]

Convert HTTP POST parameters into Python parameters.

static fill_defaults(adapter_interface, data, fill_unselected_branches=False)[source]

Change the default values in the Input Interface Tree.

fill_input_tree_with_options(attributes_list, project_id, category_key)[source]

For a datatype node in the input tree, load all instances from the db that fit the filters.

flatten(params_list, prefix=None)[source]

Internal method, to be used recursively, on parameters POST.

static form_prefix(input_param, prefix=None, option_prefix=None)[source]

Compute parameter prefix. We need to be able from the flatten submitted values in UI, to be able to re-compose the tree of parameters, and to make sure all submitted names are uniquely identified.

populate_option_values_for_dtype(project_id, type_name, filter_condition=None, category_key=None)[source]

Converts all datatypes that match the project_id, type_name and filter_condition to a {name: , value:} dict used to populate options in the input tree ui

static prepare_param_names(attributes_list, prefix=None, add_option_prefix=False)[source]

For a given attribute list, change the name of the attributes where needed. Changes refer to adding a prefix, to identify groups. Will be used on parameters page GET.

review_operation_inputs(parameters, flat_interface)[source]

Find out which of the submitted parameters are actually DataTypes and return a list holding all the dataTypes in parameters. :returns: list of dataTypes and changed parameters.

static select_simulator_inputs(full_tree, selection_dictionary, prefix='')[source]

Cut Simulator input Tree, to display only user-checked inputs.

  • full_tree – the simulator input tree
  • selection_dictionary – a dictionary that keeps for each entry a default value and if it is check or not.
  • prefix – a prefix to be added to the ui_name in case a select with subtrees is not selected