Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tvb_scripts/datatypes/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from copy import deepcopy
from tvb_scripts.utils.log_error_utils import warning

from tvb.basic.neotraits.api import HasTraits

from tvb_scripts.utils.data_structures_utils import labels_to_inds
from tvb.basic.neotraits.api import HasTraits, Attr
from tvb_scripts.utils.log_error_utils import warning


class BaseModel(HasTraits):
Expand Down Expand Up @@ -40,4 +42,3 @@ def from_tvb_file(cls, filepath, **kwargs):
@staticmethod
def labels2inds(all_labels, labels):
return labels_to_inds(all_labels, labels)

5 changes: 3 additions & 2 deletions tvb_scripts/datatypes/connectivity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# coding=utf-8

from tvb_scripts.datatypes.base import BaseModel
from tvb.datatypes.connectivity import Connectivity as TVBConnectivity

from tvb_scripts.datatypes.base import BaseModel


class ConnectivityH5Field(object):
WEIGHTS = "weights"
Expand Down Expand Up @@ -30,4 +31,4 @@ def centers(self):

# A usefull method for addressing subsets of the connectome by label:
def get_regions_inds_by_labels(self, labels):
return self.labels2inds(self.region_labels, labels)
return self.labels2inds(self.region_labels, labels)
16 changes: 8 additions & 8 deletions tvb_scripts/datatypes/head.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# coding=utf-8

from six import string_types
from collections import OrderedDict

from tvb_scripts.utils.log_error_utils import initialize_logger, raise_value_error, warning
from tvb_scripts.utils.data_structures_utils import isequal_string, is_integer
from tvb_scripts.datatypes.connectivity import Connectivity
from tvb_scripts.datatypes.sensors import SensorTypes, SensorTypesNames, SensorTypesToProjectionDict

from tvb.datatypes.surfaces import CorticalSurface
from six import string_types
from tvb.datatypes.cortex import Cortex
from tvb.datatypes.sensors import Sensors
from tvb.datatypes.projections import ProjectionMatrix
from tvb.datatypes.sensors import Sensors
from tvb.datatypes.surfaces import CorticalSurface

from tvb_scripts.datatypes.connectivity import Connectivity
from tvb_scripts.datatypes.sensors import SensorTypes, SensorTypesNames, SensorTypesToProjectionDict
from tvb_scripts.utils.data_structures_utils import isequal_string, is_integer
from tvb_scripts.utils.log_error_utils import initialize_logger, raise_value_error, warning


class Head(object):
Expand Down
28 changes: 13 additions & 15 deletions tvb_scripts/datatypes/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
from enum import Enum

import numpy as np

from tvb_scripts.utils.log_error_utils import warning
from tvb_scripts.utils.data_structures_utils import ensure_list, \
labels_to_inds, monopolar_to_bipolar, split_string_text_numbers
from tvb_scripts.datatypes.base import BaseModel

from tvb.basic.neotraits.api import Attr, NArray
from tvb.datatypes.projections import \
ProjectionSurfaceEEG, ProjectionSurfaceMEG, ProjectionSurfaceSEEG
from tvb.datatypes.sensors import EEG_POLYMORPHIC_IDENTITY, MEG_POLYMORPHIC_IDENTITY, \
INTERNAL_POLYMORPHIC_IDENTITY
from tvb.datatypes.sensors import Sensors as TVBSensors
from tvb.datatypes.sensors import SensorsEEG as TVBSensorsEEG
from tvb.datatypes.sensors import SensorsMEG as TVBSensorsMEG
from tvb.datatypes.sensors import SensorsInternal as TVBSensorsInternal
from tvb.datatypes.sensors import EEG_POLYMORPHIC_IDENTITY, MEG_POLYMORPHIC_IDENTITY, \
INTERNAL_POLYMORPHIC_IDENTITY
from tvb.datatypes.projections import \
ProjectionSurfaceEEG, ProjectionSurfaceMEG, ProjectionSurfaceSEEG
from tvb.datatypes.sensors import SensorsMEG as TVBSensorsMEG

from tvb_scripts.datatypes.base import BaseModel
from tvb_scripts.utils.data_structures_utils import ensure_list, \
labels_to_inds, monopolar_to_bipolar, split_string_text_numbers
from tvb_scripts.utils.log_error_utils import warning


class SensorTypes(Enum):
Expand All @@ -28,7 +27,6 @@ class SensorTypes(Enum):

SensorTypesNames = [getattr(SensorTypes, stype).value for stype in SensorTypes.__members__]


