neotraits Package

_h5accessors

class tvb.core.neotraits._h5accessors.Accessor(trait_attribute: Attr, h5file: H5File, name: str = None)[source]

Bases: object

abstract load()[source]
abstract store(val)[source]
class tvb.core.neotraits._h5accessors.DataSet(trait_attribute: NArray, h5file: H5File, name: str = None, expand_dimension: int = -1)[source]

Bases: Accessor

A dataset in a h5 file that corresponds to a traited NArray.

append(data: ndarray, close_file: bool = True, grow_dimension: int | None = None) None[source]

Method to be called when it is necessary to write slices of data for a large dataset, eg. TimeSeries. Metdata for such datasets is written only at file close time, see H5File.close method.

get_cached_metadata()[source]

Returns cached properties of this dataset, like min max mean etc. This cache is useful for large, expanding datasets, when we want to avoid loading the whole dataset just to compute a max.

load() ndarray[source]
property shape: Tuple[int]
store(data: ndarray) None[source]
class tvb.core.neotraits._h5accessors.DataSetMetaData(min, max, mean, is_finite=True, has_complex=False)[source]

Bases: object

simple container for dataset metadata Useful as a cache of global min max values. Viewers rely on these for colorbars.

classmethod from_array(array)[source]
classmethod from_dict(dikt)[source]
merge(other)[source]
to_dict()[source]
class tvb.core.neotraits._h5accessors.Enum(trait_attribute: Attr, h5file: H5File, name: str = None)[source]

Bases: Scalar

load()[source]
store(val)[source]
class tvb.core.neotraits._h5accessors.EquationScalar(trait_attribute: Attr, h5file: H5File, name: str = None)[source]

Bases: Accessor

An attribute in a h5 file that corresponds to a traited Equation.

KEY_PARAMETERS = 'parameters'
KEY_TYPE = 'type'
load() Equation[source]
store(data: Equation) None[source]
class tvb.core.neotraits._h5accessors.Json(trait_attribute, h5file, name=None, json_encoder=None, json_decoder=None)[source]

Bases: Scalar

A python json like data structure accessor This works with simple Attr(list) Attr(dict) List(of=…)

load()[source]
store(val)[source]

stores a json in the h5 metadata

class tvb.core.neotraits._h5accessors.JsonFinal(trait_attribute, h5file, name=None)[source]

Bases: Json

A python json like data structure accessor meant to be used with Final(dict)

class StateVariablesDecoder[source]

Bases: JSONDecoder

dict_array(dictionary)[source]
class StateVariablesEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

default(o)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class tvb.core.neotraits._h5accessors.JsonRange(trait_attribute: Attr, h5file: H5File, name: str = None)[source]

Bases: Scalar

Stores and loads a Range in the form of a json in h5.

load()[source]
store(val)[source]
class tvb.core.neotraits._h5accessors.Reference(trait_attribute: Attr, h5file: H5File, name: str = None)[source]

Bases: Uuid

A reference to another h5 file Corresponds to a contained datatype

store(val: HasTraits) None[source]

The reference is stored as a gid in the metadata. :param val: a datatype or a uuid.UUID gid

class tvb.core.neotraits._h5accessors.ReferenceList(trait_attribute, h5file, name=None, json_encoder=None, json_decoder=None)[source]

Bases: Json

store(val)[source]

stores a json in the h5 metadata

class tvb.core.neotraits._h5accessors.Scalar(trait_attribute: Attr, h5file: H5File, name: str = None)[source]

Bases: Accessor

A scalar in a h5 file that corresponds to a traited attribute. Serialized as a global h5 attribute

load() str | int | float[source]
store(val: str | int | float) None[source]
class tvb.core.neotraits._h5accessors.SparseMatrix(trait_attribute: Attr, h5file: H5File, name: str = None)[source]

Bases: Accessor

Stores and loads a scipy.sparse csc or csr matrix in h5.

constructors = {'csc': <class 'scipy.sparse._csc.csc_matrix'>, 'csr': <class 'scipy.sparse._csr.csr_matrix'>}
get_metadata()[source]
load()[source]
store(mtx: spmatrix) None[source]
class tvb.core.neotraits._h5accessors.SparseMatrixMetaData(minimum, maximum, mean, format, dtype, shape)[source]

Bases: DataSetMetaData

Essential metadata for interpreting a sparse matrix stored in h5

classmethod from_array(mtx)[source]
classmethod from_dict(dikt)[source]
static parse_shape(shapestr)[source]
to_dict()[source]
class tvb.core.neotraits._h5accessors.Uuid(trait_attribute: Attr, h5file: H5File, name: str = None)[source]

Bases: Scalar

load() UUID[source]
store(val: UUID) None[source]

_h5core

class tvb.core.neotraits._h5core.H5File(path: str)[source]

Bases: object

A H5 based file format. This class implements reading and writing to a specific h5 based file format. A subclass of this defines a new file format.

