adapters Package

abcadapter

Root classes for adding custom functionality to the code.

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

Bases: object

Root Abstract class for all TVB Adapters.

add_operation_additional_info(message)[source]

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

static array_size2kb(size)[source]
Parameters:

size – size in bytes

Returns:

size in kB

static build_adapter(stored_adapter: Algorithm) ABCAdapter[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

configure(view_model)[source]

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

static determine_adapter_class(stored_adapter: Algorithm) ABCAdapter[source]

Determine the class of an adapter based on module and classname strings from stored_adapter :param stored_adapter: Algorithm or AlgorithmDTO type :return: a subclass of ABCAdapter

extract_operation_data(operation)[source]
static fill_index_from_h5(analyzer_index, analyzer_h5)[source]

Method used only by analyzers that write slices of data. As they never have the whole array_data in memory, the metadata related to array_data (min, max, etc.) they store on the index is not correct, so we need to update them.

get_adapter_fragments(view_model)[source]

The result will be used for introspecting and checking operation changed input params from the defaults, to show in web gui. :return: a list of ABCAdapterForm classes, in case the current Adapter GUI will be composed of multiple sub-forms.

get_execution_time_approximation(view_model)[source]

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

get_form()[source]
abstract get_form_class()[source]
classmethod get_group_description()[source]
classmethod get_group_name()[source]
abstract get_output()[source]

Describes inputs and outputs of the launch method.

abstract get_required_disk_size(view_model)[source]

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

abstract get_required_memory_size(view_model)[source]

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

get_storage_path()[source]
classmethod get_ui_description()[source]
classmethod get_ui_name()[source]
classmethod get_ui_subsection()[source]
get_view_model_class()[source]
abstract launch(view_model)[source]

To be implemented in each Adapter. Will contain the logic of the Adapter. Takes a ViewModel with data, dependency direction is: Adapter -> Form -> ViewModel Any returned DataType will be stored in DB, by the Framework.

Parameters:

view_model – the data model corresponding to the current adapter

launch_mode = 'async_diff_mem'
load_entity_by_gid(data_gid: UUID | str) DataType[source]

Load a generic DataType, specified by GID.

load_traited_by_gid(data_gid: UUID | str) HasTraits[source]

Load a generic HasTraits instance, specified by GID.

load_view_model(operation)[source]
load_with_references(dt_gid: UUID | str) HasTraits[source]
path_for(h5_file_class, gid, dt_class=None)[source]
store_complete(datatype, generic_attributes=<tvb.core.entities.generic_attributes.GenericAttributes object>)[source]
stored_adapter = None
submit_form(form)[source]
view_model_to_has_traits(view_model: ViewModel) HasTraits[source]
class tvb.core.adapters.abcadapter.ABCAdapterForm[source]

Bases: Form

fill_from_post_plus_defaults(form_data)[source]
static get_filters()[source]

Should keep filters for the required_datatype. These filters are stored in DB at introspection time. :return: FilterChain

static get_input_name()[source]

The Form’s input name for the required_datatype. Will be stored in DB at introspection time. :return: str

static get_required_datatype()[source]

Each Adapter’s computation is based on a main Datatype. This method should keep the class of it. This Datatype will be stored to DB at introspection time. :return: DataType class

static get_view_model()[source]

Should keep the ViewModel class that corresponds to the current Adapter. :return: ViewModel class

class tvb.core.adapters.abcadapter.AdapterLaunchModeEnum(value)[source]

Bases: Enum

An enumeration.

ASYNC_DIFF_MEM = 'async_diff_mem'
SYNC_DIFF_MEM = 'sync_diff_mem'
SYNC_SAME_MEM = 'sync_same_mem'
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: ABCAdapter

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

KEY_CONTENT = 'mainContent'
KEY_IS_ADAPTER = 'isAdapter'
VISUALIZERS_ROOT = ''
build_display_result(template, parameters, pages=None)[source]

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

static dump_with_precision(xs, precision=3)[source]

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

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]

Describes inputs and outputs of the launch method.

get_required_disk_size(view_model)[source]

Visualizers should no occupy any additional disk space.

static handle_infinite_values(data)[source]

Replace positive infinite values with the biggest float number available in numpy, and negative infinite values with the smallest float number available in numpy.

launch_mode = 'sync_same_mem'
static prepare_shell_surface_params(shell_surface, surface_url_generator)[source]

Prepares urls that are necessary for a shell surface.

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

Bases: object

BINARY_DATATYPE_ATTRIBUTE = 'read_binary_datatype_attribute'
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_binary_datatype_attribute_url(datatype_gid, attribute_name, parameter=None)[source]
static build_h5_url(entity_gid, method_name, flatten=False, datatype_kwargs=None, parameter=None)[source]
static build_url(adapter_id, method_name, entity_gid, 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: object

remove_datatype(skip_validation=False)[source]

Perform basic operation, should overwrite in specific implementations.

abcuploader

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

Bases: ABCAdapter

Base class of the uploading algorithms

LOGGER = <Logger tvb.core.adapters.abcuploader (INFO)>
get_required_disk_size(view_model)[source]

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

get_required_memory_size(view_model)[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 get_upload_information()[source]
launch_mode = 'sync_diff_mem'
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[source]

Bases: ABCAdapterForm

static get_filters()[source]

Should keep filters for the required_datatype. These filters are stored in DB at introspection time. :return: FilterChain

static get_input_name()[source]

The Form’s input name for the required_datatype. Will be stored in DB at introspection time. :return: str

static get_required_datatype()[source]

Each Adapter’s computation is based on a main Datatype. This method should keep the class of it. This Datatype will be stored to DB at introspection time. :return: DataType class

get_upload_field_names()[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: TVBException

Exception class for problems when introspection failed.

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

Bases: LaunchException

Exception class for parameter validation issue.

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

Bases: TVBException

Exception class for problem with launching an operation.

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

Bases: 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: TVBException

Exception class for problem with parsing files an operation.

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

Bases: IntrospectionException

Exception class for problems when parsing xml files.

inputs_processor

tvb.core.adapters.inputs_processor.review_operation_inputs_from_adapter(adapter, operation)[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