SensorTypesToProjectionDict = {"EEG": ProjectionSurfaceEEG,
"MEG": ProjectionSurfaceMEG,
"SEEG": ProjectionSurfaceSEEG,
Expand All @@ -51,8 +49,8 @@ class Sensors(TVBSensors, BaseModel):

def configure(self, remove_leading_zeros_from_labels=False):
if len(self.labels) > 0:
if remove_leading_zeros_from_labels:
self.remove_leading_zeros_from_labels()
if remove_leading_zeros_from_labels:
self.remove_leading_zeros_from_labels()
self.configure()

def sensor_label_to_index(self, labels):
Expand Down Expand Up @@ -86,7 +84,7 @@ def get_bipolar_sensors(self, sensors_inds=None):


class SensorsEEG(Sensors, TVBSensorsEEG):
pass
pass


class SensorsMEG(Sensors, TVBSensorsMEG):
Expand Down
19 changes: 9 additions & 10 deletions tvb_scripts/datatypes/surface.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# coding=utf-8

import numpy as np

from tvb_scripts.datatypes.base import BaseModel
from tvb.basic.neotraits.api import NArray, Attr
from tvb.datatypes.surfaces import Surface as TVBSurface
from tvb.datatypes.surfaces import WhiteMatterSurface as TVBWhiteMatterSurface
from tvb.datatypes.surfaces import CorticalSurface as TVBCorticalSurface
from tvb.datatypes.surfaces import SkinAir as TVBSkinAir
from tvb.datatypes.surfaces import BrainSkull as TVBBrainSkull
from tvb.datatypes.surfaces import SkullSkin as TVBSkullSkin
from tvb.datatypes.surfaces import CorticalSurface as TVBCorticalSurface
from tvb.datatypes.surfaces import EEGCap as TVBEEGCap
from tvb.datatypes.surfaces import FaceSurface as TVBFaceSurface
from tvb.datatypes.surfaces import SkinAir as TVBSkinAir
from tvb.datatypes.surfaces import SkullSkin as TVBSkullSkin
from tvb.datatypes.surfaces import Surface as TVBSurface
from tvb.datatypes.surfaces import WhiteMatterSurface as TVBWhiteMatterSurface

from tvb_scripts.datatypes.base import BaseModel


class SurfaceH5Field(object):
Expand All @@ -23,7 +23,6 @@ class SurfaceH5Field(object):


class Surface(TVBSurface, BaseModel):

vox2ras = NArray(
dtype=np.float,
label="vox2ras", default=None, required=False,
Expand Down Expand Up @@ -52,9 +51,9 @@ def get_vertex_areas(self):
return vertex_areas

def add_vertices_and_triangles(self, new_vertices, new_triangles,
new_vertex_normals=np.array([]), new_triangle_normals=np.array([])):
new_vertex_normals=np.array([]), new_triangle_normals=np.array([])):
self.triangles = np.array(self.triangles.tolist() +
(new_triangles + self.number_of_vertices).tolist())
(new_triangles + self.number_of_vertices).tolist())
self.vertices = np.array(self.vertices.tolist() + new_vertices.tolist())
self.vertex_normals = np.array(self.vertex_normals.tolist() + new_vertex_normals.tolist())
self.triangle_normals = np.array(self.triangle_normals.tolist() + new_triangle_normals.tolist())
Expand Down
26 changes: 13 additions & 13 deletions tvb_scripts/datatypes/time_series.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# -*- coding: utf-8 -*-

from six import string_types
from enum import Enum
from copy import deepcopy
from enum import Enum

import numpy
from tvb_scripts.utils.log_error_utils import initialize_logger, warning
from tvb_scripts.utils.data_structures_utils import ensure_list, is_integer, monopolar_to_bipolar
from six import string_types
from tvb.basic.neotraits.api import List, Attr
from tvb.basic.profile import TvbProfile
from tvb.datatypes.sensors import Sensors, SensorsEEG, SensorsMEG, SensorsInternal
from tvb.datatypes.time_series import TimeSeries as TimeSeriesTVB
from tvb.datatypes.time_series import TimeSeriesRegion as TimeSeriesRegionTVB
from tvb.datatypes.time_series import TimeSeriesEEG as TimeSeriesEEGTVB
from tvb.datatypes.time_series import TimeSeriesMEG as TimeSeriesMEGTVB
from tvb.datatypes.time_series import TimeSeriesRegion as TimeSeriesRegionTVB
from tvb.datatypes.time_series import TimeSeriesSEEG as TimeSeriesSEEGTVB
from tvb.datatypes.time_series import TimeSeriesSurface as TimeSeriesSurfaceTVB
from tvb.datatypes.time_series import TimeSeriesVolume as TimeSeriesVolumeTVB
from tvb.datatypes.sensors import Sensors, SensorsEEG, SensorsMEG, SensorsInternal

from tvb_scripts.utils.data_structures_utils import ensure_list, is_integer, monopolar_to_bipolar
from tvb_scripts.utils.log_error_utils import initialize_logger, warning

TvbProfile.set_profile(TvbProfile.LIBRARY_PROFILE)

Expand Down Expand Up @@ -252,16 +253,16 @@ def slice_data_across_dimension_by_index(self, indices, dimension, **kwargs):
def slice_data_across_dimension_by_label(self, labels, dimension, **kwargs):
dim_index = self.get_dimension_index(dimension)
return self.slice_data_across_dimension_by_index(
self._get_index_of_label(labels,
self.get_dimension_name(dim_index)),
dim_index, **kwargs)
self._get_index_of_label(labels,
self.get_dimension_name(dim_index)),
dim_index, **kwargs)