KEY_WRITTEN_BY = 'written_by'
close()[source]
determine_datatype_from_file()[source]
static determine_type(path: str) Type[HasTraits][source]
classmethod file_name_base()[source]
static from_file(path: str) H5File[source]
gather_references(datatype_cls=None)[source]
get_class_path()[source]
static get_metadata_param(path, param)[source]
static h5_class_from_file(path: str) Type[H5File][source]
is_new_file = False
iter_accessors() Generator[Accessor][source]
iter_datasets()[source]
load_generic_attributes() GenericAttributes[source]
load_into(datatype: HasTraits) None[source]
read_subtype_attr()[source]
store(datatype: HasTraits, scalars_only: bool = False, store_references: bool = True) None[source]
store_generic_attributes(generic_attributes: GenericAttributes, create: bool = True) None[source]
store_metadata_param(key, value)[source]
class tvb.core.neotraits._h5core.ViewModelH5(path, view_model)[source]

Bases: H5File

gather_datatypes_references()[source]

Mind that ViewModelH5 stores references towards ViewModel objects (eg. Coupling) as Reference attributes, and references towards existent Datatypes (eg. Connectivity) as Uuid. Thus, the method gather_references will return only references towards other ViewModels, and we need this method to gather also datatypes references.

db

class tvb.core.neotraits.db.HasTraitsIndex[source]

Bases: DeclarativeBase

create_date
get_subtype_attr()[source]
gid
id
title
type_
tvb.core.neotraits.db.ensure_float(data)[source]
tvb.core.neotraits.db.ensure_int(data)[source]
tvb.core.neotraits.db.from_ndarray(array)[source]
tvb.core.neotraits.db.prepare_array_shape_meta(shape_array)[source]

forms

class tvb.core.neotraits.forms.ArrayField(trait_attribute: Attr, name: str | None = None, disabled: bool = False)[source]

Bases: TraitField

template = 'form_fields/str_field.html'
property value
class tvb.core.neotraits.forms.BoolField(trait_attribute: Attr, name: str | None = None, disabled: bool = False)[source]

Bases: TraitField

template = 'form_fields/bool_field.html'
class tvb.core.neotraits.forms.DynamicSelectField(trait_attribute, name=None, disabled=False, choices=None, display_none_choice=True, subform=None, display_subform=True, ui_values=None)[source]

Bases: TraitField

missing_value = 'explicit-None-value'
options()[source]

to be used from template, assumes self.data is set

subform_prefix = 'subform_'
template = 'form_fields/radio_field.html'
property value
class tvb.core.neotraits.forms.Field(name: str, disabled: bool = False, required: bool = False, label: str = '', doc: str = '', default: object | None = None)[source]

Bases: object

fill_from_post(post_data)[source]

deserialize form a post dictionary

template = None
validate()[source]

validation besides the deserialization from post

property value
class tvb.core.neotraits.forms.FloatField(trait_attribute: Attr, name: str | None = None, disabled: bool = False)[source]

Bases: TraitField

max = None
min = None
step = 'any'
template = 'form_fields/number_field.html'
class tvb.core.neotraits.forms.Form[source]

Bases: object

property fields
fill_from_post(form_data)[source]
fill_from_single_post_param(**param)[source]
fill_from_trait(trait)[source]

Sets data for all traited fields from a trait instance. Note that FormFields are not TraitFields, so this does not work recursively Override to fill in sub-forms

fill_trait(datatype)[source]

Copies the value of the TraitFields to the corresponding Attr-ibutes of the given trait instance Note that FormFields are not TraitFields, so this does not work recursively Override to fill in sub-forms

fill_trait_partially(datatype, fields=None)[source]
get_errors_dict()[source]
static get_subform_key()[source]

If the current form can be used as subform, this method should return the proper value.

property trait_fields
validate()[source]
class tvb.core.neotraits.forms.FormField(form_class, name, label='', doc='')[source]

Bases: Field

fill_from_post(post_data)[source]

deserialize form a post dictionary

template = 'form_fields/form_field.html'
validate()[source]

validation besides the deserialization from post

class tvb.core.neotraits.forms.HiddenField(trait_attribute, name=None, disabled=False)[source]

Bases: TraitField

template = 'form_fields/hidden_field.html'
class tvb.core.neotraits.forms.IntField(trait_attribute: Attr, name: str | None = None, disabled: bool = False)[source]

Bases: TraitField

max = None
min = None
template = 'form_fields/number_field.html'
class tvb.core.neotraits.forms.LabelField(trait_attribute, label_message=None, name=None)[source]

Bases: TraitField

template = 'form_fields/label_field.html'
class tvb.core.neotraits.forms.MultiSelectField(trait_attribute, name=None, disabled=False)[source]

Bases: TraitField

options()[source]

to be used from template, assumes self.data is set

template = 'form_fields/checkbox_field.html'
class tvb.core.neotraits.forms.Option(id, value, label, checked)

Bases: tuple

checked

Alias for field number 3

id

Alias for field number 0

label

Alias for field number 2

value

Alias for field number 1

class tvb.core.neotraits.forms.SelectField(trait_attribute, name=None, disabled=False, display_none_choice=True, subform=None, display_subform=True, ui_values=None, session_key=None, form_key=None)[source]

Bases: TraitField

