The Virtual Brain Project

Table Of Contents

Previous topic

core Package

Next topic

code_versions Package

This Page

adapters Package

abcadapter

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.

INTERFACE_ATTRIBUTES = 'attributes'
INTERFACE_ATTRIBUTES_ONLY = 'attributes-only'
KEYWORD_OPTION = 'option_'
KEYWORD_PARAMS = '_parameters_'
KEYWORD_SEPARATOR = '_'
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'
add_operation_additional_info(message)[source]

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)

configure(**kwargs)[source]

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.

flaten_input_interface()[source]
get_execution_time_approximation(**kwargs)[source]

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

get_form()[source]
get_form_class()[source]
classmethod get_group_description()[source]
classmethod get_group_name()[source]
get_input_tree()[source]

Describes inputs and outputs of the launch method.

get_output()[source]

Describes inputs and outputs of the launch method.

get_required_disk_size(**kwargs)[source]

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

get_required_memory_size(**kwargs)[source]

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]
launch()[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.

noise_configurable_parameters()[source]
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.

review_operation_inputs(parameters)[source]
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
submit_form(form)[source]
class tvb.core.adapters.abcadapter.ABCAdapterForm(prefix='', project_id=None, draw_ranges=True)[source]

Bases: tvb.core.neotraits.forms.Form

get_dict()[source]
static get_filters()[source]
get_form_values()[source]
static get_input_name()[source]
static get_required_datatype()[source]
get_traited_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.

array_size2kb(size)[source]
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.

tvb.core.adapters.abcadapter.nan_allowed()[source]

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.

tvb.core.adapters.abcadapter.nan_not_allowed()[source]

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.

abcdisplayer

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'
VISUALIZERS_ROOT = ''
VISUALIZERS_URL_PREFIX = ''
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.

generate_preview(**kwargs)[source]

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.

get_output()[source]
get_required_disk_size(**kwargs)[source]

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.

abcremover

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

Bases: builtins.object

remove_datatype(skip_validation=False)[source]

Perform basic operation, should overwrite in specific implementations.

abcuploader

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)>
get_required_disk_size(**kwargs)[source]

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

get_required_memory_size(**kwargs)[source]

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]

arguments_serialisation

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.

tvb.core.adapters.arguments_serialisation.parse_slice(slice_string)[source]

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.

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

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.

Parameters:
  • 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
Returns:

(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.

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

(t1, t2, t2-t1) as numbers

tvb.core.adapters.arguments_serialisation.slice_str(slice_or_tuple)[source]
>>> slice_str(slice(1, None, 2))
'1::2'
>>> slice_str((slice(None, None, 2), slice(None), 4))
'::2, :, 4'
Does not handle ... yet

constants

exceptions

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.

input_tree

Preparation validation and manipulation of adapter input trees .. moduleauthor:: Mihai Andrei <mihai.andrei@codemart.ro>

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.

Parameters:
  • 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