def slice_data_across_dimension_by_slice(self, slice_arg, dimension, **kwargs):
dim_index = self.get_dimension_index(dimension)
return self.slice_data_across_dimension_by_index(
self._slice_to_indices(
self._process_slice(slice_arg, dim_index), dim_index),
dim_index, **kwargs)
self._slice_to_indices(
self._process_slice(slice_arg, dim_index), dim_index),
dim_index, **kwargs)

def _index_or_label_or_slice(self, inputs):
inputs = ensure_list(inputs)
Expand Down Expand Up @@ -589,7 +590,6 @@ def SEEGsensor_labels(self):
TimeSeriesMEG.__name__: TimeSeriesMEG,
TimeSeriesSEEG.__name__: TimeSeriesSEEG}


if __name__ == "__main__":
kwargs = {"data": numpy.ones((4, 2, 10, 1)), "start_time": 0.0,
"labels_dimensions": {LABELS_ORDERING[1]: ["x", "y"]}}
Expand Down
14 changes: 8 additions & 6 deletions tvb_scripts/datatypes/time_series_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@

"""
from copy import deepcopy
from six import string_types
import xarray as xr

import numpy as np
from tvb.datatypes import sensors, surfaces, volumes, region_mapping, connectivity
import xarray as xr
from six import string_types
from tvb.basic.neotraits.api import HasTraits, Attr, List, narray_summary_info
from tvb.datatypes import sensors, surfaces, volumes, region_mapping, connectivity

from tvb_scripts.datatypes.time_series import TimeSeries as TimeSeriesTVB
from tvb_scripts.utils.data_structures_utils import is_integer

Expand Down Expand Up @@ -358,7 +360,7 @@ def duplicate(self, **kwargs):

def _assert_array_indices(self, slice_tuple):
if is_integer(slice_tuple) or isinstance(slice_tuple, string_types):
return ([slice_tuple], )
return ([slice_tuple],)
else:
if isinstance(slice_tuple, slice):
slice_tuple = (slice_tuple,)
Expand Down Expand Up @@ -547,9 +549,9 @@ def plot_timeseries(self, **kwargs):
outputs.append(self[:, var].plot_timeseries(**kwargs))
return outputs
if np.any([s < 2 for s in self.shape[1:]]):
if self.shape[1] == 1: # only one variable
if self.shape[1] == 1: # only one variable
figname = kwargs.pop("figname", "%s" % (self.title + "Time Series")) + ": " \
+ self.labels_dimensions[self.labels_ordering[1]][0]
+ self.labels_dimensions[self.labels_ordering[1]][0]
kwargs["figname"] = figname
return self.plot_line(**kwargs)
else:
Expand Down
4 changes: 2 additions & 2 deletions tvb_scripts/io/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import numpy as np

from tvb_scripts.datatypes.time_series import TimeSeries, TimeSeriesDimensions
from tvb_scripts.utils.log_error_utils import initialize_logger
from tvb_scripts.utils.data_structures_utils import ensure_string
from tvb_scripts.model.timeseries import Timeseries, TimeseriesDimensions


def read_edf_with_mne(path, exclude_channels):
Expand Down Expand Up @@ -79,5 +79,5 @@ def read_edf_to_Timeseries(path, sensors, rois_selection=None, label_strip_fun=N
data, times, rois, rois_inds, rois_lbls = \
read_edf(path, sensors, rois_selection, label_strip_fun, time_unit)

return Timeseries(data, time=times, labels_dimensions={TimeseriesDimensions.SPACE.value: rois_lbls},
return TimeSeries(data, time=times, labels_dimensions={TimeSeriesDimensions.SPACE.value: rois_lbls},
sample_period=np.mean(np.diff(times)), sample_period_unit=time_unit, **kwargs)
6 changes: 4 additions & 2 deletions tvb_scripts/io/h5_reader_base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-

import os

import h5py

from tvb_scripts.utils.log_error_utils import initialize_logger
from tvb_scripts.io.h5_writer import H5Writer
from tvb_scripts.utils.log_error_utils import initialize_logger


class H5ReaderBase(object):
Expand Down Expand Up @@ -33,6 +34,7 @@ def _log_success(self, name, path=None):


class H5GroupHandlers(object):
H5_SUBTYPE_ATTRIBUTE = H5Writer().H5_SUBTYPE_ATTRIBUTE

def read_dictionary_from_group(self, group, type=None):
dictionary = dict()
Expand All @@ -41,6 +43,6 @@ def read_dictionary_from_group(self, group, type=None):
for attr in group.attrs.keys():
dictionary.update({attr: group.attrs[attr]})
if type is None:
type = group.attrs[H5_SUBTYPE_ATTRIBUTE]
type = group.attrs[self.H5_SUBTYPE_ATTRIBUTE]
else:
return dictionary
Loading