missing_value = 'explicit-None-value'
options()[source]

to be used from template, assumes self.data is set

subform_prefix = 'subform_'
template = 'form_fields/radio_field.html'
property value
class tvb.core.neotraits.forms.StrField(trait_attribute: Attr, name: str | None = None, disabled: bool = False)[source]

Bases: TraitField

template = 'form_fields/str_field.html'
class tvb.core.neotraits.forms.TraitDataTypeSelectField(trait_attribute, name=None, conditions=None, draw_dynamic_conditions_buttons=True, has_all_option=False, show_only_all_option=False)[source]

Bases: TraitField

from_trait(trait, f_name)[source]
property get_dynamic_filters
property get_form_filters
missing_value = 'explicit-None-value'
options()[source]
template = 'form_fields/datatype_select_field.html'
class tvb.core.neotraits.forms.TraitField(trait_attribute: Attr, name: str | None = None, disabled: bool = False)[source]

Bases: Field

from_trait(trait, f_name)[source]
class tvb.core.neotraits.forms.TraitUploadField(traited_attribute, required_type, name, disabled=False)[source]

Bases: TraitField

template = 'form_fields/upload_field.html'
class tvb.core.neotraits.forms.UserSessionStrField(trait_attribute: Attr, name: str | None = None, disabled: bool = False, key: str | None = None)[source]

Bases: TraitField

template = 'form_fields/str_field.html'

h5

spatial_model

class tvb.core.neotraits.spatial_model.SpatialModel[source]

Bases: object

abstract static get_equation_information()[source]

uploader_view_model

class tvb.core.neotraits.uploader_view_model.UploaderViewModel(**kwargs)[source]

Bases: ViewModel

Traited class [tvb.core.neotraits.uploader_view_model.UploaderViewModel]

Attributes declared

data_subject : tvb.core.neotraits.uploader_view_model.UploaderViewModel.data_subject = Str(field_type=<class ‘str’>, default=’John Doe’, required=True)

encrypted_aes_keytvb.core.neotraits.uploader_view_model.UploaderViewModel.encrypted_aes_key = Str(field_type=<class ‘str’>, default=None, required=False)

Check our demo notebook on how to produce this key and how we expect your files to be encrypted

operation_group_gid : tvb.core.neotraits.view_model.ViewModel.operation_group_gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=False)

ranges : tvb.core.neotraits.view_model.ViewModel.ranges = Attr(field_type=<class ‘str’>, default=None, required=False)

range_values : tvb.core.neotraits.view_model.ViewModel.range_values = Attr(field_type=<class ‘str’>, default=None, required=False)

is_metric_operation : tvb.core.neotraits.view_model.ViewModel.is_metric_operation = Attr(field_type=<class ‘bool’>, default=False, required=True)

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

REQUIRED_TYPE = None
data_subject
encrypted_aes_key

view_model

class tvb.core.neotraits.view_model.DataTypeGidAttr(linked_datatype, field_type=<class 'uuid.UUID'>, filters=None, default=None, doc='', label='', required=True, final=False, choices=None)[source]

Bases: Attr

Keep a GID but also link the type of DataType it should point to

class tvb.core.neotraits.view_model.EquationAttr(field_type: type, default: Any | None = None, doc: str = '', label: str = '', required: bool = True, final: bool = False, choices: tuple | None = None)[source]

Bases: Attr

# TODO: there are places where we need eq params as a nested form. Figure out a proper model

class tvb.core.neotraits.view_model.Str(field_type=<class 'str'>, default=None, doc='', label='', required=True, final=False, choices=None)[source]

Bases: Attr

class tvb.core.neotraits.view_model.ViewModel(**kwargs)[source]

Bases: HasTraits

Traited class [tvb.core.neotraits.view_model.ViewModel]

Attributes declared

operation_group_gid : tvb.core.neotraits.view_model.ViewModel.operation_group_gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=False)

ranges : tvb.core.neotraits.view_model.ViewModel.ranges = Attr(field_type=<class ‘str’>, default=None, required=False)

range_values : tvb.core.neotraits.view_model.ViewModel.range_values = Attr(field_type=<class ‘str’>, default=None, required=False)

is_metric_operation : tvb.core.neotraits.view_model.ViewModel.is_metric_operation = Attr(field_type=<class ‘bool’>, default=False, required=True)

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

is_metric_operation

An Attr declares the following about the attribute it describes: * the type * a default value shared by all instances * if the value might be missing * documentation It will resolve to attributes on the instance.

linked_has_traits()[source]
operation_group_gid

An Attr declares the following about the attribute it describes: * the type * a default value shared by all instances * if the value might be missing * documentation It will resolve to attributes on the instance.

range_values

An Attr declares the following about the attribute it describes: * the type * a default value shared by all instances * if the value might be missing * documentation It will resolve to attributes on the instance.

ranges

An Attr declares the following about the attribute it describes: * the type * a default value shared by all instances * if the value might be missing * documentation It will resolve to attributes on the instance.

tvb.core.neotraits.view_model.replace_nan_values(input_data)[source]

Replace NAN values with a given values